penpot/common/test/common_tests/logic/composable_oracle_test.cljc
alonso.torres a25afbe2d6 🚧 Save Phase 4 random harness and grid fixes in progress
Save Stage 2 structure, text, geometry and layout generation, independent
oracle checks, frontend seeded replay and plugin visible-value checks.
Include pending grid sync and deletion fixes with focused regressions.

WIP validation: component sync 21 tests / 106 assertions; move shapes
6 tests / 33 assertions. Earlier plugin checks passed 68 full cases,
11 unit tests and types. The final generated replay, golden check,
5000-case gate, full suites and live WASM check remain unfinished.
Stages 3 (swaps/variants) and 4 (library files) have not started.

F124 benchmark ratios against Phase 1e: main 10/100/1000 copies
0.48/0.52/0.54; three levels 0.53; chain 0.56; library 0.52;
many shapes 0.42; variant switch 0.64. No regression flag.
The F125 deletion change still needs its final benchmark.

Save the detailed resume checklist and logs in the local stabilization
plan. Keep that workflow document out of the commit.

AI-assisted-by: GPT-6
2026-11-10 20:21:17 +01:00

92 lines
4.8 KiB
Clojure

(ns common-tests.logic.composable-oracle-test
(:require
[app.common.files.changes-builder :as pcb]
[app.common.geom.modifiers :as gm]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.logic.placement :as clp]
[app.common.logic.shapes :as cls]
[app.common.test-helpers.components :as thc]
[app.common.test-helpers.composable.comp.nodes :as n]
[app.common.test-helpers.composable.core :as tm]
[app.common.test-helpers.composable.gen :as cg]
[app.common.test-helpers.composable.oracle :as oracle]
[app.common.test-helpers.composable.shadow :as shadow]
[app.common.test-helpers.compositions :as tho]
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths]
[app.common.types.modifiers :as ctm]
[clojure.test :as t]))
(t/use-fixtures :each thi/test-fixture)
(t/deftest oracle-accepts-layout-owned-fill-sizing
(doseq [layout [:flex :grid]]
(let [file (-> (thf/sample-file :file1)
(tho/add-frame :main-root {:width 100 :height 100})
(tho/add-rect :main-child {:parent-label :main-root :x 20 :y 10
:width 30 :height 20 :constraints-h :scale})
(thc/make-component :component1 :main-root)
(tho/add-frame :layout-parent (merge (case layout :flex cls/initial-flex-layout
:grid cls/initial-grid-layout)
{:width 200 :height 200}))
(thc/instantiate-component :component1 :copy-root :parent-label :layout-parent
:children-labels [:copy-child])
(ths/update-shape :copy-root :layout-item-h-sizing :fill)
(cond-> (= layout :grid)
(tho/place-in-grid-columns :layout-parent 1 {1 :copy-root})))
root (ths/get-shape file :copy-root)
page (thf/current-page file)
tree (gm/set-objects-modifiers {(:id root) {:modifiers (ctm/change-size root 200 nil)}}
(:objects page))
resized (thf/apply-changes
file (cls/generate-update-shapes
(pcb/empty-changes nil (:id page)) (keys tree)
(clp/modifiers-transform tree) (:objects page) {:ignore-touched true}))]
(t/is (nil? (oracle/check (tm/make-situation resized)
{(thi/id :copy-root) {:layout-item-h-sizing {:layout-item-h-sizing :fill}}}))))))
(t/deftest oracle-accepts-measured-auto-height-text
(let [situation (cg/world [2 0 {:text true}])
file (tm/file situation)
page (thf/current-page file)
resized (thf/apply-changes
file (cls/generate-update-shapes
(pcb/empty-changes nil (:id page)) #{(thi/id :copy-child)}
#(gsh/transform-shape % (ctm/change-size % nil 80))
(:objects page) {:ignore-touched true}))]
(t/is (nil? (oracle/check (tm/with-file situation resized) {})))))
(t/deftest oracle-accepts-a-layout-copy-after-main-child-addition
(doseq [layout [:flex :grid]]
(let [result (cg/run {:world [2 0 {:layout layout}]
:ops [[:add-child 0] [:sync 1]]})]
(t/is (= 1 (get-in result [:executed :add-child]))))))
(t/deftest oracle-rejects-unmarked-layout-input-differences
(let [situation (cg/world [2 0 {:layout :flex}])
root ((n/copy-head-of "random-0") situation)
file (-> (tm/file situation)
(ths/update-shape-by-id root :layout-gap {:row-gap 10 :column-gap 10})
(ths/update-shape-by-id root :touched nil))]
(t/is (thrown? #?(:clj Exception :cljs js/Error)
(oracle/check (tm/with-file situation file) {})))))
(t/deftest design-comparison-keeps-relative-positions-under-layout-movement
(let [state (reduce cg/step (cg/initial-state [2 0 {:text true :layout :flex}])
[[:nest 0] [:detach 0]])
situation (:situation (cg/settle-state state))
file (tm/file situation)
page (thf/current-page file)
move (fn [file ids delta]
(thf/apply-changes
file (cls/generate-update-shapes
(pcb/empty-changes nil (:id page)) ids
#(gsh/move % (gpt/point delta 0))
(:objects (thf/current-page file)) {:ignore-touched true})))
moved (move file #{(thi/id :copy-root) (thi/id :copy-child)} 50)
bad (move moved #{(thi/id :copy-child)} 5)]
(t/is (= (oracle/canonical situation) (oracle/canonical (tm/with-file situation moved))))
(t/is (not= (oracle/canonical situation) (oracle/canonical (tm/with-file situation bad))))))