Repository navigation
test(undo): add outliner undo/redo property test - #13461
Conversation
There was a problem hiding this comment.
🔍 Devin Review: 2 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
|
Added logseq/db-test#1309 and #1312 to |
|
The test now sees 2 kinds of damage it missed (84f0d59, after 5f6da75, which adds the switch to ignore the known list). The visible graph holds each tag's tag properties ( Replays, before and after the change:
New It also found 2 bugs, filed separately in logseq/db-test and not listed yet: the undo of deleting a block leaves The default run passes (1 test, 0 failures) in 6.1-7.6 s inside the test, against 6.6-7.5 s before (4 runs each, alternated, load average 5). clj-kondo on the file reports 0 errors, 0 warnings. |
ee28872 to
9277ed6
Compare
shortcut-cut-and-delete-close-context-popup-test did not wait for the cut, which clears the selection in a later microtask, after with-redefs has put the real clear-selection! back. In a process that runs logseq.api.plugin-test after it, all 8 plugin tests fail with "document is not defined". Run both calls under p/with-redefs and wait.
Random sequences of outliner, page, tag, property, template, paste and recycle operations run through outliner-op/apply-ops! with the worker's undo history recording. After every operation the changed entities and the block tree are checked; then each operation is undone and redone one at a time, and the graph a user sees must match the graph before and after it. A failure shrinks to the smallest sequence and names what differs. The default run has a fixed seed and takes about 6 s. Bugs master still has are listed by the issue that tracks them, and the fix that lands removes its entry. FUZZ_N and FUZZ_SEED run it longer, FUZZ_REPLAY replays 1 sequence.
Both were found with this test and filed since the first commit. logseq#1312 shares its signature with logseq#1305, so the pattern is listed under both.
The visible graph now holds a tag's tag properties and the nodes a block's text links to, so the test sees logseq/db-test#1311 and logseq#1310. A save of a link sends the linked node in :block/refs, as the editor does; before, "[[alpha]]" was saved as plain text. Block e of the initial graph links to the tag Movie. Known: logseq#1302, logseq#1310 and logseq#1311, and the combined signatures of logseq#1310 with logseq#1305 and of logseq#1311 with logseq#1309.
bb lint:large-vars caps a var at 100 lines; op->plan had grown to 189. It is now 3 plan fns by area (outline, properties, pages) over 1 shared context, dispatched by op kind. Same plans: 120 sequences at seeds 4242 and 777 list the same signatures, counts and shortest sequences before and after.
9277ed6 to
cab277b
Compare
What changes
A new unit test,
frontend.worker.outliner-undo-property-test, checks undo and redo of the worker over random sequences of outliner operations. It is the property-based test that found the bugs fixed in #13444 and #13458 and reported in logseq/db-test#1296 to #1300, #1302 and #1304 to #1306. It runs in the normal unit suite (src/test, the:testbuild), with a fixed seed, in about 6 s.Each sequence starts from the same small graph: page 1 holds a, b (children b1, b2, and b2x under b2), c (tagged Movie). Page 2 holds d and tmpl (tagged Template, child "tmpl child"). A journal holds e. There are 4 user properties (number "rating", text "note", node "related" with many values, text "stage" with choices draft and done) and 2 tags (Topic, and Movie, which extends Topic). A sequence has 1 to 12 operations of 28 kinds, each applied through
outliner-op/apply-ops!, the entry point the app uses, with the worker's undo history recording: insert, delete, move, move up/down, indent/outdent, edit text (with page refs, tags and block refs), tag, untag, set, remove and delete property values (one block or a selection), create property, add choice, add or remove a tag property, set status, create page, create tag, rename page, delete page, restore from and purge the Recycle bin, apply template, paste a copied subtree, change a property's type, delete a choice, change a tag's parent, and set an alias. An operation is data,[kind i j flag], and picks its targets by index among the live entities, so a failing sequence replays exactly and shrinks. A selection of 2 blocks keeps the order it was picked in, as Ctrl/Cmd+click does, so selections can be reversed, nested or not adjacent.What it checks
validate-db."The graph" here is what a user sees: every live page and block, and the built-in tags and properties the operations touch, with its title, tags, ordered children and property values. A value is compared by its content, never by its entity id.
A failure shrinks to the smallest sequence and prints it with a signature naming the check, what differs and the operation shape, the operation it concerns, and the differences by node title. For example:
Known bugs
Bugs that master still has are listed in the test (
known-bugs) by the issue or pull request that tracks them, each with the signatures it produces. A sequence that hits a listed signature counts as a pass, so CI stays green on known bugs and fails on anything else. The rule, also in the namespace docstring: the pull request that fixes a listed bug removes its entry, and the default run must still pass without it; a new failure is a regression or a new bug, to be fixed, or filed and added under its issue.Every signature the test met on master
16c4ed1a0falls under these 7 entries: 2 in the default run, and 27 distinct ones in 600 more sequences at seed 11. The entries are as narrow as the bugs: #1297 needs 2 blocks with different parents, so its entries name only the 2-block shapes, and a regression in moving a single block is still caught. The signatureundo-mismatch props delete-page:propertyalso matches a second bug that I found no report of: after deleting a text property with choices and undoing, the property's own page holds one of the choices as its value. #13458 fixes a bug the test did not meet in these runs (undo of deleting blocks that refer to each other), so it has no entry.Running it longer
The default run is fixed: seed 20260926, 12 sequences of up to 12 operations. Environment variables change it for local fuzzing, for example
LOGSEQ_STABLE_IDENTS=1 FUZZ_N=500 FUZZ_SEED=$RANDOM node static/tests.js -n frontend.worker.outliner-undo-property-testFUZZ_Nsets the number of sequences,FUZZ_SEEDthe seed andFUZZ_MAX_OPSthe length.FUZZ_KINDSandFUZZ_SKIP_KINDStake comma-separated operation kinds (move,up-down).FUZZ_KNOWN_FILEnames a file of more known signatures, 1 per line, with a trailing*matching a prefix.FUZZ_DEBUGtraces every step, andFUZZ_REPLAY='[[:up-down 0 2 false]]'runs 1 sequence. WithFUZZ_NorFUZZ_SEEDset, the test prints its time and the known signatures it hit, each with its shortest sequence, so a run shows which listed bugs it met. A sequence costs about 0.4 s: 600 sequences ran in 248 s.A regression it catches
In a scratch change I reverted the first fix of #13444: the inverse of
:move-blocks-up-downinbuild-strict-inverse-outliner-opsalways took the opposite move ((if true ...)in place of(opposite-move-restores? db-before ids up?)). With the default seed the test failed and shrank to 1 operation, with the output shown above: Ctrl/Cmd+click a, then b1, move down, undo, and a stays inside b. That is bug 1 of #13444. The scratch change was not committed.Time
The test adds about 6 s to the suite: 5.4 s, 5.9 s and 5.4 s in 3 runs, timed inside the test (loading the test build is not included), on a laptop at the lowest CPU priority with other work running. Three things keep it there. The starting graph, blocks included, is built once per process, and each sequence starts from that immutable value with
d/conn-from-db, asdb-test/create-conndoes for the built-in DB. The graph a user sees is computed once per DB value. Every step validates only the entities its transactions changed (validate-tx-reportwith the closed schema), and the whole DB is validated twice per sequence.Second commit: await the cut in the context popup test
Adding a namespace changes which namespaces share a process, because the test runner deals them into batches round robin. With this test added,
frontend.handler.editor-context-popup-testandlogseq.api.plugin-testland in 1 process when the runner makes 18 or 30 batches (a machine with 3 cores, or 5 and more), though not with 24 (4 cores). In that process all 8 async tests oflogseq.api.plugin-testfail withReferenceError: document is not defined. The 2 namespaces alone in 1 process give the same 8 failures on master, and each passes alone.shortcut-cut-and-delete-close-context-popup-testcut and deleted a selection underwith-redefswithout waiting for either. The cut ends with(p/do! cut-p (clear-selection!)), soclear-selection!runs in a later microtask, afterwith-redefshas put the real functions back, and the real one needs a DOM. I did not trace how the error reaches the plugin tests. The test now runs both calls underp/with-redefsand waits for them, asfrontend.persist-db-testdoes, with the same 6 assertions. With that change the 2 namespaces pass together in 1 process.Tests
FUZZ_SEEDset to the default seed, the 3 runs printed the same known signatures with the same sequences.bb dev:run-test-namespacesdoes with 30 batches: atTZ=Etc/GMT+122503 tests, 12498 assertions, 0 failures, 0 errors; the time-zone-dependent namespaces atTZ=Pacific/Kiritimati1470 tests, 9057 assertions, 0 failures, 0 errors. Without the second commit, the same run had the 8 plugin test failures described above and no other failure.Allow edits from maintainers.