From a91bc1608b50e7ade059511303e9b1aa934613f6 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Thu, 5 Nov 2026 14:31:14 +0000 Subject: [PATCH] Test artifact hashes as opaque values --- docs/roadmap/implementation.md | 4 ++++ internal/artifact/reader_benchmark_test.go | 11 ++++++----- internal/artifact/reader_test.go | 11 ++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 364a0db..94821d0 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -757,6 +757,10 @@ second catalog matrix. Focused bundle tests pass on Go 1.27.3. meaningful without choosing an opaque value's algorithm. Keep benchmark setup outside timed work and do not add a new encoding guarantee. +Completion: size-hint tests and benchmark correctness setup compare file hashes +to the same content read inline, without selecting a hash algorithm. Artifact +tests and one-iteration checks of both benchmark paths pass on Go 1.27.3. + ## Stage 30: Remove Unconsumed State And Orphan Helpers **Catalog:** 30, remaining half of 32, 33. diff --git a/internal/artifact/reader_benchmark_test.go b/internal/artifact/reader_benchmark_test.go index 7fa6dd0..64e0033 100644 --- a/internal/artifact/reader_benchmark_test.go +++ b/internal/artifact/reader_benchmark_test.go @@ -3,8 +3,6 @@ package artifact import ( "bytes" "context" - "crypto/sha256" - "fmt" "mime" "os" "path/filepath" @@ -153,9 +151,12 @@ func checkArtifactFileRead(b *testing.B, reader Reader, ref domain.ArtifactRef, if !bytes.Equal(artifact.Body, want) || artifact.Size != int64(len(want)) { b.Fatalf("artifact size=%d body length=%d, want %d", artifact.Size, len(artifact.Body), len(want)) } - wantHash := fmt.Sprintf("%x", sha256.Sum256(want)) - if artifact.Hash != wantHash { - b.Fatalf("artifact hash=%q, want %q", artifact.Hash, wantHash) + inline, err := NewCompositeReader().Read(context.Background(), domain.ArtifactRef{Type: domain.ArtifactRefInline, Body: string(want)}) + if err != nil { + b.Fatal(err) + } + if inline.Hash == "" || artifact.Hash != inline.Hash { + b.Fatalf("file and inline hashes differ: %q/%q", artifact.Hash, inline.Hash) } } diff --git a/internal/artifact/reader_test.go b/internal/artifact/reader_test.go index 04a3b13..9fbde73 100644 --- a/internal/artifact/reader_test.go +++ b/internal/artifact/reader_test.go @@ -3,9 +3,7 @@ package artifact import ( "bytes" "context" - "crypto/sha256" "errors" - "fmt" "os" "path/filepath" "strings" @@ -284,9 +282,12 @@ func TestFileReaderUsesOpenedSizeOnlyAsACapacityHint(t *testing.T) { if artifact.Name != filepath.Base(filePath) || artifact.URI != filePath || artifact.ContentType == "" { t.Fatalf("unexpected artifact metadata: name=%q URI=%q content type=%q", artifact.Name, artifact.URI, artifact.ContentType) } - wantHash := fmt.Sprintf("%x", sha256.Sum256(tc.body)) - if artifact.Hash != wantHash { - t.Fatalf("artifact hash=%q, want %q", artifact.Hash, wantHash) + inline, err := NewCompositeReader().Read(context.Background(), domain.ArtifactRef{Type: domain.ArtifactRefInline, Body: string(tc.body)}) + if err != nil { + t.Fatal(err) + } + if inline.Hash == "" || artifact.Hash != inline.Hash { + t.Fatalf("file and inline hashes differ: %q/%q", artifact.Hash, inline.Hash) } }) }