Repository navigation
Replace margin forwarding with immutable projections - #716
Conversation
# Conflicts: # tests/test_render_widgets.py
leaf-agent
left a comment
There was a problem hiding this comment.
Six nightly render cases fail at this head. They carry pytest.mark.nightly, so the
PR's test job never selects them — ci is green while they are red, and merging
lands them on main's scheduled run. Each one reproduces with -n0 on Ubuntu with
the repo's pinned Chromium, so none of them is a parallel-run flake:
tests/test_render_drafts.py::test_registered_control_keys_activate_once—assert 'span' == 'button'tests/test_render_reactions.py::test_a_token_press_marks_the_passage_and_its_revealed_remove_takes_it_back—aria-keyshortcutsisEnter Space Escape, expectedEscapetests/test_render_navigation.py::test_numbered_ask_routes_follow_replaced_controls—aria-keyshortcutsisEnter Space Escape Meta+Enter Control+Enter 1, expectedEscape Meta+Enter Control+Enter 1tests/test_render_widgets.py::test_the_ask_itself_binds_each_contributed_action— the contributed action never gainsaria-keyshortcuts="1"tests/test_render_widgets.py::test_an_answered_boxless_ask_reopens_on_its_visible_revision_control— standing on the projected Undo, the bar reads⏎ / space · press · esc · let goinstead of1 · Undotests/test_render_widgets.py::test_a_pointer_decision_announces_without_needing_button_focus— focus is not left ondocument.bodyafter the pointer decision
Two mechanisms account for them.
Every projected margin entry is a <span role="button"> carrying its own press
declaration. createMarginEntryControl builds a span and attaches a per-control
margin.press scope, and reflectElementShortcuts now merges that scope's rows with
the projected contributor scope into one aria-keyshortcuts. So the draft pencil is no
longer the native button test_registered_control_keys_activate_once is about ("A
native draft button activates without a Leaf key binding"), and both keyshortcut
expectations come back one declaration longer than this PR wrote them. The updated
values in test_render_reactions.py and test_render_navigation.py read as though the
merge was not expected. If it is intended, the contract the deleted marginKeys
comment stated — that a native entry answers its own press and a second declaration
would be two meanings for one key — needs restating, together with what a reader on a
screen reader should now hear on every margin entry.
The numbered Ask routes no longer reach the projected controls. Three separate
widget cases fail on it, and the third is the reader-visible one: after answering an
Ask from the tray, focus lands on the suggestion's projected Undo and the shortcut bar
offers the generic margin-entry press instead of the 1 · Undo the Ask promised. With
the contributed control now resolved through this.#margin?.control(key) and
decisionControls newly skipping a null control, an Ask can lose the digit it
advertised without anything reporting it.
Four smaller points are inline: a receipt rule that can no longer match, scope being
the one entry option that reaches the shared render unvalidated, and a second writer
for data-lf-target-selected.
Commands and raw output
$ uv run pytest tests/test_render_drafts.py tests/test_render_reactions.py \
tests/test_render_options.py tests/test_render_projection.py -q -n4 -p no:randomly
3 failed, 315 passed in 462.01s
$ uv run pytest tests/test_render_anchors.py tests/test_render_navigation.py \
tests/test_render_outbox.py tests/test_render_startup.py tests/test_render_pages.py \
-q -n4 -p no:randomly
2 failed, 418 passed in 652.64s
$ uv run pytest tests/test_render_widgets.py tests/test_render_controls.py \
tests/test_render_conversations.py tests/test_render_aim.py -q -n4 -p no:randomly
8 failed, 392 passed in 628.05s
Re-run serially, the four test_render_controls.py timeouts, the
test_render_widgets.py::test_composed_corpus_runs_authored_page_modules timeout, the
test_render_options.py::test_the_gutter_runs_beside_the_exhibit_and_no_further[corpus]
timeout and
test_render_navigation.py::test_a_reader_at_the_top_of_the_document_is_one_press_from_the_chrome
all pass — those are -n4 flakes. The six above fail under -n0 as well.
tests/test_render_drafts.py:3006: AssertionError
pencil = draft_control(page, "edit")
> assert pencil.evaluate("el => el.localName") == "button"
E AssertionError: assert 'span' == 'button'
tests/test_render_reactions.py — locator resolved to
<span tabindex="0" role="button" … aria-label="shorten reaction actions"
aria-keyshortcuts="Enter Space Escape" class="lf-ui lf-margin-entry lf-react-mark"
data-lf-margin-entry-owner="standing-reac…>
- unexpected value "Enter Space Escape"
tests/test_render_widgets.py:8474: AssertionError
> assert "1\nUndo" in shortcut_bar_text(page)
E AssertionError: assert '1\nUndo' in '⏎ / space\npress\nesc\nlet go\n?\nmore'
leaf-agent
left a comment
There was a problem hiding this comment.
The six nightly cases from the last review pass at this head, and the margin file is
green (tests/test_render_margin.py 103 passed, -n0 for the three that time out under
-n4). One new nightly case is red, and it is this commit's own selector edit.
test_render_widgets.py::test_suggestion_emphasis_skips_generated_interface_between_changed_words
fails deterministically here. It is a strict-mode violation rather than timing:
.lf-margin-entry now matches the reading marker and the cluster's hidden
lf-margin-more button, because both carry that class. [role="button"] used to
separate them. .lf-margin-marker is the element the test means; with it the case passes
in 9s. Inline suggestion below. The file is pytest.mark.nightly, so test is green
while this is red, and merging lands it on main's scheduled run.
context.origin === document.activeElement is not the reading of "the reader is
holding this control" that the runtime already owns. keyboard/scopes.js says so in
the header above focused() — "Where the reader is standing, which is not always what
document.activeElement answers. Focus inside a shadow tree retargets to the host, while
the label transition above can report body" — and reactions.js passes
origin: focused() into this very call. So for a reaction margin entry the comparison
tests a deep, label-aware standing against a retargeted one, and disagrees precisely in
the two cases focused() exists for. A second class of caller never matches either:
dispatch.js's routed invocation runs reference.control.click(), and a programmatic
click does not focus, so a numbered Ask route or a command-reference invocation reads as
"not focused" even when the reader is standing on the control.
That matters because a shipped widget consumes the capability. lf-suggestion's
activate: (activation, {focus}) => this.#decide(activation, focus) carries it into
#inFlight, which uses it twice — this.#refreshMargin({immediate: Boolean(focus)}) and
focus?.("undo"). A null focus therefore also drops the synchronous
layoutMarginRows(), and the fallback refocus then resolves through
control(key, surface, true), whose checkVisibility() gate reads rows that have not
been packed. Two smaller points on the same expression: the guard sits outside the ??,
so it discards a context.focus the caller deliberately supplied — controlsOf's
onclick passes one under the comment "A contributor can replace the activated entry and
ask to retain focus" — and null rather than a no-op means focus(key) throws for any
package that does not write focus?.(key), while packages.md still calls it "a focus
capability".
The new reading scope asks the DOM for a fact it just wrote. when: () => control.matches('[role="button"]:not([aria-disabled="true"])') re-reads role and
aria-disabled that presentMarginEntryHost set from the record a moment earlier, where
the code it replaces asked records.get(control)?.behavior and record.disabled
directly. CLAUDE.md's The document starts state; the log changes it is explicit that
renderings are not semantic authority. The same row already calls
marginEntryRecord(control) twice, so the record is one read away — and that accessor
throws where the old records.get(control)?.behavior returned undefined, which is safe
today only because merge happens to drop a section whose when() is false. While
there: readingBehavior returns only "status" or "disclosure", so the
"Go to what the focused margin entry points at" / "go to it" branch can only describe
a status — which this same when declares unavailable. It is unreachable text.
shownControls is now a set of every control, so the six filters that read it are
vacuous. Deleting controlsShownByOwner left a set built from
pageInventory.flatMap((entry) => entry.offers.flatMap(controlsOf)) under the comment
"Read contributor visibility once for the whole render, before folding any controls" —
no visibility is read, and every entry.shownControls.has(control) test
(in directControlRecords, secondaryCount, the option nodes, syncControls) is
unconditionally true. Declared visible on the record is the right replacement for the
probe; the leftover set and its call sites read as live placement logic and should go
with it.
…hot flip's margin command, and a ring specimen behind a closed tab (#734) The nightly suite went red on main with 4 failures and 22 errors ([run 34960165078](https://github.com/max-sixty/leaf/actions/runs/34960165078)). Three durable causes account for 25 of those 26 nodes; the fourth was already repaired by #732, which merged 24 minutes after the run started. Each cause is one commit here. **The website adapter 404s the startup beacon.** #717 added the public startup report, handled it in `worker/src/index.ts`, and required it in `scripts/verify_site.py` — but `worker/server.py` never learned the route. Every released document posts to `<page>/api/performance`; the deployed site answers at the edge, and a site served straight from the adapter has no edge in front of it, so the POST fell through to the base handler's 404. That is a console error on every page the adapter serves, which is why one missing route reddened 23 nodes of the suite's clean-console reading. The adapter now answers 204 at its own boundary, the way `end_headers` already adds the `Leaf-Session` reading the Worker would have. **`lf-shot`'s margin entry lost the flip's name.** #716 replaced adopted source controls with immutable margin projections and deleted contributor-owned margin command rows, adding a `marginEntry` `scope` option to carry the declaration across to a control the margin generates. `lf-draft` was cut over in that commit; `lf-shot` was not, so standing on Show before / Show after left the shortcut bar with nothing to say about the flip. It is now one `commandScope`, attached to the widget's own checkbox and projected onto its margin entry. **A ring specimen moved behind a closed tab.** #721 added an example that sorts ahead of `triage-board` in the corpus, so the first `.lf-grip` landed in a tab panel that arrives hidden. Nothing inside it is focusable, so the sweep read a ring the grip paints perfectly well as undrawn. The sweep now asks the runtime's `reveal()` before focusing, deriving the surface from where the specimen sits instead of from a tab order that follows the examples directory. The fourth failure, `test_conversation_readiness_waits_for_the_keyed_thread_list`, raised `Page.evaluate: Resulting promise was garbage collected` from the `armed` re-entrancy hack around `scheduleUpdate`. #732 replaced that arrangement with an explicit `performUpdate` hold, and the test passes on main as it stands. Nothing here touches it. <details><summary>Verification</summary> Each regression was reproduced on main and bisected to its origin with `git bisect run`, one node id per run under `-n0`: the shot regression to e790513 (#716), the ring regression to eb055b1 (#721). The adapter 404 is not a bisect — the route has never existed in `server.py`; it reproduced directly and the fix clears it. On this branch: - `tests/test_render_controls.py` — all passed, ring sweep included. - `tests/test_site.py` — 1 failed of 136. `test_the_interaction_gallery_drives_real_widgets` expected `Playing`; it passes alone under `-n0` and passed in the failing run above, so it is timing under parallel load rather than this diff. - `tests/test_render_commands.py`, `tests/test_render_margin.py`, `tests/test_website_server.py` — 193 passed, 4 failed. All four are `bin/leaf` subprocesses reporting `no browser launched`; each reproduces on unmodified main in this sandbox and each was green in the failing run above. - `uv run pytest tests` — 1119 passed, 4 failed: the umask, read-only `/tmp`, and `bundleLayer` cases this sandbox cannot run. - Changed-file pre-commit hooks pass. No TypeScript changed, so the website-worker gate is unaffected. </details> --------- Co-authored-by: leaf-agent <[email protected]>
Summary
marginEntryrecords and one registration-owned activation boundaryWhy
Margin contributions used to be mutable DOM controls that Margin adopted and Page Map proxied. That made a hidden source element both presentation and semantic authority, duplicated reconciliation across surfaces, and prevented a canonical Lit renderer from owning either projection.
This is a hard cutover to one immutable contribution grammar. Opaque contribution and entry identities retain generated hosts structurally while actions and disclosures remain native buttons and statuses remain inert spans. One shared presenter owns complete semantic attributes, core lifecycle readings alone retain their adaptive host, and each surface owns only its own face and mechanical context.
Verification
uv run pytest -q— 1,120 passeduv run pytest -q -n0 tests/test_render_margin.py— 103 passednpm run check:browserandnpm run test:browser— 36 passeduv run pre-commit run --all-files