| 1 | // Run: tsx src/__tests__/reasoning-display.test.ts |
| 2 | |
| 3 | import { displayReasoningText } from "../lib/reasoningDisplay"; |
| 4 | |
| 5 | let passed = 0; |
| 6 | let failed = 0; |
| 7 | |
| 8 | function eq(a: unknown, b: unknown, label: string) { |
| 9 | if (a === b) { |
| 10 | process.stdout.write(` PASS ${label}\n`); |
| 11 | passed += 1; |
| 12 | } else { |
| 13 | process.stdout.write(` FAIL ${label}: expected ${JSON.stringify(b)}, got ${JSON.stringify(a)}\n`); |
| 14 | failed += 1; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | console.log("\nreasoning display"); |
| 19 | |
| 20 | eq( |
| 21 | displayReasoningText("a\nb\nc", { streaming: false, maxLines: 2 }), |
| 22 | "a\nb\nc", |
| 23 | "keeps completed reasoning intact", |
| 24 | ); |
| 25 | |
| 26 | eq( |
| 27 | displayReasoningText("a\nb\nc", { streaming: true, maxLines: 2 }), |
| 28 | "...\nb\nc", |
| 29 | "keeps only the tail lines while streaming", |
| 30 | ); |
| 31 | |
| 32 | eq( |
| 33 | displayReasoningText("abcdef", { streaming: true, maxChars: 3, maxLines: 10 }), |
| 34 | "...\ndef", |
| 35 | "keeps only the tail characters while streaming", |
| 36 | ); |
| 37 | |
| 38 | eq( |
| 39 | displayReasoningText("abcdef", { streaming: true, truncateStreaming: false, maxChars: 3 }), |
| 40 | "abcdef", |
| 41 | "can opt out of streaming truncation", |
| 42 | ); |
| 43 | |
| 44 | console.log(`\n${passed} passed, ${failed} failed`); |
| 45 | if (failed > 0) process.exit(1); |
| 46 |