From 680b08dcaf7e687cf887d1d8010f56350f665869 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 10 Oct 2026 18:30:55 +0200 Subject: [PATCH] :sparkles: Make composable interpreter steps wait for pending work The composable interpreter treated a step as done after a 60 ms gap with no commits, and treated its 2 s timeout as done too. Slow sync or reflow work could finish after the step, so a case could assert on a half-synced file. Each event step now waits, as the plugin waitForLayoutUpdate does, until every pending work tracked by the reflow registry has drained: the watcher's sync wait, the sync it starts, and layout and text reflow. A step that does not drain within 2 s fails the test and names the work still pending, and the next variant starts with nothing pending. The tests cover an edit with a deliberately slow sync, undo and redo steps that must wait for the watcher's touch-component, translation and derived commits, a sync that never finishes, and a restart of the edit watchers, which must keep the undo entries of an edit the same. Also in this commit: - Keep page-less changes from adding a nil page. Applying a commit locally rebuilds the object indices of every page its changes name. Changes that touch no page, such as :mod-component, name none, and their nil page id was rebuilt too: the file data in the store gained a page under a nil key holding {:objects nil}. Every component touch after an edit to a main added it, and undo never removed it. - Check undo and redo of every step in the composable cases. The composable cases tested undo only where a case asked for it, so a change generator with a wrong inverse, or a step that splits into several undo entries, went unnoticed. - Add operations and cases to the composable component suites. The composable runners could edit, add, remove and move children, swap and switch, but not run the other component operations. - Test component validation, repair and library asset sync. - Add a component sync benchmark with a recorded baseline. The coming refactors and fixes change sync code, and a slowdown must be seen and explained in the commit that causes it. - Tidy the composable suite and make its cases stricter. - Test the component sync paths no test reached. A coverage run found sync paths that no test ran. - Test variant events, token sync and switch overrides. The variant events had almost no frontend tests, and several switch, paste, token and restore paths never ran. - Test the file and container helpers and the library events. The component helpers of types/file and types/container and the library events of the workspace had the lowest coverage left. --- .serena/memories/common/testing.md | 20 + .../frontend/composable-component-tests.md | 130 +- common/dev/bench/component_sync.clj | 313 +++ common/dev/bench/component_sync_baseline.edn | 23 + common/scripts/bench-components | 8 + .../test_helpers/composable/comp/cases.cljc | 1616 ++++++++++++-- .../test_helpers/composable/comp/nodes.cljc | 1882 ++++++++++++----- .../test_helpers/composable/comp/runner.cljc | 278 ++- .../test_helpers/composable/comp/setups.cljc | 343 ++- .../composable/comp/undo_check.cljc | 241 +++ .../common/test_helpers/composable/core.cljc | 431 ++-- .../app/common/test_helpers/compositions.cljc | 30 + .../app/common/test_helpers/normalize.cljc | 70 + .../files/comp_processors_test.cljc | 1 - .../files/repair_components_test.cljc | 365 ++++ .../logic/comp_creation_test.cljc | 54 + .../logic/comp_detach_with_nested_test.cljc | 1 - .../logic/composable_runner_test.cljc | 232 +- .../logic/composable_sync_test.cljc | 100 +- .../logic/library_asset_sync_test.cljc | 147 ++ .../common_tests/logic/text_sync_test.cljc | 48 + .../logic/variants_switch_target_test.cljc | 32 +- .../logic/variants_switch_test.cljc | 156 +- common/test/common_tests/runner.cljc | 8 +- .../common_tests/types/components_test.cljc | 1 - .../common_tests/types/container_test.cljc | 216 ++ common/test/common_tests/types/file_test.cljc | 293 +++ .../composable_tests/comp/sync_test.cljs | 129 +- .../completion_contract_test.cljs | 160 ++ .../composable_tests/interpreter.cljs | 794 ++++--- .../frontend_tests/data/changes_test.cljs | 37 + .../data/workspace_edit_watchers_test.cljs | 41 + .../data/workspace_libraries_test.cljs | 220 ++ .../data/workspace_library_links_test.cljs | 189 ++ .../data/workspace_library_updates_test.cljs | 203 ++ .../data/workspace_sync_barrier_test.cljs | 38 +- .../data/workspace_undo_stack_test.cljs | 75 + .../data/workspace_variants_test.cljs | 214 +- .../logic/copying_and_duplicating_test.cljs | 61 +- frontend/test/frontend_tests/runner.cljs | 18 +- .../src/composable-tests/cases.ts | 6 + .../cases/caseCopySwapSurvivesMainChanges.ts | 84 + .../caseDetachKeepsNestedCopiesLinked.ts | 73 + .../cases/caseRemoteMainCopySyncNested.ts | 18 +- ...eResetOfNestedSwapKeepsTopCopyOverrides.ts | 68 + .../src/composable-tests/model/ShapeProp.ts | 13 + .../operations/OpCreateNestableComponent.ts | 41 +- .../composable-tests/operations/OpDetach.ts | 34 + .../composable-tests/operations/OpReset.ts | 36 + .../src/composable-tests/operations/OpSwap.ts | 40 + .../src/composable-tests/util/Assert.ts | 24 + 51 files changed, 8020 insertions(+), 1635 deletions(-) create mode 100644 common/dev/bench/component_sync.clj create mode 100644 common/dev/bench/component_sync_baseline.edn create mode 100755 common/scripts/bench-components create mode 100644 common/src/app/common/test_helpers/composable/comp/undo_check.cljc create mode 100644 common/src/app/common/test_helpers/normalize.cljc create mode 100644 common/test/common_tests/files/repair_components_test.cljc create mode 100644 common/test/common_tests/logic/library_asset_sync_test.cljc create mode 100644 common/test/common_tests/types/file_test.cljc create mode 100644 frontend/test/frontend_tests/composable_tests/completion_contract_test.cljs create mode 100644 frontend/test/frontend_tests/data/changes_test.cljs create mode 100644 frontend/test/frontend_tests/data/workspace_edit_watchers_test.cljs create mode 100644 frontend/test/frontend_tests/data/workspace_libraries_test.cljs create mode 100644 frontend/test/frontend_tests/data/workspace_library_links_test.cljs create mode 100644 frontend/test/frontend_tests/data/workspace_library_updates_test.cljs create mode 100644 frontend/test/frontend_tests/data/workspace_undo_stack_test.cljs create mode 100644 plugins/apps/composable-test-suite/src/composable-tests/cases/caseCopySwapSurvivesMainChanges.ts create mode 100644 plugins/apps/composable-test-suite/src/composable-tests/cases/caseDetachKeepsNestedCopiesLinked.ts create mode 100644 plugins/apps/composable-test-suite/src/composable-tests/cases/caseResetOfNestedSwapKeepsTopCopyOverrides.ts create mode 100644 plugins/apps/composable-test-suite/src/composable-tests/operations/OpDetach.ts create mode 100644 plugins/apps/composable-test-suite/src/composable-tests/operations/OpReset.ts create mode 100644 plugins/apps/composable-test-suite/src/composable-tests/operations/OpSwap.ts diff --git a/.serena/memories/common/testing.md b/.serena/memories/common/testing.md index b18fa3904b..95d999405c 100644 --- a/.serena/memories/common/testing.md +++ b/.serena/memories/common/testing.md @@ -48,6 +48,26 @@ For shape mutations, prefer production-path helpers such as `cls/generate-update `thf/apply-changes` validates by default and usually gives the most useful invariant failure. Pass `:validate? false` only for intentionally malformed intermediate state. +## Validation and repair tests + +`common-tests.files.repair-components-test` has one test per component error code: break a file with +the helpers (`ths/update-shape`, `thc/update-component`), assert the exact set of codes, then repair +as the backend does (validate + `cfr/repair-file` until valid, at most 10 passes, like +`app.srepl.procs.file-repair`) and assert the result. Repairs that never converge are pinned with +`tm/known-failure`. A deleted component's objects are reached with `ctkl/get-component data id true` +(`thc/get-component` skips deleted ones). + +## Component sync benchmark + +`common/dev/bench/component_sync.clj` times component sync on fixed-size worlds (one main into +10/100/1000 copies, 3 nesting levels, a chain of dependents, a variant switch, a library update). +Each world checks its result (how many rects end red) so it never times a no-op. Run from +`common/`: `scripts/bench-components` compares with `dev/bench/component_sync_baseline.edn` and +exits 1 when a world's lower quantile is more than 10% slower; `scripts/bench-components record` +rewrites the baseline (only on purpose, saying why). It takes about 4 minutes. Every commit that +touches sync, swap or change application runs it and quotes the table in its message. The lower +quantile is compared because the mean moves with background load (devenv watchers) and GC. + ## Geometry setup caution For geometry-sensitive tests, read `mem:common/geometry-invariants` before positioning shapes. Use geometry-preserving helpers or production change helpers rather than direct single-field edits. diff --git a/.serena/memories/frontend/composable-component-tests.md b/.serena/memories/frontend/composable-component-tests.md index 76db2a2cbf..5b891d4448 100644 --- a/.serena/memories/frontend/composable-component-tests.md +++ b/.serena/memories/frontend/composable-component-tests.md @@ -87,28 +87,111 @@ wrapper deftest in BOTH test namespaces (or only the frontend one if it needs fr Two pure runners (no store, JVM + CLJS): - `core/run-variant`/`run-all`: apply nodes only (no sync, `n/undo` throws). For engine tests. - `comp.runner/run-variant`/`run-all`: the case runner. Every comp node declares its kind via - `n/IComponentOperation` (`op-kind`: `:assembly`, `:user`, `:undo`, `:frontend-only`); the + `n/IComponentOperation` (`op-kind`: `:assembly`, `:user`, `:undo`, `:redo`, `:frontend-only`); the runner and the interpreter's `sync-op?` dispatch on it. A NEW node MUST implement it. User ops record their production changes (`n/record-changes`, nil when nothing changed); the runner throws if a `:user` op records nothing or another kind records changes. After a user op the runner syncs to a fixpoint (`ch/components-changed` + `generate-sync-file-changes`, one pass per cascade level, like the frontend watcher) and pushes op + syncs as one undo group. - `n/undo` reverts the latest group, no re-sync. The runner validates the file (against the + `n/undo` (`(n/undo k)` for k groups) reverts the latest group and moves it to a redo stack; `n/redo` applies it again + (interpreter: `dwu/redo`); neither re-syncs. A user op that pushes a group empties the redo + stack; one that changed nothing keeps it. The runner validates the file (against the situation's files) once settled: after the sync fixpoint and after an undo group; never between cascade passes, where an outer copy still points at the component its main dropped (`:component-id-mismatch`), nor with `{:sync? false}`. Assembly ops (create/instantiate/nest/variant - container): no sync, no undo group. `ResetCopyInstance` is a user op here (sync + undo), - unlike the interpreter (file install). `{:sync? false}` disables sync. `Rotate`/`ChangeHeight` + container): no sync, no undo group. `n/reset` (`reset-copy-instance` resets a lineage's latest copy) is a user op (sync + + undo); the interpreter sends `dwl/reset-component`. `{:sync? false}` disables sync. `Rotate`/`ChangeHeight`/`MoveShape` are `:frontend-only` and throw `::runner/frontend-only` (the placement step is frontend code). Swap and switch nodes use the production `clv/generate-component-swap-in-place` (+ `clv/find-switch-target` for switch), the same code the frontend events call. Not modelled: the `:modified-at` bump, and the swap/switch event follow-ups (token propagation, WASM text resize, layout update). Tests: `common-tests.logic.composable-runner-test`. +- Undo/redo round trip (`comp/undo_check.cljc`, alias `uc`), on by default in the pure runner + (`:undo-check?`): after each `:user` step that pushed a group, undo must give back the + normalized file before it and redo the file after it (the variant continues from the redone + file); a user step that pushed nothing must change nothing (`:no-undo-entry`); at the end, + undo back to the last assembly step (the baseline; a case's own undo below it moves it) and + redo all. Files compare through `app.common.test-helpers.normalize` (`thn/normalize-file`: + drops file/component `:modified-at`, optionally `:position-data`; shapes as plain maps). + Failures are recorded in the situation with labelled diffs (labels die with the variant, so + they are resolved when recorded) and a `:signature`, the set of what differs + (`uc/signature`: `[:object