clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/fix-sync-enrollment-startup
lofi / package / starter / tests / author-boundary_test.ts.txt
author-boundary_test.ts.txt 2.4K
1const test = (globalThis as unknown as {2 Deno: { test(name: string, body: () => void | Promise<void>): void };3}).Deno.test;45// Every author UI file is scanned with the full rule set — no exceptions, so6// a violation cannot hide in a file the loop forgot to list.7const authorUiFiles = [8 new URL("../src/pages/index.astro", import.meta.url),9 new URL("../src/layouts/Shell.astro", import.meta.url),10 new URL("../src/islands/AccountGate.tsx", import.meta.url),11 new URL("../src/islands/TaskList.tsx", import.meta.url),12 new URL("../src/islands/use-tasks.ts", import.meta.url),13];1415// schema.ts and permissions.ts declare data through @nzip/lofi/schema; the16// full rule set applies to them, raw Jazz imports included.17const schemaSurfaceFiles = [18 new URL("../src/schema.ts", import.meta.url),19 new URL("../src/permissions.ts", import.meta.url),20];2122const packageConsumers = [23 new URL("../src/app.ts", import.meta.url),24 ...authorUiFiles,25 ...schemaSurfaceFiles,26];2728const forbidden = [29 { pattern: /jazz-tools/, name: "raw Jazz import" },30 { pattern: /(?:Shared|Service|Web)?Worker\s*\(/, name: "worker construction" },31 { pattern: /(?:wss?|https?):\/\//, name: "transport URL" },32 { pattern: /workbox/i, name: "Workbox configuration" },33 { pattern: /navigator\.|globalThis\.(?:isSecureContext|SharedWorker)/, name: "browser branch" },34];3536test("author source consumes public lofi package seams and hides plumbing from product UI", async () => {37 for (38 const [path, name] of [39 ["../src/_lofi", "vendored src/_lofi runtime"],40 ["../public/sw.js", "source service worker"],41 ["../astro.config.ts", "checked-in Astro configuration"],42 ] as const43 ) {44 try {45 await Deno.stat(new URL(path, import.meta.url));46 throw new Error(`generated project still contains ${name}`);47 } catch (error) {48 if (!(error instanceof Deno.errors.NotFound)) throw error;49 }50 }51 for (const file of packageConsumers) {52 const source = await Deno.readTextFile(file);53 if (/_lofi\//.test(source)) {54 throw new Error(`${file.pathname} imports vendored framework code`);55 }56 }57 for (const file of [...authorUiFiles, ...schemaSurfaceFiles]) {58 const source = await Deno.readTextFile(file);59 for (const rule of forbidden) {60 if (rule.pattern.test(source)) {61 throw new Error(`${file.pathname} exposes forbidden ${rule.name}`);62 }63 }64 }65});