From d3b4f25f715dea88a24f962b608d83013a224a8e Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 2 Dec 2026 21:10:04 +0000 Subject: [PATCH] Remove brittle and duplicate test assertions --- docs/roadmap/audit/catalog.md | 16 ++++++++----- docs/roadmap/implementation.md | 2 +- internal/artifactmodel/metadata_test.go | 30 +++++++++++++++++++------ internal/config/native_results_test.go | 8 ++++++- internal/stage/analyze_test.go | 28 ----------------------- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/roadmap/audit/catalog.md b/docs/roadmap/audit/catalog.md index bf50985..0369a10 100644 --- a/docs/roadmap/audit/catalog.md +++ b/docs/roadmap/audit/catalog.md @@ -41,9 +41,9 @@ their scope. Unless assigned otherwise, a finding remains independent audit remediation. Shared code does not make a refactoring a prerequisite or assign the whole finding to a roadmap. -Nineteen entries are closed by the safety, transfer, audio discovery, S3 -planning, prerequisite-history, publication-import, CLI classification, inspection aggregation, and -associated documentation work; 24 remain open. **Planned** identifies +Twenty-one entries are closed by the safety, transfer, audio discovery, S3 +planning, prerequisite-history, publication-import, CLI classification, +inspection aggregation, test maintenance, and associated documentation work; 22 remain open. **Planned** identifies an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending lifecycle is removed. **Coordinate** identifies shared changes, not a commitment that a related feature implements the entire finding. Findings close only after their @@ -877,7 +877,10 @@ Related: [CAT-19](#cat-19--p3-describe-stable-prepared-products-once-for-materia ### CAT-35 — P3: Remove assertions on incidental serialization and validation order -Status: Open +Status: Closed + +**Closure.** Metadata tests compare decoded JSON members and omissions; the native campaign +validation test locates its diagnostic without requiring its position. Original findings: [TE-07](08-testing.md#te-07--p3-some-assertions-freeze-incidental-serialization-or-validation-order). @@ -966,7 +969,10 @@ configuration ownership or introduce new destination semantics. ### CAT-41 — P3: Remove the duplicate normalized-transcript test -Status: Open +Status: Closed + +**Closure.** The duplicate analysis test was removed; the manifest-authoritative source test +remains. Original findings: [TE-08](08-testing.md#te-08--p3-two-normalized-transcript-tests-are-exact-duplicates). diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 21b6960..a6566ab 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -121,7 +121,7 @@ Validation: `go test ./internal/app -run 'Test.*(Inspection|SessionState|Publish ## Stage 2: Remove Incidental And Duplicate Test Constraints -CAT IDs: CAT-35, CAT-41. Status: Pending. +CAT IDs: CAT-35, CAT-41. Status: Complete. Read [TE-07](audit/08-testing.md#te-07--p3-some-assertions-freeze-incidental-serialization-or-validation-order) and [TE-08](audit/08-testing.md#te-08--p3-two-normalized-transcript-tests-are-exact-duplicates). diff --git a/internal/artifactmodel/metadata_test.go b/internal/artifactmodel/metadata_test.go index 5be0880..1eeefad 100644 --- a/internal/artifactmodel/metadata_test.go +++ b/internal/artifactmodel/metadata_test.go @@ -2,7 +2,7 @@ package artifactmodel import ( "encoding/json" - "strings" + "reflect" "testing" ) @@ -29,16 +29,27 @@ func TestArtifactMetadataJSON(t *testing.T) { if err != nil { t.Fatalf("Marshal() complete metadata error = %v", err) } - wantComplete := `{"contract":{"media_type":"application/json","schema_id":"notarius.dnd.npc_registry","schema_version":"v1","module_key":"dnd/npc-registry"},"external_provenance":{"system":"notarius","run_id":"run-123","pipeline_id":"dnd-session","artifact_id":"npc-registry"}}` - if string(complete) != wantComplete { - t.Fatalf("complete metadata JSON = %s, want %s", complete, wantComplete) + var got map[string]any + if err := json.Unmarshal(complete, &got); err != nil { + t.Fatal(err) + } + want := map[string]any{ + "contract": map[string]any{"media_type": "application/json", "schema_id": "notarius.dnd.npc_registry", "schema_version": "v1", "module_key": "dnd/npc-registry"}, + "external_provenance": map[string]any{"system": "notarius", "run_id": "run-123", "pipeline_id": "dnd-session", "artifact_id": "npc-registry"}, + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("complete metadata = %#v, want %#v", got, want) } omitted, err := json.Marshal(envelope{}) if err != nil { t.Fatalf("Marshal() omitted metadata error = %v", err) } - if string(omitted) != `{}` { + got = nil + if err := json.Unmarshal(omitted, &got); err != nil { + t.Fatal(err) + } + if len(got) != 0 { t.Fatalf("omitted metadata JSON = %s, want {}", omitted) } @@ -50,7 +61,12 @@ func TestArtifactMetadataJSON(t *testing.T) { if err != nil { t.Fatalf("Marshal() contract without module key error = %v", err) } - if strings.Contains(string(withoutModule), "module_key") { - t.Fatalf("contract JSON unexpectedly contains omitted module_key: %s", withoutModule) + got = nil + if err := json.Unmarshal(withoutModule, &got); err != nil { + t.Fatal(err) + } + want = map[string]any{"contract": map[string]any{"media_type": "application/json", "schema_id": "notarius.dnd.npc_registry", "schema_version": "v1"}} + if !reflect.DeepEqual(got, want) { + t.Fatalf("metadata without module = %#v, want %#v", got, want) } } diff --git a/internal/config/native_results_test.go b/internal/config/native_results_test.go index 1c05d99..1d5ba67 100644 --- a/internal/config/native_results_test.go +++ b/internal/config/native_results_test.go @@ -110,7 +110,13 @@ narratio: t.Fatalf("campaign validation lost its native error: %v", err) } findings := loadError.Diagnostics() - if len(findings) == 0 || findings[0].Code != configkit.CodeValidateError || findings[0].Path.String() != "/narratio/inputs/speakers_file" { + found := false + for _, finding := range findings { + if finding.Code == configkit.CodeValidateError && finding.Path.String() == "/narratio/inputs/speakers_file" { + found = true + } + } + if !found { t.Fatalf("campaign validation findings = %+v", findings) } } diff --git a/internal/stage/analyze_test.go b/internal/stage/analyze_test.go index f4a44e2..8dd880d 100644 --- a/internal/stage/analyze_test.go +++ b/internal/stage/analyze_test.go @@ -1304,34 +1304,6 @@ func TestAnalyzeSupportsCanonicalNormalizedTranscriptSourceFromManifestOutput(t } } -func TestAnalyzeSupportsNormalizedTranscriptSourceFromManifestOutput(t *testing.T) { - env, m, fake := setupAnalyzeEnv(t) - paths := sessionPathsForEnv(env, m.SessionID) - fallbackPath := filepath.Join(paths.TranscriptsDir, "final.json") - manifestPath := filepath.Join(paths.ArtifactsDir, "normalized.from-manifest.json") - writeAnalyzeFile(t, fallbackPath, `{"segments":[{"id":999}]}`) - writeAnalyzeFile(t, manifestPath, `{"segments":[{"id":10}]}`) - setCurrentBuiltInEvidence(t, m, "normalize", artifacts.TranscriptOutputKindFinal, artifacts.ArtifactTranscriptFinal, manifestPath) - - artifact := env.Config.ArtifactCatalog.Artifacts["session_recap"] - artifact.Inputs["transcript"] = config.ScriptoriumInputConfig{ - Source: "narratio.transcript.final", - Required: true, - } - env.Config.ArtifactCatalog.Artifacts["session_recap"] = artifact - - _, err := (analyzeStage{}).Run(context.Background(), env, m) - if err != nil { - t.Fatalf("Run() error = %v", err) - } - if len(fake.RunRequests) != 1 { - t.Fatalf("run requests = %d, want 1", len(fake.RunRequests)) - } - if fake.RunRequests[0].InputPaths["transcript"] != manifestPath { - t.Fatalf("transcript input = %q, want manifest normalized transcript path", fake.RunRequests[0].InputPaths["transcript"]) - } -} - func TestAnalyzeFailsWhenNormalizedTranscriptMissing(t *testing.T) { env, m, fake := setupAnalyzeEnv(t) artifact := env.Config.ArtifactCatalog.Artifacts["session_recap"]