Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrangler: cleanup standard pricing check after legacy usage model deprecation #5035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/wrangler/src/__tests__/deprecated-usage-model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
import { mockUploadWorkerRequest } from "./helpers/mock-upload-worker";
import { mockSubDomainRequest } from "./helpers/mock-workers-subdomain";
import { msw, mswSuccessDeploymentScriptMetadata } from "./helpers/msw";
import { runInTempDir } from "./helpers/run-in-tmp";
import { runWrangler } from "./helpers/run-wrangler";
import { writeWorkerSource } from "./helpers/write-worker-source";
import writeWranglerToml from "./helpers/write-wrangler-toml";

describe("deprecated-usage-model", () => {
mockAccountId();
mockApiToken();
runInTempDir();
const std = mockConsoleMethods();

// TODO: remove the fake timers and irrelevant tests after March 1st
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date(2024, 2, 2));
});

afterAll(() => {
jest.useRealTimers();
});
Comment on lines +17 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use fake timers here anymore?


it("should warn user about ignored usage model if usage_model specified", async () => {
msw.use(...mswSuccessDeploymentScriptMetadata);
writeWranglerToml({ usage_model: "bundled" });
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest();

await runWrangler("deploy ./index");

expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] The \`usage_model\` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model

"
`);
});
it("should not warn user about ignored usage model if usage_model not specified", async () => {
msw.use(...mswSuccessDeploymentScriptMetadata);
writeWranglerToml();
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest();

await runWrangler("deploy ./index");

expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class",
"warn": "",
}
`);
});
});
224 changes: 0 additions & 224 deletions packages/wrangler/src/__tests__/standard-pricing.test.ts

This file was deleted.

50 changes: 6 additions & 44 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import path from "node:path";
import chalk from "chalk";
import { fetchResult } from "../cfetch";
import { findWranglerToml, readConfig } from "../config";
import { getEntry } from "../deployment-bundle/entry";
import { UserError } from "../errors";
Expand All @@ -22,48 +20,12 @@ import type {
StrictYargsOptionsToInterface,
} from "../yargs-types";

async function standardPricingWarning(
accountId: string | undefined,
config: Config
) {
if (Date.now() >= Date.UTC(2024, 2, 1, 14)) {
if (config.usage_model !== undefined) {
logger.warn(
"The `usage_model` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model"
);
}

// TODO: After March 1st 2024 remove the code below
return;
async function standardPricingWarning(config: Config) {
if (config.usage_model !== undefined) {
logger.warn(
"The `usage_model` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model"
);
}

try {
const { standard, reason } = await fetchResult<{
standard: boolean;
reason: string;
}>(`/accounts/${accountId}/workers/standard`);

if (!standard && reason !== "enterprise without override") {
logger.log(
chalk.blue(
`🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/${accountId}/workers/standard/opt-in.`
)
);
if (config.limits?.cpu_ms !== undefined) {
logger.warn(
"The `limits` defined in wrangler.toml can only be applied to scripts opted into Workers Standard pricing. Agree to the new pricing details to set limits for your script."
);
}
return;
}
if (standard && config.usage_model !== undefined) {
logger.warn(
"The `usage_model` defined in wrangler.toml is no longer used because you have opted into Workers Standard pricing. Please remove this setting from your wrangler.toml and use the dashboard to configure the usage model for your script."
);
return;
}
// Ignore 404 errors for the enablement check
} catch {}
}

export function deployOptions(yargs: CommonYargsArgv) {
Expand Down Expand Up @@ -305,7 +267,7 @@ export async function deployHandler(
args.siteExclude
);

if (!args.dryRun) await standardPricingWarning(accountId, config);
if (!args.dryRun) await standardPricingWarning(config);

await deploy({
config,
Expand Down
Loading
Loading