Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): de-flake version-rollback failure-surfacing test (#1852)

Nick Gomezb2e1d7cd5c41
diff --git a/packages/app/tests/integration/persistence-failure-surfacing-handlers.test.ts b/packages/app/tests/integration/persistence-failure-surfacing-handlers.test.ts
index 0872ea335..eb155f744 100644
--- a/packages/app/tests/integration/persistence-failure-surfacing-handlers.test.ts
+++ b/packages/app/tests/integration/persistence-failure-surfacing-handlers.test.ts
@@ -3,8 +3,8 @@ import { randomUUID } from 'node:crypto';
import {
agentPatch,
agentWriteMd,
+ awaitWipCommits,
createTestServer,
- pollUntil,
type TestServer,
} from './test-harness.ts';
@@ -80,27 +80,17 @@ describe('disk-persistence failure surfacing — edit_frontmatter (/api/frontmat
});
});
-async function getCheckpointShas(port: number, docName: string): Promise<string[]> {
- const r = await fetch(
- `http://127.0.0.1:${port}/api/history?docName=${encodeURIComponent(docName)}`,
- );
- if (!r.ok) return [];
- const body = (await r.json().catch(() => ({}))) as { entries?: Array<{ sha?: string }> };
- return (body.entries ?? []).map((e) => e.sha ?? '').filter((s) => /^[0-9a-f]{40}$/i.test(s));
-}
-
describe('disk-persistence failure surfacing — version rollback (/api/rollback)', () => {
- test.skip('reports a storage error instead of a false success when the rollback store fails', async () => {
+ test('reports a storage error instead of a false success when the rollback store fails', async () => {
server = await createTestServer({ gitEnabled: true, commitDebounceMs: 100 });
const docName = `rb-fault-${randomUUID()}`;
await agentWriteMd(server.port, '# V1\n\nbody one\n', { docName, position: 'replace' });
- await pollUntil(async () => (await getCheckpointShas(server.port, docName)).length >= 1, 12000);
+ await awaitWipCommits(server, docName, 1);
await agentWriteMd(server.port, '# V2\n\nbody two\n', { docName, position: 'replace' });
- await pollUntil(async () => (await getCheckpointShas(server.port, docName)).length >= 2, 12000);
+ const shas = await awaitWipCommits(server, docName, 2);
- const shas = await getCheckpointShas(server.port, docName);
- const priorSha = shas[shas.length - 1]; // oldest checkpoint = V1
+ const priorSha = shas[shas.length - 1]; // oldest WIP commit = V1
expect(priorSha).toMatch(/^[0-9a-f]{40}$/i);
process.env.OK_TEST_STORE_FAULT = docName;
diff --git a/packages/app/tests/integration/test-harness.ts b/packages/app/tests/integration/test-harness.ts
index d4a88dab1..793295dc5 100644
--- a/packages/app/tests/integration/test-harness.ts
+++ b/packages/app/tests/integration/test-harness.ts
@@ -648,6 +648,49 @@ export async function awaitBacklinkIndexed(
);
}
+export async function awaitWipCommits(
+ server: TestServer,
+ docName: string,
+ count: number,
+ timeoutMs = 20_000,
+): Promise<string[]> {
+ const intervals = [100, 250, 500, 1000];
+ let attempt = 0;
+ let lastShas: string[] = [];
+ const deadline = Date.now() + timeoutMs;
+ while (Date.now() < deadline) {
+ const flushRes = await fetch(`http://127.0.0.1:${server.port}/api/test-flush-git`, {
+ method: 'POST',
+ }).catch((err: unknown) => {
+ console.warn(
+ `[awaitWipCommits] test-flush-git fetch threw: ${String(err)} - continuing poll`,
+ );
+ return null;
+ });
+ if (flushRes !== null && !flushRes.ok) {
+ console.warn(
+ `[awaitWipCommits] test-flush-git returned ${flushRes.status} - continuing poll`,
+ );
+ }
+ const r = await fetch(
+ `http://127.0.0.1:${server.port}/api/history?docName=${encodeURIComponent(docName)}`,
+ ).catch(() => null);
+ if (r?.ok) {
+ const body = (await r.json().catch(() => ({}))) as {
+ entries?: Array<{ sha?: string; type?: string }>;
+ };
+ lastShas = (body.entries ?? [])
+ .filter((e) => e.type === 'wip' && /^[0-9a-f]{40}$/i.test(e.sha ?? ''))
+ .map((e) => e.sha as string);
+ if (lastShas.length >= count) return lastShas;
+ }
+ await wait(intervals[Math.min(attempt++, intervals.length - 1)]);
+ }
+ throw new Error(
+ `awaitWipCommits: doc ${docName} reached ${lastShas.length}/${count} WIP commits within ${timeoutMs}ms`,
+ );
+}
+
export type ServerDocState = {
ytext: Y.Text;
fragment: Y.XmlFragment;