Skip to content

Planner: splitParts regex is quadratic on a quote followed by many backticks, so the fuzz test fails at random #300

Closed

Description

@FredApps

tests/fuzz/repository-text.fuzz.test.ts ("workflow files and package scripts") fails on main from time to time, depending on the random seed. It failed in CI on #291, a docs-only PR (run 44197635763, check (ubuntu-26.04, 22)):

not ok 2 - workflow files and package scripts
  Property failed after 4 tests
  { seed: -1959240610, path: "3:6:4:7:7", endOnFailure: true }
  Counterexample: ["\"\"`````````…"]
  [cause]: Error: took 3238 ms

Reproduce (main @ 40aa308):

FC_SEED=-1959240610 npx tsx --test --test-name-pattern="workflow files and package scripts" tests/fuzz/repository-text.fuzz.test.ts

Cause. A CPU profile puts almost all the time in one regex in splitParts(), in src/planner/pipeline-steps.ts (L103):

if (parts.some((part) => !part || /"[^"]*[$`][^"]*"/.test(part)) || …

On a part that holds a " followed by a long run of backticks with no closing quote, [^"]* backtracks over the whole run from every starting point, so time grows quadratically. discoverGateChecks() reaches this through any gate script, for example "check": "tsc && \"\"" + "".repeat(n)`:

backticks discoverGateChecks({ check: "tsc && " + text })
25,000 0.9 s
50,000 3.5 s
100,000 12.9 s

Without the leading "" it takes 1 to 3 ms. The text comes from the analysed repository's package.json, so a repository can stall planning. The fuzz test was written to catch exactly this, which is why it fails whenever the generator draws that shape.

Expected: the check is linear and gives the same answers as the regex, and the fuzz test passes for every seed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions