Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -26699,9 +26699,9 @@ def bracket():
""",
)

# main's content box, body's, and where three elements stand in them. Read together in
# one pass because the whole subject is their relation: a width means nothing here except
# against the column it is or isn't wider than.
# main's content box, body's, the page's own box, and where each named element stands in
# them. Read together in one pass because the whole subject is their relation: a width
# means nothing here except against the column it is or isn't wider than.
ROOM_GEOMETRY = """() => {
const span = (el) => {
const s = getComputedStyle(el), b = el.getBoundingClientRect();
Expand All @@ -26717,8 +26717,22 @@ def bracket():
top: b.top, bottom: b.bottom,
centre: (b.left + b.right) / 2 };
};
// The page's box: what body's padding is spent out of and the column centres in.
// It is not the window. Body owns the document's scroll and reserves a stable
// gutter for it (leaf.js), so wherever a scrollbar takes room the page is that
// much narrower than the window and stands half of it to the window's left — a
// settled decision made where the gutter is, and one no strip has a part in.
// Padding included, because a strip taken here moves the column inside a box that
// has not changed size; `room` above is what the strips left and so cannot say
// where the edge they came out of is.
const page = () => {
const b = document.body, s = getComputedStyle(b);
const left = b.getBoundingClientRect().left + parseFloat(s.borderLeftWidth);
return { left, right: left + b.clientWidth, width: b.clientWidth,
centre: left + b.clientWidth / 2 };
};
return { column: span(document.querySelector('main')),
room: span(document.body),
room: span(document.body), pageBox: page(),

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.

room now sits beside pageBox answering the same question two different ways. span() takes its right edge as getBoundingClientRect().right - paddingRight, and that rect is body's border box, which contains the reserved gutter — so wherever a scrollbar takes room, room.right is 15px past where content can actually go. That is the reading this PR is removing from the note test, still in place one line above it.

Three assertions use room.right as the page's right edge: "past the page, right" in test_a_widget_that_declares_width_takes_the_room_and_the_column_stays_put and in test_a_copy_reads_the_room_from_its_own_window, and "the exhibit hangs over the panel that displaced it" in test_a_wide_widget_gives_the_panel_its_strip. The copy one is honest — :where(html:not(.lf-copy)) withholds the scroll arrangement, so body isn't the scroll container there and its border box already excludes the viewport's scrollbar. The other two are 15px looser on the runner than they read.

Nothing is red today: sideways == 0 stands beside both of them and catches overflow that reaches scrollWidth. But the bound still states something weaker than its message claims, and after this diff the next test wanting "the page's right edge" gets the window's from room and the page's from pageBox, with only the comment on page() to say which is which. Taking span's edges off clientWidth — the padding box less any gutter — rather than off the rect would let one answer serve both, and page() would then be the same reading without the paddings subtracted.

Not for this PR: it tightens assertions in two other tests and would want its own bug-back to show the direction of the failure moved as intended (tests/CLAUDE.md, "Bounds and geometry tests are especially prone to staying green after the fault moves to another edge"). Worth not leaving implicit, though, right beside a comment that spends six lines explaining the gutter.

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.

Measured it on this runner rather than leaving it as arithmetic. On WIDE_AND_NARROW_PAGE at a 1200px window: room.right is 1200, pageBox.right is 1185, and body's offsetWidth - clientWidth is that same 15. So the two readings sitting next to each other differ by exactly the gutter, on every assertion that treats room.right as the page's right edge. The runtime already takes the gutter that way — leaf.js#L4526 computes it as offsetWidth - clientWidth — which is the direction taking span's edges off clientWidth points in, and it would let page() be the same reading with the paddings left in.

Agreed it stays out of this PR. It moves a bound in two tests whose subject is width rather than the axis, so it is revertable independently of this change, and tests/CLAUDE.md's "bounds and geometry tests are especially prone to staying green after the fault moves to another edge" is exactly the case — it wants its own bug-back showing the direction of the failure moved as intended, which is a different piece of evidence from the two in the description here.

Not opening it as a follow-up right now either: eleven bot PRs are open against one maintainer, so this is recorded here rather than added to that queue.

board: box('sprint'), diff: box('patch'), prose: box('prose'),
note: box('note'), later: box('later'),
sideways: document.body.scrollWidth - document.body.clientWidth };
Expand Down Expand Up @@ -27910,29 +27924,42 @@ def test_a_note_sets_the_page_axis_with_its_whole_strip(browser, serve):

Both widths matter. The wide one proves the claim is the axis rather than only the
shortfall, and the tighter one proves that keeping the whole claim still leaves the
note on the page without horizontal scrolling."""
note on the page without horizontal scrolling.

Every reading is against the page's box rather than the window, the two being the
same width only where a scrollbar takes no room. Body owns the document's scroll and
reserves a stable gutter for it, so on most platforms the page is 15px narrower than
the window and sits 7.5px to its left — a settled fact about the scroll region
(leaf.js) that the strip has no part in. Measured from the window this says that
instead of what it is about: green wherever scrollbars overlay, red on the runner,
and in both a note painted out in the gutter counted as a note still on the page."""
url = serve(NOTE_AND_WIDE_PAGE)
page, errors = open_page(browser, url)

resized(page, 1600, 900)
roomy = page.evaluate(ROOM_GEOMETRY)
assert abs(roomy["column"]["centre"] - (1600 - 384) / 2) <= 1, (
axis = roomy["pageBox"]["left"] + (roomy["pageBox"]["width"] - 384) / 2
assert abs(roomy["column"]["centre"] - axis) <= 1, (
f"the right strip did not set the page's axis: column centred at "
f"{roomy['column']['centre']:.0f}px of 1600px"
f"{roomy['column']['centre']:.0f}px of a "
f"{roomy['pageBox']['width']:.0f}px page"
)
assert roomy["note"]["right"] <= 1600, (
f"the note is off the right edge at 1600px: {roomy['note']['right']:.0f}px"
assert roomy["note"]["right"] <= roomy["pageBox"]["right"], (
f"the note is off the right edge of a "
f"{roomy['pageBox']['width']:.0f}px page: {roomy['note']['right']:.0f}px"
)

resized(page, NOTE_BAND, 900)
tight = page.evaluate(ROOM_GEOMETRY)
assert abs(tight["column"]["centre"] - (NOTE_BAND - 384) / 2) <= 1, (
axis = tight["pageBox"]["left"] + (tight["pageBox"]["width"] - 384) / 2
assert abs(tight["column"]["centre"] - axis) <= 1, (
f"the tighter page lost the note-set axis: column centred at "
f"{tight['column']['centre']:.0f}px of {NOTE_BAND}px"
f"{tight['column']['centre']:.0f}px of a "
f"{tight['pageBox']['width']:.0f}px page"
)
assert tight["note"]["right"] <= NOTE_BAND, (
f"the note is off the right edge at {NOTE_BAND}px: "
f"{tight['note']['right']:.0f}px"
assert tight["note"]["right"] <= tight["pageBox"]["right"], (
f"the note is off the right edge of a "
f"{tight['pageBox']['width']:.0f}px page: {tight['note']['right']:.0f}px"
)
assert tight["sideways"] == 0

Expand Down