Skip to content

Commit dbe51c1

Browse files
[wrangler] Fix self-bindings showing as not connected in dev (#10915)
* 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 <smacleod@cloudflare.com> * 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 <smacleod@cloudflare.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: smacleod@cloudflare.com <smacleod@cloudflare.com>
1 parent d4f2daf commit dbe51c1

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

.changeset/ninety-times-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
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.

packages/wrangler/src/__tests__/dev.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,34 @@ describe.sequential("wrangler dev", () => {
20252025
`);
20262026
expect(std.warn).toMatchInlineSnapshot(`""`);
20272027
});
2028+
2029+
it("should show self-bindings as connected", async () => {
2030+
writeWranglerConfig({
2031+
name: "my-worker",
2032+
services: [
2033+
{ binding: "SELF", service: "my-worker" },
2034+
{
2035+
binding: "NAMED",
2036+
service: "my-worker",
2037+
entrypoint: "MyEntrypoint",
2038+
},
2039+
],
2040+
});
2041+
fs.writeFileSync("index.js", `export default {};`);
2042+
await runWranglerUntilConfig("dev index.js");
2043+
expect(std.out).toMatchInlineSnapshot(`
2044+
"
2045+
⛅️ wrangler x.x.x
2046+
──────────────────
2047+
Your Worker has access to the following bindings:
2048+
Binding Resource Mode
2049+
env.SELF (my-worker) Worker local [connected]
2050+
env.NAMED (my-worker#MyEntrypoint) Worker local [connected]
2051+
2052+
"
2053+
`);
2054+
expect(std.warn).toMatchInlineSnapshot(`""`);
2055+
});
20282056
});
20292057

20302058
describe("print bindings", () => {

packages/wrangler/src/utils/print-bindings.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,24 @@ export function printBindings(
391391
if (remote) {
392392
mode = getMode({ isSimulatedLocally: false });
393393
} else if (context.local && context.registry !== null) {
394-
const registryDefinition = context.registry?.[service];
395-
hasConnectionStatus = true;
396-
397-
if (
398-
registryDefinition &&
399-
(!entrypoint ||
400-
registryDefinition.entrypointAddresses?.[entrypoint])
401-
) {
394+
const isSelfBinding = service === context.name;
395+
396+
if (isSelfBinding) {
397+
hasConnectionStatus = true;
402398
mode = getMode({ isSimulatedLocally: true, connected: true });
403399
} else {
404-
mode = getMode({ isSimulatedLocally: true, connected: false });
400+
const registryDefinition = context.registry?.[service];
401+
hasConnectionStatus = true;
402+
403+
if (
404+
registryDefinition &&
405+
(!entrypoint ||
406+
registryDefinition.entrypointAddresses?.[entrypoint])
407+
) {
408+
mode = getMode({ isSimulatedLocally: true, connected: true });
409+
} else {
410+
mode = getMode({ isSimulatedLocally: true, connected: false });
411+
}
405412
}
406413
}
407414

0 commit comments

Comments
 (0)