| 1 | // Run: tsx src/__tests__/turn-action-copy.test.ts |
| 2 | |
| 3 | import { appendTurnActionCopyText } from "../lib/turnActionCopy"; |
| 4 | |
| 5 | let passed = 0; |
| 6 | let failed = 0; |
| 7 | |
| 8 | function eq(actual: unknown, expected: unknown, label: string) { |
| 9 | if (actual === expected) { |
| 10 | process.stdout.write(` PASS ${label}\n`); |
| 11 | passed += 1; |
| 12 | } else { |
| 13 | process.stdout.write(` FAIL ${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}\n`); |
| 14 | failed += 1; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | console.log("\nturn action copy"); |
| 19 | |
| 20 | eq( |
| 21 | appendTurnActionCopyText("", "final answer"), |
| 22 | "final answer", |
| 23 | "keeps single assistant output unchanged", |
| 24 | ); |
| 25 | |
| 26 | eq( |
| 27 | appendTurnActionCopyText("first assistant block", "second assistant block"), |
| 28 | "first assistant block\n\nsecond assistant block", |
| 29 | "accumulates multiple assistant outputs in one turn", |
| 30 | ); |
| 31 | |
| 32 | eq( |
| 33 | appendTurnActionCopyText("first assistant block\n", "second assistant block"), |
| 34 | "first assistant block\nsecond assistant block", |
| 35 | "does not add an extra blank line when the previous block already ends with newline", |
| 36 | ); |
| 37 | |
| 38 | eq( |
| 39 | appendTurnActionCopyText("first assistant block", "\nsecond assistant block"), |
| 40 | "first assistant block\nsecond assistant block", |
| 41 | "does not add an extra blank line when the next block starts with newline", |
| 42 | ); |
| 43 | |
| 44 | eq( |
| 45 | appendTurnActionCopyText("final answer", " \n\t"), |
| 46 | "final answer", |
| 47 | "ignores whitespace-only assistant fragments", |
| 48 | ); |
| 49 | |
| 50 | console.log(`\n${passed} passed, ${failed} failed`); |
| 51 | if (failed > 0) process.exit(1); |
| 52 |