doatlas-2 / artifacts /api-server /src /lib /capability /external-knowledge /__tests__ /router.test.ts
| /** | |
| * Router + adapter status — 验证: | |
| * - getAdapterStatus 返回 7 类,4 类 real / 3 类 interface_only | |
| * - logAdapterStatusBanner 真打 7 行 | |
| * - queryExternalKnowledge 路由到正确 adapter(用 stub 抛错验证) | |
| */ | |
| import test from "node:test"; | |
| import assert from "node:assert/strict"; | |
| import { | |
| getAdapterStatus, | |
| logAdapterStatusBanner, | |
| queryExternalKnowledge, | |
| NotImplementedAdapter, | |
| } from "../index.ts"; | |
| test("getAdapterStatus — 7 类 + 4 real / 3 interface_only", () => { | |
| const all = getAdapterStatus(); | |
| assert.equal(all.length, 7); | |
| const reals = all.filter((a) => a.status === "real").map((a) => a.kind).sort(); | |
| const stubs = all.filter((a) => a.status === "interface_only").map((a) => a.kind).sort(); | |
| assert.deepEqual(reals, [ | |
| "causal_network", | |
| "drug_network", | |
| "internal_experience", | |
| "literature", | |
| ]); | |
| assert.deepEqual(stubs, ["code_models", "data", "user_uploads"]); | |
| }); | |
| test("logAdapterStatusBanner — 真打 8 行(1 标题 + 7 适配器)", () => { | |
| const lines: string[] = []; | |
| logAdapterStatusBanner({ info: (m) => lines.push(m) }); | |
| assert.equal(lines.length, 8); | |
| assert.match(lines[0]!, /adapter status/); | |
| // 4 real + 3 interface_only | |
| assert.equal(lines.filter((l) => l.includes("REAL")).length, 4); | |
| assert.equal(lines.filter((l) => l.includes("interface_only")).length, 3); | |
| }); | |
| test("queryExternalKnowledge — 路由到 stub adapter 抛 NotImplementedAdapter", async () => { | |
| await assert.rejects( | |
| () => | |
| queryExternalKnowledge({ | |
| kind: "code_models", | |
| capabilityId: "cap_router", | |
| params: {}, | |
| }), | |
| NotImplementedAdapter, | |
| ); | |
| }); | |
| test("queryExternalKnowledge — 未知 kind 抛 Error", async () => { | |
| await assert.rejects( | |
| () => | |
| queryExternalKnowledge({ | |
| // @ts-expect-error 故意传非法 kind | |
| kind: "nonexistent", | |
| capabilityId: "cap_router", | |
| params: {}, | |
| }), | |
| /unknown knowledge kind/, | |
| ); | |
| }); | |