diff --git a/src/domain/artifactComparison.ts b/src/domain/artifactComparison.ts index fb4768483f..bfe8fef8ac 100644 --- a/src/domain/artifactComparison.ts +++ b/src/domain/artifactComparison.ts @@ -287,7 +287,8 @@ export type UnreportedArtifactPathClassifier = ( * number of paths it omitted from `changes`. Only a path observed once on each * side of a fully covered comparison is unchanged; this matches the paths * counted in `summary.unchanged`. A path neither inventory observed is not - * evidence of equality. + * evidence of equality: it is unobserved under complete coverage and unknown + * otherwise. */ export const prepareUnreportedArtifactPaths = ( result: ArtifactComparisonResult, @@ -306,11 +307,19 @@ export const prepareUnreportedArtifactPaths = ( const leftByPath = occurrencesByPath(left.occurrences); const rightByPath = occurrencesByPath(right.occurrences); return (logicalPath) => { - // The index holds only observed paths; absence on both sides is unobserved. + // The index holds only observed paths. Absence on both sides proves the + // selector names no compared member only when coverage is complete; + // otherwise the path may lie where the comparison never reached. const leftMatches = leftByPath.get(logicalPath); const rightMatches = rightByPath.get(logicalPath); if (leftMatches === undefined && rightMatches === undefined) - return { status: "unobserved" }; + return fullyCovered + ? { status: "unobserved" } + : { + status: "unknown", + limitation: + "The selected artifact path was not observed in either inventory, and the comparison does not have complete coverage; it may name a member the comparison never reached.", + }; if (fullyCovered && leftMatches?.length === 1 && rightMatches?.length === 1) return { status: "unchanged" }; return { diff --git a/src/domain/staticRuntimeCorrelation.test.ts b/src/domain/staticRuntimeCorrelation.test.ts index c1c1a2a2c6..701fe877cc 100644 --- a/src/domain/staticRuntimeCorrelation.test.ts +++ b/src/domain/staticRuntimeCorrelation.test.ts @@ -817,3 +817,65 @@ describe("prepared unreported artifact paths", () => { ); }); }); + +describe("unobserved artifact paths", () => { + it("keeps a path neither inventory observed unknown without complete coverage", () => { + const partial = createEvidence( + evidenceSubjectInput(artifactLeft.subject), + artifactLeft.provider, + { + operation: artifactLeft.operation, + parameters: artifactLeft.parameters, + result: { + ...artifactInventoryResultSchema.parse( + artifactLeft.normalized_result, + ), + coverage: { scope: "root", status: "unknown" }, + }, + confidence: artifactLeft.confidence, + authority: artifactLeft.authority, + }, + ); + const comparison = createEvidence( + unknownTarget("derived-from-linked-evidence"), + ARTIFACT_COMPARISON_PROVIDER, + { + predicateType: "rea.artifact-comparison", + operation: "compare_artifacts", + parameters: { + left_evidence_ids: [partial.evidence_id], + right_evidence_ids: [partial.evidence_id], + }, + result: compareArtifacts(partial, partial), + confidence: "derived", + authority: "analyst-inference", + evidenceLinks: [partial.evidence_id], + }, + ); + const input = select("never/reached.js"); + const result = correlateStaticAndRuntime( + { + ...input, + static_comparisons: [comparison], + mappings: input.mappings.map((item) => ({ + ...item, + static: { + ...item.static, + comparison_evidence_id: comparison.evidence_id, + }, + })), + }, + { + sourceEvidence: (id) => + id === partial.evidence_id ? partial : undefined, + }, + ); + expect(result.correlations.items[0]).toMatchObject({ + static: { status: "unknown", conclusion_kind: "unresolved_branch" }, + classification: "unresolved_branch", + }); + expect(result.correlations.items[0]?.limitations.join(" ")).toMatch( + /not observed in either inventory/u, + ); + }); +});