A new branch restores an old paper model layout after undo
Level 3 · node · Reliability · Future replay checkpoints are not invalidated when edit history branches
Scenario
A fictional paper model exhibition editor keeps a history of changes to the model counts on each stand. It supports undo and redo, reconstructing layouts from stored checkpoints and subsequent edits. Entering a new count after undo removes the previous redo path, yet an old layout reappears at certain positions. Trace the state changes across the edit history, checkpoint store, and replay logic.
Requirements
createEditor() starts with an empty layout. setCount(stand, count) appends an edit assigning the count for a stand. Stands are ordinary string identifiers and counts are nonnegative integers. Undo and redo move one position within the history bounds. Appending an edit after undo discards the old future history. checkpoint() saves the layout at the current position, and read() replays edits from the nearest valid checkpoint to the current position and returns an independent layout object. Checkpoints outside the current branch must not affect later reconstruction. Checkpoints in the shared past must remain usable.
Acceptance criteria
- Sequential edits and reads after checkpoints return the correct counts for all stands.
- Undo and redo without new edits restore the original layouts correctly.
- Branching after undo prevents discarded checkpoints from affecting the new layout and leaves no old edits available for redo.
- Repeated branches and new checkpoints preserve consistent layouts and history positions, and modifying a returned layout does not change internal state.