Skip to content

Commit 803ba8e

Browse files
Your Nameclaude
andcommitted
Fix setkeys identity hash collision for objects missing all keys
Objects lacking all configured setkeys fields were colliding to the same identity hash because the fallback check was dead code. This caused silent deduplication during set diffs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d7c015 commit 803ba8e

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

v2/object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (o jsonObject) ident(opts *options) [8]byte {
9494
hashes = append(hashes, v.hashCode(opts))
9595
}
9696
}
97-
if len(hashes) == 0 {
97+
if len(hashes) == 1 {
9898
return o.hashCode(opts)
9999
}
100100
return hashes.combine()

v2/set_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,22 @@ func TestSetDiff(t *testing.T) {
324324
a: `{"apiVersion":"v1","kind":"Pod","metadata":{"name":"nginx"},"spec":{"containers":[{"name":"nginx","image":"nginx:1.14.2","ports":[{"containerPort":80}]}]}}`,
325325
b: `{"apiVersion":"v1","kind":"Pod","metadata":{"name":"nginx"},"spec":{"containers":[{"name":"nginx","image":"nginx:1.14.2","ports":[{"containerPort":8080}]}]}}`,
326326
want: ss(
327-
`@ ["spec","containers",{"name":"nginx"},"ports",{"name":null},"containerPort"]`,
328-
`- 80`,
329-
`+ 8080`,
327+
`@ ["spec","containers",{"name":"nginx"},"ports",{}]`,
328+
`- {"containerPort":80}`,
329+
`+ {"containerPort":8080}`,
330+
),
331+
}, {
332+
name: "objects missing all setkeys fields are distinct",
333+
options: m(
334+
setOption{},
335+
SetKeys("id"),
336+
),
337+
a: `[]`,
338+
b: `[{},{"":"0"}]`,
339+
want: ss(
340+
`@ [{}]`,
341+
`+ {}`,
342+
`+ {"":"0"}`,
330343
),
331344
}, {
332345
name: "complex set key diff",

0 commit comments

Comments
 (0)