diff --git a/.changeset/eighty-peas-clean.md b/.changeset/eighty-peas-clean.md new file mode 100644 index 000000000000..52ea80b202d2 --- /dev/null +++ b/.changeset/eighty-peas-clean.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +fix: Improvements to `--init-from-dash` + +Adds user-specified CPU limit to `wrangler.toml` if one exists. Excludes `usage_model` from `wrangler.toml` in all cases, since this field is deprecated and no longer used. diff --git a/packages/wrangler/src/__tests__/init.test.ts b/packages/wrangler/src/__tests__/init.test.ts index 02d9c6d91d47..06c6f290684b 100644 --- a/packages/wrangler/src/__tests__/init.test.ts +++ b/packages/wrangler/src/__tests__/init.test.ts @@ -16,6 +16,7 @@ import { msw } from "./helpers/msw"; import { runInTempDir } from "./helpers/run-in-tmp"; import { runWrangler } from "./helpers/run-wrangler"; import type { RawConfig } from "../config"; +import type { UserLimits } from "../config/environment"; import type { PackageManager } from "../package-manager"; /** @@ -2575,6 +2576,7 @@ describe("init", () => { ], customDomains = [], workersDev = true, + limits, }: { id?: string; usage_model?: string; @@ -2585,6 +2587,7 @@ describe("init", () => { routes?: unknown[]; customDomains?: unknown[]; workersDev?: boolean; + limits?: UserLimits; } = {}) { return { schedules, @@ -2603,6 +2606,7 @@ describe("init", () => { created_on: "1987-09-27", migration_tag: "some-migration-tag", usage_model, + limits, compatibility_date, tail_consumers: [{ service: "listener" }], }, @@ -2643,7 +2647,6 @@ describe("init", () => { const mockConfigExpected: RawConfig = { workers_dev: true, - usage_model: "bundled", main: "src/index.js", compatibility_date: "1987-09-27", name: "isolinear-optical-chip", @@ -3007,7 +3010,6 @@ describe("init", () => { main = \\"src/index.js\\" compatibility_date = \\"1987-09-27\\" workers_dev = false - usage_model = \\"bundled\\" [[routes]] pattern = \\"delta.quadrant\\" @@ -3123,7 +3125,6 @@ describe("init", () => { main = \\"src/index.js\\" compatibility_date = \\"1987-09-27\\" workers_dev = true - usage_model = \\"bundled\\" [[routes]] pattern = \\"delta.quadrant\\" @@ -3257,23 +3258,48 @@ describe("init", () => { }, }); }); - it("should ignore usage_model = standard", async () => { + + it("should include user limits", async () => { worker = makeWorker({ id: "isolinear-optical-chip", - usage_model: "standard", + limits: { + cpu_ms: 75, + }, }); - await expect( - downloadWorker("LCARS", "isolinear-optical-chip") - ).resolves.toMatchObject({ - config: { - ...mockConfigExpected, - main: "index.js", - usage_model: undefined, + const { config } = await downloadWorker( + "LCARS", + "isolinear-optical-chip" + ); + expect(config).toMatchObject({ + ...mockConfigExpected, + main: "index.js", + limits: { + cpu_ms: 75, }, }); }); + it.each(["bundled", "unbound", "standard"])( + "should ignore usage_model = %s", + async (usage_model) => { + worker = makeWorker({ + id: "isolinear-optical-chip", + usage_model, + }); + + const { config } = await downloadWorker( + "LCARS", + "isolinear-optical-chip" + ); + expect(config).toMatchObject({ + ...mockConfigExpected, + main: "index.js", + }); + expect(config.usage_model).toBeUndefined(); + } + ); + it("should use fallback compatibility date if none is upstream", async () => { worker = makeWorker({ id: "isolinear-optical-chip", @@ -3387,7 +3413,6 @@ describe("init", () => { compatibility_date: "1988-08-07", main: "src/index.js", workers_dev: true, - usage_model: "bundled", name: "isolinear-optical-chip", tail_consumers: [{ service: "listener" }], }), @@ -3489,34 +3514,6 @@ describe("init", () => { }, }); }); - - it("should have an explicit usage model for non-standard users", async () => { - 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, - } - ); - - 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", - }), - }, - }); - }); }); }); }); diff --git a/packages/wrangler/src/init.ts b/packages/wrangler/src/init.ts index c58d1371dc11..072cf14083be 100644 --- a/packages/wrangler/src/init.ts +++ b/packages/wrangler/src/init.ts @@ -92,6 +92,9 @@ export type ServiceMetadataRes = { created_on: string; migration_tag: string; usage_model: "bundled" | "unbound"; + limits: { + cpu_ms: number; + }; compatibility_date: string; compatibility_flags: string[]; last_deployed_from?: "wrangler" | "dash" | "api"; @@ -896,7 +899,6 @@ async function getWorkerConfig( workersDev, serviceEnvMetadata, cronTriggers, - standard, ] = await Promise.all([ fetchResult( `/accounts/${accountId}/workers/services/${workerName}/environments/${serviceEnvironment}/bindings` @@ -918,7 +920,6 @@ async function getWorkerConfig( fetchResult( `/accounts/${accountId}/workers/scripts/${workerName}/schedules` ), - fetchResult(`/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.` @@ -956,14 +957,11 @@ async function getWorkerConfig( new Date().toISOString().substring(0, 10), compatibility_flags: serviceEnvMetadata.script.compatibility_flags, ...(allRoutes.length ? { routes: allRoutes } : {}), - usage_model: - standard?.standard == true - ? undefined - : serviceEnvMetadata.script.usage_model, placement: serviceEnvMetadata.script.placement_mode === "smart" ? { mode: "smart" } : undefined, + limits: serviceEnvMetadata.script.limits, ...(durableObjectClassNames.length ? { migrations: [