From 5224a54cb729d7d18ea9b62e52d05018f7daf228 Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Sun, 27 Sep 2026 18:34:59 +0200 Subject: [PATCH] :construction: WIP Step 12.3, Test cleanup + missing coverage AI-assisted-by: muse-spark, deepseek-flash --- .../frontend_tests/benches/boolean_test.cljs | 15 ++++++++ .../benches/contracts_test.cljs | 37 +++++++++++++++++++ .../render_wasm/serialization_test.cljs | 9 ----- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/frontend/test/frontend_tests/benches/boolean_test.cljs b/frontend/test/frontend_tests/benches/boolean_test.cljs index 8781b137b3..969b3d285e 100644 --- a/frontend/test/frontend_tests/benches/boolean_test.cljs +++ b/frontend/test/frontend_tests/benches/boolean_test.cljs @@ -6,7 +6,10 @@ (ns frontend-tests.benches.boolean-test (:require + [app.common.geom.point :as gpt] + [app.common.geom.shapes.intersect :as gint] [app.common.types.path :as path] + [app.common.types.path.segment :as segm] [app.common.uuid :as uuid] [benches.render-wasm.scenes.builder :as b :include-macros true] [benches.render-wasm.scenes.common :as common] @@ -33,6 +36,18 @@ [(:frame-id (first children)) (:frame-id (second children))])) (t/is (= [0 0 100 100] (helpers/selrect bool))))) +(t/deftest difference-excludes-points-in-removed-overlap + (let [instance (b/scene {:seed 1} + (b/bool {:bool-type :difference} + (b/rect {:x 0 :y 0 :width 100 :height 100}) + (b/rect {:x 50 :y 50 :width 100 :height 100}))) + bool (first (helpers/children-of instance uuid/zero)) + lines (segm/path->lines bool)] + (t/is (true? (gint/is-point-inside-nonzero? (gpt/point 25 25) lines)) + "a point in the kept region stays inside the content") + (t/is (false? (gint/is-point-inside-nonzero? (gpt/point 75 75) lines)) + "a point in the subtracted overlap is excluded from the content"))) + (t/deftest union-derives-canonical-bounds (let [instance (b/scene {:seed 1} (b/bool {:bool-type :union} diff --git a/frontend/test/frontend_tests/benches/contracts_test.cljs b/frontend/test/frontend_tests/benches/contracts_test.cljs index d90b65ed68..3e238710ac 100644 --- a/frontend/test/frontend_tests/benches/contracts_test.cljs +++ b/frontend/test/frontend_tests/benches/contracts_test.cljs @@ -147,6 +147,43 @@ (t/is (= ::cases/invalid-case (:type data))) (t/is (some? (::sm/explain data))))))) +(t/deftest rects-workload-ranges-are-rejected + (let [schema (:params-schema (core/registered-scene :rects)) + good {:count 1000 :width 1920 :height 1080 :min-size 20 :max-size 100}] + (t/is (true? (sm/validate schema good))) + (t/testing "reversed size range" + (t/is (false? (sm/validate schema (assoc good :min-size 100 :max-size 20))))) + (t/testing "non-finite sizes" + (doseq [bad [(assoc good :width js/Infinity) + (assoc good :height js/NaN) + (assoc good :min-size js/Infinity) + (assoc good :max-size js/NaN)]] + (t/is (false? (sm/validate schema bad)) (pr-str bad)))))) + +(t/deftest view-coordinates-are-finite + (let [good {:scale 1 :x 0 :y 0}] + (t/is (true? (sm/validate core/schema:view good))) + (doseq [bad [(assoc good :scale js/Infinity) + (assoc good :x js/NaN) + (assoc good :y js/Infinity) + (assoc good :viewport {:width js/NaN})]] + (t/is (false? (sm/validate core/schema:view bad)) (pr-str bad))))) + +(t/deftest serializable-rejects-json-lossy-values + (t/is (true? (core/serializable? {:id :rects/load :seed 42 :tags ["a" 1]}))) + (t/is (false? (core/serializable? {:v js/NaN}))) + (t/is (false? (core/serializable? {:v js/Infinity}))) + (t/is (false? (core/serializable? {:v js/-Infinity}))) + (t/is (false? (core/serializable? {[1 2] "k"}))) + (t/is (false? (core/serializable? {{:a 1} "k"})))) + +(t/deftest wire-ids-round-trip-through-json + (doseq [id [:rects/load :rects :fresh :render-full]] + (let [encoded (core/encode-id id) + wire (.stringify js/JSON #js {:id encoded}) + through (unchecked-get (.parse js/JSON wire) "id")] + (t/is (= id (core/decode-id through)) (str id))))) + (t/deftest duplicate-scene-id-from-another-namespace-is-rejected (t/is (= ::core/duplicate-scene (:type (failure-data diff --git a/frontend/test/frontend_tests/render_wasm/serialization_test.cljs b/frontend/test/frontend_tests/render_wasm/serialization_test.cljs index b204bc13b6..88fba33b67 100644 --- a/frontend/test/frontend_tests/render_wasm/serialization_test.cljs +++ b/frontend/test/frontend_tests/render_wasm/serialization_test.cljs @@ -92,15 +92,6 @@ path? (conj [:path id (:content shape)]))))) cases)) -(t/deftest tail-cases-flags-are-consistent - (doseq [{:keys [shape tail? svg? path?]} tail-cases] - (t/is (boolean? tail?) "tail? is a boolean") - (t/is (= tail? (boolean (or svg? path?))) "tail? matches the write flags") - (t/is (= svg? (some? (:svg-attrs shape))) "svg? matches the shape") - (t/is (= path? (boolean (and (contains? #{:path :bool} (:type shape)) - (some? (:content shape))))) - "path? matches the shape"))) - (t/deftest needs-shape-tail-matches-spec-table (doseq [{:keys [shape tail?]} tail-cases] (t/is (= tail? (serialize-shape/needs-shape-tail? shape))