import { expect, test } from "bun:test"; import { encodeControlTemplate, resolveControlTemplate, renderControlTemplates, } from "../src/control-templates.ts"; import { runWithRequestContext } from "../src/request-context.ts"; import { createContext } from "../src/context.ts"; import { resolveRequestUrl } from "../src/headers.ts"; test("registry templates omit duplicated SSR ranges but preserve source and foreign controls", () => { runWithRequestContext({} as never, () => { const leaf = `

${"Large leaf".repeat(400)}

`; let body = leaf; for (let depth = 0; depth < 12; depth++) { const reference = encodeControlTemplate([{ cond: "open", body }]); body = `${body}`; } const html = renderControlTemplates(); expect(html.length).toBeLessThan(10000); const compacted = JSON.parse(/data-wrn-controls[^>]*>(.*?)<\/script>/s.exec(html)![1]!); expect( compacted.filter((branches: Array<{ body: string }>) => branches[0]!.body.includes(leaf)), ).toHaveLength(1); expect(html).toContain("data-wrn-control-client"); expect(body).toContain(leaf); const foreign = 'Keep'; const incomplete = body.replace(/