Skip to content

verify:test-timeouts scans source with a hand-written scanner where an AST would be exact #2337

Closed as not planned

Description

@cliffhall

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:

  • retry declared on an individual test or suite (findTestLevelRetries)
  • asyncUtilTimeout configured 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 (typescript is a root devDependency,
    already used by scripts/lib/tsc-program.mjs) — ts.createSourceFile plus a
    walk. No new dependency at all, and it handles TSX, which matters since
    *.stories.tsx and the web tests are the bulk of what is scanned.
  • Or oxc-parser / acorn if 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 retry property 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's asyncUtilTimeout read 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

  • findTestLevelRetries and checkAsyncUtilSource resolve 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

  1. added this to the v2.8.0 milestone on Sep 12, 2026
  2. added
    v2
    chore
    on Sep 12, 2026
  3. cliffhall commented on Sep 12, 2026

    @cliffhall
    MemberAuthor

    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.mts is loaded by all six projects and
      reads ctx.task.retry, the value Vitest actually resolved for the test. That
      is strictly more than the scan reached: a per-test option, a describe option
      inherited by children, a project-level setting, and a --retry flag typed
      into 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.ts
      asserts getConfig().asyncUtilTimeout, which is the value the project's own
      waitFors 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 the
    rest) 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.md rather than a ticket: a rule
    about 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 a
    tool can be asked to resolve.

  4. removed this from the v2.8.0 milestone on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    chorev2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions