(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestTruncateOutput(t *testing.T) { |
| 21 | t.Parallel() |
| 22 | |
| 23 | t.Run("EmptyOutput", func(t *testing.T) { |
| 24 | t.Parallel() |
| 25 | result := runForegroundWithOutput(t, "") |
| 26 | assert.Empty(t, result.Output) |
| 27 | }) |
| 28 | |
| 29 | t.Run("ShortOutput", func(t *testing.T) { |
| 30 | t.Parallel() |
| 31 | result := runForegroundWithOutput(t, "short") |
| 32 | assert.Equal(t, "short", result.Output) |
| 33 | }) |
| 34 | |
| 35 | t.Run("ExactlyAtLimit", func(t *testing.T) { |
| 36 | t.Parallel() |
| 37 | output := strings.Repeat("a", maxOutputToModel) |
| 38 | result := runForegroundWithOutput(t, output) |
| 39 | assert.Equal(t, maxOutputToModel, len(result.Output)) |
| 40 | assert.Equal(t, output, result.Output) |
| 41 | }) |
| 42 | |
| 43 | t.Run("OverLimit", func(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | output := strings.Repeat("b", maxOutputToModel+1024) |
| 46 | result := runForegroundWithOutput(t, output) |
| 47 | assert.Equal(t, maxOutputToModel, len(result.Output)) |
| 48 | }) |
| 49 | |
| 50 | t.Run("MultiByteCutMidCharacter", func(t *testing.T) { |
| 51 | t.Parallel() |
| 52 | // Build output that places a 3-byte UTF-8 character |
| 53 | // (U+2603, snowman ☃) right at the truncation boundary |
| 54 | // so the cut falls mid-character. |
| 55 | padding := strings.Repeat("x", maxOutputToModel-1) |
| 56 | output := padding + "☃" // ☃ is 3 bytes, only 1 byte fits |
| 57 | result := runForegroundWithOutput(t, output) |
| 58 | assert.LessOrEqual(t, len(result.Output), maxOutputToModel) |
| 59 | assert.True(t, utf8.ValidString(result.Output), |
| 60 | "truncated output must be valid UTF-8") |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | // runForegroundWithOutput runs a foreground command through the |
| 65 | // Execute tool with a mock that returns the given output, and |
nothing calls this directly
no test coverage detected