Skip to content

Commit c41fb32

Browse files
committed
[wrangler] skip fetching all deployable versions when the user already specified the desired version
1 parent 0386553 commit c41fb32

3 files changed

Lines changed: 83 additions & 23 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Skip unnecessary `GET /versions?deployable=true` API call in `wrangler versions deploy` when all version IDs are explicitly provided and `--yes` is passed
6+
7+
When deploying a specific version non-interactively (e.g. `wrangler versions deploy <id> --yes`), Wrangler previously always fetched the full list of deployable versions to populate the interactive selection prompt — even though the prompt is skipped entirely when `--yes` is used and all versions are already specified. The deployable-versions list is now only fetched when actually needed (i.e. when no version IDs are provided, or when running interactively).

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

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { writeWranglerConfig } from "@cloudflare/workers-utils/test-helpers";
2+
import { HttpResponse, http } from "msw";
23
import { beforeEach, describe, it, test } from "vitest";
34
import { normalizeOutput } from "../../../e2e/helpers/normalize";
45
import {
@@ -17,6 +18,7 @@ import {
1718
mockSubDomainRequest,
1819
} from "../helpers/mock-workers-subdomain";
1920
import {
21+
createFetchResult,
2022
msw,
2123
mswGetVersion,
2224
mswListNewDeployments,
@@ -30,6 +32,47 @@ import { runInTempDir } from "../helpers/run-in-tmp";
3032
import { runWrangler } from "../helpers/run-wrangler";
3133
import { writeWorkerSource } from "../helpers/write-worker-source";
3234

35+
// MSW handler that returns the full annotations for version 30000000-... when
36+
// fetched individually (GET /versions/:id). The generic mswGetVersion() mock
37+
// returns no annotations, but the real API returns the same data as the list
38+
// endpoint. Used in tests that skip fetchDeployableVersions (--yes + explicit IDs).
39+
const mswGetVersion30000000 = http.get(
40+
"*/accounts/:accountId/workers/scripts/:workerName/versions/30000000-0000-0000-0000-000000000000",
41+
() =>
42+
HttpResponse.json(
43+
createFetchResult({
44+
id: "30000000-0000-0000-0000-000000000000",
45+
number: "NCC-74656",
46+
annotations: {
47+
"workers/triggered_by": "rollback",
48+
"workers/rollback_from": "MOCK-DEPLOYMENT-ID-1111",
49+
"workers/message": "Rolled back for this version",
50+
},
51+
metadata: {
52+
author_id: "Kathryn-Jane-Gamma-6-0-7-3",
53+
author_email: "Kathryn-Janeway@federation.org",
54+
source: "wrangler",
55+
created_on: "2021-02-02T00:00:00.000000Z",
56+
modified_on: "2021-02-02T00:00:00.000000Z",
57+
},
58+
resources: {
59+
bindings: [],
60+
script: {
61+
etag: "aaabbbccc",
62+
handlers: ["fetch"],
63+
last_deployed_from: "api",
64+
},
65+
script_runtime: {
66+
compatibility_date: "2020-01-01",
67+
compatibility_flags: [],
68+
usage_model: "standard",
69+
limits: { cpu_ms: 50 },
70+
},
71+
},
72+
})
73+
)
74+
);
75+
3376
describe("versions deploy", () => {
3477
mockAccountId();
3578
mockApiToken();
@@ -115,7 +158,7 @@ describe("versions deploy", () => {
115158
│ Tag: -
116159
│ Message: -
117160
118-
├ Fetching deployable versions
161+
├ Fetching versions
119162
120163
├ Which version(s) do you want to deploy?
121164
├ 1 Worker Version(s) selected
@@ -180,7 +223,7 @@ describe("versions deploy", () => {
180223
│ Tag: -
181224
│ Message: -
182225
183-
├ Fetching deployable versions
226+
├ Fetching versions
184227
185228
├ Which version(s) do you want to deploy?
186229
├ 0 Worker Version(s) selected
@@ -212,7 +255,7 @@ describe("versions deploy", () => {
212255
│ Tag: -
213256
│ Message: -
214257
215-
├ Fetching deployable versions
258+
├ Fetching versions
216259
217260
├ Which version(s) do you want to deploy?
218261
├ 1 Worker Version(s) selected
@@ -259,7 +302,7 @@ describe("versions deploy", () => {
259302
│ Tag: -
260303
│ Message: -
261304
262-
├ Fetching deployable versions
305+
├ Fetching versions
263306
264307
├ Which version(s) do you want to deploy?
265308
├ 1 Worker Version(s) selected
@@ -306,7 +349,7 @@ describe("versions deploy", () => {
306349
│ Tag: -
307350
│ Message: -
308351
309-
├ Fetching deployable versions
352+
├ Fetching versions
310353
311354
├ Which version(s) do you want to deploy?
312355
├ 2 Worker Version(s) selected
@@ -361,7 +404,7 @@ describe("versions deploy", () => {
361404
│ Tag: -
362405
│ Message: -
363406
364-
├ Fetching deployable versions
407+
├ Fetching versions
365408
366409
├ Which version(s) do you want to deploy?
367410
├ 1 Worker Version(s) selected
@@ -408,7 +451,7 @@ describe("versions deploy", () => {
408451
│ Tag: -
409452
│ Message: -
410453
411-
├ Fetching deployable versions
454+
├ Fetching versions
412455
413456
├ Which version(s) do you want to deploy?
414457
├ 2 Worker Version(s) selected
@@ -463,7 +506,7 @@ describe("versions deploy", () => {
463506
│ Tag: -
464507
│ Message: -
465508
466-
├ Fetching deployable versions
509+
├ Fetching versions
467510
468511
├ Which version(s) do you want to deploy?
469512
├ 2 Worker Version(s) selected
@@ -496,6 +539,7 @@ describe("versions deploy", () => {
496539

497540
describe("max versions restrictions (temp)", () => {
498541
test("2+ versions fails", async ({ expect }) => {
542+
msw.use(mswGetVersion30000000);
499543
const result = runWrangler(
500544
"versions deploy 10000000-0000-0000-0000-000000000000 20000000-0000-0000-0000-000000000000 30000000-0000-0000-0000-000000000000 --yes"
501545
);
@@ -521,7 +565,7 @@ describe("versions deploy", () => {
521565
│ Tag: -
522566
│ Message: -
523567
524-
├ Fetching deployable versions
568+
├ Fetching versions
525569
526570
├ Which version(s) do you want to deploy?
527571
├ 3 Worker Version(s) selected
@@ -545,6 +589,7 @@ describe("versions deploy", () => {
545589
});
546590

547591
test("--max-versions allows > 2 versions", async ({ expect }) => {
592+
msw.use(mswGetVersion30000000);
548593
const result = runWrangler(
549594
"versions deploy 10000000-0000-0000-0000-000000000000 20000000-0000-0000-0000-000000000000 30000000-0000-0000-0000-000000000000 --max-versions=3 --yes"
550595
);
@@ -568,7 +613,7 @@ describe("versions deploy", () => {
568613
│ Tag: -
569614
│ Message: -
570615
571-
├ Fetching deployable versions
616+
├ Fetching versions
572617
573618
├ Which version(s) do you want to deploy?
574619
├ 3 Worker Version(s) selected
@@ -634,7 +679,7 @@ describe("versions deploy", () => {
634679
│ Tag: -
635680
│ Message: -
636681
637-
├ Fetching deployable versions
682+
├ Fetching versions
638683
639684
├ Which version(s) do you want to deploy?
640685
├ 1 Worker Version(s) selected
@@ -686,7 +731,7 @@ describe("versions deploy", () => {
686731
│ Tag: -
687732
│ Message: -
688733
689-
├ Fetching deployable versions
734+
├ Fetching versions
690735
691736
├ Which version(s) do you want to deploy?
692737
├ 1 Worker Version(s) selected
@@ -745,7 +790,7 @@ describe("versions deploy", () => {
745790
│ Tag: -
746791
│ Message: -
747792
748-
├ Fetching deployable versions
793+
├ Fetching versions
749794
750795
├ Which version(s) do you want to deploy?
751796
├ 1 Worker Version(s) selected
@@ -813,7 +858,7 @@ describe("versions deploy", () => {
813858
│ Tag: -
814859
│ Message: -
815860
816-
├ Fetching deployable versions
861+
├ Fetching versions
817862
818863
├ Which version(s) do you want to deploy?
819864
├ 1 Worker Version(s) selected
@@ -884,7 +929,7 @@ describe("versions deploy", () => {
884929
│ Tag: -
885930
│ Message: -
886931
887-
├ Fetching deployable versions
932+
├ Fetching versions
888933
889934
├ Which version(s) do you want to deploy?
890935
├ 1 Worker Version(s) selected
@@ -943,7 +988,7 @@ describe("versions deploy", () => {
943988
│ Tag: -
944989
│ Message: -
945990
946-
├ Fetching deployable versions
991+
├ Fetching versions
947992
│"
948993
`);
949994
});

packages/wrangler/src/versions/deploy.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,23 @@ async function promptVersionsToDeploy(
362362
versionCache: VersionCache,
363363
yesFlag: boolean
364364
): Promise<VersionId[]> {
365+
// If the user has already specified all versions they want to deploy and
366+
// has passed --yes (so there's no interactive prompt), skip fetching the
367+
// full deployable-versions list and only fetch the specific versions needed.
368+
const skipDeployableVersionsFetch =
369+
yesFlag && defaultSelectedVersionIds.length > 0;
370+
365371
await spinnerWhile({
366-
startMessage: "Fetching deployable versions",
372+
startMessage: "Fetching versions",
367373
async promise() {
368-
await fetchDeployableVersions(
369-
complianceConfig,
370-
accountId,
371-
workerName,
372-
versionCache
373-
);
374+
if (!skipDeployableVersionsFetch) {
375+
await fetchDeployableVersions(
376+
complianceConfig,
377+
accountId,
378+
workerName,
379+
versionCache
380+
);
381+
}
374382
await fetchVersions(
375383
complianceConfig,
376384
accountId,

0 commit comments

Comments
 (0)