1
0

feat: 基础设施加固 — 修复构建、数据保留、错误边界、bundle 拆分

- 修复 build script 引用已删除的 registerCheckers,恢复生产构建
- 生产入口添加 SIGINT/SIGTERM 优雅关闭(与 dev.ts 一致)
- 新增 runtime.retention 配置(默认 7d),ProbeStore.prune() 定时清理过期数据
- parseDuration 扩展支持 h/d 单位
- 新增前端 ErrorBoundary 组件,防止渲染错误白屏
- Vite codeSplitting.groups 拆分 vendor chunks(业务代码 1180KB → 47KB)
- 同步 delta specs 到主规范
This commit is contained in:
2026-05-13 16:48:56 +08:00
parent 26f0bfe104
commit bcfb907bd3
25 changed files with 458 additions and 26 deletions

View File

@@ -419,4 +419,87 @@ describe("ProbeStore", () => {
freshStore.close();
});
test("prune 删除过期数据", () => {
const pruneStore = new ProbeStore(join(tempDir, "prune.db"));
pruneStore.syncTargets([httpTarget]);
const t = pruneStore.getTargets()[0]!;
pruneStore.insertCheckResult({
durationMs: 100,
failure: null,
matched: true,
statusDetail: "200 OK",
targetId: t.id,
timestamp: "2020-01-01T00:00:00.000Z",
});
pruneStore.insertCheckResult({
durationMs: 100,
failure: null,
matched: true,
statusDetail: "200 OK",
targetId: t.id,
timestamp: new Date().toISOString(),
});
const deleted = pruneStore.prune(86400000);
expect(deleted).toBe(1);
const history = pruneStore.getHistory(t.id, "2000-01-01T00:00:00.000Z", "2099-12-31T23:59:59.999Z");
expect(history.total).toBe(1);
pruneStore.close();
});
test("prune 无过期数据返回 0", () => {
const pruneStore = new ProbeStore(join(tempDir, "prune-none.db"));
pruneStore.syncTargets([httpTarget]);
const t = pruneStore.getTargets()[0]!;
pruneStore.insertCheckResult({
durationMs: 100,
failure: null,
matched: true,
statusDetail: "200 OK",
targetId: t.id,
timestamp: new Date().toISOString(),
});
const deleted = pruneStore.prune(86400000);
expect(deleted).toBe(0);
pruneStore.close();
});
test("prune 不影响保留期内数据", () => {
const pruneStore = new ProbeStore(join(tempDir, "prune-keep.db"));
pruneStore.syncTargets([httpTarget]);
const t = pruneStore.getTargets()[0]!;
const now = Date.now();
pruneStore.insertCheckResult({
durationMs: 100,
failure: null,
matched: true,
statusDetail: "200 OK",
targetId: t.id,
timestamp: new Date(now - 3600000).toISOString(),
});
pruneStore.insertCheckResult({
durationMs: 200,
failure: null,
matched: true,
statusDetail: "200 OK",
targetId: t.id,
timestamp: new Date(now).toISOString(),
});
const deleted = pruneStore.prune(7200000);
expect(deleted).toBe(0);
const history = pruneStore.getHistory(t.id, "2000-01-01T00:00:00.000Z", "2099-12-31T23:59:59.999Z");
expect(history.total).toBe(2);
pruneStore.close();
});
});