📎 Drop the typography file when a test text clears its typography

A copy text that cleared a library typography in the generated histories
kept the run's typography file reference with no typography, which the
design panel never writes. The oracle then saw a reference the copy could
not own. Restyling the typography of a test text now replaces the file
reference too.

Harness only; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-08 17:00:24 +01:00
parent 1da982bbd7
commit bef82a1a45
3 changed files with 21 additions and 3 deletions

View File

@ -332,8 +332,9 @@
(defn restyle
"Set the run style `k` to `v` on every run of `text`.
Named colors and explicit fills replace each other. Font edits replace
stale raw identities while preserving the other font unit."
Named colors and explicit fills replace each other, a typography replaces
the file of the one before. Font edits replace stale raw identities while
preserving the other font unit."
[text k v]
(update-paragraphs text
(fn [[style runs]]
@ -341,6 +342,7 @@
[letters (cond-> (assoc run-style k v)
(= k :color) (dissoc :fills)
(= k :fills) (dissoc :color)
(= k :typography) (dissoc :typography-ref-file)
(= k :family) (dissoc :font-family :font-id)
(= k :weight) (dissoc :font-weight :font-variant-id)
(= k :italic) (dissoc :font-style :font-variant-id))])

View File

@ -1880,6 +1880,16 @@
(t/is (= 1 (get-in result [:executed :library-sync])))
(t/is (= 1 (count (tm/aux-files (:situation result)))))))
(t/deftest clearing-a-library-typography-in-a-copy-drops-its-reference
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true
:stale-libraries true :layout nil :layout-item-margins false
:grid-square false :library-depth 1 :library true
:rich-variants true :layout-children false :library-text true
:grid-empty false :layout-copies true :text true}]
:ops [[:delete 0 0 0 0] [:delete 10 0 0 0] [:swap 3 0 0 0]
[:library-text-style 0 8 1] [:delete 0 0 0 0] [:library-edit 0 0 0]
[:edit 0 1 1 2] [:library-sync] [:text-style 14 8 0 0]]}))))
(t/deftest random-library-compositions
(let [coverage (atom {})
failure (atom nil)]

View File

@ -135,7 +135,13 @@
(thtx/restyle-paragraphs typed :line-height 2))))
(t/testing "changing another style keeps it"
(t/is (= [[{:line-height 1.6} ["Read" {:family "Roboto" :size 16 :typography :body :color :red}]]]
(thtx/restyle typed :color :red)))))
(thtx/restyle typed :color :red))))
(t/testing "clearing the typography drops the file it comes from"
(let [cleared (-> typed
(thtx/restyle :typography-ref-file (thi/new-id! :library))
(thtx/restyle :typography nil))]
(t/is (not-any? :typography-ref-file
(tree-seq map? :children (thtx/content cleared)))))))
(t/is (= [[{:align "center"} ["Buy now" {:weight 700}]]
[{:align "center"} ["Ends Sunday" {:weight 700}]]]
(thtx/set-letters [[{:align "center"} ["Add " {:weight 700}] ["to cart"]]]