From 53140935489b3946f983c79e6a5c91e5f8b1d56e Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 15 Nov 2026 10:37:42 +0100 Subject: [PATCH] :paperclip: Replay the programs of a file through the frontend in node With `PENPOT_REPLAY_PROGRAMS` naming an EDN file of programs, a frontend generated test replays each of them and logs its own results, which compares the frontend with the model on many programs without a browser. Without it the test does nothing. Harness only; the benchmark is not run. Also in this commit: - Give the generated text component a measurable size. The generated worlds' text component had a board and a text of a hundredth of a pixel, where turning or moving them left the transform to float noise and the checks reported differences no design shows. The board is 100 by 100 and the text 100 by 20; `add-frame-with-text` sets up its text with the size its child params give. AI-assisted-by: claude-opus-5-5 --- .../common/test_helpers/composable/gen.cljc | 6 +++++- .../app/common/test_helpers/compositions.cljc | 5 ++++- common/src/app/common/test_helpers/texts.cljc | 8 +++++--- .../composable_tests/generated_test.cljs | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index ff11f45fa6..8da997bd8d 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -328,7 +328,11 @@ s)] (cond-> s (:text opts) - (tm/with-file (-> (thtx/add-text-component-with-copy (tm/file s) [[["Hello world"]]]) + ;; a board and a text of a measurable size: the turns and moves + ;; of a hundredth of a pixel are float noise + (tm/with-file (-> (thtx/add-text-component-with-copy (tm/file s) [[["Hello world"]]] + :frame-params {:width 100 :height 100} + :child-params {:width 100 :height 20}) (cond-> (:text-styles opts) (ths/add-sample-typography :generated-typography :font-id "gfont-roboto" :font-family "Roboto" diff --git a/common/src/app/common/test_helpers/compositions.cljc b/common/src/app/common/test_helpers/compositions.cljc index a286c98962..fb75fb3a24 100644 --- a/common/src/app/common/test_helpers/compositions.cljc +++ b/common/src/app/common/test_helpers/compositions.cljc @@ -86,7 +86,10 @@ (defn add-frame-with-text [file frame-label child-label text & {:keys [frame-params child-params]}] - (let [shape (-> (cts/setup-shape {:type :text :x 0 :y 0 :grow-type :auto-width}) + (let [;; the geometry `child-params` gives goes into the setup, which derives + ;; the shape's corners from it + shape (-> (cts/setup-shape (merge {:type :text :x 0 :y 0 :grow-type :auto-width} + (select-keys child-params [:x :y :width :height]))) (update :content txt/change-text text) (assoc :position-data nil :parent-label frame-label))] diff --git a/common/src/app/common/test_helpers/texts.cljc b/common/src/app/common/test_helpers/texts.cljc index 438c6eede4..a43a18644c 100644 --- a/common/src/app/common/test_helpers/texts.cljc +++ b/common/src/app/common/test_helpers/texts.cljc @@ -294,11 +294,13 @@ (defn add-text-component-with-copy "Add the component :component1, whose main :main-root holds the text :main-child written as `text`, and its copy :copy-root, whose text is - :copy-child." - [file text] + :copy-child. `frame-params` and `child-params` add to the main's board + and text, as their size." + [file text & {:keys [frame-params child-params]}] (-> file (tho/add-frame-with-text :main-root :main-child "" - :child-params {:content (content text)}) + :frame-params frame-params + :child-params (merge {:content (content text)} child-params)) (thc/make-component :component1 :main-root) (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))) diff --git a/frontend/test/frontend_tests/composable_tests/generated_test.cljs b/frontend/test/frontend_tests/composable_tests/generated_test.cljs index 408347ba00..f3ffa3945a 100644 --- a/frontend/test/frontend_tests/composable_tests/generated_test.cljs +++ b/frontend/test/frontend_tests/composable_tests/generated_test.cljs @@ -21,6 +21,7 @@ [app.main.repo :as rp] [app.main.store :as st] [beicon.v2.core :as rx] + [cljs.reader :as reader] [cljs.test :as t :include-macros true] [clojure.test.check.generators :as gen] [frontend-tests.composable-tests.interpreter :as ftm] @@ -1122,3 +1123,22 @@ (await (replay {:world [1 0 {:tokens true :variants true :rich-variants false :text false :layout :flex :layout-copies false}] :ops [[:transform 0 10 0 8] [:apply-token 12 11] [:style 12 3 0 1] [:token-value 0 2]]}))) + +(t/deftest ^:async programs-of-a-file-replay-through-the-frontend + ;; the programs of the EDN file `PENPOT_REPLAY_PROGRAMS` names, when it + ;; names one, each replayed and reported on its own + (when-let [path (unchecked-get (.-env js/process) "PENPOT_REPLAY_PROGRAMS")] + (let [programs (try + (reader/read-string (str (.readFileSync (.getBuiltinModule js/process "fs") path))) + (catch :default cause + (js/console.log "REPLAY-FILE unreadable" (ex-message cause)) + []))] + (loop [index 0] + (when (< index (count programs)) + (let [before (:report-counters (t/get-current-env))] + (await (replay (nth programs index))) + (let [after (:report-counters (t/get-current-env))] + (js/console.log "REPLAY-FILE" index + (pr-str (merge-with - (select-keys after [:pass :fail :error]) + (select-keys before [:pass :fail :error])))))) + (recur (inc index)))))))