Skip to content

Read two lines of one label as one label - #58

Closed
leaf-agent wants to merge 5 commits into
mainfrom
fix/ci-33014379730
Closed

leaf-agent wants to merge 5 commits into
mainfrom
fix/ci-33014379730

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

ceb4214 ("Draw a page's numbers with lf-chart") reddened ci on main: test_example_renders[heat-loss], and the exported copies of heat-loss and gallery, all failed with the same three findings in every scheme and in print.

AssertionError: the copy draws its own words over each other:
['<lf-chart id=heat-weekly> draws "17" in the same place as <lf-chart id=heat-weekly>\'s "Nov"',
 '<lf-chart id=heat-weekly> draws "1" in the same place as <lf-chart id=heat-weekly>\'s "Dec"',
 '<lf-chart id=heat-weekly> draws "5" in the same place as <lf-chart id=heat-weekly>\'s "Jan"']

The three pairs are the three ticks where a month begins. A dated axis names the month there, on a line under the day, and Plot draws that as two tspans of one <text>: <text transform="translate(561.8,299)"><tspan x="0" y="0.71em">5</tspan><tspan x="0" dy="1em">Jan</tspan></text>. Measured in the browser, the two lines step 11.5px apart and each reports a 14px line box, because the box carries the font's own leading and the drawing asked for a dy of exactly 1em. So the boxes overlap by 2.5px, past COVERED_WORDS's 2px of slack, on a drawing where no glyph comes near another. The chart is drawn correctly — overhang already measures the second line and grows the bottom margin for it.

Solution

COVERED_WORDS already skips a pair where one element contains the other, because a paragraph and the <em> inside it are one run of words the flow lays out together. A wrapped paragraph's own lines are the identical shape and never reported either: they are boxes of one text node, which the same-element skip takes. Two lines of one label are two nodes only because SVG spells a line break as an element, so the pass now reads the <text> that draws them and holds out a pair inside one of them, next to the skip it belongs with. Nothing else moves: two separate <text> elements landing on each other is still a finding, which is what CHART_COLLISIONS and the corpus sweeps ask about.

The alternative was to give the axis a tickFormat so no label takes two lines, and it is the worse drawing: one line per tick means the month repeats on every tick or goes missing, and the labels get wider at exactly the width — a phone's column — where they are already close.

Testing

  • tests/test_render_widgets.py::test_the_gate_passes_a_chart_whose_tick_names_its_month_on_a_second_line — new. It asserts the page is carrying a two-line tick at all, pulls a label's second line onto its first so the overlap belongs to the test rather than to whatever leading the axis settles on, runs the gate's own reading (empty), then runs the same reading with the hold defeated by its own predicate, where it has to report; the two existing COVERED_WORDS exemption tests (the float and the collapse) are written this way.
  • uv run pytest tests/test_render_gate.py tests/test_render_export.py tests/test_render_widgets.py — the three failures above are gone.
  • uv run pytest tests on the rebased branch — 587 passed, 6 skipped, nothing red.
  • pre-commit run --files … on both changed files.
The unrelated red this branch was rebased past

Main was also red for a second, later cause while this was in review: cae9ea5 ("Split widget element runtime") moved quoted out of leaf.js, while render_checks.py still called leaf.quoted(el) after import('/leaf.js'), which failed test_smoke.py and five test_example_renders cases with TypeError: leaf.quoted is not a function. Main answered that itself in a5e062d, routing the gate's probes through /runtime/widget-api.js. This branch is rebased onto dbc0065, so its own ci no longer carries that failure and uv run pytest tests is 587 passed, 6 skipped here.


Automated fix for failed run

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gate change reads right and I couldn't fault it: label is read once per run rather than per pair, the null guard keeps HTML pages on the containment skip alone, and neither of the two existing COVERED_WORDS exemption tests replaces a string this new line collides with — both still pass. I ran the new test, the chart cases, and the gate's heat-loss cases here; all green, and reverting render_checks.py to the base makes the new test fail on held, so it isn't vacuous.

One note on the new test's second leg, inline.

Comment thread tests/test_render_widgets.py Resolved
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Still red on main, and now on its own. Run 33016679240 (8a08f53, "Split widget measurement runtime") failed 14 tests, and the three this PR answers are among them — the same heat-weekly findings, verbatim, on test_example_renders[heat-loss] and both test_an_exported_example_stands_on_its_own cases.

The other eleven were the leaf.quoted regression, and main has since answered those itself: a5e062d routes the render-gate probes through /runtime/widget-api.js. So this is the last thing holding ci red. I checked out main at a5e062d and ran the three cases the two causes split into:

test_example_renders[heat-loss]     FAILED   9 COVERED_WORDS findings (light, print, dark)
test_example_renders[postmortem]    passed
test_smoke.py                       passed

The hold this adds is not on main — render_checks.py:1018 still compares only a.el, contains, and the reverse, with no reading of which <text> a run is a line of.

The nine findings, unchanged from the run
[light] <lf-chart id=heat-weekly> draws "17" in the same place as <lf-chart id=heat-weekly>'s "Nov"
[light] <lf-chart id=heat-weekly> draws "1" in the same place as <lf-chart id=heat-weekly>'s "Dec"
[light] <lf-chart id=heat-weekly> draws "5" in the same place as <lf-chart id=heat-weekly>'s "Jan"
[print] … same three
[dark]  … same three

A dated axis names the month where one begins, on a line under the day: the
tick for the first week of December reads 1 over Dec. Those are two tspans of
one SVG <text>, offset by the dy the drawing asked for, and each reports a line
box carrying the font's own leading — a couple of pixels taller than the step
between them. COVERED_WORDS compared them as two elements and called every such
tick a collision, so examples/heat-loss.html failed the render gate and its
export for drawing an ordinary axis, in both schemes and in print.

A wrapped paragraph is the identical shape and was never reported, because its
lines are boxes of one text node and the same-element skip takes them. Two
lines of one label are two nodes only because SVG spells a line break as an
element, so the pass reads the <text> that draws them and holds a pair inside
one of them out, next to the paragraph-and-<em> skip it belongs with.

The new test takes the reading twice, as the float and collapse exemptions do:
once as the gate runs it, and once with the hold defeated, where it has to
report the lines it just passed.
The test's unheld reading borrowed its collision from whatever leading
lf-chart's date axis settles on, so an ordinary change to that drawing
would empty it and fail the test for a reason that has nothing to do with
the exemption it names. Pull a label's second line onto the first before
either reading instead: the hold does not care how far apart a label's
lines are, so held stays empty, and reported has to report whatever the
axis is drawn with.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

One more run under the same three findings, and the branch is verified green against today's main.

Run 33017981619 (4af9466, "Publish factory-owned widget APIs directly") is the same fourteen the comment above describes: eleven leaf.quoted, plus the three heat-weekly findings this PR answers, verbatim.

What is new is the other side of that split. Main is now at dbc0065, two commits past a5e062d, and I re-ran the sweep there rather than at a5e062d: test_render_gate.py over design-decision, gallery, heat-loss, postmortem, release-notes, ship-review gives 11 passed, 1 failed — the failure is heat-loss, with the nine COVERED_WORDS findings unchanged across light, print, and dark. So the leaf.quoted cause has stayed closed for two further commits, and these three remain the only thing red on main.

Then this branch at its current head, a759ef6 — which is rebased onto dbc0065, so nothing to re-base — over test_render_gate.py and test_render_export.py for heat-loss and gallery: 6 passed. That is the six cases the two causes' overlap contained, green on top of today's main rather than the main the branch was first written against. No fix PR opened for this run.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Confirming the comment above from the whole suite rather than three cases: ci on main at a5e062d settled at 3 failed, 1279 passed, 6 skipped (run 33018628548, completed 22:36Z), and the three are test_render_gate.py::test_example_renders[heat-loss] plus both test_an_exported_example_stands_on_its_own cases — the heat-weekly findings this PR answers, and nothing else anywhere in the run.

I was dispatched for run 33017141598 (b1b23c4), which was the same fourteen: these three and the eleven leaf.quoted ones a5e062d closed. So there is nothing further for me to open, and the earlier reading that this is the last thing between main and green now rests on a full-suite result on the commit rather than on targeted cases.

@max-sixty max-sixty closed this Aug 26, 2026
@max-sixty max-sixty reopened this Aug 26, 2026
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Main has moved two commits past what the comments above measured, and one of them rewrites the file this PR changes — so the question is no longer whether these three findings are still red, but whether this is still the fix for them. It is, on both halves.

Run 33018883535 (0736905, "Add table of contents widget and move render helper") is the same three and nothing else: 3 failed, 1281 passed, 6 skipped. I was dispatched for it and am not opening a PR.

Then the part that is new. 268e925 ("Read the layer's facts where they are declared") landed on main after every run named above and touches render_checks.py — 41 lines, all of them in BAKE, none near COVERED_WORDS. Checked out at that commit, test_render_gate.py -k heat-loss still fails with the nine findings across light, print and dark, so main is red on its own head for this and not for anything 268e925 brought. This branch's current head 705b923 already carries the merge of it, and over test_render_gate.py, test_render_export.py and test_render_widgets.py it is 141 passed — the six cases the two causes overlapped on, the new two-line-tick test, and every other chart and gate reading in those three modules, green against today's main rather than against dbc0065.

What was run

On origin/main at 268e925:

tests/test_render_gate.py -k heat-loss --run-nightly -n0
  1 failed, 1 passed — 9 COVERED_WORDS findings on heat-weekly ([light] [print] [dark] × 17/Nov, 1/Dec, 5/Jan)

On this branch at 705b923 (which contains 942f7aa Merge branch 'main'):

tests/test_render_gate.py tests/test_render_export.py tests/test_render_widgets.py --run-nightly
  141 passed in 171.86s

I had run the same three modules on a hand-merge of 419747b onto 268e925 before the sibling push landed — also 141 passed — so the result is the merge's, not the assertion 705b923 adds to the new test.

@max-sixty

Copy link
Copy Markdown
Owner

Landed directly on main as 999f933, preserving the fix and regression test per the repository landing workflow.

@max-sixty max-sixty closed this Aug 26, 2026
max-sixty added a commit that referenced this pull request Aug 26, 2026
## Problem

This came out of reviewing #58, which landed as
[999f933](999f933)
while the review was running. The fix itself is right and this does not
touch it — what it leaves behind is an exemption with one leg.

`999f933c` holds a label's own lines out of `COVERED_WORDS`: an SVG
`<text>` spells a line break as an element, so two lines of one tick are
two nodes where a wrapped paragraph's are one, and the pair overlapped
by construction on a drawing where no glyph comes near another.
`test_the_gate_passes_a_chart_whose_tick_names_its_month_on_a_second_line`
proves the hold fires. Nothing proves it is narrow.

Widen `el.closest('text')` to `closest('g')` or `closest('svg')` — every
tick of an axis sits inside both — and every word of a chart stops being
read against every other word of that chart. The whole suite stays
green. I ran it rather than reasoning about it: with the predicate
widened, `tests/test_render_gate.py`, `tests/test_render_widgets.py` and
`tests/test_render_export.py` give 18 passed over every case naming this
pass, the new exemption test among them.

Nothing else in the suite can see it, for four separate reasons:

- The corpus sweeps and the copy assert this pass returns nothing, which
a wider hold only makes more true.
- `test_no_two_of_a_chart_s_words_land_in_the_same_place` reads
`CHART_COLLISIONS`, which compares whole `<text>` boxes and never
reaches this pass.
- The exemption test defeats the predicate wholesale (`.replace("a.label
&& a.label === b.label", "false")`), so its `reported` leg is identical
however `label` was computed.
- The only standing bug-back on `COVERED_WORDS` *reporting* is
`test_the_covered_words_gate_still_reads_a_control_in_the_flow`, and
that is an HTML page whose runs never get an SVG label at all.

That test's docstring is the precedent this is written from: "a gate
that has only ever passed has been tested for nothing, and this one is
one predicate away from exempting every control there is." The same
sentence is true of the new predicate one element up. `tests/CLAUDE.md`
states the general shape under **Make a green test non-vacuous** — "A
reading blind to one mechanism does not report that it is blind — it
returns the same clean result it returns when nothing is wrong."

## Solution

The other half, put back as a bug, the way the float's two halves are
already written. One whole `<text>` stood on another by copying its
`transform`, so the labels stay whole and what lands is two of them
rather than two lines of one. Arranged that way rather than by spreading
a label's lines, because the hold asks which `<text>` drew a line and
not how far a line was moved — and because it depends on neither the
axis's leading nor a neighbouring chart's layout.

Test-only. `render_checks.py` is untouched.

## Testing

Every run below at `-n0` on this branch, based on `999f933c`.

- `uv run pytest tests/test_render_widgets.py` — 58 passed.
- Bug-back, `closest('text')` → `closest('svg')`: the new test fails on
`two of a chart's labels stood on each other unreported: []`; the
exemption test still passes.
- Bug-back, `closest('text')` → `closest('g')`: same failure, same
complement.
- The complement, with `if (a.label && a.label === b.label) continue;`
removed entirely: the exemption test fails on `held` with `<lf-chart
id=c-line> draws "1" in the same place as <lf-chart id=c-line>'s "Jun"`,
and the new test still passes. The two are about different halves and
neither stands in for the other.
- Repeated 5× at `-n0`: passed each time.
- `pre-commit run --files tests/test_render_widgets.py` — passed.

<details><summary>What the arrangement produces</summary>

The two ticks and the finding, printed from the reading during
development:

```
MOVED: ['20', '22']
FOUND: ['<lf-chart id=c-line> draws "20" in the same place as <lf-chart id=c-line>\'s "22"']
```

The assertion matches on both labels in their quoted form rather than on
the chart id, so a finding about some other pair in the same chart
cannot satisfy it.

</details>

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
max-sixty added a commit that referenced this pull request Aug 27, 2026
## Problem

This came out of reviewing #58, which landed as
[999f933](999f933)
while the review was running. The fix itself is right and this does not
touch it — what it leaves behind is an exemption with one leg.

`999f933c` holds a label's own lines out of `COVERED_WORDS`: an SVG
`<text>` spells a line break as an element, so two lines of one tick are
two nodes where a wrapped paragraph's are one, and the pair overlapped
by construction on a drawing where no glyph comes near another.
`test_the_gate_passes_a_chart_whose_tick_names_its_month_on_a_second_line`
proves the hold fires. Nothing proves it is narrow.

Widen `el.closest('text')` to `closest('g')` or `closest('svg')` — every
tick of an axis sits inside both — and every word of a chart stops being
read against every other word of that chart. The whole suite stays
green. I ran it rather than reasoning about it: with the predicate
widened, `tests/test_render_gate.py`, `tests/test_render_widgets.py` and
`tests/test_render_export.py` give 18 passed over every case naming this
pass, the new exemption test among them.

Nothing else in the suite can see it, for four separate reasons:

- The corpus sweeps and the copy assert this pass returns nothing, which
a wider hold only makes more true.
- `test_no_two_of_a_chart_s_words_land_in_the_same_place` reads
`CHART_COLLISIONS`, which compares whole `<text>` boxes and never
reaches this pass.
- The exemption test defeats the predicate wholesale (`.replace("a.label
&& a.label === b.label", "false")`), so its `reported` leg is identical
however `label` was computed.
- The only standing bug-back on `COVERED_WORDS` *reporting* is
`test_the_covered_words_gate_still_reads_a_control_in_the_flow`, and
that is an HTML page whose runs never get an SVG label at all.

That test's docstring is the precedent this is written from: "a gate
that has only ever passed has been tested for nothing, and this one is
one predicate away from exempting every control there is." The same
sentence is true of the new predicate one element up. `tests/CLAUDE.md`
states the general shape under **Make a green test non-vacuous** — "A
reading blind to one mechanism does not report that it is blind — it
returns the same clean result it returns when nothing is wrong."

## Solution

The other half, put back as a bug, the way the float's two halves are
already written. One whole `<text>` stood on another by copying its
`transform`, so the labels stay whole and what lands is two of them
rather than two lines of one. Arranged that way rather than by spreading
a label's lines, because the hold asks which `<text>` drew a line and
not how far a line was moved — and because it depends on neither the
axis's leading nor a neighbouring chart's layout.

Test-only. `render_checks.py` is untouched.

## Testing

Every run below at `-n0` on this branch, based on `999f933c`.

- `uv run pytest tests/test_render_widgets.py` — 58 passed.
- Bug-back, `closest('text')` → `closest('svg')`: the new test fails on
`two of a chart's labels stood on each other unreported: []`; the
exemption test still passes.
- Bug-back, `closest('text')` → `closest('g')`: same failure, same
complement.
- The complement, with `if (a.label && a.label === b.label) continue;`
removed entirely: the exemption test fails on `held` with `<lf-chart
id=c-line> draws "1" in the same place as <lf-chart id=c-line>'s "Jun"`,
and the new test still passes. The two are about different halves and
neither stands in for the other.
- Repeated 5× at `-n0`: passed each time.
- `pre-commit run --files tests/test_render_widgets.py` — passed.

<details><summary>What the arrangement produces</summary>

The two ticks and the finding, printed from the reading during
development:

```
MOVED: ['20', '22']
FOUND: ['<lf-chart id=c-line> draws "20" in the same place as <lf-chart id=c-line>\'s "22"']
```

The assertion matches on both labels in their quoted form rather than on
the chart id, so a finding about some other pair in the same chart
cannot satisfy it.

</details>

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
leaf-agent added a commit that referenced this pull request Sep 22, 2026
Writing the attribute from Marked's authored text made the checked string
and the emitted string one string, and took away the decode Marked's own
renderer was relying on: every character reference in a link or image
destination started resolving literally, so `?a=1&amp;b=2` reached the
query as one parameter named `a` with `1&amp;b=2` in it, and an image with
that shape 404ed.

Take the decode here instead, in the one place a destination is read, so
that reading is what `safeUrl` checks and what `escapeAttribute` puts back
unchanged. Every legitimate destination resolves where it did before the
guard changed, and `javascript&#58;` is refused outright rather than
resolving to a relative path carrying a literal `&#58;`.

The contract test carries both halves now. Its earlier assertion held
vacuously over an empty list of anchors, so it stayed green whether or not
a link was rendered; it now names the one href the document is allowed to
resolve, beside a live destination whose `&amp;` has to survive.
max-sixty added a commit that referenced this pull request Sep 22, 2026
…#929)

Markdown destinations such as `[press me](javascript&#58;alert(1))`
passed the scheme guard as relative paths, then became executable links
when the document decoded the attribute. Links and images now use
Marked’s standard renderer, parse that output in an inert template, and
validate the destination the document actually reads before publishing
it.

Keeping Marked responsible for element rendering preserves flattened
image alt text, titles, entity handling, autolinks, and URL
normalization. Page-media inspection wraps the same rendered image and
derives its accessible button name from that image’s alt.

The browser regression covers encoded executable links and images,
ordinary URL entities, autolink entities, formatted alt text, titles,
and keyboard inspection of page media. Reintroducing raw token alt text
makes it fail. An additional adversarial check refused 18 encoded
executable link/image variants.

Validation: 121 chrome/conversation browser tests; 1,273 everyday cases
(two rerun after local setup); 33 runtime tests; and pre-commit checks.

> _This was written by Codex on behalf of max-sixty_

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants