Skip to content

test(cloudflare): Add Vite-build support to the integration-test runner#22422

Merged
JPeer264 merged 1 commit into
jp/cloudflare-auto-instrument-read-wranglerfrom
jp/cloudflare-auto-instrument-test-runner
Jul 22, 2026
Merged

test(cloudflare): Add Vite-build support to the integration-test runner#22422
JPeer264 merged 1 commit into
jp/cloudflare-auto-instrument-read-wranglerfrom
jp/cloudflare-auto-instrument-test-runner

Conversation

@JPeer264

Copy link
Copy Markdown
Member

Teach the integration-test runner to support suites that opt into the Sentry Vite plugin. When a suite ships a vite.config.*, the runner runs vite build first (so the plugin's auto-instrumentation transform runs) and points wrangler dev at the generated dist/<worker>/wrangler.json, matched to the right source config via its userConfigPath. Suites without a Vite config keep running straight from source, unchanged (= wrangler).

No suite uses this path yet; the auto-instrument feature commits that follow add their own vite-autoinstrument/* integration suites.

@JPeer264 JPeer264 self-assigned this Jul 21, 2026
Comment thread yarn.lock Outdated
pathe "^2.0.3"
source-map-js "^1.2.1"

vite@7.3.2:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High severity vulnerability may affect your project—review required:
Line 30374 lists a dependency (vite) with a known High severity vulnerability.

ℹ️ Why this matters

Affected versions of vite and vite-plus are vulnerable to Exposure of Sensitive Information to an Unauthorized Actor / Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). Vite's server.fs.deny blocklist—which protects sensitive files such as .env and certificate files from being served—can be bypassed on Windows using alternate path representations (NTFS Alternate Data Stream syntax like /.env::$DATA?raw, or 8.3 short filenames), allowing an attacker to read otherwise-denied files when the dev server is exposed to the network.

References: GHSA, CVE

To resolve this comment:
Check if you expose the Vite dev server or vite-plus to the network by configuring a non-loopback address using the --host CLI flag on Windows.

  • If you're affected, upgrade this dependency to at least version 7.3.5 at yarn.lock.
  • If you're not affected, comment /fp we don't use this [condition]
💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-read-wrangler branch 2 times, most recently from 7fa0bdf to f794a64 Compare July 21, 2026 15:25
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch from fee009a to 61ecd75 Compare July 21, 2026 15:25
@JPeer264
JPeer264 marked this pull request as ready for review July 21, 2026 15:26
@JPeer264
JPeer264 requested a review from a team as a code owner July 21, 2026 15:26
@JPeer264
JPeer264 requested review from andreiborza and isaacs and removed request for a team July 21, 2026 15:26
Comment on lines +66 to +73
function builtFromSource(builtConfigPath: string, sourceConfigPath: string): boolean {
try {
const built = JSON.parse(readFileSync(builtConfigPath, 'utf8')) as { userConfigPath?: string; configPath?: string };
return built.userConfigPath === sourceConfigPath || built.configPath === sourceConfigPath;
} catch {
return false;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The strict path comparison in builtFromSource() will likely fail because path.join() creates an OS-specific absolute path, while the Vite plugin may generate a relative or differently formatted path string.
Severity: MEDIUM

Suggested Fix

Before comparing the paths in builtFromSource(), normalize them. Convert both built.userConfigPath and sourceConfigPath to a consistent format, such as absolute paths with normalized separators, using functions from the path module.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: dev-packages/cloudflare-integration-tests/runner.ts#L66-L73

Potential issue: The `builtFromSource()` function compares a generated config path
(`built.userConfigPath`) with a locally constructed path (`sourceConfigPath`) using
strict string equality (`===`). The `sourceConfigPath` is an absolute path created with
`path.join()`, which uses OS-native separators. The `userConfigPath`, generated by the
`@cloudflare/vite-plugin`, is likely to be a relative path or use a different separator
format (e.g., forward slashes). This mismatch will cause the comparison to fail,
preventing Vite-built test suites from being located and throwing an error. This issue
is particularly likely to manifest on Windows due to path separator differences.

Did we get this right? 👍 / 👎 to inform future reviews.

@JPeer264
JPeer264 requested a review from timfish July 21, 2026 15:36
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-read-wrangler branch from f794a64 to e5d9096 Compare July 22, 2026 06:04
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch from 61ecd75 to 752340f Compare July 22, 2026 06:04
Comment thread dev-packages/cloudflare-integration-tests/runner.ts
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-read-wrangler branch from 0015911 to e0afe44 Compare July 22, 2026 11:05
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch from 752340f to 18edf5c Compare July 22, 2026 11:05
Comment thread dev-packages/cloudflare-integration-tests/runner.ts
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-read-wrangler branch from e0afe44 to 2607d0b Compare July 22, 2026 11:22
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch 2 times, most recently from 12be617 to 9206a0e Compare July 22, 2026 12:54
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-read-wrangler branch from 2607d0b to 8864e2e Compare July 22, 2026 12:54
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch 2 times, most recently from b4a2514 to ecbeab8 Compare July 22, 2026 13:11
Teach the integration-test runner to support suites that opt into the Sentry
Vite plugin. When a suite ships a `vite.config.*`, the runner runs `vite build`
first (so the plugin's auto-instrumentation transform runs) and points
`wrangler dev` at the generated `dist/<worker>/wrangler.json`, matched to the
right source config via its `userConfigPath`. Suites without a Vite config keep
running straight from source, unchanged.

No suite uses this path yet; the auto-instrument feature commits that follow add
their own `vite-autoinstrument/*` integration suites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-read-wrangler branch from 8864e2e to 989fd3d Compare July 22, 2026 13:12
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch from ecbeab8 to 1225849 Compare July 22, 2026 13:12
Comment on lines +66 to +72
function builtFromSource(builtConfigPath: string, sourceConfigPath: string): boolean {
try {
const built = JSON.parse(readFileSync(builtConfigPath, 'utf8')) as { userConfigPath?: string; configPath?: string };
return built.userConfigPath === sourceConfigPath || built.configPath === sourceConfigPath;
} catch {
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The code assumes the @cloudflare/vite-plugin generates userConfigPath or configPath in the output wrangler.json, but this behavior is unverified and likely does not exist.
Severity: HIGH

Suggested Fix

Verify the actual output of the @cloudflare/vite-plugin. If it does not generate userConfigPath or configPath, update the plugin to include this necessary metadata. Alternatively, find another reliable method to associate the built wrangler.json with its source vite.config.* file. Ensure the matching logic is robust before adding integration suites that depend on it.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: dev-packages/cloudflare-integration-tests/runner.ts#L66-L72

Potential issue: The test runner logic for Vite-based suites relies on matching a
generated `wrangler.json` to its source configuration file. This is done by checking for
a `userConfigPath` or `configPath` property within the generated JSON file. However, it
is unverified whether the `@cloudflare/vite-plugin` actually adds these properties to
its output. If these properties are missing, the `builtFromSource()` check will always
fail, `builtConfig` will remain `undefined`, and the runner will throw an error. This
will cause all Vite-based integration tests to fail as soon as they are added.

@JPeer264
JPeer264 merged commit 2e32c3b into develop Jul 22, 2026
288 checks passed
@JPeer264
JPeer264 deleted the jp/cloudflare-auto-instrument-test-runner branch July 22, 2026 15:34
andreiborza pushed a commit that referenced this pull request Jul 23, 2026
andreiborza pushed a commit that referenced this pull request Jul 23, 2026
andreiborza added a commit that referenced this pull request Jul 23, 2026
…runner (#22539)

Backport of: #22422

---------

Co-authored-by: Jan Peer Stöcklmair <jan.peer@sentry.io>
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.

2 participants