| 1 | import { createRoot } from "react-dom/client"; |
| 2 | import { ArchivedSessionsList } from "../components/ArchivedSessionsList"; |
| 3 | import { LocaleProvider } from "../lib/i18n"; |
| 4 | import type { SessionLifecycleRequest } from "../generated/desktopContract.generated"; |
| 5 | import { installDesktopHostStub } from "../__tests__/desktopHostStub"; |
| 6 | |
| 7 | let generation = 7, targetGeneration = 7; |
| 8 | let unknown = false, preview = true; |
| 9 | let finishPreview: (() => void) | undefined; |
| 10 | const requests: SessionLifecycleRequest[] = []; |
| 11 | const ref = { hostId: "local", sessionId: "fixture-session" }; |
| 12 | const host = installDesktopHostStub({ |
| 13 | ListTrashEntries: async () => ({ generation, items: [{ id: ref.sessionId, ref, title: "Fixture conversation", workspaceTitle: "Global", archivedAt: 0, canPurge: true, canRestore: preview, canPreview: preview, health: "ready" }] }), |
| 14 | ReadSessionHistory: async () => new Promise(resolve => { finishPreview = () => resolve({ messages: [{ role: "user", content: "late fixture history" }] }); }), |
| 15 | ApplySessionLifecycle: async (request: SessionLifecycleRequest) => { |
| 16 | requests.push(structuredClone(request)); |
| 17 | if (unknown) { unknown = false; throw new Error("network outcome unknown"); } |
| 18 | const committed = request.expectedGeneration >= targetGeneration; |
| 19 | return { operationId: request.operationId, generation, committed, items: request.targets.map(target => ({ target, committed, retryable: false, errorCode: committed ? "" : "state_conflict" })) }; |
| 20 | }, |
| 21 | }); |
| 22 | Object.assign(window, { trashFixture: { |
| 23 | requests, |
| 24 | changeTarget() { targetGeneration = ++generation; host.emit("project-tree:changed"); }, |
| 25 | changeOther() { generation++; host.emit("project-tree:changed"); }, |
| 26 | loseResult() { unknown = true; }, |
| 27 | invalidatePreview() { preview = false; host.emit("project-tree:changed"); }, |
| 28 | finishPreview() { finishPreview?.(); }, |
| 29 | } }); |
| 30 | createRoot(document.getElementById("root")!).render(<LocaleProvider><ArchivedSessionsList active onOpenSession={async () => {}} /></LocaleProvider>); |
| 31 |