import { afterEach, test } from "node:test"; import assert from "node:assert/strict"; import type { Model } from "@earendil-works/pi-ai"; import { buildStatuslineFooterLine } from "../statusline.ts"; const previousCycles = process.env.CRTR_CYCLES; afterEach(() => { if (previousCycles === undefined) delete process.env.CRTR_CYCLES; else process.env.CRTR_CYCLES = previousCycles; }); function model(id: string): Model<"anthropic-messages"> { return { id, name: id, api: "anthropic-messages", provider: "anthropic", baseUrl: "https://api.anthropic.com", reasoning: false, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 0, maxTokens: 0, }; } function makeCtx(overrides: Partial[1]> = {}) { return { cwd: "/Users/silasrhyneer/Code/cli/crouter", model: model("claude-opus-4-8"), getContextUsage() { return { tokens: 42 }; }, ...overrides, } as Parameters[1]; } function makeFooterData(subscription = "provider-rotation: personal") { return { getGitBranch() { return "main"; }, getExtensionStatuses() { return new Map(subscription ? [["provider-rotation", subscription]] : []); }, }; } test("renders the footer clusters in order and keeps cwd/git right-aligned", () => { process.env.CRTR_CYCLES = "3"; const line = buildStatuslineFooterLine(120, makeCtx(), makeFooterData(), { staged: 0, modified: 0, untracked: 0, conflicts: 0, ahead: 0, behind: 0, stashed: 0 }); assert.match(line, /^claude-opus-4-8 · provider-rotation: personal · 42 tokens · ↻3\s+crouter \(main ✓\)$/); }); test("omits empty subscription and missing cycle, and preserves the spacer on narrow widths", () => { delete process.env.CRTR_CYCLES; const wide = buildStatuslineFooterLine(120, makeCtx(), makeFooterData(""), { staged: 0, modified: 0, untracked: 0, conflicts: 0, ahead: 0, behind: 0, stashed: 0 }); assert.match(wide, /^claude-opus-4-8 · 42 tokens\s+crouter \(main ✓\)$/); assert.doesNotMatch(wide, /provider-rotation/); assert.doesNotMatch(wide, /↻/); const narrow = buildStatuslineFooterLine(22, makeCtx({ model: model("a-very-long-model-name") }), makeFooterData(""), { staged: 0, modified: 0, untracked: 0, conflicts: 0, ahead: 0, behind: 0, stashed: 0 }); assert.match(narrow, /\s+crouter \(main ✓\)$/); assert.doesNotMatch(narrow, /[A-Za-z]crouter \(main ✓\)$/); });