diff --git a/test/app/app.test.tsx b/test/app/app.test.tsx index 400f3bf..cde6df4 100644 --- a/test/app/app.test.tsx +++ b/test/app/app.test.tsx @@ -1,8 +1,9 @@ import { afterEach, describe, expect, test } from "bun:test"; +import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts"; import { omittedCommand, withApproval, withCompletedTurn, withOmittedOutput, withQuestion, withWorking } from "./fixtures.ts"; import { loadLayout } from "../../src/layout.ts"; -import { fakeSession, renderApp, v2ThreadId } from "./harness.tsx"; +import { fakeSession, renderApp, v2Projection, v2ThreadId } from "./harness.tsx"; let app: Awaited> | null = null; const open = async (...args: Parameters) => (app = await renderApp(...args)); @@ -331,6 +332,52 @@ describe("command output", () => { }); }); +describe("details panel", () => { + const steps = Array.from({ length: 8 }, (_, index) => ({ id: `s${index}`, text: `Step ${index}`, status: index < 2 ? "completed" : index === 2 ? "running" : "pending" })); + const projection = { + ...v2Projection, + providerTurns: [{ tokenUsage: { usedTokens: 62_000, maxTokens: 100_000, updatedAt: "2026-06-20T00:00:00.000Z" } }], + turnItems: [{ id: "todo", type: "todo_list", planId: "p", steps }], + } as unknown as OrchestrationV2ThreadProjection; + const vcs = { + status: "live", + local: { + isRepo: true, + hasPrimaryRemote: true, + isDefaultRef: true, + refName: "main", + hasWorkingTreeChanges: true, + workingTree: { files: [{ path: "README.md", insertions: 29, deletions: 167 }, { path: "docs/", insertions: 0, deletions: 0 }], insertions: 29, deletions: 167 }, + }, + remote: { hasUpstream: true, aheadCount: 0, behindCount: 0, pr: null }, + }; + + test("shows the context left, tasks, changes and branch", async () => { + const app = await open({ width: 200, session: fakeSession({ projection, vcs }) }); + const frame = app.frame(); + expect(frame).toContain("Context ████░░░░░░ 38% left"); + expect(frame).toMatch(/Tasks +2\/8/); + expect(frame).toContain("◐ Step 2"); + expect(frame).not.toContain("Step 7"); + expect(frame).toMatch(/M README\.md +\+29 −167/); + expect(frame).toMatch(/\? docs\/ +new/); + expect(frame).toContain("▸ View diff"); + // Up to date: no ahead/behind counts, no hint. + expect(frame).toMatch(/┃ main +\n/); + expect(frame).not.toContain("↑0"); + const more = app.find("› 3 more"); + await app.click(more.x, more.y); + expect(app.frame()).toContain("Step 7"); + expect(app.frame()).toContain("‹ fewer"); + }); + + test("leaves out the context line without usage reports", async () => { + const app = await open({ width: 200 }); + expect(app.frame()).not.toContain("Context"); + expect(app.frame()).not.toContain("Tasks"); + }); +}); + describe("mouse", () => { test("the header button opens the palette", async () => { const app = await open(); diff --git a/test/app/harness.tsx b/test/app/harness.tsx index 7fc935d..d15a9c6 100644 --- a/test/app/harness.tsx +++ b/test/app/harness.tsx @@ -38,6 +38,8 @@ export function fakeSession( readonly snapshot?: OrchestrationV2ShellSnapshot; readonly projection?: OrchestrationV2ThreadProjection; readonly status?: ConnectionStatus; + /** Git status for every folder; loading by default. */ + readonly vcs?: unknown; readonly results?: Record; readonly failures?: Record; } = {}, @@ -57,7 +59,7 @@ export function fakeSession( watchServers: live({ status: "live", items: [] }), watchAutomations: live({ status: "live", items: [] }), watchTerminals: live({ status: "live", items: [] }), - watchVcs: (_cwd: string, listener: (value: unknown) => void) => live({ status: "loading", local: null, remote: null })(listener), + watchVcs: (_cwd: string, listener: (value: unknown) => void) => live(state.vcs ?? { status: "loading", local: null, remote: null })(listener), }; const session = new Proxy(known, { get(target, name) {