|
8 | 8 | ThreadId, |
9 | 9 | } from "@t3tools/contracts"; |
10 | 10 | import type { LegendListRef } from "@legendapp/list/react"; |
| 11 | +import * as DateTime from "effect/DateTime"; |
11 | 12 | import { act, createRef, Profiler, useState, type ComponentProps, type ReactElement } from "react"; |
12 | 13 | import { createRoot, type Root } from "react-dom/client"; |
13 | 14 | import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; |
@@ -319,6 +320,77 @@ describe("MessagesTimeline work rows", () => { |
319 | 320 | expect(text()).toContain("Context compacted"); |
320 | 321 | }); |
321 | 322 |
|
| 323 | + it("ticks a running compaction and warns once it passes two minutes", async () => { |
| 324 | + const compaction = ( |
| 325 | + id: string, |
| 326 | + status: string, |
| 327 | + label: string, |
| 328 | + fields: Record<string, unknown> = {}, |
| 329 | + ) => |
| 330 | + work(id, { |
| 331 | + runId: "run-1", |
| 332 | + label, |
| 333 | + tone: "info", |
| 334 | + itemType: "compaction", |
| 335 | + sourceActivityKind: "context-compaction", |
| 336 | + toolLifecycleStatus: status === "running" ? "inProgress" : status, |
| 337 | + structuredPayload: { |
| 338 | + id, |
| 339 | + type: "compaction", |
| 340 | + status, |
| 341 | + startedAt: DateTime.makeUnsafe(Date.now() - 118_000), |
| 342 | + ...fields, |
| 343 | + }, |
| 344 | + }); |
| 345 | + await renderTimeline( |
| 346 | + [ |
| 347 | + compaction("compaction-done", "completed", "Context compacted", { |
| 348 | + beforeTokenCount: 180_000, |
| 349 | + afterTokenCount: 40_000, |
| 350 | + }), |
| 351 | + compaction("compaction-failed", "failed", "Context compaction failed", { |
| 352 | + beforeTokenCount: 180_000, |
| 353 | + afterTokenCount: 180_000, |
| 354 | + }), |
| 355 | + compaction("compaction-stopped", "interrupted", "Context compaction stopped"), |
| 356 | + compaction("compaction-running", "running", "Compacting context"), |
| 357 | + ], |
| 358 | + { |
| 359 | + isWorking: true, |
| 360 | + activeTurnInProgress: true, |
| 361 | + latestRun: { |
| 362 | + runId: RunId.make("run-1"), |
| 363 | + status: "running", |
| 364 | + startedAt: CREATED_AT, |
| 365 | + completedAt: null, |
| 366 | + }, |
| 367 | + }, |
| 368 | + ); |
| 369 | + const separator = (label: string) => |
| 370 | + container.querySelector<HTMLElement>(`[role="separator"][aria-label="${label}"]`)!; |
| 371 | + await vi.waitFor(() => expect(separator("Compacting context")).not.toBeNull()); |
| 372 | + |
| 373 | + const running = separator("Compacting context"); |
| 374 | + const timers = running.querySelectorAll(".tabular-nums"); |
| 375 | + expect(timers).toHaveLength(1); |
| 376 | + expect(timers[0]!.closest("[aria-hidden]")).toBeNull(); |
| 377 | + expect(timers[0]!.textContent).toBe("1m"); |
| 378 | + expect(running.textContent).not.toContain("taking longer than expected"); |
| 379 | + await vi.waitFor(() => expect(running.textContent).toContain("taking longer than expected"), { |
| 380 | + timeout: 5_000, |
| 381 | + }); |
| 382 | + expect(running.textContent).toContain("2m"); |
| 383 | + |
| 384 | + for (const label of ["Context compaction failed", "Context compaction stopped"]) { |
| 385 | + const row = separator(label); |
| 386 | + expect(row.textContent).toBe(label); |
| 387 | + expect(row.querySelector(".tabular-nums")).toBeNull(); |
| 388 | + } |
| 389 | + const done = separator("Context compacted"); |
| 390 | + expect(done.textContent).toMatch(/^Context compacted 180K.*40K tokens$/); |
| 391 | + expect(done.querySelector(".tabular-nums")).toBeNull(); |
| 392 | + }); |
| 393 | + |
322 | 394 | it("formats changed file paths from the workspace root", async () => { |
323 | 395 | await renderTimeline( |
324 | 396 | [ |
|
0 commit comments