1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 formatClaudeResumeCompactionQuestion,
5 isClaudeResumeCompactionQuestion,
6} from "./claudeCompaction.ts";
7
8describe("claude resume compaction copy", () => {
9 // The matcher must recognize every question the formatter can produce.
10 // This is the drift guard: rewording one side fails here.
11 it.each([
12 { ageMinutes: 145, estimatedTokens: 275_123 },
13 { ageMinutes: 70, estimatedTokens: 100_000 },
14 { ageMinutes: 59, estimatedTokens: 1_234_567 },
15 { ageMinutes: 0, estimatedTokens: 0 },
16 ])("matches its own formatted question (%o)", (input) => {
17 const question = formatClaudeResumeCompactionQuestion(input);
18 expect(isClaudeResumeCompactionQuestion(question)).toBe(true);
19 });
20
21 it("formats ages above and below one hour", () => {
22 expect(
23 formatClaudeResumeCompactionQuestion({ ageMinutes: 145, estimatedTokens: 275_123 }),
24 ).toBe("This session is 2h 25m old and uses 275,123 tokens. Compact it before continuing?");
25 expect(formatClaudeResumeCompactionQuestion({ ageMinutes: 45, estimatedTokens: 1_000 })).toBe(
26 "This session is 45m old and uses 1,000 tokens. Compact it before continuing?",
27 );
28 });
29
30 it("does not match unrelated questions", () => {
31 expect(
32 isClaudeResumeCompactionQuestion("The build cache is large. Compact it before continuing?"),
33 ).toBe(false);
34 });
35});