Serialise startup compatibility dialogues

This commit is contained in:
vorotamoroz
2026-07-21 03:39:12 +00:00
parent 462b769e34
commit f195b9be0c
7 changed files with 64 additions and 1 deletions
@@ -3,6 +3,7 @@ export interface ConfiguredStartupLifecycleRuntime {
reportDatabaseNotReady(): void;
hasCompromisedChunks(): Promise<boolean>;
hasIncompleteDocuments(): Promise<boolean>;
waitForCompatibilityReview(): Promise<void>;
runDoctor(): Promise<boolean>;
migrateBulkSend(): Promise<void>;
}
@@ -33,6 +34,7 @@ export async function runConfiguredStartupLifecycle(runtime: ConfiguredStartupLi
}
if (!(await runtime.hasCompromisedChunks())) return false;
if (!(await runtime.hasIncompleteDocuments())) return false;
await runtime.waitForCompatibilityReview();
if (!(await runtime.runDoctor())) return false;
await runtime.migrateBulkSend();
return true;
@@ -19,6 +19,7 @@ function createRuntime(): ConfiguredStartupLifecycleRuntime & { events: string[]
events.push("incomplete-documents");
return true;
}),
waitForCompatibilityReview: vi.fn(async () => {}),
runDoctor: vi.fn(async () => {
events.push("doctor");
return true;
@@ -38,6 +39,25 @@ describe("runConfiguredStartupLifecycle", () => {
expect(runtime.events).toEqual(["compromised-chunks", "incomplete-documents", "doctor", "bulk-send"]);
});
it("keeps Config Doctor behind the initial compatibility review", async () => {
const runtime = createRuntime();
Object.assign(runtime, {
waitForCompatibilityReview: vi.fn(async () => {
runtime.events.push("compatibility-review");
}),
});
await expect(runConfiguredStartupLifecycle(runtime)).resolves.toBe(true);
expect(runtime.events).toEqual([
"compromised-chunks",
"incomplete-documents",
"compatibility-review",
"doctor",
"bulk-send",
]);
});
it("stops before onboarding or checks when the database is unavailable", async () => {
const runtime = createRuntime();
runtime.databaseReady = false;