diff --git a/packages/prompts-core/test/opencode-coupling-audit.test.ts b/packages/prompts-core/test/opencode-coupling-audit.test.ts new file mode 100644 index 000000000..4205fdc92 --- /dev/null +++ b/packages/prompts-core/test/opencode-coupling-audit.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, test } from "bun:test" +import { readdir, readFile } from "node:fs/promises" +import { dirname, join } from "node:path" +import { fileURLToPath } from "node:url" + +const SOURCE_DIR = join(dirname(fileURLToPath(import.meta.url)), "../src") + +describe("opencode coupling audit", () => { + test("#given prompts-core source #then no file imports @opencode-ai packages", async () => { + const offenders = await findOpenCodeImports(SOURCE_DIR) + + expect(offenders).toEqual([]) + }) +}) + +async function findOpenCodeImports(sourceDir: string): Promise { + const files = await collectTypeScriptFiles(sourceDir) + const offenders: string[] = [] + + for (const filePath of files) { + const source = await readFile(filePath, "utf8") + if (source.includes("@opencode-ai")) offenders.push(filePath) + } + + return offenders +} + +async function collectTypeScriptFiles(directory: string): Promise { + const entries = await readdir(directory, { withFileTypes: true }) + const files: string[] = [] + + for (const entry of entries) { + const entryPath = join(directory, entry.name) + if (entry.isDirectory()) { + files.push(...(await collectTypeScriptFiles(entryPath))) + } else if (entry.isFile() && entry.name.endsWith(".ts")) { + files.push(entryPath) + } + } + + return files +}