import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { stripVTControlCharacters } from "node:util"; import { runInNewContext } from "node:vm"; import type { TUI } from "@earendil-works/pi-tui"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { exportFromFile } from "../src/core/export-html/index.ts"; import { CURRENT_SESSION_VERSION, type SessionHeader, SessionManager, type SessionMessageEntry, } from "../src/core/session-manager.ts"; import { createReadToolDefinition } from "../src/core/tools/read.ts"; import { formatReadLineRange } from "../src/core/tools/render-utils.ts"; import { ToolExecutionComponent } from "../src/modes/interactive/components/tool-execution.ts"; import { TreeSelectorComponent } from "../src/modes/interactive/components/tree-selector.ts"; import { initTheme } from "../src/modes/interactive/theme/theme.ts"; interface HtmlViewer { formatReadLineRange: typeof formatReadLineRange; getTreeNodeDisplayHtml(entry: SessionMessageEntry): string; renderEntry(entry: SessionMessageEntry): string; } // Runs the exported viewer's real data loading and renderers, stopping before DOM initialization. function loadHtmlViewer(html: string): HtmlViewer { const sessionData = html.match(/