Skip to content

Commit 4492eb0

Browse files
use resolved local config for remote deploy config diffing logic (#10393)
--------- Co-authored-by: Somhairle MacLeòid <[email protected]>
1 parent 070b813 commit 4492eb0

File tree

6 files changed

+339
-270
lines changed

6 files changed

+339
-270
lines changed

.changeset/tender-beds-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Use resolved local config for remote deploy config diffing logic

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13009,16 +13009,16 @@ export default{
1300913009
await runWrangler("deploy --x-remote-diff-check");
1301013010

1301113011
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
13012-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mYour local configuration differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
13012+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
1301313013
13014-
\\"name\\": \\"test-name\\",
13015-
\\"main\\": \\"./index.js\\",
13014+
\\"workers_dev\\": true,
13015+
\\"preview_urls\\": true,
1301613016
\\"vars\\": {
1301713017
- \\"MY_VAR\\": \\"abc\\"
1301813018
+ \\"MY_VAR\\": 123
1301913019
},
13020-
\\"observability\\": {
13021-
\\"enabled\\": true
13020+
\\"define\\": {},
13021+
\\"durable_objects\\": {
1302213022
1302313023
Deploying the Worker will override the remote configuration with your local one.
1302413024
@@ -13074,16 +13074,16 @@ export default{
1307413074
// to be able to show toml content/diffs, that combined with the fact that json(c) config files are the
1307513075
// recommended ones moving forward makes this small shortcoming of the config diffing acceptable
1307613076
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
13077-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mYour local configuration differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
13077+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
1307813078
13079-
\\"name\\": \\"test-name\\",
13080-
\\"main\\": \\"./index.js\\",
13079+
\\"workers_dev\\": true,
13080+
\\"preview_urls\\": true,
1308113081
\\"vars\\": {
1308213082
- \\"MY_VAR\\": \\"abc\\"
1308313083
+ \\"MY_VAR\\": \\"this is a toml file\\"
1308413084
},
13085-
\\"observability\\": {
13086-
\\"enabled\\": true
13085+
\\"define\\": {},
13086+
\\"durable_objects\\": {
1308713087
1308813088
Deploying the Worker will override the remote configuration with your local one.
1308913089

packages/wrangler/src/__tests__/deploy/config-diffs.test.ts

Lines changed: 152 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getRemoteConfigDiff } from "../../deploy/config-diffs";
2-
import type { RawConfig } from "../../config";
2+
import type { Config, RawConfig } from "../../config";
33

44
describe("getRemoteConfigsDiff", () => {
55
it("should handle a very simple diffing scenario (no diffs, random order)", () => {
@@ -25,7 +25,7 @@ describe("getRemoteConfigsDiff", () => {
2525
tail_consumers: undefined,
2626
observability: { enabled: true },
2727
limits: undefined,
28-
} as unknown as RawConfig
28+
} as unknown as Config
2929
);
3030

3131
expect(diff.toString()).toEqual("");
@@ -48,23 +48,23 @@ describe("getRemoteConfigsDiff", () => {
4848
{
4949
compatibility_date: "2025-07-09",
5050
main: "/tmp/src/index.js",
51-
compatibility_flags: undefined,
51+
compatibility_flags: [],
5252
name: "silent-firefly-dbe3",
5353
workers_dev: true,
5454
limits: undefined,
5555
placement: undefined,
5656
tail_consumers: undefined,
5757
observability: { enabled: true, head_sampling_rate: 1 },
58-
}
58+
} as unknown as Config
5959
);
6060

6161
expect(diff.toString()).toMatchInlineSnapshot(`
6262
" {
6363
- \\"compatibility_date\\": \\"2025-07-08\\",
6464
+ \\"compatibility_date\\": \\"2025-07-09\\",
6565
\\"main\\": \\"/tmp/src/index.js\\",
66-
\\"name\\": \\"silent-firefly-dbe3\\",
67-
\\"workers_dev\\": true,"
66+
\\"compatibility_flags\\": [],
67+
\\"name\\": \\"silent-firefly-dbe3\\","
6868
`);
6969
expect(nonDestructive).toBe(false);
7070
});
@@ -80,44 +80,43 @@ describe("getRemoteConfigsDiff", () => {
8080
placement: undefined,
8181
limits: undefined,
8282
tail_consumers: undefined,
83-
observability: { enabled: true, head_sampling_rate: 1 },
83+
account_id: "account-id-123",
84+
kv_namespaces: [{ binding: "MY_KV", id: "my-kv-123" }],
8485
},
8586
{
86-
$schema: "node_modules/wrangler/config-schema.json",
8787
name: "silent-firefly-dbe3",
8888
main: "src/index.js",
8989
compatibility_date: "2025-07-08",
90-
observability: {
91-
enabled: true,
92-
head_sampling_rate: 1,
93-
logs: {
94-
head_sampling_rate: 0.95,
95-
invocation_logs: true,
96-
},
97-
},
9890
account_id: "account-id-123",
99-
kv_namespaces: [{ binding: "MY_KV", id: "my-kv-123" }],
100-
}
91+
kv_namespaces: [
92+
{ binding: "MY_KV", id: "my-kv-123" },
93+
{ binding: "MY_KV_2", id: "my-kv-456" },
94+
],
95+
} as unknown as Config
10196
);
10297
expect(diff.toString()).toMatchInlineSnapshot(`
103-
" \\"compatibility_date\\": \\"2025-07-08\\",
104-
\\"observability\\": {
105-
\\"enabled\\": true,
106-
- \\"head_sampling_rate\\": 1
107-
+ \\"head_sampling_rate\\": 1,
108-
+ \\"logs\\": {
109-
+ \\"head_sampling_rate\\": 0.95,
110-
+ \\"invocation_logs\\": true
111-
+ }
112-
},
113-
- \\"account_id\\": \\"account-id-123\\"
114-
+ \\"account_id\\": \\"account-id-123\\",
115-
+ \\"kv_namespaces\\": [
98+
" {
99+
\\"binding\\": \\"MY_KV\\",
100+
\\"id\\": \\"my-kv-123\\"
101+
+ },
116102
+ {
117-
+ \\"binding\\": \\"MY_KV\\",
118-
+ \\"id\\": \\"my-kv-123\\"
119-
+ }
120-
+ ]
103+
+ \\"binding\\": \\"MY_KV_2\\",
104+
+ \\"id\\": \\"my-kv-456\\"
105+
}
106+
],
107+
- \\"workers_dev\\": true,
108+
\\"observability\\": {
109+
\\"enabled\\": false,
110+
\\"head_sampling_rate\\": 1,
111+
112+
...
113+
114+
\\"head_sampling_rate\\": 1,
115+
\\"invocation_logs\\": true
116+
}
117+
- }
118+
+ },
119+
+ \\"workers_dev\\": true
121120
}"
122121
`);
123122
expect(nonDestructive).toBe(true);
@@ -138,28 +137,35 @@ describe("getRemoteConfigsDiff", () => {
138137
kv_namespaces: [{ binding: "MY_KV", id: "my-kv-123" }],
139138
},
140139
{
141-
$schema: "node_modules/wrangler/config-schema.json",
142140
name: "silent-firefly-dbe3",
143141
main: "src/index.js",
144142
compatibility_date: "2025-07-09",
145143
observability: {
146144
enabled: false,
147145
},
148146
account_id: "account-id-123",
149-
}
147+
} as unknown as Config
150148
);
151149
expect(diff.toString()).toMatchInlineSnapshot(`
152-
" \\"$schema\\": \\"node_modules/wrangler/config-schema.json\\",
150+
" {
153151
\\"name\\": \\"silent-firefly-dbe3\\",
154152
\\"main\\": \\"src/index.js\\",
155153
- \\"compatibility_date\\": \\"2025-07-08\\",
156154
+ \\"compatibility_date\\": \\"2025-07-09\\",
157155
\\"observability\\": {
158-
- \\"enabled\\": true
159-
+ \\"enabled\\": false
156+
- \\"enabled\\": true,
157+
+ \\"enabled\\": false,
158+
\\"head_sampling_rate\\": 1,
159+
\\"logs\\": {
160+
\\"enabled\\": false,
161+
162+
...
163+
164+
}
160165
},
161-
- \\"account_id\\": \\"account-id-123\\",
162-
+ \\"account_id\\": \\"account-id-123\\"
166+
\\"account_id\\": \\"account-id-123\\",
167+
- \\"workers_dev\\": true,
168+
+ \\"workers_dev\\": true
163169
- \\"kv_namespaces\\": [
164170
- {
165171
- \\"binding\\": \\"MY_KV\\",
@@ -170,4 +176,108 @@ describe("getRemoteConfigsDiff", () => {
170176
`);
171177
expect(nonDestructive).toBe(false);
172178
});
179+
180+
// The Observability field in the remote configuration has some specific behaviors, for that we have
181+
// the following tests to make double sure to get these various observability cases right
182+
// (note: this is however a best effort diffing since we cannot really perform a full one since we loose
183+
// some information remotely for example `{ observability: { enabled: false, logs: { enabled: false, invocation_logs: false } }, }`
184+
// remotely just becomes `undefined` completely loosing the fact that `logs` and `invocation_logs` were ever set)
185+
describe("observability", () => {
186+
function getObservabilityDiff(
187+
remoteObservability: RawConfig["observability"],
188+
localObservability: Config["observability"]
189+
) {
190+
return getRemoteConfigDiff(
191+
{
192+
observability: remoteObservability,
193+
workers_dev: true,
194+
},
195+
{
196+
observability: localObservability,
197+
} as unknown as Config
198+
);
199+
}
200+
201+
it("should treat a remote undefined equal to a remote { enabled: false }", () => {
202+
const { diff } = getObservabilityDiff(
203+
// remotely the observability field is undefined when observability is disabled
204+
undefined,
205+
{ enabled: false }
206+
);
207+
expect(diff.toString()).toMatchInlineSnapshot(`""`);
208+
});
209+
210+
it("should treat a remote undefined equal to a remote { enabled: false, logs: { enabled: false } }", () => {
211+
const { diff } = getObservabilityDiff(
212+
// remotely the observability field is undefined when observability is disabled
213+
undefined,
214+
{ enabled: false, logs: { enabled: false } }
215+
);
216+
expect(diff.toString()).toMatchInlineSnapshot(`""`);
217+
});
218+
219+
it("should correctly show the diff of boolean when the remote is undefined and the local is { enabled: true }", () => {
220+
const { diff } = getObservabilityDiff(
221+
// remotely the observability field is undefined when observability is disabled
222+
undefined,
223+
{ enabled: true }
224+
);
225+
expect(diff.toString()).toMatchInlineSnapshot(`
226+
" {
227+
\\"observability\\": {
228+
- \\"enabled\\": false,
229+
+ \\"enabled\\": true,
230+
\\"head_sampling_rate\\": 1,
231+
\\"logs\\": {
232+
\\"enabled\\": false,"
233+
`);
234+
});
235+
236+
it("should correctly show the diff of boolean when the remote is undefined and the local is { logs: { enabled: false } }", () => {
237+
const { diff } = getObservabilityDiff(
238+
// remotely the observability field is undefined when observability is disabled
239+
undefined,
240+
{ logs: { enabled: true } }
241+
);
242+
expect(diff.toString()).toMatchInlineSnapshot(`
243+
" {
244+
\\"observability\\": {
245+
\\"logs\\": {
246+
- \\"enabled\\": false,
247+
+ \\"enabled\\": true,
248+
\\"head_sampling_rate\\": 1,
249+
\\"invocation_logs\\": true
250+
},"
251+
`);
252+
});
253+
254+
it("should correctly not show head_sampling_rate being added remotely", () => {
255+
const { diff } = getObservabilityDiff(
256+
// remotely head_sampling_rate is set to 1 even if enabled is false
257+
{ enabled: false, head_sampling_rate: 1, logs: { enabled: true } },
258+
{ enabled: false, logs: { enabled: true, invocation_logs: true } }
259+
);
260+
expect(diff.toString()).toMatchInlineSnapshot(`""`);
261+
});
262+
263+
it("should correctly not show logs.invocation_logs being added remotely", () => {
264+
const { diff } = getObservabilityDiff(
265+
// remotely head_sampling_rate is set to 1 even if enabled is false
266+
{
267+
logs: { enabled: true, head_sampling_rate: 1, invocation_logs: true },
268+
},
269+
{ logs: { enabled: true, head_sampling_rate: 0.9 } }
270+
);
271+
expect(diff.toString()).toMatchInlineSnapshot(`
272+
" \\"observability\\": {
273+
\\"logs\\": {
274+
\\"enabled\\": true,
275+
- \\"head_sampling_rate\\": 1,
276+
+ \\"head_sampling_rate\\": 0.9,
277+
\\"invocation_logs\\": true
278+
},
279+
\\"enabled\\": false,"
280+
`);
281+
});
282+
});
173283
});

0 commit comments

Comments
 (0)