From 6056c9ce75cb359c7f19bae92f89e16674388de7 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 00:43:30 +0000 Subject: [PATCH 1/3] fix: self-bindings show as connected in wrangler dev Fixes #8970 Self-bindings (service bindings where a worker binds to itself) were incorrectly showing as [not connected] in wrangler dev. This change detects self-bindings by comparing the service name to the worker name and always marks them as connected, since a worker is inherently connected to itself. - Modified print-bindings.ts to check for self-bindings before registry lookup - Added test for self-bindings showing as [connected] - Manually verified with workers-with-assets fixture Co-Authored-By: smacleod@cloudflare.com --- .changeset/ninety-times-sniff.md | 5 ++++ packages/wrangler/src/__tests__/dev.test.ts | 28 +++++++++++++++++++ packages/wrangler/src/utils/print-bindings.ts | 25 +++++++++++------ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .changeset/ninety-times-sniff.md diff --git a/.changeset/ninety-times-sniff.md b/.changeset/ninety-times-sniff.md new file mode 100644 index 000000000000..6777d2a6d39c --- /dev/null +++ b/.changeset/ninety-times-sniff.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Fixed self-bindings (service bindings to the same worker) showing as [not connected] in wrangler dev. Self-bindings now correctly show as [connected] since a worker is always available to itself. diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index d600cdb5c7ab..fc85525e9569 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -2024,6 +2024,34 @@ describe.sequential("wrangler dev", () => { `); expect(std.warn).toMatchInlineSnapshot(`""`); }); + + it("should show self-bindings as connected", async () => { + writeWranglerConfig({ + name: "my-worker", + services: [ + { binding: "SELF", service: "my-worker" }, + { + binding: "NAMED", + service: "my-worker", + entrypoint: "MyEntrypoint", + }, + ], + }); + fs.writeFileSync("index.js", `export default {};`); + await runWranglerUntilConfig("dev index.js"); + expect(std.out).toMatchInlineSnapshot(` + " + ⛅️ wrangler x.x.x + ────────────────── + Your Worker has access to the following bindings: + Binding Resource Mode + env.SELF (my-worker) Worker local [connected] + env.NAMED (my-worker#MyEntrypoint) Worker local [connected] + + " + `); + expect(std.warn).toMatchInlineSnapshot(`""`); + }); }); describe("print bindings", () => { diff --git a/packages/wrangler/src/utils/print-bindings.ts b/packages/wrangler/src/utils/print-bindings.ts index 56bcc8f6a80d..9176ce383140 100644 --- a/packages/wrangler/src/utils/print-bindings.ts +++ b/packages/wrangler/src/utils/print-bindings.ts @@ -399,17 +399,24 @@ export function printBindings( if (remote && getFlag("REMOTE_BINDINGS")) { mode = getMode({ isSimulatedLocally: false }); } else if (context.local && context.registry !== null) { - const registryDefinition = context.registry?.[service]; - hasConnectionStatus = true; - - if ( - registryDefinition && - (!entrypoint || - registryDefinition.entrypointAddresses?.[entrypoint]) - ) { + const isSelfBinding = service === context.name; + + if (isSelfBinding) { + hasConnectionStatus = true; mode = getMode({ isSimulatedLocally: true, connected: true }); } else { - mode = getMode({ isSimulatedLocally: true, connected: false }); + const registryDefinition = context.registry?.[service]; + hasConnectionStatus = true; + + if ( + registryDefinition && + (!entrypoint || + registryDefinition.entrypointAddresses?.[entrypoint]) + ) { + mode = getMode({ isSimulatedLocally: true, connected: true }); + } else { + mode = getMode({ isSimulatedLocally: true, connected: false }); + } } } From d59b5a631982d4e248ecaa85540c49495923c6d1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 01:27:01 +0000 Subject: [PATCH 2/3] fix: correct test snapshot for self-bindings table formatting The table column widths are dynamically calculated based on content length. The self-bindings test has longer binding names than other service binding tests, which causes wider column spacing in the output. Updated the snapshot to match the actual table formatting. Co-Authored-By: smacleod@cloudflare.com --- packages/wrangler/src/__tests__/dev.test.ts | 6 +-- packages/wrangler/src/utils/print-bindings.ts | 40 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index fc85525e9569..5540aa005227 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -2044,9 +2044,9 @@ describe.sequential("wrangler dev", () => { ⛅️ wrangler x.x.x ────────────────── Your Worker has access to the following bindings: - Binding Resource Mode - env.SELF (my-worker) Worker local [connected] - env.NAMED (my-worker#MyEntrypoint) Worker local [connected] + Binding Resource Mode + env.SELF (my-worker) Worker local [connected] + env.NAMED (my-worker#MyEntrypoint) Worker local [connected] " `); diff --git a/packages/wrangler/src/utils/print-bindings.ts b/packages/wrangler/src/utils/print-bindings.ts index 9176ce383140..bb2e597e198d 100644 --- a/packages/wrangler/src/utils/print-bindings.ts +++ b/packages/wrangler/src/utils/print-bindings.ts @@ -394,33 +394,33 @@ export function printBindings( if (entrypoint) { value += `#${entrypoint}`; - } + } - if (remote && getFlag("REMOTE_BINDINGS")) { - mode = getMode({ isSimulatedLocally: false }); - } else if (context.local && context.registry !== null) { - const isSelfBinding = service === context.name; + if (remote && getFlag("REMOTE_BINDINGS")) { + mode = getMode({ isSimulatedLocally: false }); + } else if (context.local && context.registry !== null) { + const isSelfBinding = service === context.name; - if (isSelfBinding) { - hasConnectionStatus = true; + if (isSelfBinding) { + hasConnectionStatus = true; + mode = getMode({ isSimulatedLocally: true, connected: true }); + } else { + const registryDefinition = context.registry?.[service]; + hasConnectionStatus = true; + + if ( + registryDefinition && + (!entrypoint || + registryDefinition.entrypointAddresses?.[entrypoint]) + ) { mode = getMode({ isSimulatedLocally: true, connected: true }); } else { - const registryDefinition = context.registry?.[service]; - hasConnectionStatus = true; - - if ( - registryDefinition && - (!entrypoint || - registryDefinition.entrypointAddresses?.[entrypoint]) - ) { - mode = getMode({ isSimulatedLocally: true, connected: true }); - } else { - mode = getMode({ isSimulatedLocally: true, connected: false }); - } + mode = getMode({ isSimulatedLocally: true, connected: false }); } } + } - return { + return { name: binding, type: friendlyBindingNames.services, value, From 79e025aedcc4edd570e37abba7cd986ae2b9c35e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:15:30 +0000 Subject: [PATCH 3/3] fix: correct indentation in print-bindings.ts Prettier auto-fixed indentation issues that were causing the 'Checks' CI job to fail. The code logic remains unchanged. Co-Authored-By: smacleod@cloudflare.com --- packages/wrangler/src/utils/print-bindings.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/wrangler/src/utils/print-bindings.ts b/packages/wrangler/src/utils/print-bindings.ts index bb2e597e198d..9176ce383140 100644 --- a/packages/wrangler/src/utils/print-bindings.ts +++ b/packages/wrangler/src/utils/print-bindings.ts @@ -394,33 +394,33 @@ export function printBindings( if (entrypoint) { value += `#${entrypoint}`; - } + } - if (remote && getFlag("REMOTE_BINDINGS")) { - mode = getMode({ isSimulatedLocally: false }); - } else if (context.local && context.registry !== null) { - const isSelfBinding = service === context.name; + if (remote && getFlag("REMOTE_BINDINGS")) { + mode = getMode({ isSimulatedLocally: false }); + } else if (context.local && context.registry !== null) { + const isSelfBinding = service === context.name; - if (isSelfBinding) { - hasConnectionStatus = true; - mode = getMode({ isSimulatedLocally: true, connected: true }); - } else { - const registryDefinition = context.registry?.[service]; - hasConnectionStatus = true; - - if ( - registryDefinition && - (!entrypoint || - registryDefinition.entrypointAddresses?.[entrypoint]) - ) { + if (isSelfBinding) { + hasConnectionStatus = true; mode = getMode({ isSimulatedLocally: true, connected: true }); } else { - mode = getMode({ isSimulatedLocally: true, connected: false }); + const registryDefinition = context.registry?.[service]; + hasConnectionStatus = true; + + if ( + registryDefinition && + (!entrypoint || + registryDefinition.entrypointAddresses?.[entrypoint]) + ) { + mode = getMode({ isSimulatedLocally: true, connected: true }); + } else { + mode = getMode({ isSimulatedLocally: true, connected: false }); + } } } - } - return { + return { name: binding, type: friendlyBindingNames.services, value,