The ekb-mcp -> hose-use rename migration (LEGACY_* constants, syncLegacyEnterprisesDir/syncLegacyGlobalConfig with 7-day grace cleanup, dual-source enterprises resolution) has completed its job: legacy data self-deleted on active machines years of grace ago. Config resolution now returns the single primary ~/.config/hose-use source; startup no longer scans the legacy dir. - core/config/loader.ts: drop legacy constants, sync functions, and LEGACY path from diagnostics candidates; loader.test.ts drops the three legacy-migration cases - domains/approval/db.ts deleted: pure pass-through over core/db whose consumers (repository.ts) already call core/db directly; the four test files now import getDatabase/closeDatabase from core/db - scripts/dev-hygiene.ts: drop the config.legacy finding and legacyConfig snapshot field - docs/daily/* removed: Python-era (ekb-cli/ekb-mcp) notes describing commands and architecture that no longer exist (preserved in git history) No behavior change on machines without legacy data: tsc clean, 313 tests pass (316 minus the 3 removed legacy cases).
98 lines
3.6 KiB
TypeScript
98 lines
3.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
import { runCli } from "../runner.js";
|
|
import { runAiProCli } from "../../aipro-cli.js";
|
|
import { closeDatabase, getDatabase } from "../../core/db/index.js";
|
|
import { ApprovalRepository } from "../../domains/approval/repository.js";
|
|
|
|
describe("CLI - 上下文自省与 AI PRO 状态命令 (Zero-Source-Reading Context)", () => {
|
|
beforeEach(() => {
|
|
process.env.HOSE_APPROVAL_DB = ":memory:";
|
|
const db = getDatabase(":memory:");
|
|
const repo = new ApprovalRepository(db);
|
|
|
|
repo.createRule({
|
|
scope: "差旅报销",
|
|
body: "差旅报销时,[必须上传发票]{硬性}。",
|
|
});
|
|
repo.createRule({
|
|
scope: "业务招待",
|
|
body: "招待报销时,[必须提供餐饮点餐水单]{硬性}。",
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
closeDatabase();
|
|
delete process.env.HOSE_APPROVAL_DB;
|
|
});
|
|
|
|
test("hose-use context 打印文本格式仪表盘", async () => {
|
|
const res = await runCli(["context"]);
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("全局运行上下文与身份诊断");
|
|
expect(res.stdout).toContain("AI PRO 规约库");
|
|
expect(res.stdout).toContain("差旅报销");
|
|
expect(res.stdout).toContain("业务招待");
|
|
});
|
|
|
|
test("hose-use context --json 输出完备的结构化数据", async () => {
|
|
const res = await runCli(["context", "--json"]);
|
|
expect(res.exitCode).toBe(0);
|
|
|
|
const data = JSON.parse(res.stdout);
|
|
expect(data.tool).toBe("hose-use");
|
|
expect(data.corporationsSummary).toBeDefined();
|
|
expect(data.aiProGateway).toBeDefined();
|
|
expect(data.aiProGateway.scopesCount).toBe(2);
|
|
expect(data.aiProGateway.rulesCount).toBe(2);
|
|
expect(data.runtime.mode).toBeDefined();
|
|
expect(data.runtime.configFile).toBeDefined();
|
|
});
|
|
|
|
test("hose-use status 与 whoami 别名成功解析至 context", async () => {
|
|
const resStatus = await runCli(["status", "--json"]);
|
|
expect(resStatus.exitCode).toBe(0);
|
|
const dataStatus = JSON.parse(resStatus.stdout);
|
|
expect(dataStatus.tool).toBe("hose-use");
|
|
|
|
const resWhoami = await runCli(["whoami", "--json"]);
|
|
expect(resWhoami.exitCode).toBe(0);
|
|
const dataWhoami = JSON.parse(resWhoami.stdout);
|
|
expect(dataWhoami.tool).toBe("hose-use");
|
|
});
|
|
|
|
test("hose-aipro status 输出 AI PRO 专属上下文", async () => {
|
|
const res = await runAiProCli(["status"]);
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("合思 AI PRO 确定性审批网关运行上下文");
|
|
expect(res.stdout).toContain("规约场景库");
|
|
expect(res.stdout).toContain("差旅报销");
|
|
});
|
|
|
|
test("hose-aipro status --json 输出结构化数据", async () => {
|
|
const res = await runAiProCli(["status", "--json"]);
|
|
expect(res.exitCode).toBe(0);
|
|
|
|
const data = JSON.parse(res.stdout);
|
|
expect(data.tool).toBe("hose-aipro");
|
|
expect(data.ruleEngine.scopesCount).toBe(2);
|
|
expect(data.ruleEngine.rulesCount).toBe(2);
|
|
expect(data.sessions).toBeDefined();
|
|
});
|
|
|
|
test("hose-use aipro status 双向桥接成功转发", async () => {
|
|
const res = await runCli(["aipro", "status", "--json"]);
|
|
expect(res.exitCode).toBe(0);
|
|
|
|
const data = JSON.parse(res.stdout);
|
|
expect(data.tool).toBe("hose-aipro");
|
|
expect(data.ruleEngine.scopesCount).toBe(2);
|
|
});
|
|
|
|
test("hose-aipro 帮助页在顶部动态展示当前企业页眉", async () => {
|
|
const res = await runAiProCli(["help"]);
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("[当前");
|
|
expect(res.stdout).toContain("hose-aipro status");
|
|
});
|
|
});
|