Skip to content

test(undo): add outliner undo/redo property test - #13461

Merged
tiensonqin merged 8 commits into
logseq:masterfrom
yuxi-liu-wired:test/outliner-undo-property
Sep 30, 2026
Merged

tiensonqin merged 8 commits into
logseq:masterfrom
yuxi-liu-wired:test/outliner-undo-property

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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 :test build), 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

  • After every operation: the entities the operation changed pass the closed DB schema; every live block has a live parent on its page, with no parent cycle and distinct sibling orders; an operation the outliner rejects (throws) left the graph as it was; an operation that changed the graph added an undo entry.
  • Undo, 1 operation at a time from the last: each undo gives back the graph from before that operation, and the checks above hold.
  • Redo, 1 operation at a time: each redo gives back the graph from after that operation, and the checks above hold.
  • After the undos and after the redos: the whole DB passes 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:

Undo/redo violation, seed 20260926.
Smallest failing sequence (rerun it with FUZZ_REPLAY='[[:up-down 0 2 false]]'):
  [[:up-down 0 2 false]]
Signature: undo-mismatch children up-down:cross-parent-down
At operation: [:up-down 0 2 false]
What differs:
  {:node "page 1", :children {:expected ["a" "b" "c"], :actual ["b" "c"]}}
  {:node "b", :children {:expected ["b1" "b2"], :actual ["a" "b1" "b2"]}}

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 16c4ed1a0 falls 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 signature undo-mismatch props delete-page:property also 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-test

FUZZ_N sets the number of sequences, FUZZ_SEED the seed and FUZZ_MAX_OPS the length. FUZZ_KINDS and FUZZ_SKIP_KINDS take comma-separated operation kinds (move,up-down). FUZZ_KNOWN_FILE names a file of more known signatures, 1 per line, with a trailing * matching a prefix. FUZZ_DEBUG traces every step, and FUZZ_REPLAY='[[:up-down 0 2 false]]' runs 1 sequence. With FUZZ_N or FUZZ_SEED set, 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-down in build-strict-inverse-outliner-ops always 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, as db-test/create-conn does 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-report with 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-test and logseq.api.plugin-test land 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 of logseq.api.plugin-test fail with ReferenceError: 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-test cut and deleted a selection under with-redefs without waiting for either. The cut ends with (p/do! cut-p (clear-selection!)), so clear-selection! runs in a later microtask, after with-redefs has 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 under p/with-redefs and waits for them, as frontend.persist-db-test does, with the same 6 assertions. With that change the 2 namespaces pass together in 1 process.

Tests

  • The new namespace: 3 runs, each 1 test with 1 assertion and 0 failures. With FUZZ_SEED set to the default seed, the 3 runs printed the same known signatures with the same sequences.
  • clj-kondo on the 2 changed files: 0 errors, 0 warnings.
  • The whole unit suite over both commits, dealt into processes as bb dev:run-test-namespaces does with 30 batches: at TZ=Etc/GMT+12 2503 tests, 12498 assertions, 0 failures, 0 errors; the time-zone-dependent namespaces at TZ=Pacific/Kiritimati 1470 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.


Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Added logseq/db-test#1309 and #1312 to known-bugs (e8ba3a9). Both were found with this test after the first commit. #1312 (undo of deleting a parent tag leaves its child tags under Root Tag) has the same signature as #1305, undo-mismatch props delete-page:tag, so that pattern is now listed under both and stays known until both are fixed. The default run passes (1 test, 0 failures); clj-kondo on the file reports 0 errors, 0 warnings.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

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 (:logseq.property.class/properties) and the nodes a block's text links to, that is the refs whose uuid the stored title holds; the title alone reads a live link and the same text stored without a ref alike. The :save operation now saves a link as the editor does, with [[uuid]] or ((uuid)) in the title and the linked node in :block/refs. Before, "edit [[alpha]]" was stored as plain text, so no operation made a link. Block e of the initial graph links to the tag Movie, so deleting Movie reaches a link in 1 operation.

Replays, before and after the change:

New known-bugs entries, each replayed: #1302 undo-mismatch props delete:* (a node property value pointing at a deleted block; open fix #13457); #1310 undo-mismatch children+refs+title delete-page:* (a property and a plain page lose their links the same way) and, together with #1305, undo-mismatch children+props+refs+tags+title delete-page:tag; #1311 undo-mismatch tag-props delete-page:property and, together with #1309, undo-mismatch props+tag-props delete-page:property. FUZZ_IGNORE_KNOWN=1 drops the list, and a FUZZ_KNOWN_FILE line * makes a run list every signature it meets.

It also found 2 bugs, filed separately in logseq/db-test and not listed yet: the undo of deleting a block leaves ((uuid)) references to it as plain text, and the undo of deleting a block stores its page links by name ([[Movie]] where the block held [[<uuid>]]). A run with FUZZ_N meets them as undo-mismatch children+refs+title delete:* and undo-mismatch refs delete:*.

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.

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.
@tiensonqin
tiensonqin force-pushed the test/outliner-undo-property branch from 9277ed6 to cab277b Compare September 30, 2026 09:01
@tiensonqin
tiensonqin merged commit 92a9262 into logseq:master Sep 30, 2026
10 checks passed
@yuxi-liu-wired
yuxi-liu-wired deleted the test/outliner-undo-property branch September 30, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants