Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

test(scripts): hoist the doc-links corpus walk out of the timed window - #8419

Merged
baozhoutao merged 1 commit into
mainfrom
claude/issue-8062-doc-links-corpus-test-headroom
Sep 7, 2026
Merged

baozhoutao merged 1 commit into
mainfrom
claude/issue-8062-doc-links-corpus-test-headroom

Conversation

@baozhoutao

Copy link
Copy Markdown
Contributor

Fixes #8062

What was measured, and on what box

Every run below went through the shared heavy-verify lock
(../objectstack/scripts/pm/os-verify-lock.sh, the convention recorded as objectui#8403),
and each one printed its own VERDICT command-exit 0 line. The lock was held for every
number in this PR.
The lock excludes other locked runs, not unlocked sibling work, so
treat the absolutes as shared-box seconds and the ratios as the durable part.

Re-derived first, before changing anything —
pnpm exec vitest run scripts/__tests__/check-doc-links.test.ts --reporter=verbose:

test before after
agrees with the real renderers on every heading in the scan surface 3964 ms 25 ms
has no setext headings, which the ATX-only scan would not see 3659 ms 35 ms
whole file, 121 tests 10.32 s 6.10 s

The card's idle figures (4429 ms / 3792 ms) reproduced, so the premise still holds. Against
vitest's 15000 ms default the headroom goes from 3.8x and 4.1x to 600x and 428x, and
the file as a whole gets 4.2 s faster because the walk is now paid once instead of twice.

Which of the two shapes this is: shape 2, with the split measured

The work had drifted into a bounded window; it does not belong there. A standalone profile of
the identical walk (plain node, no vitest, under the lock) splits the cost:

files 273 · bytes 2,550,739
collect            29 ms
read               12 ms
getTableOfContents  pass 1 3138 ms · pass 2 2746 ms
assertion work (github-slugger + headingAnchors)   27 ms

So ~99% of each test's window was fumadocs' remark parse of the whole corpus, and both
tests parsed the same 273 files
— the hint in the card is right: it was shared work paid
twice over identical inputs. Everything the two tests actually assert adds up to 27 ms.

No timeout was raised. Nothing was skipped, quarantined or narrowed.

The repair

ANCHOR_CORPUS is now built once at module scope: collect the SCAN_ROOTS files, read
each one, strip frontmatter with the existing documentBody(), and hand it to fumadocs'
getTableOfContents with remark-mdx for .mdx — byte for byte the same call the two tests
each used to make. Each it() then measures only its own assertion.

Module scope is the only home that qualifies, and AGENTS.md's test-discipline rule is the
reason for both halves of that:

  • the cost lands in the import phase, which no testTimeout governs (vitest's own summary
    moves it there: import 225ms before, import 4.22s after);
  • it is deliberately not a beforeAll, which would trade the 15 s testTimeout for the
    narrower 10 s hookTimeout — moving the problem, not fixing it.

The two loadToc / loadSlugger / loadMdx helpers and documentBody() moved out of the
describe body to module scope unchanged (a describe callback is synchronous, so the top-level
await could not live inside it). loadSlugger() is still awaited inside the tests that use it;
the github-slugger parity tests are untouched.

Proof that nothing asserted changed

  1. Not one assertion line moved. git diff origin/main..HEAD -- scripts/__tests__/check-doc-links.test.ts | grep -E '^[-+].*expect\(' prints nothing — no expect( line was added, removed or edited anywhere in the diff.
  2. Both tests still go red on a real corpus change. Ablation: append a setext H2 to ROADMAP.md (a genuinely scanned file), proven on disk by git hash-object moving e022b5d1 to ec9e1df5 and by a grep -c of the injected text. Result — both corpus tests FAIL (Tests 2 failed | 119 passed (121)), in 36 ms and 37 ms, so the fixture really does feed both assertions. Restore leg proven by state: hash back to e022b5d1, git diff HEAD empty.
  3. The corpus is not narrower than it was. A temporary assertion printed ANCHOR_CORPUS.length 273 · docsFiles 184 · diskFiles 89, identical to an independent walk of SCAN_ROOTS outside the test ({"total":273,"docs":184,"disk":89}). The file's own lit-instrument assertions (docsFiles over 150, diskFiles over 50) are unchanged and still pass. That mutation was restored the same way, hash and empty git diff HEAD.

Checks run, with real verdicts

command result
pnpm exec vitest run scripts/__tests__/check-doc-links.test.ts --reporter=verbose Test Files 1 passed (1) · Tests 121 passed (121)
pnpm exec vitest run scripts/ Test Files 121 passed (121) · Tests 3615 passed (3615) · 93.34 s
pnpm lint Tasks: 47 successful, 47 total, exit 0 (0 errors; the warning counts are pre-existing)
pnpm type-check:scripts exit 0 — and tsc --listFiles confirms it really includes this test file, so that green is a measurement
node scripts/check-changeset-presence.mjs exit 0 — "No source or published contract of a released package changed in this range, so no changeset is owed." Checked, not guessed; no changeset added.
pnpm check:control-bytes OK, 6661 tracked text files
pnpm check:lint-rule-coverage · check:vi-mock-specifiers · check:vi-mock-inherit · check:pre-install-import-graph all exit 0

Scope fences respected: the corpus, SCAN_ROOTS, the renderers and the github-slugger parity
test are all untouched. One file changed.


Drafted by an agent seat, session session_01FhBNJcLRZLe8M87VcUgpKr; stays in draft.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr


Generated by Claude Code

`check-doc-links.test.ts` has two whole-corpus tests that each walked every
`SCAN_ROOTS` entry and handed all 273 files (2.5 MB of markdown) to fumadocs'
`getTableOfContents`. Both timed out at vitest's 15 s default under container
load.

Measured on this tree, under the shared verify lock: the remark parse is
2.7-3.1 s per pass and everything the two tests actually assert adds up to
27 ms. The unbounded corpus walk was inside the bounded assertion window, and
paid twice over identical inputs.

Hoist the parse to module scope as `ANCHOR_CORPUS`, where the cost lands in the
import phase that no `testTimeout` governs — and not in a `beforeAll`, which
would trade the 15 s budget for the narrower 10 s `hookTimeout`. Each test now
times its own assertion and asserts exactly what it asserted before.

  agrees with the real renderers ...  3964 ms -> 25 ms
  has no setext headings ...          3659 ms -> 35 ms
  whole file (121 tests)             10.32 s -> 6.10 s

No timeout was raised and no assertion was weakened.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr
@github-actions github-actions Bot added the tests label Sep 7, 2026
@claude

claude Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

ACCEPT — domain:devx @ objectui execution seat, PM session session_01FhBNJcLRZLe8M87VcUgpKr, R46, reviewed 2026-09-07T21:35Z against GitHub and the tree, ⛔ never against the report's narrative.

The dispatch forbade the reflex; the dev didn't just avoid it, it proved the reflex would have been wrong

The brief said don't raise a number because a number was exceeded, and demanded the dev name which of two shapes this defect is. The answer is shape 2 — unbounded shared work that had drifted into a bounded window — and it is settled by a standalone profile rather than by argument:

files 273, bytes 2,550,739
getTableOfContents pass 1  3138 ms
getTableOfContents pass 2  2746 ms
assertion work                27 ms

⇒ ~99 % of each 15 s window was fumadocs' remark parse of the whole corpus, and both tests parsed the same 273 files — the walk was paid twice over identical inputs. Everything the two tests actually assert totals 27 ms. A raised timeout would have bought nothing and hidden that.

⭐ And the obvious "clean" alternative is actively worse, which the dev caught. beforeAll was rejected with a reason, not a preference: it trades the 15 s testTimeout for the narrower 10 s hookTimeout, and this repo's own object-ui/no-dynamic-import-in-test-hook rule forbids the dynamic import there anyway. So the tempting middle option would have moved the cliff closer while looking tidier. Module scope puts the cost in the import phase, which no timeout governs.

Verified independently: AGENTS.md:227 does forbid this reflex verbatim — 「禁止用「调高超时」或「把文件塞进 vitest.config.mts 的 heavyDomTests」来修 flaky —— 两者都只是把竞态藏起来」 — so the dev's citation is real and the rejected option was a rule violation, not merely a weaker choice.

The premise was re-derived, and it held within 10 %

3964 ms and 3659 ms today against the card's 4429 / 3792 — still 3.8× and 4.1× of the default, still at the edge. The dev held the shared verify lock for every heavy run and says so, which is what makes the numbers readable at all on a box where this defect was originally caused by contention.

Result, and the proof that nothing was bought by weakening anything

before after
heading-agreement test 3964 ms 25 ms
setext-detection test 3659 ms 35 ms
whole file (121 tests) 10.32 s 6.10 s

The vitest summary shows the cost moving rather than vanishing: import 225 ms → 4.22 s, tests 9.28 s → 1.56 s. Headroom against the 15 s default goes 3.8× → 600× and 4.1× → 428×.

Checked here, not taken on trust: the diff is one file, +104/-70, with 0 changed lines containing expect( and 0 added lines matching .skip / timeout: / heavyDomTests. Nothing asserted moved, nothing was skipped, no budget was raised.

⭐ The ablation is the right one and it fires on both legs. A setext H2 was appended to ROADMAP.md — a genuinely scanned file — with the mutation proven on disk by blob hash before any result was read (e022b5d1… → ec9e1df5…, injected-text count 1). Both corpus tests then failed, in 36 ms and 37 ms. ⇒ The shared fixture really does feed both assertions and still sees the whole corpus; a hoist that quietly narrowed the corpus would have stayed green here. Restore proven by state (git diff HEAD empty, hash restored), under an EXIT INT TERM trap with an absolute root.

And the corpus itself was measured rather than assumed: ANCHOR_CORPUS.length 273 / docs 184 / disk 89, identical to an independent walk of SCAN_ROOTS taken outside the test — with the file's own non-vacuity floors (docs > 150, disk > 50) left intact.

Scope

One file. ⛔ Not the corpus, ⛔ not SCAN_ROOTS, ⛔ not the renderers, ⛔ not the github-slugger parity test. check-changeset-presence run rather than guessed: exit 0, none owed. type-check:scripts green and shown non-vacuous — tsc --listFiles | grep -c on the edited file returns 1, so the pass is a measurement of this file rather than an exclusion. Not governed surface; PR stays draft.

⚠️ One lane correction recorded, not a falsification: the gh CLI is not installed in this container, so the PR went through the GitHub MCP tool while plain REST reads and comment writes work fine. Consistent with what this seat has been using all shift.

Next: CI convergence → flip ready → post-flip guard → auto-merge SQUASH → queue confirmation → landing probe (ANCHOR_CORPUS built at module scope on re-fetched origin/main, and zero expect( lines changed by the squashed commit; control: the file's own docsFiles > 150 / diskFiles > 50 floors still present — they are what stop a future narrowing of the corpus from reading green) → LANDED here and on #8062, which closes via Fixes.


Generated by Claude Code

@baozhoutao
baozhoutao marked this pull request as ready for review September 7, 2026 21:43
@baozhoutao
baozhoutao added this pull request to the merge queue Sep 7, 2026
@claude

claude Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Armed: PR #8419 flipped ready at 2026-09-07T21:43:04Z on head 382d1560e after CI converged all green (28 checks, Live E2E excluded, read 21:42:57Z); post-flip Governed Surface Queue Guard completed/success at 21:43:23Z; auto-merge SQUASH enabled; queued (added_to_merge_queue at 21:43:33Z, read 21:43:39Z).

Landing probe on merge, on re-fetched origin/main: ANCHOR_CORPUS built once at module scope (not in a beforeAll — that would trade the 15 s testTimeout for the narrower 10 s hookTimeout, and object-ui/no-dynamic-import-in-test-hook forbids the dynamic import there), and the squashed commit changing zero lines containing expect(.

Control: the file's own non-vacuity floors — docsFiles > 150 and diskFiles > 50 — still present. ⚠️ That is the control this change specifically needs. A hoist that quietly narrowed the corpus makes both tests faster and green, and is indistinguishable from a correct one by timing alone; those floors, plus the measured 273 / 184 / 89 matching an independent walk of SCAN_ROOTS, are what say the fixture still sees everything the two tests used to walk themselves.

⭐ Recorded for the next reader: the fix removed a whole corpus parse rather than moving a deadline. The two tests spent ~99 % of their windows on fumadocs' remark parse of 273 files (3138 ms + 2746 ms) against 27 ms of actual assertion work, and both parsed the same files — the walk was paid twice over identical inputs. Raising the timeout would have bought nothing and hidden that; AGENTS.md:227 forbids it outright.

Then LANDED here and on #8062, which closes via Fixes. — domain:devx @ objectui seat, PM session session_01FhBNJcLRZLe8M87VcUgpKr.


Generated by Claude Code

Merged via the queue into main with commit 0203a29 Sep 7, 2026
31 checks passed
@baozhoutao
baozhoutao deleted the claude/issue-8062-doc-links-corpus-test-headroom branch September 7, 2026 21:59
@claude

claude Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

LANDED — merged into main at 2026-09-07T21:59:48Z as 0203a29e9 (squash), read 21:59:53Z. #8062 closed completed via Fixes.

Content probe on re-fetched origin/main (tip 0203a29e9, read 22:01Z) — the claim, the control, and the assertion-integrity check:

  1. ANCHOR_CORPUS is built once at module scope (:2080, top-level await) and consumed by both corpus tests (:2145, :2173). ⛔ Not a beforeAll — that would have traded the 15 s testTimeout for the narrower 10 s hookTimeout, and object-ui/no-dynamic-import-in-test-hook forbids the dynamic import there. The tempting tidier option was the worse one.
  2. Control — the non-vacuity floors survived: expect(docsFiles).toBeGreaterThan(150) and expect(diskFiles).toBeGreaterThan(50) at :2162-2163. ⚠️ This was the control this change specifically needed. A hoist that quietly narrowed the corpus makes both tests faster and green, and is indistinguishable from a correct one by timing alone; those floors, plus the measured 273 / 184 / 89 matching an independent walk of SCAN_ROOTS, are what say the shared fixture still sees everything the two tests used to walk themselves.
  3. The squashed commit changed expect( lines: 0. Nothing asserted moved.

⭐ What landed is the removal of a whole corpus parse, not a moved deadline. The two tests spent ~99 % of their windows on fumadocs' remark parse of 273 files — 3138 ms + 2746 ms — against 27 ms of actual assertion work, and both parsed the same files, so the walk was paid twice over identical inputs. Result: 3964 ms → 25 ms and 3659 ms → 35 ms, whole file 10.32 s → 6.10 s, with the cost visibly moving into the import phase (225 ms → 4.22 s) rather than vanishing.

⛔ Raising the timeout would have bought nothing and hidden all of that. AGENTS.md:227 forbids it outright — 「禁止用「调高超时」或「把文件塞进 vitest.config.mts 的 heavyDomTests」来修 flaky」 — so the option this dispatch warned against was a rule violation, not merely a weaker choice.


Generated by Claude Code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

finding(test-infra): two whole-corpus tests in check-doc-links.test.ts run at 3-4x of the 15s default and time out under container load

2 participants