From f0434ad146d67bd517dc205ddc2b60209003c2cc Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 25 Sep 2025 15:43:45 +0100 Subject: [PATCH] fix: allow Workflow bindings when calling getPlatformProxy() Workflow bindings are not supported in practice when using `getPlatformProxy()`. But their existence in a Wrangler config file should not prevent other bindings from working. Previously, calling `getPlatformProxy()` would crash if there were any Workflow bindings defined. Now, instead, you get a warning telling you that these bindings are not available. --- .changeset/modern-flowers-care.md | 10 +++ .../tests/get-platform-proxy.env.test.ts | 61 +++++++++---------- .../wrangler_workflow.jsonc | 22 +++++++ .../src/api/integrations/platform/index.ts | 11 ++++ 4 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 .changeset/modern-flowers-care.md create mode 100644 fixtures/get-platform-proxy/wrangler_workflow.jsonc diff --git a/.changeset/modern-flowers-care.md b/.changeset/modern-flowers-care.md new file mode 100644 index 00000000000..359a56d6e20 --- /dev/null +++ b/.changeset/modern-flowers-care.md @@ -0,0 +1,10 @@ +--- +"wrangler": patch +--- + +fix: allow Workflow bindings when calling getPlatformProxy() + +Workflow bindings are not supported in practice when using `getPlatformProxy()`. +But their existence in a Wrangler config file should not prevent other bindings from working. +Previously, calling `getPlatformProxy()` would crash if there were any Workflow bindings defined. +Now, instead, you get a warning telling you that these bindings are not available. diff --git a/fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts b/fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts index 3ec934746d9..8e49a4308a9 100644 --- a/fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts +++ b/fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts @@ -16,6 +16,7 @@ import type { Hyperdrive, ImagesBinding, KVNamespace, + Workflow, } from "@cloudflare/workers-types"; import type { Unstable_DevWorker } from "wrangler"; @@ -31,16 +32,21 @@ type Env = { MY_HYPERDRIVE: Hyperdrive; ASSETS: Fetcher; IMAGES: ImagesBinding; + MY_WORKFLOW_INTERNAL: Workflow; + MY_WORKFLOW_EXTERNAL: Workflow; }; const wranglerConfigFilePath = path.join(__dirname, "..", "wrangler.jsonc"); describe("getPlatformProxy - env", () => { let devWorkers: Unstable_DevWorker[]; + let warn = {} as MockInstance; beforeEach(() => { // Hide stdout messages from the test logs vi.spyOn(console, "log").mockImplementation(() => {}); + vi.spyOn(console, "error").mockImplementation(() => {}); + warn = vi.spyOn(console, "warn").mockImplementation(() => {}); }); describe("var bindings", () => { @@ -261,41 +267,20 @@ describe("getPlatformProxy - env", () => { }); describe("DO warnings", () => { - let warn = {} as MockInstance; - beforeEach(() => { - warn = vi.spyOn(console, "warn").mockImplementation(() => {}); - }); - afterEach(() => { - warn.mockRestore(); - }); - it("warns about internal DOs and doesn't crash", async () => { await getPlatformProxy({ configPath: path.join(__dirname, "..", "wrangler_internal_do.jsonc"), }); - expect(warn).toMatchInlineSnapshot(` - [MockFunction warn] { - "calls": [ - [ - "▲ [WARNING]  You have defined bindings to the following internal Durable Objects: - - - {"class_name":"MyDurableObject","name":"MY_DURABLE_OBJECT"} - These will not work in local development, but they should work in production. - - If you want to develop these locally, you can define your DO in a separate Worker, with a separate configuration file. - For detailed instructions, refer to the Durable Objects section here: https://developers.cloudflare.com/workers/wrangler/api#supported-bindings - - ", - ], - ], - "results": [ - { - "type": "return", - "value": undefined, - }, - ], - } - `); + expect(warn.mock.calls[0][0].replaceAll(/[\r\n]+/g, "\n")) + .toMatchInlineSnapshot(` + "▲ [WARNING]  You have defined bindings to the following internal Durable Objects: + - {"class_name":"MyDurableObject","name":"MY_DURABLE_OBJECT"} + These will not work in local development, but they should work in production. + + If you want to develop these locally, you can define your DO in a separate Worker, with a separate configuration file. + For detailed instructions, refer to the Durable Objects section here: https://developers.cloudflare.com/workers/wrangler/api#supported-bindings + " + `); }); it("doesn't warn about external DOs and doesn't crash", async () => { @@ -304,6 +289,20 @@ describe("getPlatformProxy - env", () => { }); expect(warn).not.toHaveBeenCalled(); }); + + it("warns about Workflows and doesn't crash", async () => { + await getPlatformProxy({ + configPath: path.join(__dirname, "..", "wrangler_workflow.jsonc"), + }); + expect(warn.mock.calls[0][0].replaceAll(/[\r\n]+/g, "\n")) + .toMatchInlineSnapshot(` + "▲ [WARNING]  You have defined bindings to the following Workflows: + - {"binding":"MY_WORKFLOW_INTERNAL","name":"my-workflow-internal","class_name":"MyWorkflowInternal"} + - {"binding":"MY_WORKFLOW_EXTERNAL","name":"my-workflow-external","class_name":"MyWorkflowExternal","script_name":"OtherWorker"} + These are not available in local development, so you will not be able to bind to them when testing locally, but they should work in production. + " + `); + }); }); describe("with a target environment", () => { diff --git a/fixtures/get-platform-proxy/wrangler_workflow.jsonc b/fixtures/get-platform-proxy/wrangler_workflow.jsonc new file mode 100644 index 00000000000..d636accf61b --- /dev/null +++ b/fixtures/get-platform-proxy/wrangler_workflow.jsonc @@ -0,0 +1,22 @@ +{ + "name": "workflow-test", + "main": "src/index.ts", + // An internal workflow is indicated by the binding not specifying a script name. + // This implies the workflow is exported alongside this worker in `index.ts`, which it isn't actually. + // However we don't care about this here because `getPlatformProxy()` will discard all user code anyway. + // We are simply making sure the warning shows up. + "compatibility_date": "2023-11-21", + "workflows": [ + { + "binding": "MY_WORKFLOW_INTERNAL", + "name": "my-workflow-internal", + "class_name": "MyWorkflowInternal", + }, + { + "binding": "MY_WORKFLOW_EXTERNAL", + "name": "my-workflow-external", + "class_name": "MyWorkflowExternal", + "script_name": "OtherWorker", + }, + ], +} diff --git a/packages/wrangler/src/api/integrations/platform/index.ts b/packages/wrangler/src/api/integrations/platform/index.ts index 23bc296a563..b766b2e07c9 100644 --- a/packages/wrangler/src/api/integrations/platform/index.ts +++ b/packages/wrangler/src/api/integrations/platform/index.ts @@ -226,6 +226,17 @@ async function getMiniflareOptionsFromConfig(args: { } } + if (config.workflows?.length > 0) { + logger.warn(dedent` + You have defined bindings to the following Workflows: + ${config.workflows.map((b) => `- ${JSON.stringify(b)}`).join("\n")} + These are not available in local development, so you will not be able to bind to them when testing locally, but they should work in production. + `); + + // Remove workflows from bindings to prevent Miniflare from complaining + bindings.workflows = []; + } + const { bindingOptions, externalWorkers } = buildMiniflareBindingOptions( { name: config.name,