| 1 | import React from "react"; |
| 2 | import { createRoot } from "react-dom/client"; |
| 3 | import { HistoricalImportList } from "../src/components/HistoricalImportList"; |
| 4 | import { HistoricalSessionBanners } from "../src/components/SessionTakeoverDialog"; |
| 5 | import { LocaleProvider } from "../src/lib/i18n"; |
| 6 | import { installDesktopHostStub } from "../src/__tests__/desktopHostStub"; |
| 7 | import "../src/styles.css"; |
| 8 | |
| 9 | let status = { |
| 10 | items: [ |
| 11 | { id: "old-a", title: "Retained conversation A", format: "legacy", status: "available" }, |
| 12 | { id: "old-b", title: "Retained conversation B", format: "canonical", status: "available" }, |
| 13 | ], running: false, paused: false, remaining: 0, |
| 14 | }; |
| 15 | let imports = 0; |
| 16 | let branchImports = 0; |
| 17 | const historicalSource = { hostId: "local", sourceKey: "old-a", path: "/fixture/old-a.jsonl" }; |
| 18 | const controls: string[] = []; |
| 19 | installDesktopHostStub({ |
| 20 | CheckHistoricalSourceUpdate: async () => ({ sourceKey: "old-a", status: "available", version: "v2", source: historicalSource, retryable: false }), |
| 21 | PrepareHistoricalSourceVersion: async () => { |
| 22 | branchImports++; |
| 23 | return { operationId: "branch-v2", sourceKey: "old-a", status: "preparing", revision: 1, retryable: false }; |
| 24 | }, |
| 25 | GetSessionPreparation: async () => branchImports === 1 |
| 26 | ? { operationId: "branch-v2", sourceKey: "old-a", status: "failed", errorCode: "import_failed", revision: 2, retryable: true } |
| 27 | : { operationId: "branch-v2", sourceKey: "old-a", status: "ready", target: { hostId: "local", sessionId: "branch-v2" }, revision: 2, retryable: false }, |
| 28 | ListHistoricalSessions: async () => structuredClone(status), |
| 29 | GetHistoricalImportStatus: async () => structuredClone(status), |
| 30 | ImportHistoricalSession: async (id: string) => { |
| 31 | imports++; |
| 32 | if (id === "old-a" && imports === 1) throw new Error("historical session is in use; retry after closing the other instance"); |
| 33 | status = { ...status, items: status.items.map(item => item.id === id ? { ...item, status: "imported", session: { hostId: "local", sessionId: "imported-a" } } : item) }; |
| 34 | return { session: { hostId: "local", sessionId: "imported-a" }, workspaceId: "global", generation: 2 }; |
| 35 | }, |
| 36 | StartHistoricalImport: async () => { controls.push("start"); status = { ...status, running: true, remaining: 2 }; return structuredClone(status); }, |
| 37 | ControlHistoricalImport: async (action: string) => { |
| 38 | controls.push(action); |
| 39 | status = { ...status, paused: action === "pause", running: action !== "cancel", remaining: action === "cancel" ? 0 : status.remaining }; |
| 40 | return structuredClone(status); |
| 41 | }, |
| 42 | }); |
| 43 | createRoot(document.getElementById("root")!).render(<LocaleProvider> |
| 44 | <div data-testid="source-update-banner"><HistoricalSessionBanners |
| 45 | tab={{ id: "base", scope: "global", workspaceRoot: "", workspaceName: "Global", topicId: "base", topicTitle: "Base", label: "Base", ready: true, running: false, sessionId: "base" }} |
| 46 | navigate={async intent => { if (intent.kind === "canonical-session") document.body.dataset.openedBranch = intent.ref.sessionId; }} |
| 47 | /></div> |
| 48 | <HistoricalImportList active onOpenSession={async () => {}} /> |
| 49 | </LocaleProvider>); |
| 50 | window.addEventListener("beforeunload", () => { document.body.dataset.fixture = JSON.stringify({ controls, imports }); }); |
| 51 |