Skip to content

fix(ci): inject CodSpeed V8 flags via vitest execArgv#4

Merged
kelsos merged 1 commit intomainfrom
fix/codspeed-natives-syntax
Apr 18, 2026
Merged

fix(ci): inject CodSpeed V8 flags via vitest execArgv#4
kelsos merged 1 commit intomainfrom
fix/codspeed-natives-syntax

Conversation

@kelsos
Copy link
Copy Markdown
Owner

@kelsos kelsos commented Apr 18, 2026

Summary

The Benchmarks (CodSpeed) job is failing with SyntaxError: Unexpected token '%' at @codspeed/core/src/optimization.ts:10 (the V8 native %OptimizeFunctionOnNextCall).

Root cause

@codspeed/vitest-plugin reads vitest's package.json to detect the major version and picks the v3 vs v4 execArgv injection path accordingly.

Our pnpm-workspace.yaml overrides alias vitest to @voidzero-dev/vite-plus-test@0.1.18, so the plugin sees major version 0 and falls back to the v3 path (poolOptions.forks.execArgv) — which vitest 4 ignores. The --allow-natives-syntax V8 flag never reaches the benchmark worker.

Fix

When CodSpeed is running (detected via CODSPEED_ENV which the action sets), resolve V8 flags from @codspeed/core ourselves and inject them into vitest 4's top-level execArgv.

Considered alternatives

  • NODE_OPTIONS=--allow-natives-syntax on the CI step — Node's NODE_OPTIONS allowlist explicitly blocks --allow-natives-syntax. Fails at runtime with --allow-natives-syntax is not allowed in NODE_OPTIONS.
  • Swap bench script to vitest bench --run — bypasses vp but loses vite-plus's config resolution. Workable fallback if the execArgv approach regresses.

Credit

The codspeed-hq bot correctly identified this root cause in a draft PR (#3). We closed that PR and re-authored the same fix here to keep contributors human.

Test plan

  • Benchmarks (CodSpeed) CI job completes successfully
  • CodSpeed posts a PR comment with benchmark measurements
  • All other required checks pass (typecheck, tests, lint, coverage, build, commitlint)
  • After merge, first run on main establishes the CodSpeed baseline

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

The `Benchmarks (CodSpeed)` job was failing with `SyntaxError: Unexpected
token '%'` at `@codspeed/core/src/optimization.ts:10` (the V8 native
`%OptimizeFunctionOnNextCall`).

Root cause: @codspeed/vitest-plugin reads vitest's package.json to detect
the major version and picks the v3 vs v4 `execArgv` injection path
accordingly. Our pnpm override aliases `vitest` to
`@voidzero-dev/vite-plus-test@0.1.18`, so the plugin sees major version 0
and falls back to the v3 path (`poolOptions.forks.execArgv`), which
vitest 4 ignores. The `--allow-natives-syntax` V8 flag never reaches the
benchmark worker.

Fix: when CodSpeed is running (`CODSPEED_ENV` set by the action), resolve
V8 flags from @codspeed/core ourselves and inject them into vitest 4's
top-level `execArgv`.

`NODE_OPTIONS=--allow-natives-syntax` is not a viable workaround — Node
security-lists disallow that specific flag in NODE_OPTIONS.

Credit: @codspeed-hq bot identified this root cause in the draft PR that
we closed in favor of a human-authored commit.
@kelsos kelsos force-pushed the fix/codspeed-natives-syntax branch from e75758d to ea43477 Compare April 18, 2026 14:41
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 18, 2026

Congrats! CodSpeed is installed 🎉

🆕 20 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

@kelsos kelsos changed the title fix(ci): pass --allow-natives-syntax to CodSpeed bench fix(ci): inject CodSpeed V8 flags via vitest execArgv Apr 18, 2026
@kelsos kelsos merged commit ea43477 into main Apr 18, 2026
11 checks passed
@kelsos kelsos deleted the fix/codspeed-natives-syntax branch April 18, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant