From 468aaea5ca70df68b96a846fd3a246f36f18be23 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 14 Nov 2026 23:40:54 +0100 Subject: [PATCH] :paperclip: Compare each key within its shape when naming a difference `oracle/inequivalence` compared a shape's values on their own, so the geometry tolerance of `equivalent?` did not apply and float noise was named as the first difference. Each key is compared within the shape it belongs to. Harness only; the benchmark is not run. Also in this commit: - Replay layout, structure and grid track edits as the UI does. The frontend interpreter set a layout's gap, padding and item alignment and a layout child's margin with a plain shape update, where the sidebar goes through the layout events that reflow the layout; a copy then kept its children where the old gap put them. It dispatches those events now. - Watch the targets of a replayed program in the browser. With `watch`, the browser replay logs the events the store handles and each move of the shapes the program's operations target. AI-assisted-by: claude-opus-5-5 --- .../test_helpers/composable/oracle.cljc | 6 ++- .../composable_tests/interpreter.cljs | 45 ++++++++++++++++--- frontend/test/frontend_tests/wasm_replay.cljs | 33 +++++++++++++- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/common/src/app/common/test_helpers/composable/oracle.cljc b/common/src/app/common/test_helpers/composable/oracle.cljc index 567434b75a..097a9cb6f0 100644 --- a/common/src/app/common/test_helpers/composable/oracle.cljc +++ b/common/src/app/common/test_helpers/composable/oracle.cljc @@ -386,8 +386,10 @@ (let [paired-expected (paired-matrix-effects expected actual) paired-actual (paired-matrix-effects actual expected)] (or (some (fn [k] - (when-not (uc/same-state? (get paired-expected k) (get paired-actual k) 0.01) - {:path (conj path k) :expected (get paired-expected k) :actual (get paired-actual k)})) + ;; each key within the shape, whose geometry takes the tolerance + (let [slice #(select-keys % [k :parent-id :type])] + (when-not (uc/same-state? (slice paired-expected) (slice paired-actual) 0.01) + {:path (conj path k) :expected (get paired-expected k) :actual (get paired-actual k)}))) (keys paired-expected)) {:path path :expected paired-expected :actual paired-actual})) diff --git a/frontend/test/frontend_tests/composable_tests/interpreter.cljs b/frontend/test/frontend_tests/composable_tests/interpreter.cljs index 3fdae3f879..ef114ce0f6 100644 --- a/frontend/test/frontend_tests/composable_tests/interpreter.cljs +++ b/frontend/test/frontend_tests/composable_tests/interpreter.cljs @@ -33,7 +33,10 @@ [app.common.uuid :as uuid] [app.main.data.changes :as dch] [app.main.data.workspace :as dw] + [app.main.data.workspace.bool :as dwb] + [app.main.data.workspace.groups :as dwg] [app.main.data.workspace.libraries :as dwl] + [app.main.data.workspace.path.shapes-to-path :as dwps] [app.main.data.workspace.reflow :as wrf] [app.main.data.workspace.selection :as dws] [app.main.data.workspace.shape-layout :as dwsl] @@ -164,11 +167,11 @@ [(dwsl/update-layout-child [id] (select-keys shape [:layout-item-margin :layout-item-margin-type]))]) - (:layout-item-margin-type :layout-item-align-self - :layout-item-h-sizing :layout-item-v-sizing - :layout-item-min-w :layout-item-max-w - :layout-item-min-h :layout-item-max-h - :layout-item-absolute :layout-item-z-index) + (:layout-item-margin :layout-item-margin-type :layout-item-align-self + :layout-item-h-sizing :layout-item-v-sizing + :layout-item-min-w :layout-item-max-w + :layout-item-min-h :layout-item-max-h + :layout-item-absolute :layout-item-z-index) [(dwsl/update-layout-child [id] {property value})] ;; the layers panel's rename, which renames a main's component too @@ -177,7 +180,8 @@ ;; Container controls use the sidebar transaction and reflow event. (:layout-flex-dir :layout-wrap-type :layout-justify-content - :layout-align-content :layout-gap-type :layout-padding-type :layout-justify-items) + :layout-align-content :layout-gap-type :layout-padding-type :layout-justify-items + :layout-gap :layout-padding :layout-align-items) [(dwsl/update-layout [id] {property value})] [(dwsh/update-shapes #{id} (fn [shape] (n/set-property shape property value)))])) @@ -236,6 +240,35 @@ (n/swap-target-id situation to) (boolean keep-touched?))]) + (instance? n/EditStructure op) + ;; the context menu's group, mask, bool and path actions on the shapes + ;; the operation names + (let [{:keys [action targets params]} op + ids (mapv #(tm/target-shape-id situation %) targets)] + (case action + :group [(dwg/group-shapes nil ids)] + :mask [(dwg/mask-group ids)] + :ungroup [(dwg/ungroup-shapes ids)] + :unmask [(dwg/unmask-group ids)] + :bool [(dwb/create-bool (:bool-type params) :ids ids)] + :path [(dwps/convert-selected-to-path ids)])) + + (instance? n/EditGridTrack op) + ;; the grid editor's track menu, and its merge of the cells of an area + (let [{:keys [target action value]} op + id (tm/target-shape-id situation target) + {:keys [type index track to move-content? row column row-span column-span]} value] + (case action + :add [(dwsl/add-layout-track [id] type track index)] + :remove [(dwsl/remove-layout-track [id] type index)] + :resize [(dwsl/change-layout-track [id] type index track)] + :reorder [(dwsl/reorder-layout-track [id] type index to move-content?)] + :merge (let [cells (->> (vals (:layout-grid-cells (tm/shape-by-id situation id))) + (filter #(and (<= row (:row %) (+ row row-span -1)) + (<= column (:column %) (+ column column-span -1)))) + (mapv :id))] + [(dwsl/merge-cells id cells)]))) + (instance? n/MoveToCell op) ;; the board's new cells, as a canvas drop commits them (let [{:keys [board child row column]} op] diff --git a/frontend/test/frontend_tests/wasm_replay.cljs b/frontend/test/frontend_tests/wasm_replay.cljs index 2c20b51d49..a2a43d5273 100644 --- a/frontend/test/frontend_tests/wasm_replay.cljs +++ b/frontend/test/frontend_tests/wasm_replay.cljs @@ -13,8 +13,9 @@ Query parameters: `programs` names the file or `edn` holds the programs, `start` the first index, `engine=plain` replays with the WASM engine off, - and `debug` logs the targets, the WASM layouts and the shapes each - program ends with." + `debug` logs the targets, the WASM layouts and the shapes each program + ends with, and `watch` logs the events and the moves of the shapes the + operations target." (:require [app.common.test-helpers.composable.comp.nodes :as n] [app.common.test-helpers.composable.core :as tm] @@ -88,6 +89,10 @@ ([id] (kept-text-size id nil)) ([_ _] (ptk/reify ::kept-text-size))) +(def ^:private watched + "The ids of the shapes the replayed operations target." + (atom #{})) + (def ^:private plain-op->events ftm/op->events) (defn- replay-events @@ -97,6 +102,9 @@ headless page does not have, so the edit goes through the SVG editor's commit and the engine lays out what follows." [op situation] + (when (and (query-param "watch") (some? (:target op))) + (when-let [id (try (tm/target-shape-id situation (:target op)) (catch :default _ nil))] + (swap! watched conj id))) (when (and (query-param "debug") (some? (:target op))) (js/console.log "WASM-REPLAY target" (pr-str (type op)) (pr-str (try (tm/target-shape-id situation (:target op)) (catch :default _ nil))))) @@ -192,6 +200,25 @@ :layouts @wasm-layouts})) results)))) +(defn- watch-shape! + "Log the events the store handles and each change of the place of the + shapes the replayed operations target." + [] + (rx/sub! st/stream #(js/console.log "WASM-REPLAY event" (str (ptk/type %)))) + (add-watch st/state ::watch-shape + (fn [_ _ old state] + (let [objects (dsh/lookup-page-objects state) + previous (dsh/lookup-page-objects old)] + (when-not (identical? objects previous) + (doseq [[id shape] objects + :when (contains? @watched id) + :let [before (get previous id)] + :when (not= (:selrect shape) (:selrect before))] + (js/console.log "WASM-REPLAY watch" (:name shape) + (pr-str (select-keys (:selrect before) [:x :y :width :height])) + "->" (pr-str (select-keys (:selrect shape) [:x :y :width :height])) + (pr-str (:touched shape))))))))) + (defn ^:export init "Load the WASM engine on a canvas of the page, then replay the programs." [] @@ -205,6 +232,8 @@ (set! dwwt/resize-wasm-text kept-text-size) (set! dwwt/resize-wasm-text-debounce kept-text-size) (set! dwwt/resize-wasm-text-all kept-text-size))) + (when (query-param "watch") + (watch-shape!)) (.addEventListener js/globalThis "unhandledrejection" #(js/console.log "WASM-REPLAY unhandled" (str (.-reason %)))) (p/let [_ @wasm.api/module