Skip to content

Read markHere in the module that defines it, not in the file it left - #51

Closed
leaf-agent wants to merge 2 commits into
mainfrom
fix/ci-33003757211
Closed

leaf-agent wants to merge 2 commits into
mainfrom
fix/ci-33003757211

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Problem

ci on main is red at tests/test_interact_document.py::test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag. The commit under it, 9664448 ("Split ask model and view runtimes"), moved markHere out of leaf.js into runtime/asks/view.js and changed no behaviour. The test read the function out of leaf.js by name, so the split took its grounding with it and the assertion failed for the one thing it does not mean to hold still — which file the runtime keeps a writer in.

Solution

The test asks whether markHere still writes PAGE_PAINT_ATTRIBUTE.ask, because the theme's :not(:where([data-lf-ask]) *) exclusions answer for a mark nothing would otherwise leave on the page. Which module holds markHere is a separate fact about the runtime's own composition, so the reading no longer asserts it: _runtime_function(name) in interact_support.py walks leaf.js and runtime/**/*.js, requires exactly one module to define the name, and returns that function's source.

The bound is the second half of the fix, and it makes the reading stricter than the one it replaces. The old function markHere\(\)(?:.|\n)*?PAGE_PAINT_ATTRIBUTE\.ask had no end, so any later writer in the same file could answer for markHere. _runtime_function stops at the closing brace standing at the declaration's own indentation — which prettier guarantees, and which a brace count over strings, comments, and ${} holes does not.

Testing

uv run pytest tests -q — 585 passed, 6 skipped; the one error is this sandbox having no Chromium installed (test_smoke.py browser gate), unrelated to a file-side change. pre-commit run --files on both changed files passes. The nightly test_render_* modules need that browser, and this change touches no runtime, theme, or registry source, so CI covers them.

Bug-backs run against the working tree, each reverted after:

Bug-backs
  • The paint leaves markHere, a later writer in the same file keeps it. Rewrote markHere's body to PAGE_PAINT_ATTRIBUTE.exhibit and appended a decoyPaint function writing PAGE_PAINT_ATTRIBUTE.ask after it. The new reading fails; the regex it replaces returns a match on that same file, which is the vacuity the bound closes.
  • Two definitions. Added a second function markHere() to runtime/asks/model.js — fails with the runtime defines markHere() 2 times, rather than reporting on whichever file the walk reached first.

Automated fix for failed run

The ask runtime split moved markHere into runtime/asks/view.js, and the
theme-exclusion test read it out of leaf.js by name, so a commit that changed
no behaviour reddened main.

Read the function through _runtime_function, which finds the single module
defining it and bounds the source at the closing brace standing at the
declaration's own indentation. That is also stronger than the search it
replaces: the old unbounded regex ran past markHere and would have accepted a
later writer in the same file painting the mark markHere had stopped painting.

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

One observation on _runtime_function, plus what I checked.

The fix is right about the coupling it removes, and the bound is real — I read the returned source back for markHere and it stops at runtime/asks/view.js's closing } at declaration indentation, 17 lines, not one writer further. The bug-backs in the description cover both the vacuity the old unbounded regex allowed and the two-definitions case.

What the fix narrows rather than removes is the shape of the declaration. opening matches function NAME( only, and runtime/asks/view.js already mixes both forms — readingBlock sits three lines under markHere as a const … = () =>. So rewriting markHere into that form changes no behaviour and still reddens the suite, which is the case this PR exists to close, and the message it fails with sends the reader looking for a function that left the layer rather than one that changed shape. Widening the pattern means a second close form (}; for the expression), which is more machinery than the case earns; naming the actual reading in the message costs nothing and makes that false red self-diagnosing.

Checked
  • uv run pytest tests/test_interact_document.py -k ancestor_exclusions -n0 passes.
  • re is still used throughout test_interact_document.py after the removed js = … line, and nothing else in that test referenced js.
  • The from interact_support import (…) insertion keeps isort order (_report < _runtime_function < _status); ci's lint is green on this head.
  • No existing helper in interact_support.py reads a runtime function by name — the neighbouring readings (_paint_names, _marker_for) take module-level constants out of presentation.js by path, which is a different question.
  • The walk covers assets/leaf.js and assets/runtime/**/*.js and does not reach assets/vendor/, so the highlight bundle is not scanned.
  • ci's test was still in progress when I read the rollup.

Comment thread tests/interact_support.py Resolved
`_runtime_function` reads a `function NAME(` declaration and no other form, and
`runtime/asks/view.js` already mixes both — `readingBlock` sits three lines under
`markHere` as a `const … = () =>`. Rewriting `markHere` into that form changes no
behaviour and still reddens the suite, which is the case this branch exists to
close, and the message it failed with sent the reader looking for a writer that
had left the layer rather than one that had changed shape.

Widening the pattern needs a second close form for the expression, which is more
machinery than the case earns. Naming the actual reading costs nothing and makes
that false red self-diagnosing.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

ci on main failed again with this same assertion on run 33006152625 (commit 803c593, "Split selection comment runtime") — same test, same assert None, and the cause is unchanged: markHere is defined in plugins/leaf/skills/leaf/assets/runtime/asks/view.js, and the assertion reads it out of leaf.js. Nothing in 803c593 touches markHere; it is 9664448 still, surfacing on every commit that follows it.

The three commits main has taken since this branch's base (803c593, da57c46, 8ba3077) all split further runtime out of leaf.js, so the question worth checking was whether the _runtime_function walk still finds markHere under them. It does: merging current main (8ba3077) into fix/ci-33003757211 locally, uv run pytest tests/test_interact_document.py -q -n0 is 90 passed. At main's head without the branch, the single test still fails with the same assert None, so the two ci runs in flight on da57c46 and 8ba3077 will land red the same way.

No new fix opened — this PR is the fix.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Superseded — main fixed this test itself. 3b9ea44 ("Add contextual glosses to authored text") carries Update the ask-marker architecture test to read markHere from its split runtime module, and points the assertion at runtime/asks/view.js directly. So the premise this PR was opened on — ci red on main at test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag — is gone, and the two runs the comment above predicted red (33007056265 on da57c46, and the one on 8ba3077) were the last of them.

Verified on main at 3b9ea44: uv run pytest tests/test_interact_document.py -q -n0 is 90 passed. This branch now conflicts with main in exactly that hunk, so there is nothing left here to merge as a fix.

Closing rather than rebasing: 3b9ea44 is a decision about how this assertion should find markHere, and re-proposing _runtime_function over it would be arguing the same point twice. The branch is left in place — the part that does not overlap 3b9ea44 is the bound (the current regex still has no end, so a later writer in view.js can answer for markHere), and it is reachable here if that turns out to be worth a separate change.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Agreed on the close — ci is green and the premise this was opened on is gone.

One thing the supersession leaves behind, though: 3b9ea44 repointed the assertion at runtime/asks/view.js rather than removing the path from it, so the coupling that produced the red is intact — this is the second path the reading has been pinned to, and main is mid-way through a run of runtime splits. The unbounded (?:.|\n)*? is still there too, which lets any later writer in the same file answer for markHere.

Carried the path-independent, bounded reading onto main on its own in #55, with a bug-back showing the pinned regex failing where the new reading holds.

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

`seenScroller` asked the layout, not the reader: `panelCovers() ?
threadsBox : pageScroller`. Beside the page — the ordinary wide window —
a reader standing in the comment list pressed `d` and the document
behind them stepped instead. That is the same nothing the covering rule
was written to prevent: the region being read does not move, and the
document is somewhere else when the reader looks back at it. This is
item 1 of #53.

## Solution

Focus is the first answer, covering is still the second: `inPanel() ||
panelCovers()`. The second is not the first restated — under the sheet
the reader may be standing outside the panel altogether (the Comments
button that raised it is the banner's), and the page behind the sheet is
a page nobody can see. Focus says which region is the reader's; covering
says which one the window will show them.

`inPanel` is one predicate rather than two readings of the same line —
`PANEL.at` was already spelling it (`panelOpen && containsAcross(panel,
focused())`) and now reads it from the same place.

`seenScroller` also serves the chord's `g g` / `g G`, so those edges now
name the list's top and bottom when the reader is standing in it. That
follows the same sentence the row already lived by under a covering
panel, and keeping one reading of "the box the reader is reading" is
what stops the two coming apart — but it is the one behaviour change
here beyond `d`/`u`, so it's worth a maintainer's eye.

Items 2–4 of #53 are design calls left untouched; I've commented on the
issue with what the code says about each.

## Testing

`test_the_half_page_keys_follow_the_reader_into_the_panel` in
`tests/test_render_drafts.py`, beside the existing
`..._move_the_region_the_reader_is_scrolling`. One factor separates its
two presses — the window, the layout, the panel and the list are
identical, and only where the focus stands changes — so the first press
is the control that says the panel is beside the page (focus on the
banner button, the document steps), and the second is the subject (focus
on the list via `c`, the list steps). It fails on the current runtime at
`assert 0 > 0` — the list did not move — and passes with the fix.

Also run: `tests/test_render_navigation.py` (38 passed),
`tests/test_render_drafts.py` + `tests/test_render_conversations.py` (81
passed), and `uv run pytest tests` (585 passed, 1 failed). That one
failure is
`test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag`, which
fails identically on this branch's base with the change stashed; #51 is
the open fix for it.

---
Refs #53 — automated triage

---------

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

`seenScroller` asked the layout, not the reader: `panelCovers() ?
threadsBox : pageScroller`. Beside the page — the ordinary wide window —
a reader standing in the comment list pressed `d` and the document
behind them stepped instead. That is the same nothing the covering rule
was written to prevent: the region being read does not move, and the
document is somewhere else when the reader looks back at it. This is
item 1 of #53.

## Solution

Focus is the first answer, covering is still the second: `inPanel() ||
panelCovers()`. The second is not the first restated — under the sheet
the reader may be standing outside the panel altogether (the Comments
button that raised it is the banner's), and the page behind the sheet is
a page nobody can see. Focus says which region is the reader's; covering
says which one the window will show them.

`inPanel` is one predicate rather than two readings of the same line —
`PANEL.at` was already spelling it (`panelOpen && containsAcross(panel,
focused())`) and now reads it from the same place.

`seenScroller` also serves the chord's `g g` / `g G`, so those edges now
name the list's top and bottom when the reader is standing in it. That
follows the same sentence the row already lived by under a covering
panel, and keeping one reading of "the box the reader is reading" is
what stops the two coming apart — but it is the one behaviour change
here beyond `d`/`u`, so it's worth a maintainer's eye.

Items 2–4 of #53 are design calls left untouched; I've commented on the
issue with what the code says about each.

## Testing

`test_the_half_page_keys_follow_the_reader_into_the_panel` in
`tests/test_render_drafts.py`, beside the existing
`..._move_the_region_the_reader_is_scrolling`. One factor separates its
two presses — the window, the layout, the panel and the list are
identical, and only where the focus stands changes — so the first press
is the control that says the panel is beside the page (focus on the
banner button, the document steps), and the second is the subject (focus
on the list via `c`, the list steps). It fails on the current runtime at
`assert 0 > 0` — the list did not move — and passes with the fix.

Also run: `tests/test_render_navigation.py` (38 passed),
`tests/test_render_drafts.py` + `tests/test_render_conversations.py` (81
passed), and `uv run pytest tests` (585 passed, 1 failed). That one
failure is
`test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag`, which
fails identically on this branch's base with the change stashed; #51 is
the open fix for it.

---
Refs #53 — automated triage

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
max-sixty added a commit that referenced this pull request Oct 12, 2026
… pages and exports (#2549)

From the review of the Lit survey PRs (item #51 in that review's
numbering, not a GitHub issue).

**#51: a command scope's attachment reads its own element only.** An
imperative `keys()` attach called `paintKeys()`, which made the next
frame re-read the `aria-keyshortcuts` of every scoped element on the
page. A declaration changes no other element's shortcuts, and the
attached element was already read on its own at the head of the next
frame (`unpainted`, drained by `reflectFirstScopes`). So `attachScope`
now only schedules that frame, the same rule #2504 gave a `commandsOn`
re-render. `commandsOn`'s two attach branches become one `attachScope`
call, `standScope` folds into `attachScope`, and the directive's
withdrawal schedules a frame instead of a page-wide pass, since
`detachScope` already re-reads the element.

**Interactive exports now take that reading too.** An export's repaint
frame mounted only `reflectKeys`, so it never drained `unpainted` or ran
the head-of-frame button passes. Before this PR, the attach's own
`paintKeys()` was what read a late scope there. Even then, a
`commandsOn` re-render or withdrawal in an export was read only if
another owner dirtied the frame. The export now mounts
`reflectFirstScopes` as well (`leaf.js`), and `repaint.js` records that
the two key slots go together. I found no shipped page where an export
showed the gap: a test exporting a screenshot comparison, whose divider
attaches after presentation, passed with and without this change,
because another owner dirties that frame. So the PR adds no browser test
for it.

Behaviour that changed: an attach no longer marks the whole page's
shortcuts for re-reading. A scope that a painter attaches mid-frame (the
banner's touch controls, 18 per page) now gets its `aria-keyshortcuts`
at the head of the next frame rather than at the tail of the current
one.

Measured:

| | `paintKeys()` on attach (main) | this PR |
|---|---|---|
| happy-dom, one `keys()` attach beside 300 scoped elements:
`getAttribute` calls | 1,813 | 7 |
| happy-dom, same, time per attach | 1.4 ms | 0.19 ms |
| Chrome, full `reflectKeys` passes over one key journey (review-a-plan
/ triage-board / pr-walkthrough / ship-review / command-hub) | 9 / 3 / 6
/ 10 / 4 | 9 / 3 / 6 / 10 / 4 |

On the shipped pages, the change saves no full passes: in each frame
where an attach lands, another owner has already called `paintKeys()`.
The saving is for an attach in an otherwise quiet frame on a page with
many scoped elements. The case for the change is that both attachment
paths now follow one rule, which removes a branch.

History: `keys()` called `repaint()` until #1788 changed it to
`paintKeys()`, the same commit that added the button-availability pass
to `reflectFirstScopes`. That commit gives no reason for the switch, and
that button pass now runs at the head of every frame either way.

Line deltas:

| | source | tests |
|---|---|---|
| #51 (`keyboard/scopes.js`, `repaint.js`, `leaf.js`) | −9 (+21 −30) |
+8 (+9 −1) |

Checks: all 361 runtime tests. The extended `command-controls` case
attaches imperatively beside another scoped element and asserts that the
other element isn't read; that assertion fails on `main`. Also 63
browser cases that assert `aria-keyshortcuts`, the shortcut bar or the
command reference, run from `test_render_navigation`, `_controls`,
`_anchors`, `_options`, `_widgets`, `_margin`, `_threads`, `_reactions`,
`_drafts`, `_projection` and `_semantic_selection`, plus six
interactive-export cases in `test_render_export`.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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.

1 participant