|
|
|
|
@@ -56,7 +56,7 @@ func TestArtifactCatalogRejectsDuplicateExtractionRegistration(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestHydrateExtractionArtifactsAcceptsOnlyCompleteCurrentBundle(t *testing.T) {
|
|
|
|
|
func TestHydrateExtractionArtifactsAcceptsCurrentFlatEvidence(t *testing.T) {
|
|
|
|
|
paths, currentManifest, definitions := validExtractionCatalogFixture(t)
|
|
|
|
|
catalog := registeredExtractionCatalog(t, definitions)
|
|
|
|
|
catalog.HydrateExtractionArtifacts(paths, currentManifest, definitions)
|
|
|
|
|
@@ -76,9 +76,6 @@ func TestHydrateExtractionArtifactsAcceptsOnlyCompleteCurrentBundle(t *testing.T
|
|
|
|
|
if entry.Checksum != wantOutput.Checksum || entry.Size != info.Size() {
|
|
|
|
|
t.Fatalf("hydrated content identity = (%q, %d), want (%q, %d)", entry.Checksum, entry.Size, wantOutput.Checksum, info.Size())
|
|
|
|
|
}
|
|
|
|
|
if entry.Contract == nil || *entry.Contract != *wantOutput.Contract {
|
|
|
|
|
t.Fatalf("hydrated contract = %#v, want %#v", entry.Contract, wantOutput.Contract)
|
|
|
|
|
}
|
|
|
|
|
resolved, err := ResolveSessionArtifactWithCatalog(paths, currentManifest, entry.SourceID, catalog)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("ResolveSessionArtifactWithCatalog() error = %v", err)
|
|
|
|
|
@@ -88,7 +85,7 @@ func TestHydrateExtractionArtifactsAcceptsOnlyCompleteCurrentBundle(t *testing.T
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInspectExtractionEvidenceClassifiesBundleStates(t *testing.T) {
|
|
|
|
|
func TestInspectExtractionEvidenceClassifiesCurrentStates(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
state ExtractionEvidenceState
|
|
|
|
|
@@ -100,8 +97,8 @@ func TestInspectExtractionEvidenceClassifiesBundleStates(t *testing.T) {
|
|
|
|
|
{name: "absent", state: ExtractionEvidenceAbsent, mutate: func(_ *testing.T, _ *SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Status = manifest.StatusFailed
|
|
|
|
|
}},
|
|
|
|
|
{name: "obsolete version", state: ExtractionEvidenceObsolete, mutate: func(_ *testing.T, _ *SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].Contract.SchemaVersion = "99"
|
|
|
|
|
{name: "wrong size", state: ExtractionEvidenceObsolete, mutate: func(_ *testing.T, _ *SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].Size++
|
|
|
|
|
}},
|
|
|
|
|
{name: "changed direct transcript", wantInputUnavailable: true, recomputeInputIdentity: true, mutate: func(t *testing.T, _ *SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
writeExtractionFixtureFile(t, m.Stages["trim"].Outputs[0].LocalPath, `{"segments":[{"id":"changed"}]}`)
|
|
|
|
|
@@ -179,11 +176,11 @@ func TestHydrateExtractionArtifactsRejectsUntrustedManifestState(t *testing.T) {
|
|
|
|
|
{name: "inconsistent producer identity", mutate: func(_ *testing.T, _ SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].ProducerRunID = "another-run"
|
|
|
|
|
}},
|
|
|
|
|
{name: "incompatible contract", mutate: func(_ *testing.T, _ SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].Contract.SchemaVersion = "99"
|
|
|
|
|
{name: "incorrect size", mutate: func(_ *testing.T, _ SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].Size++
|
|
|
|
|
}},
|
|
|
|
|
{name: "incompatible provenance", mutate: func(_ *testing.T, _ SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].ExternalProvenance.RunID = "another-notarius-run"
|
|
|
|
|
m.Stages["extract"].Outputs[0].ExternalProvenance.ArtifactID = "other-lane"
|
|
|
|
|
}},
|
|
|
|
|
{name: "missing file", mutate: func(t *testing.T, _ SessionPaths, m *manifest.Manifest) {
|
|
|
|
|
if err := os.Remove(m.Stages["extract"].Outputs[0].LocalPath); err != nil {
|
|
|
|
|
@@ -244,8 +241,7 @@ func setExtractionStatus(status manifest.StageStatus) func(*testing.T, SessionPa
|
|
|
|
|
func extractionFixtureDefinitions() map[string]ExtractionArtifactDefinition {
|
|
|
|
|
return map[string]ExtractionArtifactDefinition{
|
|
|
|
|
"encounters": {
|
|
|
|
|
LaneID: "encounters", PipelineID: "campaign.extract", MediaType: "application/json",
|
|
|
|
|
SchemaID: "encounters", SchemaVersion: "1", ModuleKey: "encounters",
|
|
|
|
|
LaneID: "encounters", PipelineID: "campaign.extract",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -264,11 +260,8 @@ func validExtractionCatalogFixture(t *testing.T) (SessionPaths, *manifest.Manife
|
|
|
|
|
root := t.TempDir()
|
|
|
|
|
paths := SessionPaths{Root: root, ArtifactsDir: filepath.Join(root, "artifacts")}
|
|
|
|
|
trimmedPath := filepath.Join(paths.Root, filepath.FromSlash(TranscriptPathFinalTrimmed))
|
|
|
|
|
bundleRoot := filepath.Join(paths.ArtifactsDir, "notarius", "extract-run-1")
|
|
|
|
|
lanePath := filepath.Join(bundleRoot, "lanes", "encounters.json")
|
|
|
|
|
indexPath := filepath.Join(bundleRoot, "index.json")
|
|
|
|
|
lanePath := filepath.Join(paths.ArtifactsDir, "encounters.json")
|
|
|
|
|
writeExtractionFixtureFile(t, lanePath, `{"encounters":[]}`)
|
|
|
|
|
writeExtractionFixtureFile(t, indexPath, `{"lanes":[]}`)
|
|
|
|
|
writeExtractionFixtureFile(t, trimmedPath, `{"segments":[]}`)
|
|
|
|
|
definitions := extractionFixtureDefinitions()
|
|
|
|
|
m := manifest.New("session", fixtureTime)
|
|
|
|
|
@@ -285,18 +278,16 @@ func validExtractionCatalogFixture(t *testing.T) (SessionPaths, *manifest.Manife
|
|
|
|
|
m.Stages["extract"] = &manifest.StageRecord{
|
|
|
|
|
Name: "extract", Status: manifest.StatusSucceeded,
|
|
|
|
|
Metadata: map[string]any{
|
|
|
|
|
"narratio_run_id": "extract-run-1", "bundle_root": bundleRoot,
|
|
|
|
|
"receipt": map[string]any{"run_id": "notarius-run-1", "pipeline_id": "campaign.extract"},
|
|
|
|
|
"narratio_run_id": "extract-run-1",
|
|
|
|
|
"completion": map[string]any{"pipeline": "campaign.extract"},
|
|
|
|
|
extractionMetadataInput: input.Metadata(),
|
|
|
|
|
},
|
|
|
|
|
Outputs: []manifest.ArtifactRecord{
|
|
|
|
|
{
|
|
|
|
|
Kind: "notarius_lane", SourceID: ExtractionArtifactSourceID("encounters"), LocalPath: lanePath,
|
|
|
|
|
ProducerRunID: "extract-run-1", Checksum: extractionFixtureChecksum(t, lanePath),
|
|
|
|
|
Contract: &artifactmodel.ContractMetadata{MediaType: "application/json", SchemaID: "encounters", SchemaVersion: "1", ModuleKey: "encounters"},
|
|
|
|
|
ExternalProvenance: &artifactmodel.ExternalProvenance{System: "notarius", RunID: "notarius-run-1", PipelineID: "campaign.extract", ArtifactID: "encounters"},
|
|
|
|
|
ProducerRunID: "extract-run-1", Checksum: extractionFixtureChecksum(t, lanePath), Size: int64(len(`{"encounters":[]}`)),
|
|
|
|
|
ExternalProvenance: &artifactmodel.ExternalProvenance{System: "notarius", PipelineID: "campaign.extract", ArtifactID: "encounters"},
|
|
|
|
|
},
|
|
|
|
|
{Kind: "notarius_index", LocalPath: indexPath, ProducerRunID: "extract-run-1", Checksum: extractionFixtureChecksum(t, indexPath)},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return paths, m, definitions
|
|
|
|
|
|