Skip to content

Refactor#13845

Draft
emily-shen wants to merge 4 commits intomainfrom
refactor
Draft

Refactor#13845
emily-shen wants to merge 4 commits intomainfrom
refactor

Conversation

@emily-shen
Copy link
Copy Markdown
Contributor

Fixes #[insert GH or internal issue link(s)].

Describe your change...


  • 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:

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

⚠️ No Changeset found

Latest commit: d253678

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This refactoring extracts shared deploy/versions-upload logic into shared.ts, moves autoconfig and open-next delegation into autoconfig.ts, and inlines the core deploy logic from deploy() into deployWorker() inside index.ts.

Issues found (ranked by severity)

  1. Duplicate describe("legacy") block in test file — lines 1132-1141 are an incomplete copy of the block that starts at line 1142. This will cause a parse/syntax error or malformed test structure.

  2. D1 binding special error handler removed — The old deploy() function had a special case that caught API error 10021 with the specific D1 binding message and re-threw a user-friendly error. That handler was deleted from the new deployWorker() in index.ts (compare with the old code around the catch block). The source-mapping logic was kept, but the D1 guard was dropped.

  3. telemetryMessage: true used for missing worker name — Per packages/wrangler/AGENTS.md, telemetryMessage: true sends the user-facing message as the telemetry label and is discouraged when a stable static label is available. The old deploy and versions-upload paths had distinct stable labels (deploy command missing worker name / versions upload missing worker name).

Comment on lines +1132 to +1141
describe("legacy", () => {
it("uses the script name when no environment is specified", async ({
expect,
}) => {
writeWranglerConfig();
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest({
useServiceEnvironments: 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.

This block (lines 1132-1141) is an incomplete duplicate of the describe("legacy") block that immediately follows it at line 1142. It opens a describe and it callback, sets up mocks, but never closes any braces or calls runWrangler. This will either cause a syntax error or produce a broken nested test structure.

Suggested change
describe("legacy", () => {
it("uses the script name when no environment is specified", async ({
expect,
}) => {
writeWranglerConfig();
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest({
useServiceEnvironments: false,
});

err.notes[0].text,
retrieveSourceMap
);
}
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.

The old deploy() function had a D1-specific error handler here that caught API error 10021 with the message "binding DB of type d1 must have a valid \id` specified [code: 10021]"and re-threw a user-friendlyUserErrorpointing towrangler d1 list`. That handler was removed in this refactor — was that intentional? If not, it should be re-added before the source-mapping logic:

Suggested change
}
if (
err.notes[0].text ===
"binding DB of type d1 must have a valid `id` specified [code: 10021]"
) {
throw new UserError(
"You must use a real database in the database_id configuration. You can find your databases using 'wrangler d1 list', or read how to develop locally with D1 here: https://developers.cloudflare.com/d1/configuration/local-development",
{ telemetryMessage: "deploy d1 database binding invalid id" }
);
}

if (!name) {
throw new UserError(
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
{ telemetryMessage: true }
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.

Per packages/wrangler/AGENTS.md: "telemetryMessage: true is usually less useful because user-facing copy is harder to group and parse than a stable telemetry label." The old code used distinct labels: "deploy command missing worker name" and "versions upload missing worker name". Since resolveSharedConfig already receives a command parameter, you could use it to preserve the distinction:

Suggested change
{ telemetryMessage: true }
{ telemetryMessage: `${command} missing worker name` }

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: d253678

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 7, 2026

Review posted successfully on PR #13845. Here's a summary of what I found:

  1. Duplicate describe("legacy") block (HIGH) — Lines 1132-1141 in core.test.ts are an incomplete duplicate of the block at line 1142. This will cause a syntax error. Suggested deletion via inline suggestion.

  2. D1 binding error handler removed (MEDIUM) — The old deploy() had a special-case handler for D1 binding validation errors (API error 10021) that produced a user-friendly message. It was dropped during the refactor but not moved anywhere. Suggested re-adding it in the catch block.

  3. telemetryMessage: true instead of stable label (LOW) — The shared resolveSharedConfig uses telemetryMessage: true for the missing worker name error, losing the distinct labels the old code had. Suggested using the command parameter to preserve the distinction.

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants