From 3e6c98c01aa74e2789663868df114f365d7f395a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 7 Nov 2026 18:37:51 +0100 Subject: [PATCH] :sparkles: Generate and check random component histories The Phase 4 bug hunt: random component programs, an independent model of what they should leave, and the regression programs of what they found. The production fixes they found are the commits before this one, each with its regression programs; this commit holds the test harness, the rest of the tests and the memories they grew with. A regression program that needs the harness runs once this commit is in. - Generation (composable gen): worlds of components, nested copies, variants, libraries (stale and dependent), flex and grid layouts and texts; operations for structure, geometry, styles, texts, layout items, grid tracks and cells, swaps, variant switches, update main, reset, detach, library edits and syncs, undo and redo; shrinking, coverage accounting per operation kind, and PENPOT_GEN_SEED, PENPOT_GEN_NUM and PENPOT_GEN_HISTORIES to choose the seed, the number of programs and their length. - The oracle: invariants on touched groups, overrides, refs, settled versus full sync, design snapshots and the model values, with its own model of authored intent (shadow, geometry, grid and variant rules) instead of production's results. - The frontend replays generated programs through the workspace events and the completion contract, with undo and redo checks. - The oracle unit tests, the test runners' registrations, the golden masters recorded again where a fix changed them, and the memories of the component sync contract and its tests. Harness only; the benchmark is not run. Also in this commit: - Adapt develop's variant set and reload tests to this branch. Develop's tests of transforming a component into a variant set call the event with the set's id and expect the defining commit to hold only the main. Here the transform builds the whole set, its second member included, in one commit: transform-in-variant takes an optional variant id, and the tests expect both members in that commit. - Restore the requires and test wiring the rebase merges dropped. - Generate variant property edits and added variants. The random programs switched between the members of a variant set but never changed the set. AI-assisted-by: claude-opus-5-5 --- .../memories/common/changes-architecture.md | 35 +- .../memories/common/component-data-model.md | 46 +- .../common/component-swap-pipeline.md | 20 +- .../common/component-sync-contract.md | 52 +- .../memories/common/geometry-invariants.md | 10 +- .../memories/common/layout-grid-subtleties.md | 9 +- .serena/memories/common/testing.md | 127 ++ .../frontend/composable-component-tests.md | 63 +- .../workspace-state-persistence-subtleties.md | 34 +- .../workspace-transform-subtleties.md | 12 +- .../test_helpers/composable/comp/cases.cljc | 8 +- .../test_helpers/composable/comp/files.cljc | 298 +++ .../test_helpers/composable/comp/nodes.cljc | 420 +++- .../test_helpers/composable/comp/runner.cljc | 117 +- .../composable/comp/undo_check.cljc | 71 +- .../common/test_helpers/composable/core.cljc | 2 +- .../common/test_helpers/composable/gen.cljc | 1330 ++++++++++++ .../test_helpers/composable/geometry.cljc | 154 ++ .../common/test_helpers/composable/grid.cljc | 202 ++ .../test_helpers/composable/oracle.cljc | 736 +++++++ .../test_helpers/composable/shadow.cljc | 765 +++++++ .../test_helpers/composable/variants.cljc | 185 ++ .../app/common/test_helpers/normalize.cljc | 4 +- common/src/app/common/test_helpers/texts.cljc | 26 +- .../logic/comp_expected_geometry_test.cljc | 76 + .../common_tests/logic/comp_sync_test.cljc | 37 +- .../logic/composable_gen_test.cljc | 1844 ++++++++++++++++- .../logic/composable_oracle_test.cljc | 329 ++- .../logic/composable_runner_test.cljc | 38 +- .../test/common_tests/logic/golden_master.edn | 44 +- .../common_tests/logic/source_gen_test.cljc | 148 ++ .../logic/text_notation_test.cljc | 68 + .../logic/text_override_rule_test.cljc | 25 + common/test/common_tests/runner.cljc | 6 + .../app/main/data/workspace/libraries.cljs | 1 + .../src/app/main/data/workspace/variants.cljs | 38 +- .../completion_contract_test.cljs | 155 +- .../composable_tests/generated_test.cljs | 873 +++++++- .../composable_tests/golden_master.edn | 56 +- .../composable_tests/grid_layout_test.cljs | 127 ++ .../composable_tests/interpreter.cljs | 277 ++- .../data/workspace_font_variants_test.cljs | 7 +- .../data/workspace_undo_test.cljs | 12 +- .../data/workspace_variants_test.cljs | 24 +- .../logic/comp_watcher_test.cljs | 2 + .../frontend_tests/plugins/library_test.cljs | 4 +- frontend/test/frontend_tests/runner.cljs | 4 +- 47 files changed, 8529 insertions(+), 392 deletions(-) create mode 100644 common/src/app/common/test_helpers/composable/comp/files.cljc create mode 100644 common/src/app/common/test_helpers/composable/gen.cljc create mode 100644 common/src/app/common/test_helpers/composable/geometry.cljc create mode 100644 common/src/app/common/test_helpers/composable/grid.cljc create mode 100644 common/src/app/common/test_helpers/composable/oracle.cljc create mode 100644 common/src/app/common/test_helpers/composable/shadow.cljc create mode 100644 common/src/app/common/test_helpers/composable/variants.cljc diff --git a/.serena/memories/common/changes-architecture.md b/.serena/memories/common/changes-architecture.md index 82da7bb71e..d08395a620 100644 --- a/.serena/memories/common/changes-architecture.md +++ b/.serena/memories/common/changes-architecture.md @@ -36,4 +36,37 @@ For component touched semantics and sync groups, read `mem:common/component-data ## Inspection -To inspect what a UI action emitted, use `mem:frontend/cljs-repl` with the snippets in `mem:common/component-debugging-recipes` rather than adding temporary source instrumentation. \ No newline at end of file +To inspect what a UI action emitted, use `mem:frontend/cljs-repl` with the snippets in `mem:common/component-debugging-recipes` rather than adding temporary source instrumentation. + +- Structural add/remove and change-parent inverses restore the copy parent's + `:remote-synced` as well as `:touched`. Removing or adding a child clears + the former even when touched groups do not change; restoring only the + groups loses prior state on undo (F157). + +- Undo of bulk removals moves restored siblings in original sibling order. + Component sync records each removal's current index from builder objects; + indexes in the original container become stale after earlier removals. + When the builder lacks a main's container (inverse sync), use that main + container's original index. Both rules preserve order after several + siblings disappear (F158). + +- A move inverse can restore component nesting that existed before the + move, even when the normal component-loop check would reject creating + it now (F177). `change-parent` records `:restore-component-nesting` on + the inverse only when the original position already repeats a component. + The change applier still rejects object-tree cycles and copy-structure + edits. Normal forward moves keep the component-loop guard. + +Normal duplication checks the component nesting guard too (F181). A finite +repeated component tree can use a swapped child to cut recursion; adding +another child in its main can open an expanding branch. cld/allow-duplicate? +combines copy-structure and nesting guards for normal frontend/pure nodes. +The duplicate builder checks the actual destination after ALT placement; +a duplicate at the page root remains allowed. Undo still restores existing +nesting through its explicit inverse flag, not through a forward bypass. + +Component restoration reports its component id from components-changed +(F183). Its main does not exist in the old page objects, so add/mod-object +detection cannot find it. Restore can rename a variant when its container +has gone; the restored component and its dependents must sync in that same +undo group. diff --git a/.serena/memories/common/component-data-model.md b/.serena/memories/common/component-data-model.md index e7f062df35..5b5317e8ea 100644 --- a/.serena/memories/common/component-data-model.md +++ b/.serena/memories/common/component-data-model.md @@ -30,7 +30,7 @@ Masters are not normally touched through `set-shape-attr`, but touched flags can - A copy sub-head the user SWAPPED to another component keeps `:shape-ref` on the near-main child it replaces (its *position*); `:component-id`/`:component-file` name the component its *content* comes from; the touched group `:swap-group` marks the swap. Its children refer into its own component's main. - So for a swapped head the position shape (`find-ref-shape`, X in the near main) and the content shape (its component's main root) differ. `ctf/find-ref-shape` gives position (parent heads are tried outermost first); code that needs the content of a swapped head goes through the content helper, never through `get-ref-shape` with the head's own component. -- A copy sub-head whose component differs from its near main's component must have `:swap-group`; one that matches must not. +- A copy sub-head whose component differs from its near main's component must have `:swap-group`. An authored swap keeps this group if a later main edit chooses the same component: equal does not mean untouched. Only an explicit swap back clears it. - A head takes a position only through `ctf/take-position` (swap in a copy, keep-touched switch, update-main into a copy, the `:ref-not-in-near-main` repair): it refers to the position, is swapped iff its component differs, and otherwise its descendants are remapped to the position's descendants. Setting `:shape-ref`/`:swap-group` by hand leaves the children referring to the wrong main, which validation does not catch and the next sync turns into delete + re-add. - Copy children are paired to main children by `shape-ref` (`is-main-of?`, seek, not index), swapped or not. `find-near-match` (positional) is only a validator/repair heuristic; validity requires membership of the ref among the near-main parent's children, not index equality (`mem:common/file-change-validation-migration-subtleties`). - Copy child ORDER converges to the main's via the async sync (`moved` branch of `compare-children`); local code must never reorder copy children directly (guards in `:mov-objects`/`:reorder-children`). @@ -40,6 +40,16 @@ Masters are not normally touched through `set-shape-attr`, but touched flags can `make-component-instance` in `app.common.types.container` produces a clean component copy through `update-new-shape`, dissociating attrs such as `:touched`, `:remote-synced`, `:variant-id`, and `:variant-name` on cloned shapes. +With `:main-instance? true` (library absorption), nested copies keep their +`:touched` and `:remote-synced`; they remain copies inside the new main. + +`:content-scale` is an optional positive shape number (absent means 1), +accumulated by scale-content transforms on both renderers. It belongs to +`:geometry-group`, survives clone/serialization, and leaves the data when +the accumulated scale returns to 1. Sync derives styles from the ratio of +the copy's scale to its main's, separately from constraint resizing. +Old files default to 1; historical scale gestures cannot be reconstructed. + `duplicate-component` in `app.common.logic.duplicate` creates a new component master by cloning existing component shapes, setting component metadata, and applying a position delta. It does not have the same clean-copy semantics as `make-component-instance`, so inherited attrs on the source can matter. When a bug depends on touched state, identify which cloning path produced the shape before changing sync logic. @@ -50,4 +60,36 @@ A variant container is a frame with `:is-variant-container true`. Its children a Predicates are broad: `ctk/is-variant?` checks `:variant-id` and applies to both variant master shapes and component rows; `ctk/is-variant-container?` checks the container shape flag. -Moving/dropping a shape into a variant container through the move-to-frame path can auto-convert it into a variant via `generate-make-shapes-variant`, which may duplicate the underlying component. Treat drag/drop into variant containers as a component/variant operation, not a plain reparent. \ No newline at end of file +Moving/dropping a shape into a variant container through the move-to-frame path can auto-convert it into a variant via `generate-make-shapes-variant`, which may duplicate the underlying component. Treat drag/drop into variant containers as a component/variant operation, not a plain reparent. + +- `ctk/remove-swap-group` removes `:touched` when it removes the final group. + New main clones must use the same empty-state representation as + `process-operation :set-touched`; otherwise a later move+undo changes + `:touched #{}` to a missing field and cannot restore the exact state (F156). + +Content ref chains (get-ref-chain-until-target-ref, including touched walks) +take find-content-ref-shape at every link. A swapped intermediate head +follows its own main; collecting its replaced position's content overrides +creates phantom groups in copies of that swap (F165). Position advancement +still uses advance-shape-ref and find-ref-shape. + +A swapped head pushed into a main can become a plain nested copy of its own +component. If the old position supplied rotation or flips that differ from +that component's expected parent placement, the new nested copy needs a +geometry-group override. Otherwise a later sync discards the orientation +that update-main just pushed (F168). The source copy clears its overrides. +Compare against the parent's pushed frame: the inverse sync has already +written its new rotation, while the original container still has the old +one. Using that old frame creates phantom geometry overrides (F172). + +Pushing a swapped subtree into a nested copy can remap it to an ordinary +position with the same component. Content differences against that new +reference become authored overrides on the promoted head and descendants; +otherwise a later full sync discards the values update-main just pushed +(F174). The source copy clears its overrides and follows the new subtree. + +When sync turns a parent, its subtree moves with that turn before the child +walk continues (F179). This includes ordinary and swapped children with +authored geometry. Normalize parent axis directions for the turn: resize +already runs through dimensions and constraints. Refresh the walk from +current builder objects so later direct syncs do not turn stale records. diff --git a/.serena/memories/common/component-swap-pipeline.md b/.serena/memories/common/component-swap-pipeline.md index d2fabb22cd..30ebe26856 100644 --- a/.serena/memories/common/component-swap-pipeline.md +++ b/.serena/memories/common/component-swap-pipeline.md @@ -39,4 +39,22 @@ The generic fallback branch copies from `previous-shape`. It represents the inte `common/src/app/common/test_helpers/compositions.cljc` has `swap-component-in-shape`, which drives `generate-component-swap` plus `generate-keep-touched` with the production `keep-touched?` flag. Use it for focused common tests of variant-switch behavior. -`common/test/common_tests/logic/variants_switch_test.cljc` is the canonical reference suite for swap+touched scenarios. Read nearby tests before adding another case. \ No newline at end of file +`common/test/common_tests/logic/variants_switch_test.cljc` is the canonical reference suite for swap+touched scenarios. Read nearby tests before adding another case. + +## Variant geometry comparison + +Switch carry compares the two mains' geometry with `gsh/close-attrs?`. +The clean target already has the copy's rotation, which can turn 100 into +99.99999999999994. Exact dimension equality drops valid resize overrides +(F160). Fixed layout sizes and composite geometry use the same tolerance; +nongeometry scalar attributes still compare exactly. + +After carrying geometry, the switch syncs its new subtree once from the +updated builder objects. Untouched children must follow a retained root +size through constraints; copying only root attrs leaves them in the old +frame (F162). The direct sync keeps carried groups and child swaps. + +Variant carry must collect groups and match children through deleted near +mains too (F180). Copies keep those values after deletion. Both the content +ref-chain walk and find-shape-ref-child-of include deleted component data; +otherwise a switch loses inherited size, rotation groups and child fills. diff --git a/.serena/memories/common/component-sync-contract.md b/.serena/memories/common/component-sync-contract.md index 7541185de4..35c40e0841 100644 --- a/.serena/memories/common/component-sync-contract.md +++ b/.serena/memories/common/component-sync-contract.md @@ -22,33 +22,50 @@ Intended semantics of copies, `:touched` and component sync. This is the spec: w - Edit on a copy shape (authored): sets the attr's group (text content: `:content-group` + the text groups it changes), clears `:remote-synced`. Descendants moved/resized only because of it stay untouched. - Rename: an explicit rename touches `:name-group` on root or child. Automatic renames (text name following its content) are derived: the editors write the name with `:ignore-touched #{:name}`, and sync gives an untouched copy text the name of its own letters when the main's name is automatic. Untouched names sync from the near main; a touched root name on update-main renames the component. - Edit on a main: no touched change on the main; triggers sync. -- Sync main→copy: every untouched group gets the near main's value (geometry: expected geometry); touched groups keep their values; never sets or clears `:touched`. Main child added → added clean to copies. Main child deleted → copy child removed, overrides or not. Main reorder → copies follow. A swapped sub-head pairs with the main child it replaces (its `:shape-ref`) and takes only that child's placement (position, rotation, flips, constraints, `layout-item-*`); everything else syncs from its own component's main. A main child deleted → its swapped copies go with it. A swap made in the main reaches copies without `:swap-group` and spares those with it. +- Sync main→copy: every untouched group gets the near main's value (geometry: expected geometry); touched groups keep their values; never sets or clears `:touched` during attribute sync. If a main detaches a nested head, its images become ordinary shapes and lose their now-invalid `:swap-group`. Main child added → added clean to copies. Main child deleted → copy child removed, overrides or not. Main reorder → copies follow. A swapped sub-head pairs with the main child it replaces (its `:shape-ref`) and takes only that child's placement (position, rotation, flips, constraints, `layout-item-*`); everything else syncs from its own component's main. A main child deleted → its swapped copies go with it. A swap made in the main reaches copies without `:swap-group` and spares those with it. - Sync cascade is eager: one sync runs to a fixpoint in memory (copies of A, including the A copy in B's main → copies of B → …) and commits once in the triggering op's undo group. The file is never left partly synced. Syncing only the components reported as changed equals a full-file sync. Code: `cll/generate-sync-file-cascade` (first pass as `generate-sync-file-changes`, then `generate-sync-components-cascade` over `cll/changed-components` of each pass); the frontend `sync-file` commits it to the synced file, and a library file's sync then syncs the current file's copies of the library components its cascade changed. - Reset: the selected head's subtree becomes equal to its near main (expected geometry); all its touched groups cleared, `:swap-group` included: a swapped head turns back into the near main's component in place, keeping its id. Nothing outside that subtree changes. -- Update main (from a top copy head): the copy's differing values go to the main; the copy's touched cleared; other copies then sync and keep their own overrides. A swapped child replaces the main child it stands for, and neither keeps `:swap-group`. +- Update main (from a top copy head): the copy's differing values go to the main; the copy's touched cleared; other copies then sync and keep their own overrides. A swapped child replaces the main child it stands for, and neither keeps `:swap-group`. The main's authored groups are unioned with the copy's even on a repeated update; `:remote-synced` records an earlier update and must never clear those groups (F114). - Detach: the subtree loses component links, `:touched`, `:remote-synced`. First-level nested heads stay copies, move one nesting level up and inherit the near main's touched groups, so values their old near main overrode become overrides. A swapped head left with no enclosing copy becomes a plain copy of its own component (`:shape-ref` = its main root, no `:swap-group`). +- Direct content sync of a swapped head leaves its placement attributes and their tokens alone (F216). The enclosing main supplies constraints, fixed-scroll and layout item attributes; syncing either source first must give the same result. +- Reheading a swapped child on detach or clipboard copy retains placement that differs from its own content main as placement overrides (F217). Compare constraints with implicit defaults in the destination context, and fixed-scroll as a boolean; equal placement does not create groups. - Instantiate / nest a copy: the new subtree has no touched groups. +- Relocate into a blocked parent: the move also locks each moved root (`generate-relocate`). A copy root whose blocked value changes gains `:modifiable-group`; predict this from the destination before the move, rather than reading the resulting touched set. - Duplicate a copy: the new subtree keeps the source's values and touched; if its nesting level changes, touched is inherited as in detach. Paste and move out of a copy follow the same rule. -- Swap without keep-touched: the new subtree is clean and keeps `swap-keep-attrs` values; the new head keeps the old shape's id. Inside a copy it keeps the old `:shape-ref` and gets `:swap-group` (none when the new component is the near main's); inside a main it is a plain nested copy. -- Variant switch with keep-touched: an attr is carried from the old copy only when its group is touched and the old and new mains hold the same value for it. Resulting touched = groups of carried attrs (+ `:swap-group` when the head is inside a copy). A value equal to the new main is not carried and not touched. Texts: the same per text group (letters carried only when both mains have the same letters; a style group when both mains agree on it once placed on each other's letters). +- Swap without keep-touched: the new subtree keeps `swap-keep-attrs` values; the new head keeps the old shape's id. A retained rotation or flip that differs from the new component's expected placement becomes a `:geometry-group` override so later sync preserves it, including orientation inherited from the old component. The swap authors that choice. Size-only overrides clear. Orientation inherited from the position source or + the parent stays untouched, including references into deleted mains (F154). Other content overrides clear. Inside a copy it keeps the old `:shape-ref` and gets `:swap-group` (none when the new component is the near main's); inside a main it is a plain nested copy. Swapping back produces a clean copy of the near position, including its content overrides, without authoring new groups (F176). Sync through the enclosing copy that owns the new refs; direct sync from the chosen component skips those indirect refs. +- Variant switch with keep-touched: an attr is carried from the old copy only when its group is touched and the old and new mains hold the same value for it. Resulting touched = groups of carried attrs (+ `:swap-group` when the head is inside a copy). The root also keeps a retained rotation or flip as a geometry override when it differs from the new expected placement, including orientation supplied by the old component (F146, F175). Placement still supplied by an enclosing copy remains inherited when no root geometry override was carried. A value equal to the new main is not carried and not touched. Texts: the same per text group (letters carried only when both mains have the same letters; a style group when both mains agree on it once placed on each other's letters). - Delete component: copies keep their data. The deleted main cannot be edited, so it starts no sync, but changes from components nested in it still pass through: sync updates its stored shapes (`:objects` of the deleted component), its copies, and the components that nest it. Restore brings back an up-to-date main. - Undo/redo: restores the exact prior state, `:touched` and `:remote-synced` included, of the op and the sync it caused together (same undo group, one step). Undo never needs a re-sync. +- Sync skips exactly equal numeric values, including integer/float forms + inside points and selection rectangles (F187). Representation alone must + not create changes or undo entries. This comparison has no tolerance: + a real subpixel difference still syncs. ## Text overrides - A text is letters (with line breaks) and a style per letter, all in `:content`. Its groups: `:text-content-text` (letters and line breaks) and one per style unit: `-family` (family, font id), `-weight` (weight, style, variant id), `-size`, `-line-height`, `-spacing`, `-decoration`, `-case`, `-fills`, `-typography` (typography reference), `-align`, `-direction` (paragraphs), `-valign` (root). Any of them implies `:content-group`. Splitting runs by styling is a style change, never a text override; an override covers the whole text, not single letters. - Touch: compare old and new content. Letters differ -> `:text-content-text`. A style unit is touched when a shared letter changes its value or, if the letters changed, when a value appears that the text did not have (typed letters take a neighbour's style and touch nothing). A token on the copy touches the units of the attributes it sets. - Merge (sync, and switch with the carried units): letters from the copy if overridden, else from the main. Each unit from the copy if overridden, else from the main (the source), placed on the result letters: (1) a source with one value across the text applies to every letter; (2) else letters both texts share (stretches of 3+ equal letters, by a letter diff) take the source's value; (3) else the value of the letter before, across line breaks; letters at the start take the first shared letter after them; with nothing shared, the source's first letter. Paragraph units follow the paragraph of the first shared letter, else the paragraph before. Adjacent runs with equal styles join. -- Typography reference: kept on the result only when every unit the typography sets comes from the same side as the reference; a run that loses it still follows typography updates through its main. +- Typography reference: kept on the result only when every unit the typography sets comes from the same side as the reference; a run that loses it still follows typography updates through its main. Applying a typography explicitly authors its reference and all six style units (family, weight, size, line height, spacing, case), including equal values and reapplication of an inherited asset. This differs from a raw content edit, which touches only changed units. - Family and weight from different sides: sync keeps the weight side's variant id; the frontend then picks the closest variant of the family. - Library color and typography syncs are derived writes: they never touch. ## Geometry ownership - Copy root: position is its own; rotation/flip belong to it only when its `:geometry-group` is touched. Resizing it touches the root only. +- Content scaling is distinct from constraint resize. `:content-scale` + stores the accumulated scale (default 1); expected placement scales + styles by copy/main scale before syncing. Descendants remain untouched; + later main style edits still reach them at that scale. Reset restores + the near main's scale together with its geometry and styles. - Children of a resized or transformed shape: derived (expected geometry), untouched, and still follow later main edits. Code: a transform touches only the shapes the user transformed (`clp/calculate-ignore-tree` takes their ids; the frontend keeps them in `:workspace-modifiers-ids`); sync places the main subtree of a copy shape with its own geometry like that shape before walking its children. - Layout-owned (never touched; sync writes, then reflow): x/y of non-absolute children of flex/grid frames; width/height on axes sized fill, or auto on a layout frame. +- Grid copy cell overrides do not own untouched track lists. Inherit shrinking track counts, move or shorten affected cells, preserve their other metadata, and retain explicit track-list overrides (user decision, F247). Do not retain extra tracks solely to keep out-of-bounds cell coordinates; the existing minimum-track rule for participating children still applies. - Grow-owned (never touched; sync writes, then re-measure on SVG and WASM): width+height of auto-width text, height of auto-height text. Every editor and resize path writes the measured size as derived; on WASM `sync-file` re-measures the auto-grow texts of the current page it wrote (texts on other pages keep the synced size until measured). +- Transform settlement corrects geometry on the existing copy subtree + (F223). Its sync proposal must not pull pending library content, styles + or structure. Path content can carry geometry; text content cannot. - `set-shape-attr`'s `ignore-geometry` does not cover `:width`/`:height`; a derived size write needs `ignore-touched` (transforms get it from the ignore tree). - Repairs are not overrides: `files/repair` writes with `ignore-touched`; only the text repairs set groups, explicitly. @@ -60,3 +77,28 @@ Intended semantics of copies, `:touched` and component sync. This is the spec: w - `{:type :set-touched}` replaces `:touched` wholesale and only on copies (an empty set is dropped). The builders write only it (`pcb/update-shapes` turns a `:touched` change into it); `{:type :set :attr :touched}`, a raw assoc with no copy guard, is still applied for stored changes. - Builders that write to copies must emit the inverse `:set-touched` in undo (as `pcb/update-shapes` does). + +A parent turn settles swapped descendant placement in the transform's +change builder (F182). Its content and position reference can have different +sizes, so rotating the content rigidly can leave its untransformed anchor +different from full sync. Keep the swapped head/children untouched and put +the derived correction in the same undo group. Authored geometry stays. + +Reset drops the root's geometry override from the whole sync context +(F185), including the branch that clones replacement children. Clearing it +only while updating existing shapes can turn a newly added child by the +old override after its parent has already reset. The reset and replacement +children share one undo group and stay stable through later sync. + +Update-main also settles untouched swapped heads carried through a parent +turn in the updated main (F186). A rigid rotation can leave the wrong +anchor when the replaced position and swap content have different sizes. +Apply the main's nonlocal changes to its own file, settle changed placement, +and append those changes to the same inverse-sync group. Keep the source +copy's local changes routed separately, including for linked libraries. + +Detach settles inherited placement for surviving swapped heads whose +position references advance to another frame (F219). A rotated head's old +and new position frames can have different dimensions. Correct the head +and children in detach's own undo group, without pulling content from the +new reference or creating a geometry override. Authored geometry stays. diff --git a/.serena/memories/common/geometry-invariants.md b/.serena/memories/common/geometry-invariants.md index f90475a285..b78034c242 100644 --- a/.serena/memories/common/geometry-invariants.md +++ b/.serena/memories/common/geometry-invariants.md @@ -20,6 +20,14 @@ After a geometric mutation, equivalent fields such as `:y`, `(:y :selrect)`, and - `gsh/transform-shape`: applies a full transform. - `cts/setup-shape`: initializes geometry for new shapes; variant test helpers such as `thv/add-variant-with-child` use it. +## Flip flags through parent placement + +When composing a parent's orientation onto content, compose flip flags from +the source shape and the origin/target parent frames. Matrix decomposition +can set both flags during a large rotation, even when several smaller +rotations authored neither flip (F170). Keep the original nil/false value +when the parent frames do not change that axis's flip. + ## Edits that break the invariant - `(assoc shape :x ...)` or `(assoc shape :y ...)`: updates only one field and leaves `:selrect` / `:points` stale. @@ -45,4 +53,4 @@ Using `(ths/update-shape file label :y 101)` leaves `:selrect.y` stale. Downstre When a copy shape changes geometry through the proper pipeline (`set-shape-attr` via `process-operation :set`), `:touched` gains `:geometry-group` unless ignored. Tests can either drive the production update with `cls/generate-update-shapes`, or inject `(assoc shape :touched #{:geometry-group})` when only touched state matters. -If a test needs both a new position and touched state, move the shape first with geometry-preserving helpers, then inject or assert touched state. \ No newline at end of file +If a test needs both a new position and touched state, move the shape first with geometry-preserving helpers, then inject or assert touched state. diff --git a/.serena/memories/common/layout-grid-subtleties.md b/.serena/memories/common/layout-grid-subtleties.md index 2a48b9d149..845ca64f8b 100644 --- a/.serena/memories/common/layout-grid-subtleties.md +++ b/.serena/memories/common/layout-grid-subtleties.md @@ -5,6 +5,13 @@ - Layout container data and child layout-item data are removed by different helpers. Do not assume clearing a layout frame also clears all child layout metadata. - Layout data can affect both container attrs and immediate child attrs; validate behavior for both sides when changing cleanup or propagation. +## Empty flex layouts + +- No children means no layout lines. Skip stretch-per-line division and + baseline placement when the line count is zero. Both row and column + layouts can become empty after component sync; resizing them must still + return valid layout data (F169). + ## Grid assignment - Grid `assign-cells` ensures at least one column and row, skips absolute-position children, creates non-tracked rows/cols when children exceed tracked cells, and asserts that assigned cells do not overlap. @@ -13,4 +20,4 @@ - The `:reorder-children` change it emits is refused on parents inside component copies unless `allow-altering-copies` (same rule as `:mov-objects`); `pcb/reorder-grid-children` also skips copy grids producer-side. Copy child order is owned by the component sync engine. - Grid deassignment removes cells for shapes that are no longer direct children or have become absolute-positioned. - Auto-positioning is not just sorting: some auto cells are converted to manual when empty/manual/span state would break the auto sequence, then auto single-span items can be compacted. -- `fix-overlaps` is marked dev-only and removes one overlapping cell, preferring empty cells first. Avoid depending on it as normal production repair. \ No newline at end of file +- `fix-overlaps` is marked dev-only and removes one overlapping cell, preferring empty cells first. Avoid depending on it as normal production repair. diff --git a/.serena/memories/common/testing.md b/.serena/memories/common/testing.md index 582275469f..50f23ae201 100644 --- a/.serena/memories/common/testing.md +++ b/.serena/memories/common/testing.md @@ -97,3 +97,130 @@ For geometry-sensitive tests, read `mem:common/geometry-invariants` before posit ## Debugging Use `mem:common/component-debugging-recipes` for shape-tree dumps, undo/change inspection, and temporary live instrumentation recipes. + +## Composable undo comparison + +`comp/undo-check` keeps normalized snapshots exact, including `:touched` and +`:remote-synced`. Comparison permits only absolute floating noise below 1e-10 +inside shape geometry: x/y, width/height, rotation, points, selrect and transform +matrices. Reflow can recompute 0.01 as 0.010000000000005116 after undo (F130). +This tolerance does not apply to opacity, other authored attrs or touched groups. +The regression rejects a 1e-5 height change and a 5e-15 opacity change. + + +## Generated component programs + +`composable/gen` builds seeded EDN programs and resolves targets from current +shape-tree order. Run `common-tests.logic.composable-gen-test`; set +`PENPOT_GEN_NUM` and `PENPOT_GEN_SEED` to replay a count and seed. Before merge, +Phase 4 requires 5000 scenarios per property. `cg/run` accepts the printed +program and an optional expected trace; changed targets or skips fail replay. +Use separate fresh JVMs for concurrent checks: `world` resets the global test +label map, so concurrent futures in one JVM corrupt each other's fixtures. + +The independent shadow tracks authored groups and values; the oracle checks +validation, touched membership, retained values, propagation and geometry. +Settlement also checks partial/full sync equivalence, idempotence and exact +undo/redo snapshots. Library routing in `comp/files` applies both the working +file and auxiliary file changes, then cascades both in the same undo group. + +Stale-library and dependency generation includes source transforms on main +roots/children, letters and all twelve text style units. `:library-text true` +adds a separate source text component without reusing consumer shape IDs. +Source edits keep consumer history separate and copies stale until an +acceptance or command that explicitly refreshes that subtree. Requested +source geometry/text checks use the source editor's before-state and intent; +dropped source edits must fail I9. `common-tests.logic.source-gen-test` +covers the action matrix and independent source/consumer undo histories. + +Backend parity uses `oracle/canonical` and `oracle/equivalent?`: IDs become +file/page/tree paths, flip +nil/false values become booleans, and derived layout/text dimensions and text +run splitting are omitted. Free copy-head placement after leaving a layout is +also omitted: pure execution has no reflow history. Each backend still checks +child offsets and propagation; a changed child offset fails the comparison. +These exclusions do not apply to undo snapshots or authored scalar values. +Swapped-head constraints and layout-item inputs use the position reference; +content inputs use the component's content main. + + +For long generated JVM checks, bound heap growth with -J-Xmx1536m (adjust +only if a run reports a real heap limit failure). Several uncapped JVMs can +fill host RAM and swap and make browser checks time out before tests start. +Keep concurrency low; use fresh processes for test-label isolation. + +Canonical design data keeps unrounded geometry. Matrices are represented +by their effect on local shape bounds, so their tolerance has pixel units +rather than comparing dimensionless coefficients (F153). Undo snapshots +and golden masters keep raw matrices. Use oracle/equivalent? to compare +it: the absolute 0.01 tolerance applies only inside shape geometry. Rounding +first can split two positions 7e-7 px apart across a 0.005 boundary (F150). +Scalar values and touched stay exact. comp/undo-check/same-state? supplies +the shared comparison; its undo default remains 1e-10. + +Measured auto-width/auto-height text compares its oriented first corner, +not the unrotated selrect x/y, which can move as height/width changes +(F220). Canonical comparison and requested geometry both retain that +anchor at the existing 0.01 tolerance. Layout-owned positions remain +derived; fixed text dimensions and raw undo geometry remain checked. + +Swapped-head dimensions use the content main; position, rotation, flips, +constraints and layout-item inputs use the position source (F151). +When sizes differ, expected geometry keeps the position source's +untransformed top-left anchor after resizing. Resizing around a rotated +corner shifts that anchor and creates a false I4 failure (F167). +A detached swapped head that becomes a plain copy loses swap-group without +inheriting its former position's groups. Descendants whose refs do not change +keep their existing shadow groups (F155). + +For free copy-head placement, expected geometry keeps the placement matrix +it applied. Re-decomposing a 0.01px frame can add scale noise that becomes +a .011px error in its larger children (F161). Child geometry, scalar values +and undo comparisons remain checked; this does not widen their tolerance. + +Detach's shadow expresses inherited geometry in the surviving copy's frame +before merging groups (F163). Compute orientation from the source and copy +before detaching, never from the resulting child, whose geometry is checked. + +The switch shadow compares numeric geometry of the two mains with float +tolerance too (F164). A 1e-12 size difference must keep a resize override; +a 1px difference must discard it. Nongeometry values remain exact. + +Expected child placement takes unit axis directions from the parent +matrices. Resize already runs through dimensions and constraints; a +minimum-size clamp can leave residual matrix scale that must not resize +fixed children again (F173). Canonical matrices and undo remain raw. The +fixture still rejects a real100→80px fixed-child height change. + +Update-main's shadow uses the source values and the new near reference to +predict content overrides when a pushed swap becomes an ordinary nested +copy (F174). Read the reference id from the new shape for correspondence, +but never read its resulting values or touched groups to decide what the +user authored. The negative control corrupts both promoted head and child +fills and still predicts the source fills. + +A switch retains orientation supplied by the old component even when the +old copy has no geometry override (F175). Predict this choice from the old +root and the new expected parent placement. A negative control removes the +new root's rotation; the shadow must still expect the old angle. Ordinary +position inheritance after swapping back must sync without creating new +groups (F176); the same shrunk program runs through the pure and async +frontend paths. + +Retained orientation must merge into a geometry group that already carries +size (F178). Its presence does not mean the angle was carried: the two +variant mains can agree on size and disagree on rotation. The control keeps +the expected80px height and90deg angle even if the result loses its angle. + +Duplicate candidates and pure Duplicate nodes use cld/allow-duplicate?, the +normal frontend eligibility guard (F181). Finite repeated component nesting +can still be unsafe to duplicate inside its main; the portable regression +checks refusal, mixed batches and allowed ALT duplication at the page root. +This is an operation precondition, not an oracle exception. + +The switch shadow follows an authored swapped near head to its content +main, using the model's swap group and component identity (F184). Following +the replaced position instead can lose an inherited fill override. Keep +these choices independent of the resulting touched set and values. The +negative control ignores a different fill on the replaced position and +still expects the authored fill if the switch result is corrupted. diff --git a/.serena/memories/frontend/composable-component-tests.md b/.serena/memories/frontend/composable-component-tests.md index a4fb3aba7d..f82e8d8399 100644 --- a/.serena/memories/frontend/composable-component-tests.md +++ b/.serena/memories/frontend/composable-component-tests.md @@ -76,8 +76,8 @@ Layout: real frontend), `comp/sync_test.cljs` (one `t/async` deftest per shared case; registered in `frontend_tests/runner.cljs`). - JVM/JS: `common-tests.logic.composable-sync-test` runs the shared cases through the pure - runner; all except those that need frontend code: N, Z, AI and the rotation case (placement - step), X (pending sync), AJ (reflow), AT, AU, AV, AX (variant action events). + runner; all except those that need frontend code: Z and AI (layout reflow), X (pending sync), AJ (reflow), AT, AU, AV, AX + (variant action events). N and the rotation case also run on the JVM. Judging (both runners): each variant is judged before the next one runs (`r/run-each`, and the interpreter's `check`), while the label map still names its shapes; a variant whose inline @@ -109,15 +109,17 @@ Two pure runners (no store, JVM + CLJS): 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. `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` (their modifiers come from frontend events; the placement step itself is common, `app.common.logic.placement`). Swap and switch nodes use the production + undo); the interpreter sends `dwl/reset-component`. `{:sync? false}` disables sync. + `Rotate` and `ChangeHeight` are shared user operations. Their pure modifiers + use CLJC constraints and `app.common.logic.placement`; the frontend interpreter + still drives the workspace events. `MoveShape` remains frontend-only. 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 + normalized files before it and redo the files 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`: @@ -137,6 +139,11 @@ Two pure runners (no store, JVM + CLJS): workspace undo index (`:undo-index`/`:redo-index` phases): a step must add exactly one undo entry or group. File installs (assembly ops) are its baselines; a skipped optional and an inline `Test` are not. The interpreter empties `:workspace-undo` per variant. Frontend snapshots drop `:position-data` under WASM. + Both runners use `uc/snapshot-files` for the current file and every + auxiliary/library file. File differences prefix signatures with + `[:file