|
| 1 | +import { existsSync, readdirSync, readFileSync } from "node:fs"; |
| 2 | +import { join, relative } from "node:path"; |
| 3 | +import { describe, expect, test } from "bun:test"; |
| 4 | + |
| 5 | +// CL-9021: the root pin for the sessions package was dropped because no |
| 6 | +// first-party tree imports it. The only remaining references are the inert |
| 7 | +// `vendor/intx-workflow-host/` provenance files (not a workspace member, |
| 8 | +// excluded from typecheck/test/build per docs/VENDORING.md) plus prose |
| 9 | +// comments. Fail if a built tree gains an import or the pin creeps back. |
| 10 | + |
| 11 | +const repoRoot = join(import.meta.dir, ".."); |
| 12 | +const pkg = JSON.parse( |
| 13 | + readFileSync(join(repoRoot, "package.json"), "utf8"), |
| 14 | +) as { |
| 15 | + dependencies: Record<string, string>; |
| 16 | +}; |
| 17 | + |
| 18 | +// Trees that participate in typecheck (tsconfig include) and the test suite. |
| 19 | +const FIRST_PARTY_TREES = [ |
| 20 | + "src", |
| 21 | + "packages", |
| 22 | + "scripts", |
| 23 | + "e2e", |
| 24 | + "evals", |
| 25 | + "testkit", |
| 26 | +]; |
| 27 | + |
| 28 | +const SESSIONS_IMPORT = |
| 29 | + /(?:from\s+|require\(\s*|import\(\s*)["']@intx\/hub-sessions(?:\/[^"']*)?["']\s*\)?/; |
| 30 | + |
| 31 | +function tsFiles(dir: string): string[] { |
| 32 | + const files: string[] = []; |
| 33 | + const walk = (current: string) => { |
| 34 | + for (const entry of readdirSync(current, { withFileTypes: true })) { |
| 35 | + const absolute = join(current, entry.name); |
| 36 | + if (entry.isDirectory()) walk(absolute); |
| 37 | + else if (entry.name.endsWith(".ts")) files.push(absolute); |
| 38 | + } |
| 39 | + }; |
| 40 | + if (existsSync(dir)) walk(dir); |
| 41 | + return files; |
| 42 | +} |
| 43 | + |
| 44 | +describe("no sessions package", () => { |
| 45 | + test("package.json carries no dependency on the sessions package", () => { |
| 46 | + expect(pkg.dependencies["@intx/hub-sessions"]).toBeUndefined(); |
| 47 | + }); |
| 48 | + |
| 49 | + test("no first-party tree imports the sessions package", () => { |
| 50 | + const offenders: string[] = []; |
| 51 | + for (const tree of FIRST_PARTY_TREES) { |
| 52 | + for (const file of tsFiles(join(repoRoot, tree))) { |
| 53 | + if (SESSIONS_IMPORT.test(readFileSync(file, "utf8"))) |
| 54 | + offenders.push(relative(repoRoot, file).split("/").join("/")); |
| 55 | + } |
| 56 | + } |
| 57 | + expect(offenders).toEqual([]); |
| 58 | + }); |
| 59 | +}); |
0 commit comments