Skip to content

Commit bc4d6c8

Browse files
authored
fix: make wrangler deploy not call Workflows API if it binds to a different script (#7964)
Basically, if a worker bounds to a Workflow defined in another script, it would do a PUT call to the Workflow API, overriding the config and because it would change the `script_name`, it would break new instances (because this one will probably not have the class exported). This commit makes it so that Wrangler does not call the API if the `script_name` is different.
1 parent ce8bfbd commit bc4d6c8

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
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+
Fix scripts binding to a workflow in a different script overriding workflow config

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12347,6 +12347,66 @@ export default{
1234712347
Current Version ID: Galaxy-Class"
1234812348
`);
1234912349
});
12350+
12351+
it("should not call Workflow's API if the workflow binds to another script", async () => {
12352+
writeWranglerConfig({
12353+
main: "index.js",
12354+
name: "this-script",
12355+
workflows: [
12356+
{
12357+
binding: "WORKFLOW",
12358+
name: "my-workflow",
12359+
class_name: "MyWorkflow",
12360+
script_name: "another-script",
12361+
},
12362+
],
12363+
});
12364+
12365+
mockSubDomainRequest();
12366+
mockUploadWorkerRequest({
12367+
expectedScriptName: "this-script",
12368+
expectedBindings: [
12369+
{
12370+
type: "workflow",
12371+
name: "WORKFLOW",
12372+
workflow_name: "my-workflow",
12373+
class_name: "MyWorkflow",
12374+
script_name: "another-script",
12375+
},
12376+
],
12377+
});
12378+
12379+
const handler = http.put(
12380+
"*/accounts/:accountId/workflows/:workflowName",
12381+
() => {
12382+
expect(
12383+
false,
12384+
"Workflows API should not be called at all, in this case."
12385+
);
12386+
}
12387+
);
12388+
msw.use(handler);
12389+
await fs.promises.writeFile(
12390+
"index.js",
12391+
`
12392+
export default {};
12393+
`
12394+
);
12395+
12396+
await runWrangler("deploy");
12397+
12398+
expect(std.out).toMatchInlineSnapshot(`
12399+
"Total Upload: xx KiB / gzip: xx KiB
12400+
Worker Startup Time: 100 ms
12401+
Your worker has access to the following bindings:
12402+
- Workflows:
12403+
- WORKFLOW: MyWorkflow (defined in another-script)
12404+
Uploaded this-script (TIMINGS)
12405+
Deployed this-script triggers (TIMINGS)
12406+
https://this-script.test-sub-domain.workers.dev
12407+
Current Version ID: Galaxy-Class"
12408+
`);
12409+
});
1235012410
});
1235112411
});
1235212412

packages/wrangler/src/triggers/deploy.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ export default async function triggersDeploy(
256256
logger.once.warn("Workflows is currently in open beta.");
257257

258258
for (const workflow of config.workflows) {
259+
// NOTE: if the user provides a script_name thats not this script (aka bounds to another worker)
260+
// we don't want to send this worker's config.
261+
if (
262+
workflow.script_name !== undefined &&
263+
workflow.script_name !== scriptName
264+
) {
265+
continue;
266+
}
267+
259268
deployments.push(
260269
fetchResult(`/accounts/${accountId}/workflows/${workflow.name}`, {
261270
method: "PUT",

0 commit comments

Comments
 (0)