Skip to content

Commit

Permalink
Version followups - fix rollback, version view improvements (#6118)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Jun 21, 2024
1 parent 87eb4c6 commit 1621992
Show file tree
Hide file tree
Showing 16 changed files with 974 additions and 170 deletions.
7 changes: 7 additions & 0 deletions .changeset/brave-doors-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: rollback in the case of a secret change, the prompt meant to show was not showing due to the spinner in an interactive env. It will now properly show.

chore: improve the view of `wrangler versions view` and change up copy a little for `versions secret` commands.
79 changes: 54 additions & 25 deletions packages/wrangler/src/__tests__/helpers/msw/handlers/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,33 +266,62 @@ export const mswListVersions = http.get(
}
);

export const mswGetVersion = http.get(
"*/accounts/:accountId/workers/scripts/:workerName/versions/:versionId",
({ params }) => {
const versionId = String(params["versionId"]);
export const mswGetVersion = (version?: ApiVersion) =>
http.get(
"*/accounts/:accountId/workers/scripts/:workerName/versions/:versionId",
({ params }) => {
const versionId = String(params["versionId"]);

if (versionId === "ffffffff-ffff-ffff-ffff-ffffffffffff") {
return HttpResponse.json(createFetchResult({}, false));
}
if (versionId === "ffffffff-ffff-ffff-ffff-ffffffffffff") {
return HttpResponse.json(createFetchResult({}, false));
}

return HttpResponse.json(
createFetchResult({
id: versionId,
number: "1701-E",
annotations: {
"workers/triggered_by": "upload",
},
metadata: {
author_id: "Picard-Gamma-6-0-7-3",
author_email: "Jean-Luc-Picard@federation.org",
source: "wrangler",
created_on: "2021-01-01T00:00:00.000000Z",
modified_on: "2021-01-01T00:00:00.000000Z",
},
})
);
}
);
return HttpResponse.json(
createFetchResult(
version ??
({
id: versionId,
number: 1,
annotations: {
"workers/triggered_by": "upload",
},
metadata: {
author_id: "Picard-Gamma-6-0-7-3",
author_email: "Jean-Luc-Picard@federation.org",
source: "wrangler",
created_on: "2021-01-01T00:00:00.000000Z",
modified_on: "2021-01-01T00:00:00.000000Z",
},
resources: {
bindings: [
{
type: "analytics_engine",
name: "ANALYTICS",
dataset: "analytics_dataset",
},
{
type: "kv_namespace",
name: "KV",
namespace_id: "kv-namespace-id",
},
],
script: {
etag: "aaabbbccc",
handlers: ["fetch", "scheduled"],
last_deployed_from: "api",
},
script_runtime: {
compatibility_date: "2020-01-01",
compatibility_flags: ["test", "flag"],
usage_model: "standard",
limits: { cpu_ms: 50 },
},
},
} as ApiVersion)
)
);
}
);

export const mswPostNewDeployment = http.post(
"*/accounts/:accountId/workers/scripts/:workerName/deployments",
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/rollback.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { http, HttpResponse } from "msw";
import { describe, expect, test } from "vitest";
import { CANNOT_ROLLBACK_WITH_MODIFIED_SECERT_CODE } from "../versions/api";
import { CANNOT_ROLLBACK_WITH_MODIFIED_SECERT_CODE } from "../versions/rollback";
import { collectCLIOutput } from "./helpers/collect-cli-output";
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConfirm, mockPrompt } from "./helpers/mock-dialogs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("deployments list", () => {
const std = collectCLIOutput();

beforeEach(() => {
msw.use(mswListNewDeployments, mswGetVersion);
msw.use(mswListNewDeployments, mswGetVersion());
});

describe("without wrangler.toml", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("deployments list", () => {
const std = collectCLIOutput();

beforeEach(() => {
msw.use(mswListNewDeployments, mswGetVersion);
msw.use(mswListNewDeployments, mswGetVersion());
});

describe("without wrangler.toml", () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/wrangler/src/__tests__/versions/secrets/bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ describe("versions secret put", () => {
✨ Successfully created secret for key: SECRET_1
✨ Successfully created secret for key: SECRET_2
✨ Successfully created secret for key: SECRET_3
✨ Success! Created version id with 3 secrets. To deploy this version to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with 3 secrets.
➡️ To deploy this version to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -104,7 +105,8 @@ describe("versions secret put", () => {
✨ Successfully created secret for key: SECRET_1
✨ Successfully created secret for key: SECRET_2
✨ Successfully created secret for key: SECRET_3
✨ Success! Created version id with 3 secrets. To deploy this version to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with 3 secrets.
➡️ To deploy this version to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ describe("versions secret put", () => {

expect(std.out).toMatchInlineSnapshot(`
"🌀 Deleting the secret SECRET on the Worker script-name
✨ Success! Created version id with deleted secret SECRET. To deploy this version without the secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
��� Success! Created version id with deleted secret SECRET.
➡️ To deploy this version without the secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand All @@ -70,7 +71,8 @@ describe("versions secret put", () => {
"? Are you sure you want to permanently delete the secret SECRET on the Worker script-name?
🤖 Using fallback value in non-interactive context: yes
🌀 Deleting the secret SECRET on the Worker script-name
✨ Success! Created version id with deleted secret SECRET. To deploy this version without the secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with deleted secret SECRET.
➡️ To deploy this version without the secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand All @@ -96,7 +98,8 @@ describe("versions secret put", () => {
"? Are you sure you want to permanently delete the secret SECRET on the Worker script-name?
🤖 Using fallback value in non-interactive context: yes
🌀 Deleting the secret SECRET on the Worker script-name
✨ Success! Created version id with deleted secret SECRET. To deploy this version without the secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with deleted secret SECRET.
➡️ To deploy this version without the secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down
15 changes: 10 additions & 5 deletions packages/wrangler/src/__tests__/versions/secrets/put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe("versions secret put", () => {

expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secret for the Worker \\"script-name\\"
✨ Success! Created version id with secret NEW_SECRET. To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with secret NEW_SECRET.
➡️ To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -108,7 +109,8 @@ describe("versions secret put", () => {

expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secret for the Worker \\"script-name\\"
✨ Success! Created version id with secret NEW_SECRET. To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with secret NEW_SECRET.
➡️ To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -143,7 +145,8 @@ describe("versions secret put", () => {

expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secret for the Worker \\"script-name\\"
✨ Success! Created version id with secret NEW_SECRET. To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with secret NEW_SECRET.
➡️ To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -181,7 +184,8 @@ describe("versions secret put", () => {

expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secret for the Worker \\"script-name\\"
✨ Success! Created version id with secret NEW_SECRET. To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with secret NEW_SECRET.
➡️ To deploy this version with secret NEW_SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -216,7 +220,8 @@ describe("versions secret put", () => {

expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secret for the Worker \\"script-name\\"
✨ Success! Created version id with secret SECRET. To deploy this version with secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
✨ Success! Created version id with secret SECRET.
➡️ To deploy this version with secret SECRET to production traffic use the command \\"wrangler versions deploy --x-versions\\"."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("versions deploy", () => {
msw.use(
mswListNewDeployments,
mswListVersions,
mswGetVersion,
mswGetVersion(),
mswPostNewDeployment,
mswPatchNonVersionedScriptSettings
);
Expand Down
Loading

0 comments on commit 1621992

Please sign in to comment.