Skip to content

[wrangler] Allow test harness to reuse dry-run output - #15000

Open
edmundhung wants to merge 1 commit into
mainfrom
edmundhung/create-test-harness-outdir
Open

[wrangler] Allow test harness to reuse dry-run output#15000
edmundhung wants to merge 1 commit into
mainfrom
edmundhung/create-test-harness-outdir

Conversation

@edmundhung

Copy link
Copy Markdown
Member

Allow Wrangler projects to build a Worker once with wrangler deploy --dry-run --outdir and reuse that output with createTestHarness(). The harness retains the Wrangler configuration and selected environment while avoiding rebuilds during startup and reset.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: The public API TSDoc and changeset document the new option.

A picture of a cute animal (not mandatory, but encouraged)

Note

This is a contribution from an AI agent: Codex, GPT-5.

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: efb2464

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Minor
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@edmundhung
edmundhung force-pushed the edmundhung/create-test-harness-outdir branch from f14eb8f to efb2464 Compare August 3, 2026 17:19
@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15000

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15000

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15000

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@15000

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15000

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@15000

miniflare

npm i https://pkg.pr.new/miniflare@15000

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15000

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@15000

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@15000

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@15000

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@15000

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15000

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@15000

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@15000

wrangler

npm i https://pkg.pr.new/wrangler@15000

commit: efb2464

@edmundhung
edmundhung marked this pull request as ready for review August 4, 2026 10:06
@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team August 4, 2026 10:06
@workers-devprod

workers-devprod commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +556 to +559
const outputFileName = config.no_bundle
? path.basename(main)
: `${path.parse(main).name}.js`;
main = path.join(outDir, outputFileName);

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.

🟡 Prebuilt-output reuse always fails for projects that turn off bundling

The prebuilt entrypoint is looked for inside the output folder (fs.existsSync(main) at packages/wrangler/src/api/test-harness.ts:560) even for projects that disable bundling, where the build never copies the entry file there, so the test harness always fails to start with a message telling the user to re-run a build they already ran.
Impact: Anyone using this new build-once option on a project configured with bundling disabled cannot start the test harness at all.

Why the entry file is absent from the output directory when bundling is disabled

When no_bundle is set, wrangler deploy --dry-run --outdir X goes through noBundleWorker() (packages/wrangler/src/deployment-bundle/no-bundle-worker.ts:8-29), which only calls writeAdditionalModules(modules, outDir) and returns resolvedEntryPointPath: entry.file — i.e. the original source path. Nothing writes the entry module into the outdir (packages/wrangler/src/deployment-bundle/maybe-build-worker.ts:139-145; only the esbuild path at :146-189 writes into destination).

So outputFileName = path.basename(main) resolved against outDir (e.g. worker-output/index.js) never exists, and resolveWorkerConfig throws the Could not find the prebuilt Worker entrypoint ... UserError, instructing the user to run exactly the command they already ran.

The non-no_bundle branch (${path.parse(main).name}.js) is correct — esbuild sets entryNames: path.parse(entryFile).name with outdir: destination (packages/wrangler/src/deployment-bundle/bundle.ts:382-386).

A reasonable fix is to keep using the original config.main when the source config has no_bundle: true (the emitted additional modules already live in outDir), rather than expecting a copy of the entrypoint in the output directory.

Prompt for agents
In packages/wrangler/src/api/test-harness.ts, resolveWorkerConfig() computes the expected prebuilt entrypoint filename as path.basename(main) when the user's Wrangler config sets no_bundle: true. That assumption is wrong: `wrangler deploy --dry-run --outdir <dir>` with no_bundle goes through noBundleWorker() (packages/wrangler/src/deployment-bundle/no-bundle-worker.ts), which only writes the *additional* modules into the outdir and returns the original source file as resolvedEntryPointPath. The entry module itself is never copied into the outdir, so fs.existsSync() always fails and the harness throws the 'Could not find the prebuilt Worker entrypoint' UserError with an instruction to run a command the user already ran successfully.

Decide on the right behavior for no_bundle projects: either keep pointing `main` at the original (source) entry file while still setting base_dir to the outDir so the emitted additional modules are picked up, or explicitly reject the outDir option for no_bundle configs with a clear explanation. Add an e2e case covering a no_bundle config alongside the existing bundled case in packages/wrangler/e2e/createTestHarness.test.ts.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@workers-devprod workers-devprod left a comment

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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

3 participants