@@ -200,6 +200,35 @@ func TestGroupByAppend(t *testing.T) {
200200 }
201201}
202202
203+ func TestGroupByAppendAliasingIsolation (t * testing.T ) {
204+ // Verify that the backing array fix prevents mutation of the original
205+ // input slice from leaking into the groupBy output.
206+ original := []string {"a.go" , "b.json" , "c.go" }
207+ copyForInput := make ([]string , len (original ))
208+ copy (copyForInput , original )
209+
210+ input := ActionResult {Lines : copyForInput , Metadata : nil }
211+ res , err := groupBy (input , map [string ]any {
212+ "pattern" : `\.(\w+)$` ,
213+ "format" : "{{.Key}}: {{.Count}}" ,
214+ "append" : true ,
215+ })
216+ if err != nil {
217+ t .Fatal (err )
218+ }
219+
220+ // Mutate the original backing array — should not affect result
221+ copyForInput [0 ] = "CORRUPTED"
222+ copyForInput [1 ] = "CORRUPTED"
223+
224+ // Original lines in result must still be intact
225+ for i , want := range original {
226+ if res .Lines [i ] != want {
227+ t .Errorf ("backing array aliasing at line %d: got %q, want %q" , i , res .Lines [i ], want )
228+ }
229+ }
230+ }
231+
203232func TestDedup (t * testing.T ) {
204233 input := lines ("error: foo" , "error: foo" , "error: foo" , "warn: bar" , "warn: bar" )
205234 res , err := dedup (input , map [string ]any {})
@@ -269,6 +298,33 @@ func TestAggregateAppend(t *testing.T) {
269298 }
270299}
271300
301+ func TestAggregateAppendAliasingIsolation (t * testing.T ) {
302+ original := []string {"PASS a" , "FAIL b" , "PASS c" }
303+ copyForInput := make ([]string , len (original ))
304+ copy (copyForInput , original )
305+
306+ input := ActionResult {Lines : copyForInput , Metadata : nil }
307+ res , err := aggregate (input , map [string ]any {
308+ "patterns" : map [string ]any {
309+ "pass" : `^PASS` ,
310+ "fail" : `^FAIL` ,
311+ },
312+ "append" : true ,
313+ })
314+ if err != nil {
315+ t .Fatal (err )
316+ }
317+
318+ copyForInput [0 ] = "CORRUPTED"
319+ copyForInput [1 ] = "CORRUPTED"
320+
321+ for i , want := range original {
322+ if res .Lines [i ] != want {
323+ t .Errorf ("backing array aliasing at line %d: got %q, want %q" , i , res .Lines [i ], want )
324+ }
325+ }
326+ }
327+
272328func TestFormatTemplate (t * testing.T ) {
273329 input := ActionResult {
274330 Lines : []string {"a" , "b" , "c" },
0 commit comments