Skip to content

Commit e6aa865

Browse files
Ensure that wrangler deploy --dry-run doesn't fetch data from the rest API (#11465)
1 parent 9eaa9e2 commit e6aa865

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15285,6 +15285,32 @@ export default{
1528515285
`);
1528615286
});
1528715287

15288+
it("should not present a diff warning to the user when there are differences between the local config (json/jsonc) and the dash config in dry-run mode", async () => {
15289+
writeWorkerSource();
15290+
writeWranglerConfig(
15291+
{
15292+
compatibility_date: "2024-04-24",
15293+
main: "./index.js",
15294+
workers_dev: true,
15295+
preview_urls: true,
15296+
vars: {
15297+
MY_VAR: 123,
15298+
},
15299+
observability: {
15300+
enabled: true,
15301+
},
15302+
},
15303+
"./wrangler.json"
15304+
);
15305+
15306+
// Note: we don't set any mocks here since in dry-run we don't expect wragnler to interact
15307+
// with the rest API in any way
15308+
15309+
await runWrangler("deploy --dry-run");
15310+
15311+
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`""`);
15312+
});
15313+
1528815314
it("should present a diff warning to the user when there are differences between the local config (toml) and the dash config", async () => {
1528915315
writeWorkerSource();
1529015316
mockGetServiceByName("test-name", "production", "dash");
@@ -15599,13 +15625,43 @@ export default{
1559915625

1560015626
await runWrangler("deploy");
1560115627

15628+
expect(fetchSecrets).toHaveBeenCalled();
1560215629
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
1560315630
"▲ [WARNING] Environment variable \`MY_SECRET\` conflicts with an existing remote secret. This deployment will replace the remote secret with your environment variable.
1560415631

1560515632
"
1560615633
`);
1560715634
});
1560815635

15636+
it("should not fetch remote secrets in dry-run mode", async () => {
15637+
writeWorkerSource();
15638+
writeWranglerConfig(
15639+
{
15640+
compatibility_date: "2024-04-24",
15641+
main: "./index.js",
15642+
vars: {
15643+
MY_SECRET: 123,
15644+
},
15645+
observability: {
15646+
enabled: true,
15647+
},
15648+
},
15649+
"./wrangler.json"
15650+
);
15651+
15652+
// Note: we don't set any mocks here since in dry-run we don't expect wragnler to interact
15653+
// with the rest API in any way
15654+
15655+
vi.mocked(fetchSecrets).mockResolvedValue([
15656+
{ name: "MY_SECRET", type: "secret_text" },
15657+
]);
15658+
15659+
await runWrangler("deploy --dry-run");
15660+
15661+
expect(fetchSecrets).not.toHaveBeenCalled();
15662+
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`""`);
15663+
});
15664+
1560915665
it("should abort the deployment when it would (likely unintentionally) override remote secrets in non-interactive strict mode", async () => {
1561015666
setIsTTY(false);
1561115667

@@ -15652,6 +15708,8 @@ export default{
1565215708

1565315709
await runWrangler("deploy --strict");
1565415710

15711+
expect(fetchSecrets).toHaveBeenCalled();
15712+
1565515713
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
1565615714
"▲ [WARNING] Environment variable \`MY_SECRET\` conflicts with an existing remote secret. This deployment will replace the remote secret with your environment variable.
1565715715

packages/wrangler/src/deploy/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export default async function deploy(props: Props): Promise<{
473473
}
474474
}
475475

476-
if (isInteractive() || props.strict) {
476+
if (accountId && (isInteractive() || props.strict)) {
477477
const remoteSecretsCheck = await checkRemoteSecretsOverride(
478478
config,
479479
props.env

0 commit comments

Comments
 (0)