Payload-sha-only UUIDs collided under artifact_payload_staging_pkey when two task runs finalized identical deliverable bytes. Key already includes source_event_id; hash it for stable unique art-/stg- ids.
30 lines
1.1 KiB
Go
30 lines
1.1 KiB
Go
package artifactvault
|
|
|
|
import "testing"
|
|
|
|
func TestArtifactIDsFromKeyDifferForSamePayloadDifferentEvents(t *testing.T) {
|
|
payload := []byte("# same body\n")
|
|
sha := SHA256Hex(payload)
|
|
reqA := PublishRequest{
|
|
ArtifactType: "agent_commit", Environment: "dev", ProjectExternalKey: "p1",
|
|
LogicalResourceID: "doc1", SourceEventKind: "taskrun", SourceEventID: "taskrun:runA:completed",
|
|
}
|
|
reqB := PublishRequest{
|
|
ArtifactType: "agent_commit", Environment: "dev", ProjectExternalKey: "p1",
|
|
LogicalResourceID: "doc1", SourceEventKind: "taskrun", SourceEventID: "taskrun:runB:completed",
|
|
}
|
|
keyA := IdempotencyKey(reqA, sha)
|
|
keyB := IdempotencyKey(reqB, sha)
|
|
if keyA == keyB {
|
|
t.Fatal("idempotency keys must differ across source events")
|
|
}
|
|
artA, stgA := artifactIDsFromKey(keyA)
|
|
artB, stgB := artifactIDsFromKey(keyB)
|
|
if artA == artB || stgA == stgB {
|
|
t.Fatalf("same-payload different events must not share UUIDs: art=%q/%q stg=%q/%q", artA, artB, stgA, stgB)
|
|
}
|
|
if artA == "art-"+sha[:16] || stgA == "stg-art-"+sha[:16] {
|
|
t.Fatal("UUIDs must not be derived from payload sha alone")
|
|
}
|
|
}
|