@decocms/tanstack 7.64.2 → 7.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,13 @@
1
- import { setBlocks } from "@decocms/blocks/cms";
2
- import { afterEach, describe, expect, it } from "vitest";
3
- import { __resetKvHydrationStateForTests } from "./kvHydration";
1
+ import { computeRevision, revisionKey, setBlocks, snapshotKey } from "@decocms/blocks/cms";
2
+ import {
3
+ __resetAutoconfigStateForTests,
4
+ autoconfigApps,
5
+ } from "@decocms/blocks-admin/apps/autoconfig";
6
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
4
7
  import { segmentToken } from "./cdnSegment";
8
+ import { __resetKvHydrationStateForTests } from "./kvHydration";
5
9
  import {
10
+ buildEnforcedCsp,
6
11
  buildGeoCacheParam,
7
12
  createDecoWorkerEntry,
8
13
  DECO_ADMIN_FRAME_ANCESTORS,
@@ -60,10 +65,7 @@ describe("injectGeoCookies", () => {
60
65
  });
61
66
 
62
67
  it("strips cf-ipcity from the outgoing Request headers while preserving the value in __cf_geo_city cookie", () => {
63
- const req = makeRequest(
64
- { city: "Brasília", country: "BR" },
65
- { "cf-ipcity": "Brasília" },
66
- );
68
+ const req = makeRequest({ city: "Brasília", country: "BR" }, { "cf-ipcity": "Brasília" });
67
69
 
68
70
  const out = injectGeoCookies(req);
69
71
 
@@ -92,10 +94,7 @@ describe("injectGeoCookies", () => {
92
94
  });
93
95
 
94
96
  it("preserves a pre-existing cookie header", () => {
95
- const req = makeRequest(
96
- { region: "São Paulo" },
97
- { cookie: "vtex_segment=abc; another=xyz" },
98
- );
97
+ const req = makeRequest({ region: "São Paulo" }, { cookie: "vtex_segment=abc; another=xyz" });
99
98
 
100
99
  const out = injectGeoCookies(req);
101
100
 
@@ -150,9 +149,7 @@ describe("buildGeoCacheParam", () => {
150
149
 
151
150
  it("omits missing fields gracefully", () => {
152
151
  expect(buildGeoCacheParam({ country: "BR" }, "city")).toBe("BR");
153
- expect(buildGeoCacheParam({ country: "BR", region: "MG" }, "city")).toBe(
154
- "BR|MG",
155
- );
152
+ expect(buildGeoCacheParam({ country: "BR", region: "MG" }, "city")).toBe("BR|MG");
156
153
  });
157
154
 
158
155
  it("returns undefined when cf has none of country/region/city", () => {
@@ -226,11 +223,7 @@ describe("CMS redirects", () => {
226
223
  const worker = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
227
224
  observability: false,
228
225
  });
229
- const res = await worker.fetch(
230
- new Request("https://example.com/old"),
231
- EMPTY_ENV,
232
- MOCK_CTX,
233
- );
226
+ const res = await worker.fetch(new Request("https://example.com/old"), EMPTY_ENV, MOCK_CTX);
234
227
  expect(res.status).toBe(301);
235
228
  expect(res.headers.get("Location")).toBe("/new");
236
229
  });
@@ -264,11 +257,7 @@ describe("CMS redirects", () => {
264
257
  const worker = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
265
258
  observability: false,
266
259
  });
267
- const res = await worker.fetch(
268
- new Request("https://example.com/promo"),
269
- EMPTY_ENV,
270
- MOCK_CTX,
271
- );
260
+ const res = await worker.fetch(new Request("https://example.com/promo"), EMPTY_ENV, MOCK_CTX);
272
261
  expect(res.status).toBe(302);
273
262
  expect(res.headers.get("Location")).toBe("/promo%C3%A7%C3%A3o");
274
263
  });
@@ -283,11 +272,7 @@ describe("CMS redirects", () => {
283
272
  const worker = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
284
273
  observability: false,
285
274
  });
286
- const res = await worker.fetch(
287
- new Request("https://example.com/promo"),
288
- EMPTY_ENV,
289
- MOCK_CTX,
290
- );
275
+ const res = await worker.fetch(new Request("https://example.com/promo"), EMPTY_ENV, MOCK_CTX);
291
276
  expect(res.status).toBe(302);
292
277
  expect(res.headers.get("Location")).toBe("/sale");
293
278
  });
@@ -302,11 +287,7 @@ describe("CMS redirects", () => {
302
287
  const worker = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
303
288
  observability: false,
304
289
  });
305
- const res = await worker.fetch(
306
- new Request("https://example.com/other"),
307
- EMPTY_ENV,
308
- MOCK_CTX,
309
- );
290
+ const res = await worker.fetch(new Request("https://example.com/other"), EMPTY_ENV, MOCK_CTX);
310
291
  expect(res.status).toBe(200);
311
292
  });
312
293
 
@@ -317,11 +298,7 @@ describe("CMS redirects", () => {
317
298
  });
318
299
 
319
300
  // First request with no redirects — falls through
320
- const res1 = await worker.fetch(
321
- new Request("https://example.com/v1"),
322
- EMPTY_ENV,
323
- MOCK_CTX,
324
- );
301
+ const res1 = await worker.fetch(new Request("https://example.com/v1"), EMPTY_ENV, MOCK_CTX);
325
302
  expect(res1.status).toBe(200);
326
303
 
327
304
  // Hot-reload: add a redirect
@@ -333,11 +310,7 @@ describe("CMS redirects", () => {
333
310
  });
334
311
 
335
312
  // Same path should now redirect
336
- const res2 = await worker.fetch(
337
- new Request("https://example.com/v1"),
338
- EMPTY_ENV,
339
- MOCK_CTX,
340
- );
313
+ const res2 = await worker.fetch(new Request("https://example.com/v1"), EMPTY_ENV, MOCK_CTX);
341
314
  expect(res2.status).toBe(301);
342
315
  expect(res2.headers.get("Location")).toBe("/v2");
343
316
  });
@@ -414,14 +387,8 @@ describe("security headers — frame-ancestors default", () => {
414
387
 
415
388
  it("applies the default frame-ancestors CSP on HTML responses and drops X-Frame-Options", async () => {
416
389
  const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY);
417
- const res = await worker.fetch(
418
- new Request("https://example.com/"),
419
- EMPTY_ENV,
420
- MOCK_CTX,
421
- );
422
- expect(res.headers.get("Content-Security-Policy")).toBe(
423
- DEFAULT_FRAME_ANCESTORS_CSP,
424
- );
390
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
391
+ expect(res.headers.get("Content-Security-Policy")).toBe(DEFAULT_FRAME_ANCESTORS_CSP);
425
392
  expect(res.headers.get("X-Frame-Options")).toBeNull();
426
393
  // Other defaults are still present.
427
394
  expect(res.headers.get("X-Content-Type-Options")).toBe("nosniff");
@@ -431,28 +398,16 @@ describe("security headers — frame-ancestors default", () => {
431
398
  const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY, {
432
399
  securityHeaders: { "Content-Security-Policy": "frame-ancestors 'none'" },
433
400
  });
434
- const res = await worker.fetch(
435
- new Request("https://example.com/"),
436
- EMPTY_ENV,
437
- MOCK_CTX,
438
- );
439
- expect(res.headers.get("Content-Security-Policy")).toBe(
440
- "frame-ancestors 'none'",
441
- );
401
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
402
+ expect(res.headers.get("Content-Security-Policy")).toBe("frame-ancestors 'none'");
442
403
  });
443
404
 
444
405
  it("emits the full site CSP report-only alongside the enforced frame-ancestors", async () => {
445
406
  const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY, {
446
407
  csp: ["default-src 'self'", "img-src 'self' https:"],
447
408
  });
448
- const res = await worker.fetch(
449
- new Request("https://example.com/"),
450
- EMPTY_ENV,
451
- MOCK_CTX,
452
- );
453
- expect(res.headers.get("Content-Security-Policy")).toBe(
454
- DEFAULT_FRAME_ANCESTORS_CSP,
455
- );
409
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
410
+ expect(res.headers.get("Content-Security-Policy")).toBe(DEFAULT_FRAME_ANCESTORS_CSP);
456
411
  expect(res.headers.get("Content-Security-Policy-Report-Only")).toBe(
457
412
  "default-src 'self'; img-src 'self' https:",
458
413
  );
@@ -462,14 +417,83 @@ describe("security headers — frame-ancestors default", () => {
462
417
  const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY, {
463
418
  securityHeaders: false,
464
419
  });
465
- const res = await worker.fetch(
466
- new Request("https://example.com/"),
467
- EMPTY_ENV,
468
- MOCK_CTX,
469
- );
420
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
470
421
  expect(res.headers.get("Content-Security-Policy")).toBeNull();
471
422
  expect(res.headers.get("X-Content-Type-Options")).toBeNull();
472
423
  });
424
+
425
+ it("keeps report-only by default even when a site passes csp (cspMode unset)", async () => {
426
+ const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY, {
427
+ csp: ["default-src 'self'"],
428
+ });
429
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
430
+ expect(res.headers.get("Content-Security-Policy")).toBe(DEFAULT_FRAME_ANCESTORS_CSP);
431
+ expect(res.headers.get("Content-Security-Policy-Report-Only")).toBe("default-src 'self'");
432
+ });
433
+
434
+ it("enforce mode emits a nonce CSP (no report-only, no unsafe-inline) on a no-store HTML response", async () => {
435
+ const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY, {
436
+ csp: ["default-src 'self'", "script-src 'self' 'unsafe-inline' https://gtm.example"],
437
+ cspMode: "enforce",
438
+ });
439
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
440
+ const csp = res.headers.get("Content-Security-Policy") ?? "";
441
+ // Promoted to enforced — report-only is gone.
442
+ expect(res.headers.get("Content-Security-Policy-Report-Only")).toBeNull();
443
+ expect(csp).toContain("default-src 'self'");
444
+ // script-src hardened: unsafe-inline dropped, per-request nonce +
445
+ // inline-speculation-rules added, the host allowlist kept.
446
+ expect(csp).toMatch(/script-src[^;]*'nonce-[A-Za-z0-9+/=]+'/);
447
+ expect(csp).toContain("'inline-speculation-rules'");
448
+ expect(csp).toContain("https://gtm.example");
449
+ expect(csp).not.toContain("'unsafe-inline'");
450
+ // Framing protection preserved.
451
+ expect(csp).toContain("frame-ancestors");
452
+ });
453
+
454
+ it("enforce mode leaves 'unsafe-eval' in place (opt-out is explicit)", async () => {
455
+ const worker = createDecoWorkerEntry(HTML_SERVER_ENTRY, {
456
+ csp: ["script-src 'self' 'unsafe-inline' 'unsafe-eval'"],
457
+ cspMode: "enforce",
458
+ });
459
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
460
+ const csp = res.headers.get("Content-Security-Policy") ?? "";
461
+ expect(csp).toContain("'unsafe-eval'");
462
+ expect(csp).not.toContain("'unsafe-inline'");
463
+ });
464
+ });
465
+
466
+ describe("buildEnforcedCsp", () => {
467
+ const FA = "frame-ancestors 'self' https://studio.decocms.com";
468
+
469
+ it("hardens script-src: drops unsafe-inline, adds nonce + inline-speculation-rules, keeps hosts + unsafe-eval", () => {
470
+ const csp = buildEnforcedCsp(
471
+ ["script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gtm.example"],
472
+ FA,
473
+ "abc123",
474
+ );
475
+ expect(csp).toContain("script-src");
476
+ expect(csp).toContain("'self'");
477
+ expect(csp).toContain("https://gtm.example");
478
+ expect(csp).toContain("'unsafe-eval'");
479
+ expect(csp).toContain("'nonce-abc123'");
480
+ expect(csp).toContain("'inline-speculation-rules'");
481
+ expect(csp).not.toContain("'unsafe-inline'");
482
+ expect(csp).toContain(FA);
483
+ });
484
+
485
+ it("adds a script-src when the site declared none", () => {
486
+ const csp = buildEnforcedCsp(["default-src 'self'"], FA, "n0nce");
487
+ expect(csp).toContain("default-src 'self'");
488
+ expect(csp).toContain("script-src 'self' 'nonce-n0nce' 'inline-speculation-rules'");
489
+ expect(csp).toContain(FA);
490
+ });
491
+
492
+ it("drops any frame-ancestors from the site csp in favour of the canonical one", () => {
493
+ const csp = buildEnforcedCsp(["frame-ancestors 'none'", "default-src 'self'"], FA, "x");
494
+ expect(csp).not.toContain("frame-ancestors 'none'");
495
+ expect(csp).toContain(FA);
496
+ });
473
497
  });
474
498
 
475
499
  describe("POST /_cache/purge-loaders", () => {
@@ -478,10 +502,7 @@ describe("POST /_cache/purge-loaders", () => {
478
502
  setBlocks({});
479
503
  });
480
504
 
481
- const purge = (
482
- env: Record<string, unknown>,
483
- headers: Record<string, string> = {},
484
- ) => {
505
+ const purge = (env: Record<string, unknown>, headers: Record<string, string> = {}) => {
485
506
  const worker = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
486
507
  observability: false,
487
508
  });
@@ -501,18 +522,12 @@ describe("POST /_cache/purge-loaders", () => {
501
522
  });
502
523
 
503
524
  it("401s with the wrong token", async () => {
504
- const res = await purge(
505
- { PURGE_TOKEN: "secret" },
506
- { Authorization: "Bearer nope" },
507
- );
525
+ const res = await purge({ PURGE_TOKEN: "secret" }, { Authorization: "Bearer nope" });
508
526
  expect(res.status).toBe(401);
509
527
  });
510
528
 
511
529
  it("clears the loader cache with a valid token", async () => {
512
- const res = await purge(
513
- { PURGE_TOKEN: "secret" },
514
- { Authorization: "Bearer secret" },
515
- );
530
+ const res = await purge({ PURGE_TOKEN: "secret" }, { Authorization: "Bearer secret" });
516
531
  expect(res.status).toBe(200);
517
532
  expect(await res.json()).toEqual({ cleared: true, scope: "isolate" });
518
533
  });
@@ -556,14 +571,8 @@ describe("X-Cache-Segment — custom SegmentKey fields (#284)", () => {
556
571
  delivery: "store-42",
557
572
  }),
558
573
  });
559
- const res = await worker.fetch(
560
- new Request("https://example.com/"),
561
- EMPTY_ENV,
562
- MOCK_CTX,
563
- );
564
- expect(res.headers.get("X-Cache-Segment")).toBe(
565
- "desktop|r=RJ|delivery=store-42",
566
- );
574
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
575
+ expect(res.headers.get("X-Cache-Segment")).toBe("desktop|r=RJ|delivery=store-42");
567
576
  });
568
577
 
569
578
  it("produces different X-Cache-Segment hashes for requests that only differ by a custom field", async () => {
@@ -573,19 +582,11 @@ describe("X-Cache-Segment — custom SegmentKey fields (#284)", () => {
573
582
  buildSegment: () => ({ device: "desktop", delivery }),
574
583
  });
575
584
 
576
- const first = await worker.fetch(
577
- new Request("https://example.com/"),
578
- EMPTY_ENV,
579
- MOCK_CTX,
580
- );
585
+ const first = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
581
586
  const firstSegment = first.headers.get("X-Cache-Segment");
582
587
 
583
588
  delivery = "store-2";
584
- const second = await worker.fetch(
585
- new Request("https://example.com/"),
586
- EMPTY_ENV,
587
- MOCK_CTX,
588
- );
589
+ const second = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
589
590
  const secondSegment = second.headers.get("X-Cache-Segment");
590
591
 
591
592
  expect(firstSegment).not.toBe(secondSegment);
@@ -600,11 +601,7 @@ describe("X-Cache-Segment — custom SegmentKey fields (#284)", () => {
600
601
  flags: ["b", "a"],
601
602
  }),
602
603
  });
603
- const res = await worker.fetch(
604
- new Request("https://example.com/"),
605
- EMPTY_ENV,
606
- MOCK_CTX,
607
- );
604
+ const res = await worker.fetch(new Request("https://example.com/"), EMPTY_ENV, MOCK_CTX);
608
605
  expect(res.headers.get("X-Cache-Segment")).toBe("desktop|sc=1|f=a,b");
609
606
  });
610
607
  });
@@ -621,8 +618,7 @@ describe("draft preview (pull-based)", () => {
621
618
  const REFLECT_ENTRY = {
622
619
  fetch: async () => {
623
620
  const { loadBlocks } = await import("@decocms/blocks/cms");
624
- const home =
625
- (loadBlocks()["pages-home"] as { title?: string } | undefined) ?? {};
621
+ const home = (loadBlocks()["pages-home"] as { title?: string } | undefined) ?? {};
626
622
  return new Response(home.title ?? "PUBLISHED", { status: 200 });
627
623
  },
628
624
  };
@@ -630,9 +626,7 @@ describe("draft preview (pull-based)", () => {
630
626
  let realFetch: typeof fetch;
631
627
  afterEach(async () => {
632
628
  globalThis.fetch = realFetch;
633
- const { setDraftPreviewHosts, clearDraftCache } = await import(
634
- "@decocms/blocks/cms"
635
- );
629
+ const { setDraftPreviewHosts, clearDraftCache } = await import("@decocms/blocks/cms");
636
630
  setDraftPreviewHosts([]);
637
631
  clearDraftCache();
638
632
  __resetKvHydrationStateForTests();
@@ -640,9 +634,7 @@ describe("draft preview (pull-based)", () => {
640
634
  });
641
635
 
642
636
  async function enable() {
643
- const { setDraftPreviewHosts, clearDraftCache } = await import(
644
- "@decocms/blocks/cms"
645
- );
637
+ const { setDraftPreviewHosts, clearDraftCache } = await import("@decocms/blocks/cms");
646
638
  setBlocks({
647
639
  "pages-home": { name: "home", path: "/", title: "PUBLISHED" },
648
640
  });
@@ -783,7 +775,9 @@ describe('cdnCacheControl: "serverfn-segment"', () => {
783
775
 
784
776
  it("keeps no-store when the marker is from an older build", async () => {
785
777
  // Deploying does not purge the CDN, so a stale build token must not match.
786
- expect(await cdnHeader(sfnUrl(segmentToken("desktop", false, "oldbuild") as string))).toBe("no-store");
778
+ expect(await cdnHeader(sfnUrl(segmentToken("desktop", false, "oldbuild") as string))).toBe(
779
+ "no-store",
780
+ );
787
781
  });
788
782
 
789
783
  it("keeps no-store when there is no build hash", async () => {
@@ -850,7 +844,11 @@ describe("cdnCacheControl default", () => {
850
844
  observability: false,
851
845
  buildSegment: () => ({ device: "desktop" as const }),
852
846
  });
853
- const html = await w.fetch(new Request("https://example.com/"), { BUILD_HASH: BUILD_D }, MOCK_CTX);
847
+ const html = await w.fetch(
848
+ new Request("https://example.com/"),
849
+ { BUILD_HASH: BUILD_D },
850
+ MOCK_CTX,
851
+ );
854
852
  expect(html.headers.get("CDN-Cache-Control")).toBe("no-store");
855
853
 
856
854
  const sfn = await w.fetch(
@@ -913,7 +911,11 @@ describe("CDN-Cache-Control at the single response exit", () => {
913
911
  deviceSpecificKeys: false,
914
912
  geoCacheKey: "off",
915
913
  });
916
- const res = await w.fetch(new Request("https://example.com/some-category"), EMPTY_ENV, MOCK_CTX);
914
+ const res = await w.fetch(
915
+ new Request("https://example.com/some-category"),
916
+ EMPTY_ENV,
917
+ MOCK_CTX,
918
+ );
917
919
  expect(res.headers.get("CDN-Cache-Control")).toMatch(/^public, max-age=\d+$/);
918
920
  });
919
921
  });
@@ -939,3 +941,93 @@ describe('cdnCacheControl: "match-profile" guard', () => {
939
941
  expect(res.headers.get("CDN-Cache-Control")).toMatch(/^public, max-age=\d+$/);
940
942
  });
941
943
  });
944
+
945
+ /**
946
+ * Fast-deploy hydration must run BEFORE `reconfigureAppsOnce()`.
947
+ *
948
+ * `reconfigureAppsOnce()` configures apps from the blocks it sees and then
949
+ * latches its promise forever. If it ran first, a `fastDeploy` build — whose
950
+ * bundled decofile is `{}` — would configure ZERO apps, and the only recovery
951
+ * is `setBlocks()`'s onChange listener, whose promise `setBlocks` drops
952
+ * unawaited. The request would proceed with no app loaders registered.
953
+ */
954
+ describe("fast-deploy hydration ordering", () => {
955
+ // Reset BEFORE as well: both flags are module-level and latching, so an
956
+ // earlier test in this file that fired a request leaves `kvHydrated` true
957
+ // and hydration would be skipped entirely here.
958
+ beforeEach(() => {
959
+ __resetKvHydrationStateForTests();
960
+ __resetAutoconfigStateForTests();
961
+ });
962
+
963
+ afterEach(() => {
964
+ __resetKvHydrationStateForTests();
965
+ __resetAutoconfigStateForTests();
966
+ setBlocks({});
967
+ });
968
+
969
+ it("configures apps from the KV snapshot, not the stubbed bundle", async () => {
970
+ const KV_BLOCKS = { "deco-test": { "@type": "test-app", token: "from-kv" } };
971
+ const ID = "sha-ordering";
972
+
973
+ /** Blocks each configure() call observed, in order. */
974
+ const seen: unknown[] = [];
975
+ const registry = [
976
+ {
977
+ blockKey: "deco-test",
978
+ module: () =>
979
+ Promise.resolve({
980
+ configure: (block: unknown) => {
981
+ seen.push(block);
982
+ return Promise.resolve({
983
+ name: "test-app",
984
+ manifest: { name: "test-app", loaders: {}, actions: {} },
985
+ state: {},
986
+ });
987
+ },
988
+ }),
989
+ },
990
+ ];
991
+
992
+ // autoconfigApps and its onChange listener are server-only guarded on
993
+ // `typeof document`. This suite runs under jsdom, so drop `document` for
994
+ // the duration to exercise the worker path.
995
+ const realDocument = globalThis.document;
996
+ delete (globalThis as { document?: unknown }).document;
997
+ try {
998
+ // Simulates the stubbed server bundle: autoconfigApps runs at module init
999
+ // with an empty decofile, exactly as it would in a fastDeploy build.
1000
+ setBlocks({});
1001
+ await autoconfigApps({}, registry as never);
1002
+ expect(seen).toEqual([]); // nothing to configure yet — this is the trap
1003
+
1004
+ const store = new Map<string, string>([
1005
+ [snapshotKey(ID), JSON.stringify(KV_BLOCKS)],
1006
+ [revisionKey(ID), computeRevision(KV_BLOCKS)],
1007
+ ]);
1008
+ const env = {
1009
+ DECO_KV: {
1010
+ get: (k: string) => Promise.resolve(store.get(k) ?? null),
1011
+ put: () => Promise.resolve(),
1012
+ delete: () => Promise.resolve(),
1013
+ },
1014
+ DECO_FAST_DEPLOY: "1",
1015
+ DECO_DEPLOYMENT_ID: ID,
1016
+ };
1017
+
1018
+ const worker = createDecoWorkerEntry(MOCK_SERVER_ENTRY, { observability: false });
1019
+ await worker.fetch(new Request("https://example.com/"), env, MOCK_CTX);
1020
+
1021
+ // The app must have been configured with the block that came from KV.
1022
+ // Not asserting a call COUNT: both the onChange listener and the
1023
+ // one-shot reinit legitimately configure, and how many passes happen is
1024
+ // not the contract. The contract is that no pass saw the empty bundle.
1025
+ // Deep equality, not identity: the snapshot arrives via JSON.parse, so
1026
+ // the block is a structurally-equal copy.
1027
+ expect(seen.length).toBeGreaterThan(0);
1028
+ for (const block of seen) expect(block).toEqual(KV_BLOCKS["deco-test"]);
1029
+ } finally {
1030
+ globalThis.document = realDocument;
1031
+ }
1032
+ });
1033
+ });