返回 DeepSeek-Reasonix
earlyReadableHistory.ts
根目录 / desktop / frontend / src / __tests__ / helpers / earlyReadableHistory.ts
1 import { act } from "react";
2 import assert from "node:assert/strict";
3 import { getTranscriptStore } from "../../lib/transcriptStore";
4 import type { useController } from "../../lib/useController";
5
6 export const flushPromises = (): Promise<void> => new Promise(resolve => setTimeout(resolve, 0));
7
8 export async function verifyEarlyReadableHistory(
9 controller: () => ReturnType<typeof useController> | undefined,
10 release: () => void, flush: () => Promise<void>,
11 waitFor: (label: string, predicate: () => boolean) => Promise<void>,
12 ) {
13 await act(async () => { release(); await flush(); });
14 await waitFor("tab-b early readable history", () =>
15 controller()?.state.items.some(item => item.kind === "user" && item.text === "early B") ?? false);
16 assert.equal(controller()?.state.hydrating, false, "early history is readable before runtime activation");
17 assert.equal(controller()?.state.backendActivationPending, true, "readable history retains the runtime write fence");
18 }
19
20 export async function verifyDetachedPinRelease(
21 controller: () => ReturnType<typeof useController> | undefined, flush: () => Promise<void>,
22 ) {
23 const store = getTranscriptStore();
24 store.setPinned("tab-h", true);
25 await act(async () => { controller()?.commitSingleSurfaceNavigation("tab-g"); await flush(); });
26 assert.equal(store.tabIsPinned("tab-h"), false, "a detached runtime cannot pin its renderer history forever");
27 }
28
28 lines TYPESCRIPT