diff --git a/packages/chord/test/boundary.test.ts b/packages/chord/test/boundary.test.ts index 2c044bafd..8819a01c1 100644 --- a/packages/chord/test/boundary.test.ts +++ b/packages/chord/test/boundary.test.ts @@ -8,13 +8,18 @@ const sourceDirectory = resolve(packageDirectory, "src"); const IMPORT_SPECIFIER = /(?:import|export)\s+(?:type\s+)?(?:[^;]*?\sfrom\s*)?["']([^"']+)["']/gu; describe("package boundary", () => { - test("does not depend on Pi packages or files outside Chord", async () => { + // pi-telemetry is the one allowed Pi package: a leaf without dependencies, needed for Context.telemetry. + const ALLOWED = new Set(["@earendil-works/pi-telemetry"]); + + test("does not depend on Pi packages other than pi-telemetry, or on files outside Chord", async () => { const manifest = JSON.parse(await readFile(resolve(packageDirectory, "package.json"), "utf8")) as { dependencies?: Record; }; - expect(Object.keys(manifest.dependencies ?? {}).filter((name) => name.startsWith("@earendil-works/pi-"))).toEqual( - [], - ); + expect( + Object.keys(manifest.dependencies ?? {}).filter( + (name) => name.startsWith("@earendil-works/pi-") && !ALLOWED.has(name), + ), + ).toEqual([]); const paths = (await readdir(sourceDirectory, { recursive: true })).filter((path) => path.endsWith(".ts")).sort(); const violations: string[] = []; @@ -23,7 +28,9 @@ describe("package boundary", () => { const source = await readFile(file, "utf8"); for (const match of source.matchAll(IMPORT_SPECIFIER)) { const specifier = match[1]!; - if (specifier.startsWith("@earendil-works/pi-")) violations.push(`${path}: ${specifier}`); + const pkg = specifier.split("/").slice(0, 2).join("/"); + if (specifier.startsWith("@earendil-works/pi-") && !ALLOWED.has(pkg)) + violations.push(`${path}: ${specifier}`); if (specifier.startsWith(".") && !resolve(dirname(file), specifier).startsWith(`${sourceDirectory}/`)) { violations.push(`${path}: ${specifier}`); }