Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions internal/session/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Compare(before, after []model.LlmComment, afterManifest *RunManifest) Compa
reviewed := ReviewedPaths(afterManifest)
renamed := renamedPaths(afterManifest)

pool := make(map[string][]model.LlmComment, len(after))
pool := make(map[findingIdentity][]model.LlmComment, len(after))
for _, c := range after {
k := findingKey(c, c.Path)
pool[k] = append(pool[k], c)
Expand Down Expand Up @@ -84,7 +84,7 @@ func Compare(before, after []model.LlmComment, afterManifest *RunManifest) Compa
// the identity of a published GitHub Code Scanning alert - changing how it
// normalizes would re-open every alert downstream - so the two stay apart even
// though they read the same fields.
func findingKey(c model.LlmComment, path string) string {
func findingKey(c model.LlmComment, path string) findingIdentity {
body := normalizeSnippet(c.ExistingCode)
if body == "" {
// ponytail: no snippet recorded, so the prose is all the identity there
Expand All @@ -93,7 +93,13 @@ func findingKey(c model.LlmComment, path string) string {
// to survive.
body = normalizeSnippet(c.Content)
}
return normalizePath(path) + "|" + strings.ToLower(strings.TrimSpace(c.Category)) + "|" + body
return findingIdentity{normalizePath(path), strings.ToLower(strings.TrimSpace(c.Category)), body}
}

type findingIdentity struct {
path string
category string
body string
}

// normalizeSnippet collapses every whitespace run to a single space so that
Expand Down
10 changes: 10 additions & 0 deletions internal/session/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func ids(comments []model.LlmComment) []string {
return out
}

func TestCompareKeepsIdentityFieldsSeparate(t *testing.T) {
before := cmt("a.go", 1, "bug", "x.go|bug|value", "before")
after := cmt("a.go|bug|x.go", 2, "bug", "value", "after")

got := Compare([]model.LlmComment{before}, []model.LlmComment{after}, nil)
if len(got.Persisting) != 0 || !reflect.DeepEqual(got.New, []model.LlmComment{after}) || !reflect.DeepEqual(got.Resolved, []model.LlmComment{before}) {
t.Fatalf("distinct findings sharing a delimiter-joined key were conflated: %+v", got)
}
}

func TestCompare(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading