Skip to content

Make screenshot comparisons draggable - #892

Merged
max-sixty merged 4 commits into
mainfrom
codex/shot-comparison-handle
Sep 21, 2026
Merged

max-sixty merged 4 commits into
mainfrom
codex/shot-comparison-handle

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • replace the binary live screenshot flip with Web Awesome's draggable comparison
  • keep direct image clicks, named endpoints, margin controls, print output, and script-free export behavior
  • use Leaf's hollow-circle cue for a quiet handle that strengthens on hover, focus, or drag
  • load Web Awesome after Leaf presents the native fallback, and unwind it before export

Tests

  • uv run pytest tests/test_render_commands.py tests/test_render_options.py tests/test_render_pages.py -n 2 -q
  • npm run test:runtime
  • uv run pre-commit run --files ...
  • browser review at rest, endpoints, hover, click, drag, keyboard, light, and dark appearances
  • presentation timing proves the Web Awesome request starts after data-lf-presented

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The draggable comparison works well on the live page — drag, Arrow/Home/End, endpoint clicks, the rail, and the margin entry all land where the description says they do, and live print still stacks both full frames exactly as main does. Four things hold the approval.

The release bundle loads lf-shot before Web Awesome

test is red on this, and it is this branch's: verify-site-local.sh crashes on /examples/feature-gallery/versions/v1.html — the corpus page carrying lf-shot — with Uncaught TypeError: Cannot read properties of undefined (reading 'then'). I reproduced it locally against the built release.

void comparison.updateComplete.then(...) in #syncComparison assumes wa-comparison is defined by the time createElement runs. In the release bundle it is not. worker/bundle-runtime.mjs resolves the side-effect-only import "../vendor/webawesome.esm.js" into its own chunk with no import edge from the widget's chunk, and the entry lists them in the wrong order:

# widgets/lf-shot.js, as emitted
import"../runtime/bundle-QPHRQ5A6.js";   # lf-shot's body + customElements.define("lf-shot", ...)
import"../runtime/bundle-U7JT5XR4.js";   # Web Awesome, defines wa-comparison

ESM evaluates them in that order, so define("lf-shot", ...) upgrades the <lf-shot> already in the document and runs connectedCallback synchronously — before Web Awesome has registered anything. createElement("wa-comparison") hands back a plain HTMLElement, updateComplete is undefined, and the widget throws during upgrade. The other four Web Awesome importers never hit this because they consume components declared in markup, which upgrade whenever the definition lands; lf-shot is the first to read a Lit instance property at creation time.

Two levels to fix it at. Inside this PR, stop depending on synchronous upgrade — customElements.whenDefined("wa-comparison") before the element's own state is touched, or drop the updateComplete read and let the change handler and register() drive the first paint. Underneath it, the bundler is the thing that made the order silent: its preserve-module-urls plugin filters on /^\//, so an absolute /vendor/... import stays external and keeps the browser's ordering — jsdiff does — while this relative ../vendor/... one gets pulled in and reordered. Either is defensible; the narrow one unblocks the gate and leaves the bundler exactly as easy to fix, so long as it says so.

The exported copy keeps the live comparison

The widget's own comment says export "removes the live comparison and margin control", but nothing removes it. version export serializes <wa-comparison> into the copy; Web Awesome attaches its shadow root with {mode: "open"} and no serializable, so getHTML({serializableShadowRoots: true}) writes the host and its light-DOM children and drops the shadow tree. The copy then holds an unupgraded custom element that the new html.lf-copy rules re-dress as a grid, and three things fall out of that:

  • The slot="handle" span has no slot to land in, so it renders as a stray 13px hollow circle in its own auto-placed grid row above the frames.
  • aria-keyshortcuts="ArrowLeft ArrowRight Home End" rides into a file with no script and no divider behind it.
  • Printing the copy puts both frames in the same box — html.lf-copy lf-shot .lf-shotcomparison (0,2,2) outranks @media print's lf-shot > .lf-shotcomparison (0,1,1), so the print rule's display: block never applies and visibility: visible !important reveals two images stacked on top of each other. On main the printed copy stacks them down the page.

#syncComparison's disable branch already knows how to unwind this — it un-slots the frames, puts them back as direct children, and drops the comparison. The copy needs that same unwind rather than a parallel set of CSS rules dressing a live component the file cannot run. test_a_shot_still_flips_with_every_script_removed keeps passing through all three because it only asks which frames are visible.

#paint() runs at pointer frequency

Every change from the comparison calls #paint(), and wa-comparison fires one per position change: a 20-move drag produced 20 of them. Each does a page-wide paintKeys() — pruneScopedElements() plus reflectElementShortcuts over every scoped element on the page, evaluating each row's when() — and a margin.update() republish.

Only the handle's aria-valuetext is a continuous function of position. The checkbox, the captions' aria-pressed, the margin icon, and the shortcut line all change only when the position crosses 50 or reaches an endpoint, so the visible effect of the rest is the margin icon and the shortcut-bar line flipping back and forth as the divider is wiggled across the midpoint. CLAUDE.md's Cross-runtime invariants puts drag with its mechanical browser owner "until a gesture becomes a declared application fact"; deriving the chrome from the raw position makes every intermediate pixel one. Splitting #paint() so the ARIA text updates per move and the chrome repaints only when the derived endpoint changes settles both.

lf-shot now pulls 418 KiB before presentation

import "../vendor/webawesome.esm.js" makes lf-shot the first default-package widget to depend on the vendored bundle — the other four importers are all in optional packages. Measured on the same shot page: main requests no Web Awesome at all; this branch requests 427,656 bytes in one new request. It is before presentation on both counts — the static import gates the module's evaluation, and register() awaits this.#comparison?.updateComplete — so every page carrying a screenshot comparison pays it, including examples/release-notes.html and examples/developer/feature-gallery.html.

CLAUDE.md's Working on the repository asks for this case directly: compare the base and candidate scripts/verify-site-local.sh readings, and "if a change adds work before presentation, state the user-visible benefit and why that work cannot wait until after presentation." The benefit is clear; what the description does not say is why the bundle has to be on the critical path rather than upgrading the static CSS flip into a comparison after presentation. That is a call worth making explicitly, not one to make by import.


#884 also regenerates skills/leaf/packages/default/vendor/webawesome.esm.js and edits scripts/vendor-src/webawesome/leaf-theme.css. Whichever lands second wants scripts/vendor.py webawesome rerun rather than the bundle hand-merged.

Happy to push the upgrade-ordering fix, the export unwind, and the #paint() split if you want them — say the word. The payload question is yours.

How each was measured

All against dec0f31, with main as the control, using the repo's own SHOT_PAGE fixture and leaf.exporting.export_page.

Export. The serialized copy contains <wa-comparison class="lf-shotcomparison" data-lf-gen="1" aria-keyshortcuts="ArrowLeft ArrowRight Home End" position="50"> with shadowRoot === null on load. The handle span reports checkVisibility() === true at 13×13, and the frames start 13px below the comparison's own top edge. Printed: both frames at top: 4264, height: 361. On main: top: 4251 and top: 4620.

Drag. Twenty page.mouse.move steps across the handle produced twenty change events on the host.

Payload. performance.getEntriesByType('resource') on the shot page: ['webawesome.esm.js', 427656, 427356] on this branch, empty on main.

Bundle ordering. uv run scripts/site.py, then the built examples/feature-gallery/versions/v1.html served over its own release paths: customElements.get('wa-comparison') is truthy once the page settles, and the console carries the same reading 'then' TypeError CI reports, from the lf-shot chunk.

An earlier reading of mine had live print collapsing both frames to 2px; that was the probe measuring before the images decoded. With naturalHeight settled, live print matches main.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The four things I raised on dec0f31 are settled: test is green, the dynamic import plus the customElements.get("wa-comparison") gate removes the release-bundle ordering dependency, the export unwind gives the copy its frames back with print stacking them, and the #chromeState split holds the chrome repaint to the four positions the chrome actually distinguishes. Moving the bundle behind whenPagePresented() is the right call, and the timing assertion pins it.

One new consequence of that move, plus a mechanism question and a stale comment.

The upgrade discards a flip the reader made while it was loading

Making the static flip the presented state means a reader can now work it before Web Awesome arrives — that is the point of the fallback, and it works. But #syncComparison creates the comparison at a hard position = 50, so whatever the reader did in that window is thrown away when the bundle lands.

Measured on the repo's own SHOT_PAGE, flipping the fallback to after the instant data-lf-presented appears:

at presentation:  {comparison: absent, frames shown: ['after']}
after upgrade:    {position: 50, checkbox: unchecked,
                   captions: before=false after=false}

The reader chose after, the page showed after, and an asynchronous load put it back to a midpoint split with both captions unpressed. On a slow connection the window is as long as the 418 KiB takes; the gesture is undone with no event and nothing to undo it with.

The inline suggestion seeds the comparison from the checkbox, which is already the fallback's authority — #paint() reads this.#box.checked for position whenever #comparison is null. That covers the after case exactly and keeps 50 as the untouched default. It still loses an after → before round trip, since an unchecked box cannot say whether the reader chose before or never touched it; a #chose flag set where #show() and the change handler already run would close that too, and is the version I would write.

The same derivation is worth settling in one place while you are there. this.#comparison?.position ?? (this.#box.checked ? 100 : 0) is written out in #nextState(), #paint(), and the margin read(); the caption commands' when() is a fourth copy that drops the fallback half, so in this same window both rail commands read undefined !== 0 and undefined !== 100 as true and stay available — a reader on the rail is offered "show before" while before is what is on screen, against the comment that says the shown frame is not named there. A #position() accessor settles that one and makes the seed above read as adopting state rather than guessing at it.

lf-bake is a second door into the moment lfPrepareExport already owns

prepareExport sweeps every element for lfPrepareExport() and exporting.py awaits it immediately before bake() — one call site, no other path into bake. lf-diff and lf-call-diff both use it for exactly this job: unwind live-only structure so the copy serializes DOM it can operate. lf-call-diff also shows the ordering answer the new event works around — it sets its own preparingExport flag so a later render cannot undo the unwind, rather than reading lf-copy off the root.

So lf-shot can implement lfPrepareExport() and drop the document listener, the connectedCallback/disconnectedCallback pair that maintains it, and the new event from standalone.js. A flag of its own is also stricter than the class read: #upgradeComparison can be mid-await on the dynamic import when export begins, and a flag closes that window at the widget rather than relying on bake() setting lf-copy before it dispatches.

Neither hook is named in references/packages.md's "What the module owes", so whichever survives, a package author has no way to find it. If you keep the event, that paragraph is where it belongs.

The theme's comment describes the copy this commit removed

html.lf-copy lf-shot .lf-shotcomparison { display: grid; aspect-ratio: auto; … } is gone — the copy has no comparison host now, which is the fix. The block comment above still tells the next reader it becomes "a plain grid" with the checkbox over it. Inline suggestion below.


Unrelated to the verdict: whenPagePresented() is the primitive bootstrap.js hand-rolls twice and interaction-gallery-frame.js once, and the same deferral would take Web Awesome off the presentation path for lf-diff, lf-playground, lf-targeting, and lf-visual-review, which still import it statically. Both are follow-ups, not this PR's work — this change leaves them easier, not harder.

#884 still regenerates vendor/webawesome.esm.js and edits scripts/vendor-src/webawesome/leaf-theme.css; whichever lands second wants scripts/vendor.py webawesome rerun rather than the bundle hand-merged.

How the flip loss was measured

Against 221a7c0b, SHOT_PAGE with its own media, viewport 1200×900. An init script registers before the runtime, so its observer runs ahead of the widget's own:

page.add_init_script(
    """new MutationObserver(() => {
      if (!document.body?.hasAttribute('data-lf-presented')) return;
      if (window.__flipped) return;
      const box = document.querySelector('lf-shot input.lf-shotflip');
      if (!box) return;
      window.__flipped = true;
      window.__hadComparison = !!document.querySelector('lf-shot wa-comparison');
      box.click();
      window.__fallbackShown = [...document.querySelectorAll('.lf-shotframe')]
        .filter(f => getComputedStyle(f).visibility === 'visible')
        .map(f => f.dataset.lfState);
    }).observe(document, {attributes: true, subtree: true});"""
)

__hadComparison is False and __fallbackShown is ['after'] — the fallback is live and the reader's flip took. After wa-comparison appears: position 50, input.lf-shotflip unchecked, both .lf-shotcap at aria-pressed="false".

A reader gesture during the load window is not otherwise covered: test_a_shot_compares_its_frames_with_a_direct_divider waits for wa-comparison before it touches anything.

Comment thread skills/leaf/packages/default/theme.css Resolved
@max-sixty
max-sixty merged commit 7925553 into main Sep 21, 2026
5 checks passed
@max-sixty
max-sixty deleted the codex/shot-comparison-handle branch September 21, 2026 20:24
max-sixty pushed a commit that referenced this pull request Sep 21, 2026
…ontrols (#884)

`ci` on `main` went red at 725fca7 (#878): [`lint` and `test` passed
and the complete suite in `nightly` failed on seven
cases](https://github.com/max-sixty/leaf/actions/runs/35615354769). One
of them,
`test_agent_status_leaves_the_margin_transcript_where_the_reader_scrolled_it`,
also fails at 9b17c79 and is #879's; #883 has since landed it. The
remaining six are the Web Awesome rollout's, and they share one cause:
the rollout moved four packages' controls into a vendor's shadow root,
and the facts Leaf had stated about the native elements it replaced
stayed on the hosts those elements used to be. #878's stated validation
was 177 widget browser tests and the shipped runtime tests, and neither
reaches the corpus ring floor or the published site.

## What the reader sees

**The band is the vendor's, not the layer's.** `theme.css` keeps the
ring's thickness in one token so there is one band on the page. A
vendored control's ring is painted inside its own shadow root from
`--wa-focus-ring-*`, which the Leaf theme did not map, so every vendored
control wore a 3px ring next to Leaf's 2px one — and the diff filter
field's own rule, `.lf-diff-search:is(:focus-visible, …)`, stopped
matching anything at all, because a `wa-input` host is neither the Tab
stop nor the box that gets ringed. The vendor also transitions
`outline-color`, so the band faded in over 75ms rather than appearing
with the focus; `theme.css` states the opposite for the layer's own
rules, and a transition in flight is reported as the value the property
is leaving, so the band was invisible to any reading taken when it was
drawn.

The shared theme now states the band — `--wa-focus-ring-style`,
`--wa-focus-ring-width: var(--here-ring-w)` beside the
`--wa-color-focus` mapping that was already there — draws and names it
on the text field's own part, since `--lf-here-ring` does not inherit,
and drops `outline-color` from the two vendored controls that transition
it. That is one place for every package rather than a rule per host. The
diff package loses its dead filter-field rule, and the duplicate
`.lf-diff-wrap:focus-visible` #878 added beside the named one — the
second latent failure, which the corpus floor reached only once the
first was fixed.

**The chrome above the evidence grew.** `lf-visual-review` gives a
focused review a laptop's height, and both rows of chrome above the
evidence take their height from the tallest control in them. A vendored
control sizes itself from the vendor's form-control height, eight pixels
more than `.lf-btn`'s box, so the queue row and the inspector row each
grew by eight and the evidence stage lost sixteen — 366px to 350px,
under the 360px the workspace states. The package states those controls'
height again, as it did before #878 with `.lf-vr-inspector-button {
min-height: 30px }`. Measured on the rebuilt page: both rows back to
30px and the evidence back to 366px.

## What the tests were reading

`test_site.py` still read a `wa-slider` through `to_have_value` and
drove a `wa-select` with `select_option`; both now use the shapes #878
established in `test_render_widgets.py`. The corpus ring specimen named
the `wa-input` host, which is not in sequential keyboard navigation; it
now names the field the reader actually stands on, and a second specimen
keeps `diff-tools` exhibited for the controls that still wear it.

`test_a_copy_speaks_reader_origin_after_live_map_is_removed` is not a
Web Awesome failure. It asserts the card move's optimistic paint and
then closes the page — but the paint says nothing about the log, and the
export opens its own page with only the log to replay from, so a send
still in the wire is aborted by the close. That is the arrangement
`sending()` exists for, under **State races are arrangements, not
probabilities** in `tests/CLAUDE.md`; the gesture is now enclosed in it.
Nothing says #878 introduced it: the two failing `main` runs before this
one carry only the margin case, so this reads as a latent race that the
run lost.

## Two more the floor could not reach

The corpus ring floor raises inline on the first specimen it cannot
stand on, so it reports one per run and fixing one uncovers the next.
Behind the diff filter field, two had collected, and this branch takes
both because `main`'s `nightly` stays red on that case otherwise.

`lf-shot` upgrades to `wa-comparison` after presentation, and
`theme.css` shows the native checkbox only while no comparison is
mounted, so `lf-shot > input.lf-shotflip` — the control `RING_CASES`
named — is `display: none` on every live page. The reader's stop is the
comparison's own handle, which wears Leaf's band because the host maps
`--wa-focus-ring` to it, and wears the `shot` name because #892's
`#paint()` writes `--lf-here-ring` onto that shadow element inline —
`--lf-here-ring` is registered `inherits: false`, so the host's own
declaration does not reach it. The specimen moves there. That is #892's,
and the same shape as the diff field: a vendored control took over and
the reading stayed on the element it replaced.

The summary range's expand and refold controls draw the here ring and
declare no `--lf-here-ring`, which `chrome.css`'s own header forbids.
That is #886's. They share one rule, so they take one name,
`summary-fold`, and one specimen on the gallery's summarized thread.

The walk collecting its per-specimen failures the way
`test_every_base_corpus_tab_stop_has_a_visible_focus_indicator` collects
its own would have shown all three in one reading. That is a change
against the test rather than against this one, and nothing here makes it
harder.

## Verification

All six cases pass here, and so do the nightly files they live in or
that the theme change could reach: `test_render_widgets.py`,
`test_render_visual_review_journey.py`, `test_render_projection.py`,
`test_render_controls.py`, `test_render_navigation.py`,
`test_render_anchors.py`, `test_render_gate.py`, `test_site.py` — 881
passed, beside two `test_render_export.py` cases that fail in this
sandbox for a reason named below and fail identically without this
change. `pre-commit run --all-files` is clean, `npm run test:runtime` is
28 passed, and the Web Awesome regeneration is `scripts/vendor.py
webawesome` rather than a hand edit of the bundle. That reading was
taken at 4bfc53f; with `main` merged in and the two cases above taken,
`tests/test_render_controls.py -k "ring or focus_indicator"` is 21
passed and `tests/test_render_conversations.py` is 96 passed, both
`--run-nightly`.

## What this does not do

The height fix is the visual review's own, because that is the package
whose layout contract broke and where the metric was stated before. The
general question — whether the shared theme should state the vendored
control's box, so any vendored control matches the Leaf button beside it
— is left open: taking it here would move the playground, targeting and
diff geometry that #878 reviewed, with no failing case to read the
result against. Nothing in this change makes that harder to do later.

It does not settle what `shot` is declared by. `RING_NAMES` reads
declarations off stylesheets, so that name's whole population entry
stays `lf-shot:has(> input.lf-shotflip:is(:focus-visible,
.lf-focus-visible))` — a rule whose control is `display: none` wherever
the comparison mounts — while the credit comes from the handle's inline
property. The two halves the floor compares agree on a string rather
than on a rule for that one name. Putting the declaration where the
paint is, `::part(handle):focus-visible` drawing and naming the band
with the `#paint()` write dropped, is the repair; it is left out here
because it answers for `lf-shot` the question this PR leaves open for
the other vendored families, and the corpus floor reaches its end
assertions either way.

<details><summary>The failing cases and where each was read</summary>

From [the `nightly` job at
725fca7](https://github.com/max-sixty/leaf/actions/runs/35615354769):

```
FAILED tests/test_site.py::test_the_published_notification_example_runs_its_authored_module@site
  AssertionError: Locator expected to have Value '2' / Error: Not an input element
FAILED tests/test_site.py::test_published_visual_evidence_loads_from_its_page@site
  Locator.select_option: Error: Element is not a <select> element
FAILED tests/test_render_controls.py::test_every_base_corpus_tab_stop_has_a_visible_focus_indicator
  keyboard stops with no visible indication: pr-walkthrough: input#input.control [outline none, shadow none]
FAILED tests/test_render_controls.py::test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus
  .lf-diff-search in the page of pr-walkthrough is not in sequential keyboard navigation
FAILED tests/test_render_export.py::test_a_copy_speaks_reader_origin_after_live_map_is_removed
  Locator expected to have attribute '1' / Actual value: None
FAILED tests/test_render_projection.py::test_visual_review_gallery_gives_a_laptop_to_the_evidence
  assert 350.421875 >= 360
FAILED tests/test_render_margin.py::test_agent_status_leaves_the_margin_transcript_where_the_reader_scrolled_it
  assert {'working': [484, 980]} == {'working': [484, 959]}      # #879's, landed in #883
```

Five of the six reproduce here on `main`. The export case does not — it
passed on three consecutive local runs — and was diagnosed from the
arrangement rather than from a local red.

The band's own reading, taken on the focused diff filter field before
the transition was removed: `outline-width` 2px and `--lf-here-ring`
`text-entry` from the new rule, with `outline-color` still `rgba(0, 0,
0, 0)` because the vendor's `outline-color` transition had not run. That
is what made the rule look inert and is why the transition is part of
this change rather than a separate one.

Two cases in `test_render_export.py` fail in this sandbox —
`test_the_example_preview_command_exports_a_file_that_opens_on_its_own`
and `test_exporting_an_example_leaves_the_live_preview_untouched` —
because a subprocess cannot launch Chrome here. Both fail identically at
9b17c79 with this change absent, and neither is in the hosted run's
failure list. The everyday suite's five failures here are the same
sandbox's `AF_UNIX` and umask limits, as [#883
recorded](#883).

Catalog previews are not affected: the resting appearance of a vendored
control is unchanged everywhere except the visual review, which the
catalog does not carry, and a still has nothing focused.

</details>

---------

Co-authored-by: leaf-agent <[email protected]>
max-sixty pushed a commit that referenced this pull request Sep 22, 2026
…htly tests around what #886, #889 and #892 moved (#903)

`ci` on `main` went red at 7925553 (#892): [`lint` and `test` passed
and the complete suite in `nightly` failed on eleven
cases](https://github.com/max-sixty/leaf/actions/runs/35650845868). Five
of them were #884's and #891's, both since merged, and the visual-review
one is green again on today's `main`. This PR is the other six, which
arrived together because three features landed between that run and the
one before it and none of them was validated against the nightly
selection.

One is a fault in the layer. The other five are tests still standing
where those features used to put things.

**The comparison handle's lift is cast in `--shade`.** #892 gave
`wa-comparison`'s handle `box-shadow: 0 1px 3px color-mix(in srgb,
var(--ink) 20%, transparent)`. The layer states one shadow ink per
scheme precisely because a hand-mixed colour can only be right about one
ground — a drop shadow written for the light paper lifts a dark one by a
fraction of what it promises — and
`test_every_shadow_the_layer_lifts_a_box_with_is_cast_in_the_scheme_s_own_ink`
is the reading that holds every elevation shadow to the token. The
handle now spends it.

**#889 made a finding say where it is; two assertions held the old
wording.** `render-checks/locate.js` reads an element without an id as
`<strong> in <lf-option id=c-bearer>` rather than as the host alone.
That is the change #889 made on purpose, so the two nightly assertions
that spelled the host move to the stated form.

**#892 made the screenshot's checkbox a fallback; a test still pressed
it.** `test_a_widgets_native_control_names_the_press_the_platform_makes`
scrolls `lf-shot`'s transparent checkbox into view and presses Space on
it. Since #892 the theme hides that checkbox the moment Web Awesome's
comparison lands, so on the live page there is no control there to
scroll to. The test now holds the bundle from outside the page through
`primed`, which is what `tests/CLAUDE.md` asks for when the ordering
matters — an arrangement rather than a race. It needed a page of its own
to do it: `lf-diff` imports the same bundle at the top of its module, so
holding it on the combined fixture left that widget unupgraded and the
page never presented. The staged-control half of the test now runs on
`DIFF_PAGE`, and `NATIVE_CONTROL_PAGE` goes with the split.

**#886 added a thread to the gallery; a walk was counting presses to a
different one.**
`test_a_forced_inline_thread_keeps_its_control_inside_the_margin_budget`
pressed `t` twice to walk from the gallery's first thread to the crowded
suggestion's. #886's summary example anchors at `bg-thread-checkpoint`,
which sits between them, so the second press landed there and the test
went on to measure a card three thousand pixels from the cluster it
names. The walk now goes to the thread it is for, gives up when it comes
back round to one it has already stood on, and waits for each press's
arrival before the next.

**#892's upgrade arrives after the page says it has presented; a
settled-page reading started before it.**
`test_a_settled_page_with_a_standing_reaction_stops_rendering_its_margin`
counts margin layouts across thirty frames on the gallery and allows
one. The gallery carries an `lf-shot`, and moving its two frames into
`wa-comparison` lays the margin out twice a few milliseconds apart, at
whatever moment the module happens to resolve. The stamps `open_page`
waits on do not cover an upgrade deliberately placed after them, so the
page was still arriving when the count began. The test waits for the
comparison first.

## Verification

The six cases pass on this branch and five of them still fail on `main`
without it; the sixth is the intermittent one, measured below.
`tests/test_render_controls.py`, `tests/test_render_anchors.py`,
`tests/test_render_projection.py`, `tests/test_render_margin.py` and
`tests/test_render_commands.py` were run whole under `--run-nightly`,
along with the everyday suite, `npm run test:runtime` and pre-commit on
the changed files.

<details><summary>Evidence, and what this leaves</summary>

**The settled-page case is intermittent, and the hold is what names its
cause.** Without the wait it went red on 2 of 12 local runs, with both
layouts landing 6–13ms apart somewhere in the first 700ms of the window
— 296/302, 191/197, 521/527. With the wait it is 8 of 8 green. Holding
`**/vendor/webawesome.esm.js` from outside the page instead, changing
nothing else, is 8 of 8 with no layouts counted at all, which is what
identifies the shot's upgrade rather than the two-second heartbeat the
test's docstring had assumed.

**Attribution.** Each failure was placed by running the case at the
commits between the two nightly runs: the margin walk passes at 10d61b2
and 2f8ee1b and fails at 965369b (#886), and `git show 965369b --
examples/developer/feature-gallery.html` is the added
`bg-thread-checkpoint` paragraph and its thread.

**Not in this PR.** One document change producing two margin layouts on
adjacent frames is a doubled render in the thing that test exists to
bound; this change waits for it rather than removing it, and whether the
upgrade should lay out once is #892's question to answer. The wait
itself is the third place a test names, by hand, a widget of its own
fixture that is still arriving after the page said it presented —
`test_margin_layout_batches_the_composed_page_without_refolding_controls`
and `test_unchanged_margin_refresh_cost_is_bounded_by_refresh_count`
each wait on `[data-interaction-frame]` carrying
`data-interaction-ready`, and this adds `lf-shot wa-comparison`. That is
one missing fact rather than three waits: a page-level stamp a deferring
widget raises when it lands, which `open_page` could wait through, would
settle every fixture at once. It is a change to make on its own terms
rather than inside a CI repair, and until it is made the next widget to
defer will redden some other test at a wait far from its cause.
Separately, four nightly cases are red on today's `main` and are not
from this run —
`test_a_thread_beside_its_cluster_takes_the_room_to_the_visible_edge`,
`test_the_margin_groups_meanings_at_one_destination_without_moving_the_page`
and `test_a_diff_surface_keeps_the_complete_thread_lifecycle_inline` in
both schemes. All four pass at 7925553 and fail at 39d9cad, so they
are #895's, and the run that reaches them will be that commit's own.

**Environment note.** Six everyday cases and the four browser-launch
cases in `tests/test_render_commands.py` fail in this CI sandbox on a
clean tree as well — no `AF_UNIX`, no installed Chrome for the
subprocess gate — and all of them were green in the `test` job of the
run under diagnosis.

</details>

Co-authored-by: leaf-agent <[email protected]>
max-sixty pushed a commit that referenced this pull request Sep 22, 2026
…d widgets have landed (#913)

#903 merged at 57b00cd without the revision asked for on its thread,
and left two things behind. This is both of them.

**`test_staged_widget_controls_name_the_presses_their_owners_make` now
contradicts itself on `main`.** `main` had repaired that case in
e291a95 by driving the upgraded `wa-comparison` handle; #903 still
carried the older rewrite of the same case under its previous name,
which holds `**/vendor/webawesome.esm.js` from outside the page so the
fallback checkbox never gets hidden. Git combined the rename with the
body silently — no conflict, and GitHub reported the branch mergeable —
so `main` now holds the bundle and then waits for the component that
bundle defines. It cannot appear, and the case fails on its first read
of it. This restores 49952af's version of
`tests/test_render_anchors.py` and `tests/render_cases_navigation.py`,
which is e291a95's test and the `NATIVE_CONTROL_PAGE` fixture it
reaches through. No other part of #903 is touched.

**A page can now say when it has stopped arriving.** Presentation says
the reader may interact; it does not say the page has finished.
`lf-shot` puts Web Awesome's comparison after presentation on purpose
(#892), and the interaction gallery's contained documents arrive later
still — each moves boxes when it lands. Nothing outside the page could
see that, so three tests named a widget of their own fixture by hand and
waited for it: two on
`[data-interaction-frame][data-interaction-ready]`, and #903 added a
third, `lf-shot wa-comparison`, to stop
`test_a_settled_page_with_a_standing_reaction_stops_rendering_its_margin`
counting the comparison's two margin layouts as the render cycle it
denies. A widget that wants the reader to have the page first now runs
that work through `afterPresentation(() => …)`, which is the wait and
the declaration in one call, so there is no way to defer without the
page counting it. `pageArrived` answers whether anything is still
outstanding, and `open_page` waits through it. All three hand-written
waits are gone, and the next widget to defer settles every fixture
without a fourth.

## Verification

`tests/test_render_anchors.py`, `tests/test_render_gate.py`,
`tests/test_render_margin.py` and `tests/test_render_startup.py` ran
whole under `--run-nightly`: 425 passed, covering the restored
staged-control case and all three tests whose hand-written waits this
removes. The everyday suite is 1,213 passed, `npm run test:runtime` is
33 passed, pre-commit passes on the changed files, and the shot and Web
Awesome cases in `tests/test_render_widgets.py` and
`tests/test_render_commands.py` pass.

Six cases fail in this CI sandbox on a clean `main` checkout as well,
and were confirmed against one: five everyday cases that need `AF_UNIX`
or a umask the sandbox does not keep, and
`test_a_shot_still_flips_with_every_script_removed`, whose export
subprocess cannot launch a browser here.

<details><summary>Why a page-level fact rather than a fourth wait, and
what this leaves</summary>

**What the settled-page case was measuring.** Moving the shot's two
frames into `wa-comparison` lays the margin out twice a few milliseconds
apart, at whatever moment the module happens to resolve, and the test
allows one layout across thirty frames. Measured on #903's branch:
without any wait it went red on 2 of 12 local runs, with both layouts
landing 6–13ms apart inside the first 700ms of the window; holding
`**/vendor/webawesome.esm.js` from outside the page instead, changing
nothing else, was 8 of 8 with no layouts counted at all — which is what
identified the upgrade rather than the two-second heartbeat the test's
docstring had assumed. On CI it was red in
[35650845868](https://github.com/max-sixty/leaf/actions/runs/35650845868)
and
[35683511692](https://github.com/max-sixty/leaf/actions/runs/35683511692)
and green in
[35670525383](https://github.com/max-sixty/leaf/actions/runs/35670525383)
and
[35677461023](https://github.com/max-sixty/leaf/actions/runs/35677461023).

**The doubled layout itself is not fixed here.** One document change
producing two margin layouts on adjacent frames is a doubled render in
the thing that test exists to bound; whether the upgrade should lay out
once is #892's question. That is unchanged by this PR, and easier to
reach now that the page states when the upgrade has landed.

**What the new fact does not change.** `afterPresentation` does not move
work onto the presentation path — the arrival runs exactly when it ran
before, and `test_a_shot_compares_its_frames_with_a_direct_divider`
still holds the bundle's `startTime` at or after `data-lf-presented`.
What changed is only that the page can be asked whether the arrival has
landed.

**The other readers of the same fact.** `leaf version check`'s probes
stop at `currentPresented`
(`skills/leaf/scripts/leaf/render-checks/runtime.js`), and
`scripts/example-previews.py`, `scripts/record-demo.py` and
`scripts/verify_site.py` shoot on `data-lf-presented` alone, so each can
still read or photograph a page whose deferred widget has not landed.
That is the same missing wait at other readers, now one stage away from
each; a gate change alters what a public command waits for and a preview
change rewrites generated output, so neither is folded in here. The
gate's own `pageSettled` is a different fact — no finite animation still
running — which is why the new one is `pageArrived`.

</details>

Co-authored-by: leaf-agent <[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