| 1 | import assert from "node:assert/strict"; |
| 2 | import React from "react"; |
| 3 | import { renderToStaticMarkup } from "react-dom/server"; |
| 4 | import { CompactionCard } from "../components/TranscriptCards"; |
| 5 | import { LocaleProvider } from "../lib/i18n"; |
| 6 | import type { Item } from "../lib/useController"; |
| 7 | |
| 8 | type CompactionItem = Extract<Item, { kind: "compaction" }>; |
| 9 | |
| 10 | const item = (status: string, pending: boolean, extra: Partial<CompactionItem> = {}): CompactionItem => ({ |
| 11 | kind: "compaction", id: "maintenance:card", pending, trigger: "manual", messages: 8, |
| 12 | summary: "durable summary", archive: "", operationId: "card", status, ...extra, |
| 13 | }); |
| 14 | const render = (value: CompactionItem) => renderToStaticMarkup( |
| 15 | <LocaleProvider><CompactionCard item={value} /></LocaleProvider>, |
| 16 | ); |
| 17 | |
| 18 | const running = render(item("running", true)); |
| 19 | assert.match(running, /class="compaction compaction--pending"/); |
| 20 | assert.match(running, /Compacting conversation/); |
| 21 | assert.match(running, /Generating summary/); |
| 22 | assert.match(running, /compaction__spinner/); |
| 23 | assert.match(running, /role="status"/); |
| 24 | assert.doesNotMatch(running, /<button/); |
| 25 | |
| 26 | const cancelling = render(item("cancelling", true)); |
| 27 | assert.match(cancelling, /Stopping compaction/); |
| 28 | assert.doesNotMatch(cancelling, /Generating a summary/); |
| 29 | |
| 30 | const saving = render(item("finalizing", true)); |
| 31 | assert.match(saving, /Saving compaction result/); |
| 32 | |
| 33 | const confirming = render(item("confirming", true)); |
| 34 | assert.match(confirming, /Checking compaction status/); |
| 35 | |
| 36 | const completed = render(item("completed", false, { applied: true, inputTokens: 1200, resultTokens: 400 })); |
| 37 | assert.match(completed, /<button/); |
| 38 | assert.match(completed, /1200.*400/); |
| 39 | assert.match(completed, /aria-expanded="false"/); |
| 40 | |
| 41 | const failed = render(item("failed", false, { errorCode: "save_failed", detail: "disk full", applied: true })); |
| 42 | assert.match(failed, /Compaction failed/); |
| 43 | assert.match(failed, /<button/); |
| 44 | |
| 45 | const noop = render(item("noop", false)); |
| 46 | assert.match(noop, /No history to compact/); |
| 47 | assert.doesNotMatch(noop, /compaction__spinner/); |
| 48 | assert.doesNotMatch(noop, /<button/); |
| 49 | |
| 50 | const unknown = render(item("future_state", false)); |
| 51 | assert.doesNotMatch(unknown, /Context compacted/); |
| 52 | assert.match(unknown, /could not be fully restored/); |
| 53 | |
| 54 | console.log("maintenance card: running, stopping, saving, terminal and no-history styles passed"); |
| 55 |