fix: 安全性与代码质量加固(异常保护、外键级联、竞态修复、优雅关机)
This commit is contained in:
@@ -256,4 +256,45 @@ describe("ProbeStore", () => {
|
||||
expect(closedStore.getTargets()).toHaveLength(0);
|
||||
expect(closedStore.getTargetById(1)).toBeNull();
|
||||
});
|
||||
|
||||
test("删除 target 级联删除 check_results", () => {
|
||||
const cascadeStore = new ProbeStore(join(tempDir, "cascade.db"));
|
||||
const cascadeTarget: ResolvedTarget = {
|
||||
type: "http",
|
||||
name: "cascade-test",
|
||||
group: "default",
|
||||
http: { url: "http://cascade.test", method: "GET", headers: {}, maxBodyBytes: 104857600 },
|
||||
intervalMs: 30000,
|
||||
timeoutMs: 10000,
|
||||
};
|
||||
|
||||
cascadeStore.syncTargets([cascadeTarget]);
|
||||
const t = cascadeStore.getTargets()[0]!;
|
||||
|
||||
cascadeStore.insertCheckResult({
|
||||
targetId: t.id,
|
||||
timestamp: "2025-01-01T00:00:00.000Z",
|
||||
matched: true,
|
||||
durationMs: 100,
|
||||
statusDetail: "200 OK",
|
||||
failure: null,
|
||||
});
|
||||
cascadeStore.insertCheckResult({
|
||||
targetId: t.id,
|
||||
timestamp: "2025-01-01T00:01:00.000Z",
|
||||
matched: false,
|
||||
durationMs: null,
|
||||
statusDetail: null,
|
||||
failure: { kind: "error", phase: "status", path: "$", message: "fail" },
|
||||
});
|
||||
|
||||
expect(cascadeStore.getLatestCheck(t.id)).not.toBeNull();
|
||||
|
||||
cascadeStore.syncTargets([]);
|
||||
|
||||
expect(cascadeStore.getTargets()).toHaveLength(0);
|
||||
expect(cascadeStore.getLatestCheck(t.id)).toBeNull();
|
||||
|
||||
cascadeStore.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user