Skip to content
Open
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
9 changes: 9 additions & 0 deletions .changeset/cyan-tools-show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future (if we change our approach to experimental semvers) this could be minor

Copy link
Member Author

Choose a reason for hiding this comment

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

right 🤔

I am happy to change it if we want 🙂

---

Offer to update the local Wrangler configuration file to match remote configuration when running `wrangler deploy`

When running `wrangler deploy`, with `--x-remote-diff-check`, Wrangler will display the difference between local and remote configuration.
If there would be a destructive change to the remote configuration, the user is given the option to cancel the deployment.
In the case where the user does cancel deployment, Wrangler will now also offer to update the local Wrangler configuration file to match the remote configuration.
253 changes: 253 additions & 0 deletions packages/wrangler/src/__tests__/deploy/get-config-patch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
import { getConfigPatch } from "../../deploy/config-diffs";

// Note: __old (as well as *__deleted) is the value in the remote config, __new is the value in the local one, so we do want the
// __old one to override the __new

describe("getConfigPatch", () => {
test("top level config updated", () => {
expect(
getConfigPatch({
preview_urls: {
__old: false,
__new: true,
},
})
).toEqual({
preview_urls: false,
});
});

test("env var present remotely but deleted locally", () => {
expect(
getConfigPatch({
vars: {
MY_VAR__deleted: "ABC",
},
})
).toEqual({
vars: {
MY_VAR: "ABC",
},
});
});

test("updated value of env var", () => {
expect(
getConfigPatch({
vars: {
MY_VAR: {
__old: "ABC",
__new: "123",
},
},
})
).toEqual({
vars: {
MY_VAR: "ABC",
},
});
});

test("env var renamed", () => {
expect(
getConfigPatch({
vars: {
MY_VAR__deleted: "ABC",
VAR__added: "ABC",
},
})
).toEqual({
vars: {
MY_VAR: "ABC",
},
});
});

test("deleted version metadata binding", () => {
expect(
getConfigPatch({
version_metadata: {
__old: {
binding: "VERSION_METADATA",
},
__new: undefined,
},
})
).toEqual({
version_metadata: {
binding: "VERSION_METADATA",
},
});
});

test("deleted KV binding (only one KV)", () => {
expect(
getConfigPatch({
kv_namespaces: [
[
"-",
{
id: "<kv-id>",
binding: "MY_KV",
},
],
],
})
).toEqual({
kv_namespaces: [
{
id: "<kv-id>",
binding: "MY_KV",
},
],
});
});

test("deleted second KV binding in the kv_namespaces array", () => {
expect(
getConfigPatch({
kv_namespaces: [
[" "],
[
"-",
{
id: "<my-kv-a>",
binding: "MY_KV_A",
},
],
],
})
).toEqual({
kv_namespaces: [
{
/* unmodified kv */
},
{
id: "<my-kv-a>",
binding: "MY_KV_A",
},
],
});
});

test("modified KV binding", () => {
expect(
getConfigPatch({
kv_namespaces: [
[
"~",
{
id: {
__old: "<old-kv-id>",
__new: "<new-kv-id>",
},
},
],
],
})
).toEqual({
kv_namespaces: [
{
id: "<old-kv-id>",
},
],
});
});

test("deleted second KV binding in the kv_namespaces array and modified first one", () => {
expect(
getConfigPatch({
kv_namespaces: [
[" "],
[
"-",
{
id: "<my-kv-a>",
binding: "MY_KV_A",
},
],
],
})
).toEqual({
kv_namespaces: [
{
/* unmodified kv */
},
{
id: "<my-kv-a>",
binding: "MY_KV_A",
},
],
});
});

test("deleted KV binding from the middle of the kv_namespaces array", () => {
expect(
getConfigPatch({
kv_namespaces: [
[" "],
[
"-",
{
id: "<my-kv-a>",
binding: "MY_KV_A",
},
],
[" "],
],
})
).toEqual({
kv_namespaces: [
{
/* unmodified kv */
},
{
/* unmodified kv */
},
{
/* deleted kv put back */
id: "<my-kv-a>",
binding: "MY_KV_A",
},
],
});
});

test("flipped observability.logs.invocation_logs off (nested field)", () => {
expect(
getConfigPatch({
observability: {
logs: {
invocation_logs: {
__old: true,
__new: false,
},
},
},
})
).toEqual({
observability: {
logs: {
invocation_logs: true,
},
},
});
});

test("renamed version metadata binding", () => {
expect(
getConfigPatch({
version_metadata: {
binding: {
__old: "VERSION_METADATA",
__new: "VERSION_META",
},
},
})
).toEqual({
version_metadata: {
binding: "VERSION_METADATA",
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ describe("getRemoteConfigsDiff", () => {
expect(nonDestructive).toBe(true);
});

it("should handle a very simple diffing scenario where there is only an addition to an array (specifically in `kv_namespaces`)", () => {
const { diff, nonDestructive } = getRemoteConfigDiff(
{
name: "silent-firefly-dbe3",
main: "/tmp/src/index.js",
workers_dev: true,
kv_namespaces: [{ binding: "MY_KV", id: "<kv-id>" }],
preview_urls: true,
},
{
name: "silent-firefly-dbe3",
main: "/tmp/src/index.js",
workers_dev: true,
preview_urls: true,
kv_namespaces: [],
} as unknown as Config
);

assert(diff);
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
" {
kv_namespaces: [
- {
- binding: \\"MY_KV\\"
- id: \\"<kv-id>\\"
- }
]
}
"
`);
expect(nonDestructive).toBe(false);
});

it("should handle a very simple diffing scenario (some diffs, random order)", () => {
const { diff, nonDestructive } = getRemoteConfigDiff(
{
Expand Down
Loading
Loading