/* RFC-1175 AC-5: structural coverage for the single-chunk orchestrator — self-gating feature modules stay statically imported so the entry script's one dynamic import resolves the whole dispatch graph; heavy third-party deps remain lazy inside each init. Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only. RFC-1175: initial orchestrator chunk-topology tests. RFC-1178 AC-5: pin ./trusted-types.ts as the first static import of orchestrator.ts and forbid a default Trusted Types policy. */ import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const readSource = (name: string): string => readFileSync(fileURLToPath(new URL(`../${name}`, import.meta.url)), "utf8"); const DYNAMIC_RELATIVE_IMPORT = /import\(\s*["']\.\//g; describe("orchestrator chunk topology (RFC-1175 AC-5)", () => { it("orchestrator.ts contains no dynamic relative imports — dispatch code lives in the orchestrator chunk", () => { const source = readSource("orchestrator.ts"); expect(source.match(DYNAMIC_RELATIVE_IMPORT) ?? []).toEqual([]); }); it("orchestrator.ts statically imports every self-gating feature module", () => { const source = readSource("orchestrator.ts"); for (const specifier of [ "./external-links.ts", "./lordicon.ts", "./lenis.ts", "./scroll-spy.ts", "./background-video.ts", "./external-link-qr.ts", "./gsap-counter.ts", "./gsap-parallax.ts", "./gsap-reveal.ts", "./gsap-stagger.ts", "./inline-number-animation.ts", "./live-photos.ts", "./video-player.ts", "./scheduler.ts", ]) { expect(source).toContain(`from "${specifier}"`); } }); it("lordicon.ts keeps only the heavy @lordicon/element import dynamic", () => { const source = readSource("lordicon.ts"); expect(source.match(DYNAMIC_RELATIVE_IMPORT) ?? []).toEqual([]); expect(source).toContain('await import("@lordicon/element")'); }); it("lordicon.ts does not prefetch inlined data: URIs", () => { const source = readSource("lordicon.ts"); expect(source).toContain('url.startsWith("data:")'); }); it("video-player.ts keeps plyr.css lazy — no top-level stylesheet import", () => { const source = readSource("video-player.ts"); const topLevel = source .split("\n") .filter((line) => line.startsWith("import ")) .join("\n"); expect(topLevel).not.toContain("plyr/dist/plyr.css"); // m000170: ?inline keeps the stylesheet a string inside the lazy JS chunk — // a plain css import emits a preload to a standalone asset that // inlineStylesheets:"always" never writes (404 on prod). expect(source).toContain('await import("plyr/dist/plyr.css?inline")'); }); it("orchestrator.ts statically imports ./trusted-types.ts so the werkstatt policy ships in the entry chunk (RFC-1178 AC-5)", () => { const source = readSource("orchestrator.ts"); expect(source).toContain('import "./trusted-types.ts"'); // The policy import must precede every feature-module import — policy // creation has to eval before the first sink write can occur. const policyIdx = source.indexOf('import "./trusted-types.ts"'); const firstFeatureIdx = source.indexOf('from "./external-links.ts"'); expect(policyIdx).toBeGreaterThanOrEqual(0); expect(firstFeatureIdx).toBeGreaterThan(policyIdx); }); it("trusted-types.ts registers only the named werkstatt policy — never a default policy (RFC-1178)", () => { const source = readSource("trusted-types.ts"); expect(source).toContain('createPolicy("werkstatt"'); expect(source).not.toMatch(/createPolicy\(\s*["']default["']/); }); });