Skip to content

Commit

Permalink
fix: init from dash using explicit usage model for standard accounts (#…
Browse files Browse the repository at this point in the history
…4521)

Co-authored-by: Zeb Piasecki <[email protected]>
  • Loading branch information
zebp and zebp authored Dec 1, 2023
1 parent a72f64c commit 6c5bc70
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-cherries-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: init from dash specifying explicit usage model in wrangler.toml for standard users
73 changes: 70 additions & 3 deletions packages/wrangler/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,6 @@ describe("init", () => {
triggers: {
crons: ["0 0 0 * * *"],
},
usage_model: "bundled",
vars: {
"ANOTHER-NAME": "thing-TEXT",
},
Expand Down Expand Up @@ -2701,11 +2700,13 @@ describe("init", () => {
expectedScriptName = "",
expectedEnvironment = "",
expectedCompatDate,
expectedStandardEnablement = true,
}: {
expectedAccountId: string;
expectedScriptName: string;
expectedEnvironment: string;
expectedCompatDate: string | undefined;
expectedStandardEnablement?: boolean;
}) {
msw.use(
rest.get(
Expand Down Expand Up @@ -2808,6 +2809,20 @@ describe("init", () => {
})
);
}
),
rest.get(
`*/accounts/:accountId/workers/standard`,
(req, res, ctx) => {
return res.once(
ctx.status(200),
ctx.json({
success: true,
errors: [],
messages: [],
result: { standard: expectedStandardEnablement },
})
);
}
)
);
}
Expand Down Expand Up @@ -2986,7 +3001,6 @@ describe("init", () => {
main = \\"src/index.ts\\"
compatibility_date = \\"1987-9-27\\"
route = \\"delta.quadrant\\"
usage_model = \\"bundled\\"
[[migrations]]
tag = \\"some-migration-tag\\"
Expand Down Expand Up @@ -3324,6 +3338,20 @@ describe("init", () => {
})
);
}
),
rest.get(
`*/accounts/:accountId/workers/standard`,
(req, res, ctx) => {
return res.once(
ctx.status(200),
ctx.json({
success: true,
errors: [],
messages: [],
result: { standard: true },
})
);
}
)
);

Expand Down Expand Up @@ -3358,7 +3386,6 @@ describe("init", () => {
triggers: {
crons: [],
},
usage_model: "bundled",
name: "isolinear-optical-chip",
tail_consumers: [{ service: "listener" }],
}),
Expand Down Expand Up @@ -3450,6 +3477,46 @@ describe("init", () => {
},
});
});

it("should have an explicit usage model for non-standard users", async () => {
mockSupportingDashRequests({
expectedAccountId: "LCARS",
expectedScriptName: "memory-crystal",
expectedEnvironment: "test",
expectedCompatDate: "1987-9-27",
expectedStandardEnablement: false,
});
setMockFetchDashScript(mockDashboardScript);
mockConfirm(
{
text: "Would you like to use git to manage this Worker?",
result: false,
},
{
text: "No package.json found. Would you like to create one?",
result: true,
},
{
text: "Would you like to use TypeScript?",
result: true,
}
);

await runWrangler(
"init isolinear-optical-chip --from-dash memory-crystal --no-delegate-c3"
);

expect(std.out).toContain("cd isolinear-optical-chip");

checkFiles({
items: {
"isolinear-optical-chip/wrangler.toml": wranglerToml({
...mockConfigExpected,
usage_model: "bundled",
}),
},
});
});
});
});
});
Expand Down
13 changes: 11 additions & 2 deletions packages/wrangler/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export type CronTriggersRes = {
];
};

export type StandardRes = {
standard: boolean;
reason: string;
};

function isNpm(packageManager: PackageManager) {
return packageManager.type === "npm";
}
Expand Down Expand Up @@ -914,7 +919,7 @@ async function getWorkerConfig(
environments: ServiceMetadataRes["environments"] | undefined;
}
): Promise<RawConfig> {
const [bindings, routes, serviceEnvMetadata, cronTriggers] =
const [bindings, routes, serviceEnvMetadata, cronTriggers, standard] =
await Promise.all([
fetchResult<WorkerMetadata["bindings"]>(
`/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/bindings`
Expand All @@ -928,6 +933,7 @@ async function getWorkerConfig(
fetchResult<CronTriggersRes>(
`/accounts/${accountId}/workers/scripts/${fromDashScriptName}/schedules`
),
fetchResult<StandardRes>(`/accounts/${accountId}/workers/standard`),
]).catch((e) => {
throw new Error(
`Error Occurred ${e}: Unable to fetch bindings, routes, or services metadata from the dashboard. Please try again later.`
Expand Down Expand Up @@ -960,7 +966,10 @@ async function getWorkerConfig(
serviceEnvMetadata.script.compatibility_date ??
new Date().toISOString().substring(0, 10),
...routeOrRoutesToConfig,
usage_model: serviceEnvMetadata.script.usage_model,
usage_model:
standard?.standard == true
? undefined
: serviceEnvMetadata.script.usage_model,
placement:
serviceEnvMetadata.script.placement_mode === "smart"
? { mode: "smart" }
Expand Down

0 comments on commit 6c5bc70

Please sign in to comment.