Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Stabilize Open Knowledge full-check test fixtures (#5563)

Nick Gomezd289e32391cc
diff --git a/packages/app/src/components/ConsentDialogBody.dom.test.tsx b/packages/app/src/components/ConsentDialogBody.dom.test.tsx
index 9c1611bfe..bdbe01b44 100644
--- a/packages/app/src/components/ConsentDialogBody.dom.test.tsx
+++ b/packages/app/src/components/ConsentDialogBody.dom.test.tsx
@@ -1,6 +1,6 @@
import { EDITOR_LABELS } from '@inkeep/open-knowledge-core';
import { i18n } from '@lingui/core';
-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, describe, expect, test, vi } from 'vitest';
import type { ConsentStore } from '@/lib/consent-store';
@@ -123,6 +123,7 @@ async function expandAdvanced() {
describe('ConsentDialogBody runtime form behavior', () => {
afterEach(() => {
cleanup();
+ vi.useRealTimers();
i18n.activate('en');
setBridge(undefined);
vi.restoreAllMocks();
@@ -325,6 +326,7 @@ describe('ConsentDialogBody runtime form behavior', () => {
});
test('a never-settling detection probe keeps Cancel live and degrades to no wiring', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
const harness = makeStore();
setBridge(statusBridge([], { pending: true }));
vi.spyOn(console, 'warn').mockImplementation(() => {});
@@ -337,37 +339,35 @@ describe('ConsentDialogBody runtime form behavior', () => {
fireEvent.submit(screen.getByTestId('consent-form') as HTMLFormElement);
- await waitFor(() => {
- expect(
- (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
- ).toBe('true');
- });
+ expect(
+ (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
+ ).toBe('true');
expect((screen.getByTestId('consent-cancel') as HTMLButtonElement).disabled).toBe(false);
- await waitFor(() => {
- expect(harness.confirmCalls).toHaveLength(1);
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(150);
});
+ expect(harness.confirmCalls).toHaveLength(1);
+ expect((screen.getByTestId('consent-cancel') as HTMLButtonElement).disabled).toBe(true);
expect(harness.confirmCalls[0]?.editorIds).toEqual([]);
expect(harness.confirmCalls[0]?.connectEditors).toBe(true);
});
test('Escape during the detection wait cancels instead of being swallowed', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
const harness = makeStore();
setBridge(statusBridge([], { pending: true }));
render(<ConsentDialogBody payload={payload} store={harness.store} />);
fireEvent.submit(screen.getByTestId('consent-form') as HTMLFormElement);
- await waitFor(() => {
- expect(
- (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
- ).toBe('true');
- });
-
- fireEvent.keyDown(document.body, { key: 'Escape', code: 'Escape' });
+ expect(
+ (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
+ ).toBe('true');
- await waitFor(() => {
- expect(harness.cancelCalls).toEqual(['cancel']);
+ await act(async () => {
+ fireEvent.keyDown(document.body, { key: 'Escape', code: 'Escape' });
});
+ expect(harness.cancelCalls).toEqual(['cancel']);
});
test('a rejected detection probe does not hang the submit', async () => {
@@ -416,24 +416,21 @@ describe('ConsentDialogBody runtime form behavior', () => {
});
test('two rapid cancels during the detection wait issue a single cancel', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
const harness = makeStore();
setBridge(statusBridge([], { pending: true }));
render(<ConsentDialogBody payload={payload} store={harness.store} />);
fireEvent.submit(screen.getByTestId('consent-form') as HTMLFormElement);
- await waitFor(() => {
- expect(
- (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
- ).toBe('true');
- });
+ expect(
+ (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
+ ).toBe('true');
fireEvent.click(screen.getByTestId('consent-cancel'));
fireEvent.keyDown(document.body, { key: 'Escape', code: 'Escape' });
- await waitFor(() => {
- expect(harness.cancelCalls).toEqual(['cancel']);
- });
- await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(harness.cancelCalls).toEqual(['cancel']);
+ await act(async () => {});
expect(harness.cancelCalls).toEqual(['cancel']);
});
@@ -487,29 +484,26 @@ describe('ConsentDialogBody runtime form behavior', () => {
});
test('a successful cancel during the wait suppresses the parked confirm', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
const harness = makeStore();
const detection = deferredStatusBridge(['claude']);
setBridge(detection.bridge);
render(<ConsentDialogBody payload={payload} store={harness.store} />);
fireEvent.submit(screen.getByTestId('consent-form') as HTMLFormElement);
- await waitFor(() => {
- expect(
- (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
- ).toBe('true');
- });
+ expect(
+ (screen.getByTestId('consent-start') as HTMLButtonElement).getAttribute('aria-busy'),
+ ).toBe('true');
- fireEvent.click(screen.getByTestId('consent-cancel'));
- await waitFor(() => {
- expect(harness.cancelCalls).toEqual(['cancel']);
+ await act(async () => {
+ fireEvent.click(screen.getByTestId('consent-cancel'));
});
+ expect(harness.cancelCalls).toEqual(['cancel']);
- detection.release();
- await waitFor(() => {
- expect(screen.getByTestId('consent-editors-status').getAttribute('data-status')).toBe(
- 'ready',
- );
+ await act(async () => {
+ detection.release();
});
+ expect(screen.getByTestId('consent-editors-status').getAttribute('data-status')).toBe('ready');
expect(harness.confirmCalls).toEqual([]);
});
diff --git a/packages/desktop/tests/main/desktop-uninstall-handoff.test.ts b/packages/desktop/tests/main/desktop-uninstall-handoff.test.ts
index eb667f0a0..5d9a70ba7 100644
--- a/packages/desktop/tests/main/desktop-uninstall-handoff.test.ts
+++ b/packages/desktop/tests/main/desktop-uninstall-handoff.test.ts
@@ -11,7 +11,7 @@ import {
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { basename, join } from 'node:path';
import { PassThrough } from 'node:stream';
import { setTimeout as delay } from 'node:timers/promises';
import { afterEach, describe, expect, test, vi } from 'vitest';
@@ -3444,14 +3444,14 @@ function withTemporaryDirectory(shell: string, temporaryDirectory: string, scrip
return `TMPDIR=${shellQuote(temporaryDirectory)}; export TMPDIR; exec ${shellQuote(shell)} -c ${shellQuote(script)}`;
}
-function readHostPathLimit(limit: 'PATH_MAX' | 'NAME_MAX', path: string) {
- const reported = spawnSyncBounded('/usr/bin/getconf', [limit, path], {
+function readHostPathMax(path: string) {
+ const reported = spawnSyncBounded('/usr/bin/getconf', ['PATH_MAX', path], {
timeoutMs: DEFAULT_BOUNDED_SPAWN_TIMEOUT_MS,
});
const value = Number(reported.stdout.trim());
if (reported.status !== 0 || !Number.isSafeInteger(value) || value <= 0) {
throw new Error(
- `getconf ${limit} ${path} exited ${String(reported.status)} reporting ${JSON.stringify(reported.stdout.trim())}, so this host gives no ${limit} to size a path against.\nstderr: ${reported.stderr.trim()}`,
+ `getconf PATH_MAX ${path} exited ${String(reported.status)} reporting ${JSON.stringify(reported.stdout.trim())}, so this host gives no PATH_MAX to size a path against.\nstderr: ${reported.stderr.trim()}`,
);
}
return value;
@@ -3477,12 +3477,12 @@ function temporaryDirectoryWithRoomForADirectoryButNotItsFile(
fileName: string,
) {
const root = realpathSync(f.dir);
- const pathMax = readHostPathLimit('PATH_MAX', root);
+ const pathMax = readHostPathMax(root);
const directoryLength = pathMax - Math.ceil(`/${fileName}`.length / 2);
const path = directoryPathOfLength(
root,
directoryLength - `/${directoryTemplate}`.length,
- readHostPathLimit('NAME_MAX', root),
+ basename(root).length,
);
mkdirSync(path, { recursive: true });
return { path, pathMax };
diff --git a/packages/server/src/api-search-semantic-factory.test.ts b/packages/server/src/api-search-semantic-factory.test.ts
index a3d511fe3..265970c6a 100644
--- a/packages/server/src/api-search-semantic-factory.test.ts
+++ b/packages/server/src/api-search-semantic-factory.test.ts
@@ -16,7 +16,10 @@ import {
type Embedder,
type LoadOpenAiEmbedderInput,
} from './embeddings/index.ts';
-import { MAX_DIMS_DRIFT_RESETS } from './embeddings/semantic-search-service.ts';
+import {
+ MAX_DIMS_DRIFT_RESETS,
+ SemanticSearchService,
+} from './embeddings/semantic-search-service.ts';
import { getLogger } from './logger.ts';
import { createServer, type ServerInstance } from './server-factory.ts';
import { initShadowRepo } from './shadow-repo.ts';
@@ -125,6 +128,27 @@ function searchViaServer(
return callViaServer(srv, 'POST', '/api/search', bodyObj) as Promise<SearchBody>;
}
+async function searchAfterCorpusCompletion(search: () => Promise<SearchBody>): Promise<SearchBody> {
+ const embedCorpus = vi.spyOn(SemanticSearchService.prototype, 'embedCorpus');
+ try {
+ await search();
+ expect(embedCorpus, 'the search started no corpus pass to await').toHaveBeenCalled();
+ const awaitObservedPasses = () =>
+ Promise.all(
+ embedCorpus.mock.results.map((result) => {
+ if (result.type !== 'return') throw result.value;
+ return result.value;
+ }),
+ );
+ await awaitObservedPasses();
+ const settled = await search();
+ await awaitObservedPasses();
+ return settled;
+ } finally {
+ embedCorpus.mockRestore();
+ }
+}
+
beforeAll(async () => {
tmpDir = mkdtempSync(join(tmpdir(), 'ok-sem-factory-'));
for (const [rel, content] of Object.entries({
@@ -176,24 +200,23 @@ afterAll(async () => {
describe('createServer boot — flag-ON semantic search (factory glue)', () => {
test('config-enabled boot fuses a vector signal and reports coverage; excluded content stays out', async () => {
- const deadline = Date.now() + 20_000;
- let result: SearchBody | undefined;
- do {
- result = await searchViaServer(server, {
+ const result = await searchAfterCorpusCompletion(async () => {
+ const response = await searchViaServer(server, {
query: 'auth retries',
intent: 'full_text',
semantic: true,
});
- for (const r of result.results ?? []) {
+ for (const r of response.results ?? []) {
expect(r.path.startsWith('archive/')).toBe(false);
}
- if ((result.semantic?.coverage.embedded ?? 0) >= SERVED_PAGE_COUNT) break;
- await new Promise((r) => setTimeout(r, 25));
- } while (Date.now() < deadline);
+ return response;
+ });
expect(result?.semantic?.capable).toBe(true);
expect(result?.semantic?.coverage.total).toBe(SERVED_PAGE_COUNT);
- expect(result?.semantic?.coverage.embedded).toBe(SERVED_PAGE_COUNT);
+ expect(result?.semantic?.coverage.embedded, JSON.stringify(result?.semantic)).toBe(
+ SERVED_PAGE_COUNT,
+ );
expect(result?.semantic?.applied).toBe(true);
expect(result?.semantic?.outcome).toBe('applied');
@@ -427,10 +450,8 @@ test('the real search route maps terminal vector-size drift to restart_required'
semantic: true,
});
const waitForCoverage = async () => {
- await vi.waitFor(async () => {
- const result = await search();
- expect(result.semantic?.coverage.embedded).toBe(1);
- });
+ const result = await searchAfterCorpusCompletion(search);
+ expect(result.semantic?.coverage.embedded, JSON.stringify(result.semantic)).toBe(1);
};
try {
@@ -746,20 +767,16 @@ describe('createServer boot — similarityFloor config reaches core ranking', ()
});
await srv.ready;
try {
- const deadline = Date.now() + 20_000;
- let result: SearchBody | undefined;
- do {
- result = await searchViaServer(srv, {
+ const result = await searchAfterCorpusCompletion(() =>
+ searchViaServer(srv, {
query: 'auth retries',
intent: 'full_text',
semantic: true,
- });
- if ((result.semantic?.coverage.embedded ?? 0) >= 1) break;
- await new Promise((r) => setTimeout(r, 25));
- } while (Date.now() < deadline);
+ }),
+ );
expect(result?.semantic?.capable).toBe(true);
- expect(result?.semantic?.coverage.embedded).toBe(1);
+ expect(result?.semantic?.coverage.embedded, JSON.stringify(result?.semantic)).toBe(1);
expect(result?.results?.find((r) => r.path === 'rotation')).toBeUndefined();
for (const r of result?.results ?? []) expect('vector' in r.signals).toBe(false);
expect(result?.semantic?.applied).toBe(false);