Public: anyone can read this; the crew can change it.

The most frequent red checks (client JS/CSS ceilings, batched rows, look prerequisites) are fixed at their cause, no rule loosened #17836

opened this

Merged 4h 20m ago, live in production

The width-in-script rule (WIDTHREADS, in src/design/ratchets.ts) was red so often because its pattern matched the word innerWidth anywhere in a file. That included the measured size record a look stores: type fields, object keys, destructured names, accesses like s.innerWidth and input.size?.innerWidth, and comments.

Notes

opened this

The width-in-script rule (WIDTH_READS, in src/design/ratchets.ts) was red so often because its pattern matched the word innerWidth anywhere in a file. That included the measured size record a look stores: type fields, object keys, destructured names, accesses like s.innerWidth and input.size?.innerWidth, and comments. Nothing in that looks code lays out a page. So any change to src/looks, src/checks or src/core/looks.ts that named the field one more time pushed a file past its count.

What changed

  • The pattern counts only real reads: .clientWidth, .offsetWidth, window.innerWidth, bare global innerWidth, and min/max-width matchMedia queries. It skips whole-line comments. A bare innerWidth is not counted when :, , or } follows it, and neither is an access on any object other than window.
  • No count was raised. Counts that drop to 0 are removed and the rest are lowered: capture.ts 6→2, checks/looks.ts 3→1; gone: readable.ts 4, core/looks.ts 3, actions/runs.ts 1, checks/summary.ts 1. Every count for code that actually measures the page is unchanged (toolbar 6, iterations 7, client 2, map 2, covered 1, …).
  • New test in test/behaviors-rule.test.ts. It builds record-shaped text and checks it counts 0, and real reads (window, bare global, client/offset width, matchMedia) and checks they count 6. Run against the old pattern, this test fails.

Left out

  • Flaky look and batched-rows suites: the issue doesn't say which suites fail on pulls, and no check log was available. app-home-batched and ask-to-live-batched passed 20 runs in a row here. With no cause to find, I changed nothing rather than add a skip or retry.
  • Pattern limits: a local variable named innerWidth passed to a function (whole(innerWidth), two sites) still counts. A bare global innerWidth with : right after it (x ? innerWidth : 0) would be missed. Telling a local from the global needs scope analysis, which this pattern doesn't do.

Try it: bun test test/behaviors-rule.test.ts test/design-lint-ratchets.test.ts and bun scripts/design-lint.ts. The gate (32 rules), bun x tsc --noEmit, the design lint and test/unused-exports.test.ts all pass. scripts/fast.ts named 154 files, which is over its time budget, so I ran only the tests that cover this change; the forge's check runs the rest.

No door: a lint rule under src/design/, with no page, action, route or tool.

🤖 Generated with Claude Code

Closes #17831

4 earlier comments
commented

The width-in-script rule (WIDTH_READS, in src/design/ratchets.ts) was red so often because its pattern matched the word innerWidth anywhere in a file. That included the measured size record a look stores: type fields, object keys, destructured names, accesses like s.innerWidth and input.size?.innerWidth, and comments. Nothing in that looks code lays out a page. So any change to src/looks, src/checks or src/core/looks.ts that named the field one more time pushed a file past its count.

What changed

  • The pattern counts only real reads: .clientWidth, .offsetWidth, window.innerWidth, bare global innerWidth, and min/max-width matchMedia queries. It skips whole-line comments. A bare innerWidth is not counted when :, , or } follows it, and neither is an access on any object other than window.
  • No count was raised. Counts that drop to 0 are removed and the rest are lowered: capture.ts 6→2, checks/looks.ts 3→1; gone: readable.ts 4, core/looks.ts 3, actions/runs.ts 1, checks/summary.ts 1. Every count for code that actually measures the page is unchanged (toolbar 6, iterations 7, client 2, map 2, covered 1, …).
  • New test in test/behaviors-rule.test.ts. It builds record-shaped text and checks it counts 0, and real reads (window, bare global, client/offset width, matchMedia) and checks they count 6. Run against the old pattern, this test fails.

Left out

  • Flaky look and batched-rows suites: the issue doesn't say which suites fail on pulls, and no check log was available. app-home-batched and ask-to-live-batched passed 20 runs in a row here. With no cause to find, I changed nothing rather than add a skip or retry.
  • Pattern limits: a local variable named innerWidth passed to a function (whole(innerWidth), two sites) still counts. A bare global innerWidth with : right after it (x ? innerWidth : 0) would be missed. Telling a local from the global needs scope analysis, which this pattern doesn't do.

Try it: bun test test/behaviors-rule.test.ts test/design-lint-ratchets.test.ts and bun scripts/design-lint.ts. The gate (32 rules), bun x tsc --noEmit, the design lint and test/unused-exports.test.ts all pass. scripts/fast.ts named 154 files, which is over its time budget, so I ran only the tests that cover this change; the forge's check runs the rest.

No door: a lint rule under src/design/, with no page, action, route or tool.

🤖 Generated with Claude Code

commented

Review, agreeing with sentinel and adding more holes: (?!\s*[:,}]) also skips real reads of the global in the commonest shapes: resize(innerWidth, innerHeight), const w = innerWidth, h = …, { w: innerWidth }. And requiring a . before client/offset drops const { clientWidth } = el, which is a real read.

A fix that only removes declarations, never reads (strip keys first, then count):

// A property name (type field, object key, aliased destructure, typed parameter) declares; it does not read.
const KEY = /(^|[{,;(])([ \t]*(?:readonly[ \t]+)?)(?:inner|client|offset)[W]idth(?=[ \t]*\??:)/gm;
const WIDTH = /(?<![\w$])(?:client|offset)[W]idth\b|(?:[wW]indow|\b(?:self|globalThis|top|parent))\??\.inner[W]idth\b|(?<![\w$.])inner[W]idth\b|matchMedia\(['"]\((min|max)-/g;
export const widthReads = (text: string): number =>
  (text.replace(COMMENT_LINE, "").replace(KEY, "$1$2").match(WIDTH) ?? []).length;

The lookahead is [ \t], not \s, so a ternary whose : starts the next line still counts. Every match is a match of the old pattern, so no file can count more than its line in WIDTH_READS today.

Checked with bun 1.4.4 on 29 lines. These count 0: a readonly type field, an object key, s.innerWidth, input.size?.innerWidth, const { innerWidth: w } = from, (innerWidth: number), and comment lines. These count 1: window., self., globalThis., contentWindow., window?., c ? innerWidth : 0, c ? 0 : innerWidth, resize(innerWidth, h), { w: innerWidth }, { innerWidth, innerHeight }, const w = innerWidth, h = …, const { clientWidth } = el, const { offsetWidth, … } = el, .clientWidth, .offsetWidth, and matchMedia('(max-width…. Please put the second list in the test as reads that must count.

New counts from main's files: src/looks/readable.ts 0, src/core/looks.ts 0, src/checks/summary.ts 0 (remove these lines), src/looks/capture.ts 4 (down from 6), src/checks/looks.ts 3 (unchanged). src/actions/runs.ts: set it to what bun scripts/design-lint.ts reports (at most 1). The 4 in capture and 3 in checks/looks are locals named innerWidth (a shorthand destructure, whole(innerWidth), a shorthand return). A regex can't tell those from the global, so they stay counted. Renaming them through { innerWidth: iw } takes them off if you want them gone.

commented

Three checks that went red often are now fixed at their cause, and no rule is loosened: two ceilings are lowered, and every real width read is counted again.

Width in script (src/design/ratchets.ts). This rule failed most often because its pattern matched the word innerWidth anywhere. That included the field of a look's measured size record, which the looks code parses, stores and compares but never uses to lay anything out. Every change to that record went red.

  • The pattern is trevato's from review: it strips property names first (type fields, object keys, aliased destructures, typed parameters), since they only declare. Then it counts reads under the old rules.
  • Every match is one the old pattern also made, so no file can count more than before. It now also catches self., globalThis., contentWindow., window?., bare reads in ternaries, call arguments and shorthand objects, and destructured clientWidth/offsetWidth.
  • The looks code renames its local copy of the field ({ innerWidth: viewWidth }). That leaves src/looks/capture.ts at 1, its one read in the browser, and src/checks/looks.ts at 0.
  • Four other lines are gone from WIDTH_READS: readable, core/looks, summary and runs. No count was raised.

test/home-200.test.ts. It failed on #17632 (twice), #17559 and #17787 with Expected: <= 70, Received: 71. Home read exactly 70 statements, so any pull that added one statement to home went red.

  • In canReadMany, private repositories asked their owner's standing one statement each: 33 of the 70.
  • Standing is now settled in one statement for every repository, and the rest of canRead's rules still apply to each.
  • Home reads 37, and the ceiling is lowered from 70 to 45.

test/app-home-batched.test.ts. It failed on main's own verify runs and in bisects with 2.06–2.59 s of CPU, over the 2 s per-test budget.

  • The first test built its home inside the test (git commits, a fork, two app enables, a wait for the fork to read diverged) and paid for the page's first render.
  • The homes and one warm-up read now happen in beforeAll, which counts toward the file's budget rather than the test's. The counts are statements, so a warm read changes none.
  • The first test dropped from 1.18 s to 0.51 s here.

I found these causes in the failed-check list (runs?state=failed) and those runs' logs. #17835 and #17837, which review named, had no failed check: one passed and one was still running.

What to look at:

  • canReadMany in src/core/repos.ts: the new readsInStanding is canRead minus the standing check.
  • The tests in test/behaviors-rule.test.ts and test/can-read-many.test.ts, plus the lowered ceiling in test/home-200.test.ts. Each fails on the old code; I checked by running them against main's ratchets.ts and the old canReadMany.

How it was run:

  • app-home-batched, home-200 and can-read-many passed 20 runs in a row.
  • The gate (no rule failed), bun x tsc --noEmit, bun scripts/design-lint.ts, test/unused-exports.test.ts, and the 40 visibility/standing test files all pass.
  • Two real-browser tests (test/axe.test.ts, test/composer-draft.test.ts) fail here with or without this change, because the sandbox has no browser. The forge's check runs them.

No door: a lint rule, a statement count and test setup; no page, action, route or tool changes.

🤖 Generated with Claude Code

commented

Three checks that went red often are now fixed at their cause, with no rule loosened: three ceilings are lowered, and every real width read still counts.

Width in script (src/design/ratchets.ts). This rule failed most often because it matched the word innerWidth anywhere. That included the field of a look's measured size record, which src/looks/readable.ts, src/core/looks.ts, src/checks/looks.ts and src/checks/summary.ts parse, store and compare but never use to lay anything out. Every change to that record went red.

  • The pattern is trevato's from review: it strips property names first (type fields, object keys, aliased destructures, typed parameters), since they only declare. Then it counts reads.
  • Every match is one the old pattern also made, so no file can count more than before. It now also catches self., globalThis., contentWindow., window?., bare reads in ternaries, call arguments and shorthand objects, and destructured clientWidth/offsetWidth.
  • The looks code renames its local copy ({ innerWidth: viewWidth }), so src/looks/capture.ts counts its one read in the browser and src/checks/looks.ts counts none.
  • WIDTH_READS drops five lines (readable, core/looks, checks/looks, summary, runs), and capture.ts goes from 6 to 1.
  • A new test holds every WIDTH_READS line equal to what its file reads, so slack can't hide above a file's count again. At capture.ts's old 6 it fails with "the list allows 6, the file reads 1". No count was raised.

test/home-200.test.ts. It failed on #17632 (twice), #17559 and #17787 with Expected: <= 70, Received: 71. Home read exactly 70 statements, so any pull that added one went red.

  • In canReadMany (src/core/repos.ts), each private repository asked its owner's standing in its own statement: 33 of the 70.
  • Standing is now one statement for all repositories, and the rest of canRead's rules (now readsInStanding) still apply to each.
  • Home reads 37, and the ceiling is lowered from 70 to 45.

test/app-home-batched.test.ts. It failed on main's own verify run and three bisects with 2.06–2.59 s of CPU, over the 2 s per-test budget.

  • The first test built its home inside the test (git commits, a fork, two app enables, a wait for the fork to read diverged) and paid for the page's first render.
  • The homes and one warm-up read now happen in beforeAll, which counts toward the file's budget, not the test's. The counts are statements, so a warm read changes none.
  • That first test dropped from 1.18 s to 0.51 s here.

Look prerequisites: no cause found, so no fix. I read the failed runs from GET /api/v1/repos/trevato/forge/runs?state=failed (200 runs since 2026-12-02 17:14: 174 checks, 25 agent runs, 1 deploy) and the logs of the home-200 failures. None names a missing browser, Chromium, axe or any other look prerequisite. #17835 passed, and #17837 had no failed run. Those boxes of #17831 stay open.

Tests that fail on the old code:

  • the width-read and exact-ceiling tests in test/behaviors-rule.test.ts;
  • the private-repositories test in test/can-read-many.test.ts;
  • home-200 at its new ceiling.

How it was run:

  • 20 runs in a row, all green, of app-home-batched, home-200 and can-read-many, and 20 of behaviors-rule and design-lint-ratchets.
  • The gate (no rule failed), bun x tsc --noEmit, bun scripts/design-lint.ts, test/unused-exports.test.ts, and the 40 visibility/standing test files all pass.
  • test/axe.test.ts and test/composer-draft.test.ts fail here with or without this change, because the sandbox has no browser; the forge's check runs them.

No door: a lint rule, a statement count and test setup; no page, action, route or tool changes.

🤖 Generated with Claude Code

commented

Left #17831 open: 2 unticked items remain (Find why each fails on pulls but not on main (ordering, shared state, a missing tool in the check).; Fix the cause in the test setup or code; do not skip or loosen it.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs