| 61 | } |
| 62 | |
| 63 | func TestTruncateLargeCollapses(t *testing.T) { |
| 64 | in := strings.Repeat("abcd", 8000) // 32000 chars ~= 8000 tokens |
| 65 | out := Truncate(in) |
| 66 | if !strings.Contains(out, "truncated") { |
| 67 | t.Fatalf("expected truncation marker, got %q", out) |
| 68 | } |
| 69 | if Tokens(out) > ToolTruncHead+ToolTruncTail+200 { |
| 70 | t.Fatalf("truncated output too large: %d tokens", Tokens(out)) |
| 71 | } |
| 72 | if !strings.HasPrefix(out, in[:100]) { |
| 73 | t.Fatal("expected head preserved") |
| 74 | } |
| 75 | if !strings.HasSuffix(out, in[len(in)-100:]) { |
| 76 | t.Fatal("expected tail preserved") |
| 77 | } |
| 78 | // Tail bias: errors sit at the end of long output, so the kept tail must be |
| 79 | // larger than the kept head (the spill file covers the dropped middle). |
| 80 | if ToolTruncTail <= ToolTruncHead { |
| 81 | t.Fatalf("truncation must keep more tail than head, got head=%d tail=%d", ToolTruncHead, ToolTruncTail) |