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,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 {
|
||||
|
||||
Reference in new issue
Block a user