Skip to content

test(db-sync, undo-redo): tests for operator changes the suite let through - #13680

Open
yuxi-liu-wired wants to merge 4 commits into
logseq:masterfrom
yuxi-liu-wired:test/mutation-app-tests
Open

yuxi-liu-wired wants to merge 4 commits into
logseq:masterfrom
yuxi-liu-wired:test/mutation-app-tests

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Tests only. No source changes. Follows #13679, which covers deps/outliner and deps/db the same way.

These tests come from mutation testing: each change of one operator in the source (= to not=, and to or, first to last, when to when-not, true to false and so on) that the existing tests let through. Each new test passes on master and fails on at least one such change. Changes that no test could observe got no test.

What the tests cover

deps/db-sync/test/logseq/db_sync/worker/handler/sync_mutation_test.cljs (logseq.db-sync.worker.handler.sync, the server side of sync):

  • schema setup runs once; pulls and snapshot downloads are blocked while a snapshot upload is in progress
  • snapshot uploads decompress only gzip bodies, and without DecompressionStream reject only gzip; the reset parameter; a non-error "too big" rejection returns 413; the graph is marked uploading until the upload finishes
  • snapshot downloads omit gzip when the env flag is boolean false; the snapshot stream pages by the last row's address; importing an empty snapshot resets, and a stream resets only with its first chunk
  • large transactions: entries of 500 items are applied as large; 1,000 independent maps go in two chunks of 500; updates and retractEntity of an existing block, and cardinality-many retract and add, are chunked independently; groups sharing an item stay in one chunk; the checksum listener is removed; a large :db-migrate entry is applied in one transaction and a small entry as one plain transaction
  • tx batches report only :block/uuid lookups as missing blocks, reject an invalid t-before, and a :fix entry retracting only a missing block is not broadcast
  • sync/pull returns the txs after since and rejects an invalid since; the health route reports ok

src/test/frontend/worker/undo_redo_mutation_test.cljs (frontend.worker.undo-redo):

  • pending editor info goes into the next undo entry, and nil clears it
  • an entry whose newest item is a ui-state still returns its ui-state string on undo and redo after editor info is appended
  • on a synced graph, undo and redo reach the worker history action marked undo and redo
  • an edit records no added or retracted ids; a :db/retractEntity records the retracted entity, an insert the added one

Checks

  • On master (f11f5f8), app test build: logseq.db-sync.worker.handler.sync-mutation-test and frontend.worker.undo-redo-mutation-test 29 tests, 87 assertions, 0 failures, 0 errors.
  • Each test claimed to catch a change was run with that change applied and failed.
  • Lint as in CI: the app (clj-kondo --parallel --lint src, carve, large-vars, ns-docstrings, lang:lint-hardcoded) and deps/db-sync (clj-kondo --lint src test, carve, large-vars).
Which mutants each test catches

Each row: a change of one operator in the source (at the commit the mutation pass ran on) that the existing tests let through and this test fails on.

Test Source In Change Line
ensure-schema-initializes-schema-once-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs ensure-schema! true → false (set! (.-schema-ready self) true)))
health-route-reports-ok-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle true → false (http/json-response :sync/health {:ok true})
sync-pull-is-blocked-while-snapshot-upload-is-in-progress-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs <ready-for-sync? false → true (p/resolved false)
sync-pull-returns-txs-after-since-and-rejects-invalid-since-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-pull if → if-not since (if (some? raw-since) (parse-int raw-since) 0)
sync-pull-returns-txs-after-since-and-rejects-invalid-since-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-pull some? → nil? since (if (some? raw-since) (parse-int raw-since) 0)
sync-pull-returns-txs-after-since-and-rejects-invalid-since-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-pull or → and (if (or (and (some? raw-since) (not (number? since))) (neg? since))
sync-pull-returns-txs-after-since-and-rejects-invalid-since-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-pull some? → nil? (if (or (and (some? raw-since) (not (number? since))) (neg? since))
tx-batch-rejects-invalid-t-before-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-tx-batch! or → and (or (not (number? t-before)) (neg? t-before))
tx-batch-reports-only-block-uuid-lookups-as-missing-blocks-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs block-uuid-lookup-ref and → or (when (and (sequential? entity-id)
tx-batch-fix-retracting-only-a-missing-block-is-not-broadcast-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs sanitize-tx-entry = → not= {:drop-missing-retract-ops? (or (= outliner-op :fix)
large-tx-of-1000-independent-maps-is-applied-in-two-chunks-of-500-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs replaced-value-attrs when → when-not (when (and (vector? item)
large-tx-of-1000-independent-maps-is-applied-in-two-chunks-of-500-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tx-item-group-keys and → or (and (map? item) (tempid? (:db/id item)))
large-tx-of-1000-independent-maps-is-applied-in-two-chunks-of-500-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tx-item-group-keys and → or (and (vector? item)
large-tx-of-1000-independent-maps-is-applied-in-two-chunks-of-500-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs reduce-ordered-tx-chunks > → >= (> next-count large-tx-max-chunk-items))
large-tx-chunks-updates-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tempid? and → or (or (and (integer? value) (neg? value))
large-tx-chunks-updates-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs replaced-value-attrs when → when-not (when (and (vector? item)
large-tx-chunks-updates-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs replaced-value-attrs and → or (when (and (vector? item)
large-tx-chunks-updates-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs replaced-value-attrs = → not= (= :db/retract (first item))
large-tx-chunks-updates-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tx-item-group-keys and → or (and (contains? #{:db/add :db/retract} op)
large-tx-chunks-cardinality-many-retract-and-add-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs cardinality-many-attr? or → and (or (get-in (d/schema db) [attr :db/cardinality])
large-tx-chunks-cardinality-many-retract-and-add-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs replaced-value-attrs and → or (when (and (not (tempid? entity))
large-tx-chunks-cardinality-many-retract-and-add-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tx-item-group-keys and → or (and (contains? #{:db/add :db/retract} op)
large-tx-chunks-retract-entity-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tempid? and → or (or (and (integer? value) (neg? value))
large-tx-chunks-retract-entity-of-an-existing-block-independently-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs tx-item-group-keys and → or (and (vector? item)
large-tx-keeps-groups-sharing-an-item-in-one-chunk-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs merge-ranges <= → < (if (<= start prev-end)
tx-entry-of-500-items-is-applied-as-large-tx-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs reduce-ordered-tx-chunks > → >= (> next-count large-tx-max-chunk-items))
tx-entry-of-500-items-is-applied-as-large-tx-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs large-tx? >= → > (>= (count tx-data) large-tx-min-items))
small-tx-entry-is-applied-as-one-plain-transaction-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs apply-tx-entry! and → or (if (and (not= outliner-op :db-migrate)
large-db-migrate-entry-is-applied-in-one-transaction-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs apply-tx-entry! and → or (if (and (not= outliner-op :db-migrate)
large-tx-removes-its-checksum-listener-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs apply-large-tx-entry! when → when-not (when sql
snapshot-download-omits-gzip-when-env-flag-is-boolean-false-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs snapshot-stream-gzip-enabled? false → true (false? v) false
snapshot-stream-pages-by-the-last-row-addr-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs snapshot-export-stream first → last (vreset! last-addr (first (peek batch)))
import-snapshot-stream-resets-for-an-empty-snapshot-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs import-snapshot-stream! true → false reset? (and @reset-pending? true)]
import-snapshot-stream-resets-for-an-empty-snapshot-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs import-snapshot-stream! or → and (when (or reset? (seq rows))
import-snapshot-stream-resets-only-with-the-first-chunk-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs import-snapshot-stream! and → or reset? (boolean (and @reset-pending? (seq rows)))]
snapshot-upload-decompresses-only-gzip-bodies-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs maybe-decompress-stream if → if-not (if (and (= encoding snapshot-content-encoding) (exists? js/DecompressionStream)
snapshot-upload-decompresses-only-gzip-bodies-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs maybe-decompress-stream and → or (if (and (= encoding snapshot-content-encoding) (exists? js/DecompressionStream)
snapshot-upload-decompresses-only-gzip-bodies-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs maybe-decompress-stream = → not= (if (and (= encoding snapshot-content-encoding) (exists? js/DecompressionStream)
snapshot-upload-decompresses-only-gzip-bodies-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload or → and encoding (or req-encoding "")]
snapshot-upload-decompresses-only-gzip-bodies-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload and → or (if (and (= encoding snapshot-content-encoding)
snapshot-upload-decompresses-only-gzip-bodies-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload not → identity (not (exists? js/DecompressionStream)))
snapshot-upload-without-decompression-stream-rejects-only-gzip-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs maybe-decompress-stream if → if-not (if (and (= encoding snapshot-content-encoding) (exists? js/DecompressionStream)
snapshot-upload-without-decompression-stream-rejects-only-gzip-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload or → and encoding (or req-encoding "")]
snapshot-upload-without-decompression-stream-rejects-only-gzip-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload and → or (if (and (= encoding snapshot-content-encoding)
snapshot-upload-without-decompression-stream-rejects-only-gzip-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload = → not= (if (and (= encoding snapshot-content-encoding)
snapshot-upload-without-decompression-stream-rejects-only-gzip-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload not → identity (not (exists? js/DecompressionStream)))
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs import-snapshot-stream! and → or reset? (boolean (and @reset-pending? (seq rows)))]
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs parse-reset-param if → if-not (if (nil? value)
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs parse-reset-param nil? → some? (if (nil? value)
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs parse-reset-param not → identity (not (contains? #{"false" "0"} value))))
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload when → when-not _ (when reset?
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload false → true (<set-graph-ready-for-use! self graph-id false))
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload when → when-not _ (when finished?
snapshot-upload-reset-param-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload true → false (<set-graph-ready-for-use! self graph-id true))]
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload when → when-not _ (when reset?
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload true → false (storage/set-meta! (.-sql self) snapshot-uploading-meta-key true))
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload when → when-not _ (when reset?
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload false → true (<set-graph-ready-for-use! self graph-id false))
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload when → when-not _ (when finished?
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload false → true (storage/set-meta! (.-sql self) snapshot-uploading-meta-key false))
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload when → when-not _ (when finished?
snapshot-upload-marks-graph-uploading-until-finished-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs handle-sync-snapshot-upload true → false (<set-graph-ready-for-use! self graph-id true))]
snapshot-upload-returns-413-for-a-non-error-too-big-rejection-test deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs sqlite-too-big-error? or → and (let [message (-> (or (ex-message error)
set-pending-editor-info-goes-into-next-entry-test src/main/frontend/worker/undo_redo.cljs set-pending-editor-info! if → if-not (if editor-info
ui-state-entry-with-editor-info-returns-ui-state-str-test src/main/frontend/worker/undo_redo.cljs undo-redo-aux first → last :ui-state-str (second (first op))})
synced-graph-history-action-tx-meta-test src/main/frontend/worker/undo_redo.cljs undo-redo-action-meta not → identity :redo? (not undo?)
added-and-retracted-ids-test src/main/frontend/worker/undo_redo.cljs gen-undo-ops! and → or (fn [id] (and (nil? (d/entity db-after id)) (d/entity db-before id)))
added-and-retracted-ids-test src/main/frontend/worker/undo_redo.cljs gen-undo-ops! nil? → some? (fn [id] (and (nil? (d/entity db-after id)) (d/entity db-before id)))
added-and-retracted-ids-test src/main/frontend/worker/undo_redo.cljs gen-undo-ops! and → or (fn [id] (and (nil? (d/entity db-before id)) (d/entity db-after id)))
added-and-retracted-ids-test src/main/frontend/worker/undo_redo.cljs gen-undo-ops! nil? → some? (fn [id] (and (nil? (d/entity db-before id)) (d/entity db-after id)))

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
@yuxi-liu-wired
yuxi-liu-wired force-pushed the test/mutation-app-tests branch 5 times, most recently from dac7c82 to b45d3ab Compare October 22, 2026 11:01
@yuxi-liu-wired
yuxi-liu-wired force-pushed the test/mutation-app-tests branch 4 times, most recently from 9189521 to b52006c Compare October 29, 2026 11:12
@yuxi-liu-wired
yuxi-liu-wired force-pushed the test/mutation-app-tests branch 2 times, most recently from 234f64d to 98e25ae Compare November 3, 2026 12:00
@yuxi-liu-wired
yuxi-liu-wired force-pushed the test/mutation-app-tests branch 7 times, most recently from 0df95e2 to 1df040b Compare November 18, 2026 14:37
Master now confirms an empty :fix entry (2adc540: a tx-log row and a
new t, so the client's tx id is acknowledged), and its own test covers
that; this test pinned the old behavior.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the test/mutation-app-tests branch from 1df040b to 53c225e Compare November 19, 2026 12:00

This branch has not been deployed

No deployments
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.

1 participant