feat(FN-4025): defer database integrity check and expose via health endpoin

Exposes database health status via the API by deferring integrity checks asynchronously, with docs and tests covering the core DB layer, store integration, and dashboard server health endpoint.

Fusion-Task-Id: FN-4025
This commit is contained in:
Fusion
2026-05-11 14:10:23 -07:00
committed by gsxdsm
parent f9ce9bb9f2
commit 1e53b76eda
8 changed files with 142 additions and 51 deletions

View File

@@ -64,6 +64,14 @@ class MockStore extends EventEmitter {
};
}
getDatabaseHealth() {
return {
corruptionDetected: false,
integrityCheckPending: false,
integrityCheckLastRunAt: null,
};
}
getMissionStore() {
return {
listMissions: vi.fn().mockResolvedValue([]),

View File

@@ -68,6 +68,11 @@ function createMockStore(overrides: Partial<TaskStore> = {}): TaskStore {
exec: vi.fn(),
prepare: vi.fn().mockReturnValue({ run: vi.fn().mockReturnValue({ changes: 0 }), get: vi.fn(), all: vi.fn().mockReturnValue([]) }),
}),
getDatabaseHealth: vi.fn().mockReturnValue({
corruptionDetected: false,
integrityCheckPending: false,
integrityCheckLastRunAt: null,
}),
getMissionStore: vi.fn().mockReturnValue({
listMissions: vi.fn().mockReturnValue([]),
createMission: vi.fn(),
@@ -307,6 +312,36 @@ describe("createServer health and headless mode", () => {
status: "ok",
version: CLI_PACKAGE_VERSION,
uptime: expect.any(Number),
database: {
corruptionDetected: false,
integrityCheckPending: false,
integrityCheckLastRunAt: null,
},
});
});
it("reports degraded status when database corruption is detected", async () => {
const store = createMockStore({
getDatabaseHealth: vi.fn().mockReturnValue({
corruptionDetected: true,
integrityCheckPending: false,
integrityCheckLastRunAt: "2026-05-11T10:00:00.000Z",
}),
});
const app = createServer(store);
const res = await GET(app, "/api/health");
expect(res.status).toBe(200);
expect(res.body).toEqual({
status: "degraded",
version: CLI_PACKAGE_VERSION,
uptime: expect.any(Number),
database: {
corruptionDetected: true,
integrityCheckPending: false,
integrityCheckLastRunAt: "2026-05-11T10:00:00.000Z",
},
});
});