package pendingattach import "testing" func TestDedupe_CollapsesByFileID(t *testing.T) { rows := []Attachment{ {ID: "1", FileID: "a", Ord: 0}, {ID: "2", FileID: "b", Ord: 1}, {ID: "3", FileID: "a", Ord: 2}, // dup of file a } out := Dedupe(rows) if len(out) != 2 { t.Fatalf("want 2 rows, got %d: %+v", len(out), out) } if out[0].ID != "1" || out[1].ID != "2" { t.Fatalf("first-wins order not preserved: %+v", out) } } func TestDedupe_EmptyFileIDNeverCollapsed(t *testing.T) { rows := []Attachment{ {ID: "1", FileID: ""}, {ID: "2", FileID: ""}, } if got := Dedupe(rows); len(got) != 2 { t.Fatalf("empty FileID rows must not collapse, got %d", len(got)) } } func TestDedupe_ShortInputPassthrough(t *testing.T) { rows := []Attachment{{ID: "1", FileID: "a"}} if got := Dedupe(rows); len(got) != 1 { t.Fatalf("single row should pass through, got %d", len(got)) } }