// Every path bootnode serves or calls is `/v1/...`; auth is `/v1/iam/*`. // // Run: `pnpm test`. // // Walks the first-party source of every component in this repo — the Python // API, the console, the operator, the fleet service — for an `/api/` path // written as a literal or appended to a base (`"/api/…"`, `` `${base}/api/…` ``, // `f"{url}/api/…"`). The one address allowed is the Kubernetes API // (`/api/v1/namespaces/…`), which is not ours. Tests are skipped: the fleet // suite requests `/api/…` on purpose, to prove it 404s. import { strict as assert } from "node:assert" import { readdirSync, readFileSync, statSync } from "node:fs" import { join, relative } from "node:path" import { describe, it } from "node:test" import { fileURLToPath } from "node:url" const ROOT = join(fileURLToPath(new URL(".", import.meta.url)), "..", "..") const DIRS = ["api/bootnode", "api/handlers", "api/store", "api/middleware", "console/app", "console/components", "console/lib", "operator/src", "fleet", "cmd"] const SOURCE = /\.(py|go|rs|ts|tsx|js|mjs)$/ const TEST = /(\.test\.tsx?|_test\.go|\/test_[^/]*\.py)$/ const PATH = /['"`(}]\/api\// const KUBERNETES = /\/api\/v1\/namespaces/ function walk(dir: string, out: string[] = []): string[] { for (const entry of readdirSync(dir)) { if (entry === "node_modules" || entry === "__pycache__") continue const full = join(dir, entry) if (statSync(full).isDirectory()) walk(full, out) else out.push(full) } return out } describe("the /v1 prefix", () => { it("no first-party source names an /api/ path", () => { const hits: string[] = [] for (const dir of DIRS) { for (const file of walk(join(ROOT, dir))) { if (!SOURCE.test(file) || TEST.test(file)) continue readFileSync(file, "utf8") .split("\n") .forEach((line, i) => { if (PATH.test(line) && !KUBERNETES.test(line)) hits.push(`${relative(ROOT, file)}:${i + 1}: ${line.trim()}`) }) } } assert.deepEqual(hits, []) }) })