chore(legacy): remove ekb-mcp migration layer, approval db compat shim, and stale daily notes
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).
This commit is contained in:
1 parent
70fbbe22df
commit
95eb8ee676
13 files changed
+17
-451
No files matched your search
@@ -1,13 +1,13 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { runAiProCli } from "./aipro-cli.js";
|
||||
import { closeApprovalDatabase, getApprovalDatabase } from "./domains/approval/db.js";
|
||||
import { closeDatabase, getDatabase } from "./core/db/index.js";
|
||||
import { ApprovalRepository } from "./domains/approval/repository.js";
|
||||
import { getVersionInfo } from "./version.js";
|
||||
|
||||
describe("CLI - hose-aipro 审批流与网关阻拦全链路测试", () => {
|
||||
beforeEach(() => {
|
||||
process.env.HOSE_APPROVAL_DB = ":memory:";
|
||||
const db = getApprovalDatabase(":memory:");
|
||||
const db = getDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
// 预置规约规则
|
||||
@@ -22,7 +22,7 @@ describe("CLI - hose-aipro 审批流与网关阻拦全链路测试", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
closeApprovalDatabase();
|
||||
closeDatabase();
|
||||
delete process.env.HOSE_APPROVAL_DB;
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ describe("CLI - hose-aipro 审批流与网关阻拦全链路测试", () => {
|
||||
});
|
||||
|
||||
test("完整闭环:bind 挂载 ➔ review 证据核验 ➔ decide 网关阻拦与裁决 ➔ logs 审计追溯", async () => {
|
||||
const db = getApprovalDatabase(":memory:");
|
||||
const db = getDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
// 1. 创建审批会话
|
||||
@@ -125,7 +125,7 @@ describe("CLI - hose-aipro 审批流与网关阻拦全链路测试", () => {
|
||||
});
|
||||
|
||||
test("门禁防御:单据无硬性或弹性违规时,尝试执行 reject 必须被网关阻断(禁止无因驳回)", async () => {
|
||||
const db = getApprovalDatabase(":memory:");
|
||||
const db = getDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
const run = repo.createApprovalRun({
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { runCli } from "../runner.js";
|
||||
import { runAiProCli } from "../../aipro-cli.js";
|
||||
import { closeApprovalDatabase, getApprovalDatabase } from "../../domains/approval/db.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 = getApprovalDatabase(":memory:");
|
||||
const db = getDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
repo.createRule({
|
||||
@@ -21,7 +21,7 @@ describe("CLI - 上下文自省与 AI PRO 状态命令 (Zero-Source-Reading Cont
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
closeApprovalDatabase();
|
||||
closeDatabase();
|
||||
delete process.env.HOSE_APPROVAL_DB;
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { runCli } from "../runner.js";
|
||||
import { closeApprovalDatabase, getApprovalDatabase } from "../../domains/approval/db.js";
|
||||
import { closeDatabase, getDatabase } from "../../core/db/index.js";
|
||||
import { ApprovalRepository } from "../../domains/approval/repository.js";
|
||||
|
||||
describe("CLI - hose-use rule 规则与场景索引命令", () => {
|
||||
beforeEach(() => {
|
||||
process.env.HOSE_APPROVAL_DB = ":memory:";
|
||||
const db = getApprovalDatabase(":memory:");
|
||||
const db = getDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
// 预置几条测试规则 (仅需 适用场景 + 规约正文 两个要素)
|
||||
@@ -25,7 +25,7 @@ describe("CLI - hose-use rule 规则与场景索引命令", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
closeApprovalDatabase();
|
||||
closeDatabase();
|
||||
delete process.env.HOSE_APPROVAL_DB;
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync, readFileSync, statSync, utimesSync } from "node:fs";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync, readFileSync, statSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
@@ -11,8 +11,6 @@ import {
|
||||
loadGlobalConfig,
|
||||
saveGlobalConfig,
|
||||
resolveGlobalConfigFile,
|
||||
syncLegacyEnterprisesDir,
|
||||
syncLegacyGlobalConfig,
|
||||
} from "./loader.js";
|
||||
import { saveAccount, loadAccountStore, resolveAccountCachePath } from "../auth/account-store.js";
|
||||
import type { CorpConfig } from "./types.js";
|
||||
@@ -174,47 +172,6 @@ describe("core/config/loader", () => {
|
||||
expect(updated.defaultCorpId).toBe("test-corp-123");
|
||||
});
|
||||
|
||||
test("syncLegacyEnterprisesDir copies legacy credentials and removes stale legacy directory", () => {
|
||||
const primary = join(tempDir, "primary");
|
||||
const legacy = join(tempDir, "legacy");
|
||||
mkdirSync(legacy, { recursive: true });
|
||||
writeFileSync(join(legacy, "corp-old.json"), JSON.stringify(createMockCorp("corp-old", "旧企业")));
|
||||
const old = new Date(Date.now() - 10 * 24 * 60 * 60 * 1000);
|
||||
utimesSync(join(legacy, "corp-old.json"), old, old);
|
||||
utimesSync(legacy, old, old);
|
||||
|
||||
const result = syncLegacyEnterprisesDir(primary, legacy);
|
||||
expect(result.copied).toEqual(["corp-old.json"]);
|
||||
expect(result.deletedLegacyDir).toBe(true);
|
||||
expect(existsSync(join(primary, "corp-old.json"))).toBe(true);
|
||||
expect(existsSync(legacy)).toBe(false);
|
||||
});
|
||||
|
||||
test("syncLegacyEnterprisesDir preserves a recently modified legacy directory", () => {
|
||||
const primary = join(tempDir, "primary-recent");
|
||||
const legacy = join(tempDir, "legacy-recent");
|
||||
mkdirSync(legacy, { recursive: true });
|
||||
writeFileSync(join(legacy, "corp-recent.json"), JSON.stringify(createMockCorp("corp-recent", "近期企业")));
|
||||
|
||||
const result = syncLegacyEnterprisesDir(primary, legacy);
|
||||
expect(result.deletedLegacyDir).toBe(false);
|
||||
expect(existsSync(legacy)).toBe(true);
|
||||
});
|
||||
|
||||
test("syncLegacyGlobalConfig migrates and removes a stale legacy config", () => {
|
||||
const primary = join(tempDir, "config", "config.json");
|
||||
const legacy = join(tempDir, "legacy-config.json");
|
||||
writeFileSync(legacy, JSON.stringify({ stateful: false }));
|
||||
const old = new Date(Date.now() - 10 * 24 * 60 * 60 * 1000);
|
||||
utimesSync(legacy, old, old);
|
||||
|
||||
const result = syncLegacyGlobalConfig(primary, legacy);
|
||||
expect(result.copied).toBe(true);
|
||||
expect(result.deletedLegacyFile).toBe(true);
|
||||
expect(JSON.parse(readFileSync(primary, "utf8")).stateful).toBe(false);
|
||||
expect(existsSync(legacy)).toBe(false);
|
||||
});
|
||||
|
||||
test("saveCorpConfig and saveAccount enforce 0o600 file permissions and respect HOSE_ACCOUNTS_FILE", () => {
|
||||
const targetDir = join(tempDir, "secure-corps");
|
||||
const corpFile = saveCorpConfig(createMockCorp("sec-1", "安全测试企业"), targetDir);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { CorpConfig, CorpConfigSchema, GlobalConfig, GlobalConfigSchema, normalizeCorpConfig } from "./types.js";
|
||||
@@ -8,13 +8,9 @@ const USER_DIR_ENV = "HOSE_USER_ENTERPRISES_DIR";
|
||||
const GLOBAL_CONFIG_ENV = "HOSE_CONFIG_FILE";
|
||||
|
||||
export const PRIMARY_USER_ENTERPRISES_DIR = join(homedir(), ".config", "hose-use", "enterprises");
|
||||
export const LEGACY_USER_ENTERPRISES_DIR = join(homedir(), ".cache", "ekb-mcp", "enterprises");
|
||||
export const USER_ENTERPRISES_DIR = PRIMARY_USER_ENTERPRISES_DIR;
|
||||
|
||||
export const PRIMARY_GLOBAL_CONFIG_FILE = join(homedir(), ".config", "hose-use", "config.json");
|
||||
export const LEGACY_GLOBAL_CONFIG_FILE = join(homedir(), ".cache", "ekb-mcp", "config.json");
|
||||
|
||||
const LEGACY_CLEANUP_GRACE_MS = 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
function ensureDir(dir: string): void {
|
||||
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
@@ -40,14 +36,7 @@ export function resolveEnterprisesDirs(): string[] {
|
||||
const configuredUserDir = process.env[USER_DIR_ENV]?.trim();
|
||||
const userDirs = configuredUserDir
|
||||
? (existsSync(configuredUserDir) ? [configuredUserDir] : [])
|
||||
: (() => {
|
||||
try {
|
||||
syncLegacyEnterprisesDir();
|
||||
} catch {
|
||||
// Legacy migration must never prevent normal CLI startup.
|
||||
}
|
||||
return [PRIMARY_USER_ENTERPRISES_DIR, LEGACY_USER_ENTERPRISES_DIR];
|
||||
})();
|
||||
: [PRIMARY_USER_ENTERPRISES_DIR];
|
||||
|
||||
const globalConfig = loadGlobalConfig();
|
||||
const testDir = globalConfig.testEnterprisesDir?.trim();
|
||||
@@ -82,77 +71,15 @@ export function getEnterprisesDirCandidates(): string[] {
|
||||
`${CONFIG_ENV}=<path>`,
|
||||
...(testDir ? [`testEnterprisesDir: ${testDir}`] : []),
|
||||
PRIMARY_USER_ENTERPRISES_DIR,
|
||||
LEGACY_USER_ENTERPRISES_DIR,
|
||||
];
|
||||
}
|
||||
|
||||
export function resolveGlobalConfigFile(): string {
|
||||
const configured = process.env[GLOBAL_CONFIG_ENV]?.trim();
|
||||
if (configured) return configured;
|
||||
try {
|
||||
syncLegacyGlobalConfig();
|
||||
} catch {
|
||||
// Legacy migration must never prevent normal CLI startup.
|
||||
}
|
||||
if (existsSync(PRIMARY_GLOBAL_CONFIG_FILE)) return PRIMARY_GLOBAL_CONFIG_FILE;
|
||||
if (existsSync(LEGACY_GLOBAL_CONFIG_FILE)) return LEGACY_GLOBAL_CONFIG_FILE;
|
||||
return PRIMARY_GLOBAL_CONFIG_FILE;
|
||||
}
|
||||
|
||||
export function syncLegacyEnterprisesDir(
|
||||
primaryDir: string = PRIMARY_USER_ENTERPRISES_DIR,
|
||||
legacyDir: string = LEGACY_USER_ENTERPRISES_DIR
|
||||
): { copied: string[]; deletedLegacyDir: boolean } {
|
||||
if (!existsSync(legacyDir)) return { copied: [], deletedLegacyDir: false };
|
||||
|
||||
mkdirSync(primaryDir, { recursive: true, mode: 0o700 });
|
||||
const copied: string[] = [];
|
||||
const files = readdirSync(legacyDir).filter((file) => file.endsWith(".json"));
|
||||
|
||||
for (const file of files) {
|
||||
const legacyPath = join(legacyDir, file);
|
||||
const primaryPath = join(primaryDir, file);
|
||||
if (!existsSync(primaryPath) || statSync(legacyPath).mtimeMs > statSync(primaryPath).mtimeMs) {
|
||||
copyFileSync(legacyPath, primaryPath);
|
||||
copied.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const hasRecentEntry = readdirSync(legacyDir).some((file) => now - statSync(join(legacyDir, file)).mtimeMs < LEGACY_CLEANUP_GRACE_MS);
|
||||
const hasNewerLegacyFile = files.some((file) => {
|
||||
const legacyPath = join(legacyDir, file);
|
||||
const primaryPath = join(primaryDir, file);
|
||||
return existsSync(primaryPath) && statSync(legacyPath).mtimeMs > statSync(primaryPath).mtimeMs;
|
||||
});
|
||||
const directoryIsRecent = now - statSync(legacyDir).mtimeMs < LEGACY_CLEANUP_GRACE_MS;
|
||||
const deletedLegacyDir = !hasRecentEntry && !hasNewerLegacyFile && !directoryIsRecent;
|
||||
if (deletedLegacyDir) rmSync(legacyDir, { recursive: true, force: true });
|
||||
return { copied, deletedLegacyDir };
|
||||
}
|
||||
|
||||
export function syncLegacyGlobalConfig(
|
||||
primaryFile: string = PRIMARY_GLOBAL_CONFIG_FILE,
|
||||
legacyFile: string = LEGACY_GLOBAL_CONFIG_FILE
|
||||
): { copied: boolean; deletedLegacyFile: boolean } {
|
||||
if (!existsSync(legacyFile)) return { copied: false, deletedLegacyFile: false };
|
||||
mkdirSync(dirname(primaryFile), { recursive: true, mode: 0o700 });
|
||||
|
||||
let copied = false;
|
||||
if (!existsSync(primaryFile) || statSync(legacyFile).mtimeMs > statSync(primaryFile).mtimeMs) {
|
||||
copyFileSync(legacyFile, primaryFile);
|
||||
copied = true;
|
||||
}
|
||||
|
||||
const oldEnough = Date.now() - statSync(legacyFile).mtimeMs >= LEGACY_CLEANUP_GRACE_MS;
|
||||
const safeToDelete = existsSync(primaryFile) && statSync(legacyFile).mtimeMs <= statSync(primaryFile).mtimeMs && oldEnough;
|
||||
if (safeToDelete) {
|
||||
rmSync(legacyFile, { force: true });
|
||||
return { copied, deletedLegacyFile: true };
|
||||
}
|
||||
return { copied, deletedLegacyFile: false };
|
||||
}
|
||||
|
||||
export function loadGlobalConfig(): GlobalConfig {
|
||||
const file = resolveGlobalConfigFile();
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Database } from "bun:sqlite";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { closeApprovalDatabase, getApprovalDatabase } from "./db.js";
|
||||
import { closeDatabase, getDatabase } from "../../core/db/index.js";
|
||||
import { ApprovalRepository } from "./repository.js";
|
||||
import { ApprovalService } from "./service.js";
|
||||
import { ApprovalRuleValidationError } from "./types.js";
|
||||
@@ -11,12 +11,12 @@ describe("Approval Domain - SQLite 持久化与规约仓储", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
// 每次测试使用独立的内存数据库,隔离状态
|
||||
db = getApprovalDatabase(":memory:");
|
||||
db = getDatabase(":memory:");
|
||||
repo = new ApprovalRepository(db);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
closeApprovalDatabase();
|
||||
closeDatabase();
|
||||
});
|
||||
|
||||
test("数据库初始化时自动种子化默认偏好配置", () => {
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import type { Database } from "bun:sqlite";
|
||||
import {
|
||||
DEFAULT_DB_PATH,
|
||||
closeDatabase,
|
||||
getDatabase,
|
||||
resolveDatabasePath,
|
||||
runMigrations,
|
||||
} from "../../core/db/index.js";
|
||||
|
||||
export const DEFAULT_APPROVAL_DB_PATH = DEFAULT_DB_PATH;
|
||||
|
||||
export function resolveApprovalDbPath(): string {
|
||||
return resolveDatabasePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取或创建 SQLite 数据库连接单例(兼容原接口,底层使用 core/db)
|
||||
*/
|
||||
export function getApprovalDatabase(customPath?: string): Database {
|
||||
return getDatabase(customPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭并清理当前数据库连接
|
||||
*/
|
||||
export function closeApprovalDatabase(): void {
|
||||
closeDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表结构与默认数据(兼容原接口,委托给 runMigrations)
|
||||
*/
|
||||
export function initDatabaseSchema(db: Database): void {
|
||||
runMigrations(db);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
export * from "./types.js";
|
||||
export * from "./parser.js";
|
||||
export * from "./db.js";
|
||||
export * from "./repository.js";
|
||||
export * from "./service.js";
|
||||
export * from "./gateway.js";
|
||||
Reference in new issue
Block a user