Repository navigation
Adds a test guard that fails when a change of the drawing has no undo step - #3553
Merged
Merged
Conversation
…eight or linetype With nothing selected, the ribbon and the Properties palette set the current value of the drawing and added no undo step. UNDO then kept the new value and took back the step before it. The four functions now call push_undo_snapshot before the change. The lineweight message of the palette calls on_ribbon_lineweight_changed, as the other three palette messages call their functions. Co-Authored-By: Claude
8 cases in the undo sweep: the current layer, colour, lineweight and linetype, from the Properties palette and from the ribbon, with nothing selected. Co-Authored-By: Claude
… step In a test build, update, automation_op and control_request compare each drawing before and after the handler. A drawing that changed with no undo record fails the test, with the name of the message. The 60 names that do this on main are in undo_record_guard_known.txt, with reasons. A release build has no change. Co-Authored-By: Claude
The name rules, the decision rule, a change with and without an undo record, a name of the list, nested handlers and list mode. Co-Authored-By: Claude
travisjhughes
force-pushed
the
undo-record-guard
branch
from
November 23, 2026 23:18
29543fe to
9c5addf
Compare
HakanSeven12
pushed a commit
that referenced
this pull request
Nov 24, 2026
…edit #3553 and #3565 together: the save at close or quit writes the drawing's header, viewports and objects the way any save does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Caxnfk2dNQgRSYSgRP1Nt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change summary
In a test build, each handler now runs under a guard. The guard compares each open drawing before and after the handler. When the drawing changed and no undo step has the change, the test fails and names the message. This makes each of the app's 6,839 tests a test of the rule "a change of the drawing is in an undo step". Nothing changes in a release build.
This is a proposal: the guard is small, but it adds a list file that contributors must know. If you do not want it, close the pull request.
This branch contains the two commits of #3555 (an undo step for the current layer, colour, lineweight and linetype of the palette and the ribbon), because #3555 removes two names from the guard's list. Merge them in either order: after #3555, this pull request shows only the guard; if this one merges first, #3555 has nothing left. #3555 does not need the guard.
What specifically changed
src/app/update/undo_record_guard.rs(new, test builds only). Before a handler it keeps a copy of each tab's document (the entities are shared pointers, so the copy is cheap). After the handler it compares. A change is reported when no undo record was open before or after the handler, the undo and redo stacks have the same length, and the tab's edit revision is the same.#[cfg(all(test, not(target_arch = "wasm32")))]: inupdate(aroundupdate_innerandfinish_all_pending_history), inautomation_opand incontrol_request. The bodies of the last two moved, unchanged, toautomation_op_unguardedandcontrol_request_unguarded, so that the guard has one place after all their returns.src/app/update/undo_record_guard_known.txt(new). The 60 names that change a drawing with no undo step with Records an undo step for a change of the current layer, colour, lineweight or linetype #3555, in groups with a reason: 17 by design (a drawing is made, opened or saved; a live edit that the end of the command completes; a cancelled command; a view correction), 10 with no undo step and known before (a layout becomes current; a typed command or the linetype manager sets the current layer, colour or linetype), 33 not examined (style managers, drawing variables, view and plot settings).Linetype(SetCurrent)), orautomation:<op>orcontrol:<op>. The command is a part of the name, because one message does different work in different commands:CommandEscape during BACTION,ScriptLine TILEMODE,automation:run TILEMODE.OCS_UNDO_GUARD_LIST=<file>. With this variable the guard fails no test and writes each name to the file. A name of the list that is not in the file is no longer necessary.Why
The undo sweep (#3453) found changes with no undo step by a list of commands that somebody wrote: a layout switch, a property change with nothing selected. The guard finds the same class with no list of commands: each handler that a test runs is checked. A new handler that changes the drawing and forgets its undo record fails the first test that runs it, with a message that says what to do.
A measurement before this pull request showed that the class is small today: 62 of the 323 names that change a drawing in the tests made no undo step in their own message on main
32e30c8b3, 17 of them by design and 12 in two known groups. #3555 repairs 2 of those 12. The guard keeps it small.Testing
The guard's own tests (
undo_record_guard_tests.rs, 20 tests): the name rules; the decision rule; a command with an undo step passes; a change in an undo record and a change with a record that is still open are not reported; an added entity, a modified and a removed entity, and a changed header with no record are reported, with the text of the report; the guard fails the test for such a change; a name of the list is not reported; the handler around a listed handler does not report the same change, and a second handler after it still reports its own; a handler that ended leaves no depth and no answer behind; list mode writes the name.The list equals what main gives: a run with
OCS_UNDO_GUARD_LISTgave 60 names on this branch, the same 60 as the file.Fault injection, each fault built and run alone or shown separately:
push_undo_snapshot(i, "LAYER NEW")removed (layer_manager.rs)LayerNew(changed: header, layers)commit_layer_undoremoved fromLayerToggleVisible(dispatch.rs)LayerToggleVisibleLayoutSwitchremoved from the listLayoutSwitchcargo test --workspace --locked --no-fail-faston main32e30c8b3: 7,882 passed on main, 7,902 with this branch (the 20 new tests), 0 failed.cargo check, the wasm32 check and clippy give the same warnings as main; the changed and new files have no new rustfmt drift.Mutation tests (
cargo mutants --in-diff, 105 mutants): 87 caught, 12 not viable, 6 missed. Three tests were added for four of the missed ones (a modified entity, the guard's panic, the depth after a handler); each of the four, applied by hand, now fails one test. The other two are inlist_file(see Not covered).Time: no difference that I can measure. On
81f499f79the app tests took 22.3 s without the guard and 21.7 s to 23.6 s with it (several runs, macOS, Apple Silicon).Not covered
list_file, which readsOCS_UNDO_GUARD_LIST, has no test: a test cannot set the variable for the process and leave the other tests as they are. The logic behind it (checkwith a list file) has one.src/app/update/file/plot.rsalso changes the edit revision, and the guard reads that as a history step.tests/: they use the library withoutcfg(test), so the guard is not in them.OCS_UNDO_GUARD_LISTrun finds it.Impact to Contributors
<name>changed a drawing and made no undo step". The repair is an undo record in the handler (push_undo_snapshotbefore the change). If the change is not an undo step by design, add the name toundo_record_guard_known.txtwith the reason.Co-Authored-By: Claude