📎 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
This commit is contained in:
alonso.torres 2026-11-15 10:37:42 +01:00
parent 06f5abdce3
commit 5314093548
4 changed files with 34 additions and 5 deletions

View File

@ -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"

View File

@ -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))]

View File

@ -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]})))

View File

@ -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)))))))