Share typed extraction control evidence
This commit is contained in:
46
internal/artifacts/extraction_metadata_test.go
Normal file
46
internal/artifacts/extraction_metadata_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExtractionMetadataRoundTrip(t *testing.T) {
|
||||
source := ExtractionMetadata{RunID: "run", ConfigurationFingerprint: "fingerprint", Input: ExtractionInputIdentity{Checksum: "checksum", SourceID: "source", ProducerStage: "trim", OutputKind: "transcript", ProducerRunID: "input-run", Provenance: "manifest"}, References: []ExtractionReferenceIdentity{{Selector: "people", SourceID: "party", Path: "inputs/party.yml", Checksum: "sum", SizeBytes: 12}}, ReferenceCount: 1, Completion: ExtractionCompletion{Pipeline: "pipeline", ArtifactCount: 2, OutputDirectory: "/output", FallbackCount: 2}}
|
||||
direct := EncodeExtractionMetadata(source)
|
||||
before := DecodeExtractionMetadata(direct)
|
||||
body, err := json.Marshal(direct)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(body, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := DecodeExtractionMetadata(decoded); !reflect.DeepEqual(got, before) {
|
||||
t.Fatalf("decoded = %+v, want %+v", got, before)
|
||||
}
|
||||
decoder := json.NewDecoder(strings.NewReader(string(body)))
|
||||
decoder.UseNumber()
|
||||
var numberMap map[string]any
|
||||
if err := decoder.Decode(&numberMap); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := DecodeExtractionMetadata(numberMap); !reflect.DeepEqual(got, before) {
|
||||
t.Fatalf("number decoded = %+v, want %+v", got, before)
|
||||
}
|
||||
if !extractionInputMatchesMetadata(decoded, source.Input) {
|
||||
t.Fatal("persisted input did not match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractionFallbackMetadataRejectsInvalidNumbers(t *testing.T) {
|
||||
for _, value := range []any{float64(-1), float64(1.5), json.Number("-1"), "2", nil} {
|
||||
got := DecodeExtractionMetadata(map[string]any{"completion": map[string]any{"fallback_count": value}}).Completion.FallbackCount
|
||||
if got != 0 {
|
||||
t.Fatalf("fallback count for %v = %d", value, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user