Repository navigation
Description
Split out of #2334 (which implements #2323), where the Copilot review found this
class four rounds running and, on the last of them, recommended the fix directly:
"preferably with an AST rather than another regex special case."
What the guard does today
scripts/verify-test-timeouts.mjs enforces two things that no Vitest config can
report, so both are read out of source text:
retrydeclared on an individual test or suite (findTestLevelRetries)asyncUtilTimeoutconfigured in each web project's setup file
(checkAsyncUtilSource)
It began as a regex and is now a small scanner: comment-aware with string
tracking, bracket-matching, top-level argument splitting, and vitest import
alias resolution. Every one of those was added in response to a real bypass:
| Round | Bypass found |
|---|---|
| 4 | a call disabled in a trailing line comment survived an anchored strip |
| 5 | --retry in an npm script, and per-test retry, were not checked at all |
| 6 | nested parens in a chain argument (it.each([makeCase()])) were skipped; only the first configure() call was read |
| 7 | other.configure(…) matched because \b succeeds after a dot; shorthand { retry } needed no colon |
| 8 | a non-literal value ({ asyncUtilTimeout: changed }); an aliased import (import { it as case_ }); a non-literal title (it(getName(), …)) |
Each fix is correct and carries a regression test — the guard is in good shape
and catches everything above. But the trend is the finding: a scanner is an
approximation of a parser, and the review found a new valid JavaScript spelling
every single round.
The residual gap
A test call reached through a value the scan cannot resolve is still invisible.
For example a re-exported wrapper:
// helpers/test.ts
export { it } from "vitest";
// some.test.ts
import { it } from "./helpers/test";
it("x", { retry: 2 }, () => {}); // not seen: the import is not from "vitest"or a name bound at runtime. None of these exist in the repo today, and none is
reachable by accident — you would be writing a deliberate workaround. That is
why this is a follow-up and not a defect in #2334.
Work
Parse instead of scan. The build already depends on everything needed, so this
is not a new dependency decision so much as a choice of which existing one:
- TypeScript's own compiler API (
typescriptis a root devDependency,
already used byscripts/lib/tsc-program.mjs) —ts.createSourceFileplus a
walk. No new dependency at all, and it handles TSX, which matters since
*.stories.tsxand the web tests are the bulk of what is scanned. - Or
oxc-parser/acornif throughput turns out to matter (604 files are
scanned today; the current scan is not measurably slow).
With a real AST the checks become exact rather than approximate:
- a
retryproperty in the second argument of a call whose callee resolves
to a vitest test export, alias or re-export included; - a
configure()call whose callee resolves to the required import, with the
argument'sasyncUtilTimeoutread as a literal or reported as unverifiable.
The existing 47 unit tests are the specification — they encode every bypass
found across five review rounds, positives and the false-positive shapes
(fixture data, expect(client.retry), a mocked API's options, { retryCount },
a retry in a test title). Keep them and make the AST implementation pass the
same suite; do not rewrite them to match a new implementation, or the five
rounds of review that produced them are thrown away.
Not in scope
Loosening what is enforced. The invariants themselves are settled in #2323 and
AGENTS.md; this is about how reliably they are detected.
Acceptance
findTestLevelRetriesandcheckAsyncUtilSourceresolve their callees through
an AST rather than by pattern-matching source text.- The existing test suite passes unchanged, and the re-export case above is added
to it and passes. - The scanner helpers that exist only to approximate parsing (
stripComments,
matchBracket,splitArgs,collectTestAliases) are removed if the AST makes
them dead, rather than left beside it.
Activity
cliffhall commentedon Sep 12, 2026
Closing as not planned — the scanner this proposed to replace with an AST has
been deleted instead, in #2334.
The framing here was wrong, and worth recording rather than just closing. This
issue asked which parser to use. The right question was why anything was
parsing at all.
Both rules the scanner existed to enforce are observable at runtime, exactly:
retry—vitest.setup.shared.mtsis loaded by all six projects andreads
ctx.task.retry, the value Vitest actually resolved for the test. Thatis strictly more than the scan reached: a per-test option, a
describeoptioninherited by children, a project-level setting, and a
--retryflag typedinto a shell all arrive as the same number. The last of those the scanner
could never have seen — it could only read npm scripts.
asyncUtilTimeout—clients/web/src/test/asyncUtilTimeout.test.tsasserts
getConfig().asyncUtilTimeout, which is the value the project's ownwaitFors read.Neither has a spelling to anticipate, so neither can be outrun by a new one.
The result: the guard went from 868 lines to 361, every scanner helper
(
stripComments,matchBracket,splitArgs,collectTestAliases, and therest) is gone, and 33 of its 48 unit tests were deleted — all of them
pinning edge cases of a thing that no longer exists.
What replaces this issue is a rule in
AGENTS.mdrather than a ticket: a ruleabout what the code does is asserted at runtime, not read out of the source.
Reach for a
verify:*guard when the question is about configuration, which atool can be asked to resolve.