Repository navigation
refactor: replace @cortexkit/subc-client with internal mc-host TypeScript client #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
22557de
2aa67de
75f32a2
d379e77
2b0c179
a1f47a4
8f1a8f6
c907479
9e6ac16
a1b4005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import * as fs from "node:fs"; | ||
| import * as path from "node:path"; | ||
|
|
||
| /** | ||
| * Dependency-boundary gate: production packages must not depend on or import | ||
| * `@cortexkit/subc-client`. Only `PROVIDER_EXCEPTION` may import it. | ||
| */ | ||
|
|
||
| const NPM_CLIENT = "@cortexkit/subc-client"; | ||
| const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); | ||
|
|
||
| const PRODUCTION_PACKAGES = ["packages/plugin", "packages/cli", "packages/pi-plugin"]; | ||
|
|
||
| const PROVIDER_EXCEPTION = "packages/e2e-tests/src/rust-runner/fake-broca.ts"; | ||
|
|
||
| /** IMPORT_PATTERN matches import, export-from, require, and dynamic-import specifiers for NPM_CLIENT. */ | ||
| const IMPORT_PATTERN = | ||
| /(?:from\s*["']@cortexkit\/subc-client["']|import\s*\(\s*["']@cortexkit\/subc-client["']\s*\)|require\s*\(\s*["']@cortexkit\/subc-client["']\s*\)|import\s*["']@cortexkit\/subc-client["'])/; | ||
|
|
||
| function* walkSourceFiles(dir: string): Generator<string> { | ||
| for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { | ||
| if (entry.name === "node_modules" || entry.name === "dist" || entry.name.startsWith(".")) | ||
| continue; | ||
| const full = path.join(dir, entry.name); | ||
| if (entry.isDirectory()) yield* walkSourceFiles(full); | ||
| else if (/\.(ts|tsx|js|mjs|cjs)$/.test(entry.name)) yield full; | ||
| } | ||
| } | ||
|
|
||
| function manifestDependencies(packageDir: string): Record<string, string> { | ||
| const manifest = JSON.parse( | ||
| fs.readFileSync(path.join(repoRoot, packageDir, "package.json"), "utf-8"), | ||
| ) as Record<string, Record<string, string> | undefined>; | ||
| return { | ||
| ...manifest.dependencies, | ||
| ...manifest.devDependencies, | ||
| ...manifest.optionalDependencies, | ||
| ...manifest.peerDependencies, | ||
| }; | ||
| } | ||
|
|
||
| describe("mc-host-client dependency boundary", () => { | ||
| test("production manifests do not depend on the npm client", () => { | ||
| for (const pkg of PRODUCTION_PACKAGES) { | ||
| expect( | ||
| Object.keys(manifestDependencies(pkg)), | ||
| `${pkg}/package.json must not declare ${NPM_CLIENT}`, | ||
| ).not.toContain(NPM_CLIENT); | ||
| } | ||
| }); | ||
|
|
||
| test("production and consumer-side sources do not import the npm client", () => { | ||
| const offenders: string[] = []; | ||
| for (const pkg of [...PRODUCTION_PACKAGES, "packages/e2e-tests"]) { | ||
| const root = path.join(repoRoot, pkg); | ||
| if (!fs.existsSync(root)) continue; | ||
| for (const file of walkSourceFiles(root)) { | ||
| const relative = path.relative(repoRoot, file); | ||
| if (relative === PROVIDER_EXCEPTION) continue; | ||
| if (IMPORT_PATTERN.test(fs.readFileSync(file, "utf-8"))) offenders.push(relative); | ||
| } | ||
| } | ||
| expect(offenders, `only ${PROVIDER_EXCEPTION} may import ${NPM_CLIENT}`).toEqual([]); | ||
| }); | ||
|
|
||
| test("the E2E provider exception still holds the one permitted import", () => { | ||
| const source = fs.readFileSync(path.join(repoRoot, PROVIDER_EXCEPTION), "utf-8"); | ||
| expect(IMPORT_PATTERN.test(source)).toBe(true); | ||
| expect(Object.keys(manifestDependencies("packages/e2e-tests"))).toContain(NPM_CLIENT); | ||
| }); | ||
|
|
||
| test("lockfile resolves the npm client only through the E2E package", () => { | ||
| const lock = fs.readFileSync(path.join(repoRoot, "bun.lock"), "utf-8"); | ||
| const references = lock.split("\n").filter((line) => line.includes(NPM_CLIENT)); | ||
| expect(references.length).toBeGreaterThan(0); | ||
| for (const pkg of PRODUCTION_PACKAGES) { | ||
| const manifest = JSON.parse( | ||
| fs.readFileSync(path.join(repoRoot, pkg, "package.json"), "utf-8"), | ||
| ) as { name: string }; | ||
| // bun.lock lists each workspace's dependencies on its workspace | ||
| // entry line, so no production package name may share a line with | ||
| // the npm client. | ||
| for (const line of references) { | ||
| expect( | ||
| line.includes(`"${manifest.name}"`), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Lockfile assertion passes vacuously due to multiline format In Reply with
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 2b0c179. Confirmed the per-line check was vacuous — bun.lock puts dependency mappings and workspace names on separate lines. The test now parses the lockfile's blocks (trailing commas stripped) and asserts is the only workspace declaring the npm client, which also strengthens the positive direction. |
||
| `bun.lock ties ${NPM_CLIENT} to ${manifest.name}`, | ||
| ).toBe(false); | ||
| } | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.