| 1 | """Tests for typed evidence provenance on policy timelines and traces.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from loader.runtime.completion_trace import completion_trace_from_workflow_timeline |
| 6 | from loader.runtime.evidence_provenance import ( |
| 7 | EvidenceProvenance, |
| 8 | EvidenceProvenanceStatus, |
| 9 | ) |
| 10 | from loader.runtime.workflow_policy import WorkflowTimelineEntry, WorkflowTimelineEntryKind |
| 11 | |
| 12 | |
| 13 | def test_workflow_timeline_entry_derives_evidence_summary_from_provenance() -> None: |
| 14 | entry = WorkflowTimelineEntry.accountability( |
| 15 | kind=WorkflowTimelineEntryKind.COMPLETION_FINALIZE, |
| 16 | mode="execute", |
| 17 | reason_code="continuation_budget_exhausted", |
| 18 | summary="completion: stopped because follow-through evidence was still missing", |
| 19 | policy_stage="continuation_check", |
| 20 | policy_outcome="finalize", |
| 21 | evidence_provenance=[ |
| 22 | EvidenceProvenance( |
| 23 | category="verification", |
| 24 | source="dod.evidence", |
| 25 | summary="verification evidence was still missing for `pytest -q`", |
| 26 | status=EvidenceProvenanceStatus.MISSING.value, |
| 27 | subject="pytest -q", |
| 28 | ) |
| 29 | ], |
| 30 | ) |
| 31 | |
| 32 | assert entry.evidence_summary == [ |
| 33 | "verification evidence was still missing for `pytest -q`" |
| 34 | ] |
| 35 | assert entry.evidence_provenance[0].status == EvidenceProvenanceStatus.MISSING.value |
| 36 | |
| 37 | |
| 38 | def test_completion_trace_projection_preserves_evidence_provenance() -> None: |
| 39 | timeline = [ |
| 40 | WorkflowTimelineEntry.accountability( |
| 41 | kind=WorkflowTimelineEntryKind.COMPLETION_FINALIZE, |
| 42 | mode="execute", |
| 43 | reason_code="continuation_budget_exhausted", |
| 44 | summary="completion: stopped because follow-through evidence was still missing", |
| 45 | policy_stage="continuation_check", |
| 46 | policy_outcome="finalize", |
| 47 | evidence_provenance=[ |
| 48 | EvidenceProvenance( |
| 49 | category="verification", |
| 50 | source="dod.evidence", |
| 51 | summary="verification evidence was still missing for `pytest -q`", |
| 52 | status=EvidenceProvenanceStatus.MISSING.value, |
| 53 | subject="pytest -q", |
| 54 | ), |
| 55 | EvidenceProvenance( |
| 56 | category="action", |
| 57 | source="actions_taken", |
| 58 | summary="recorded work already showed the requested edit happened", |
| 59 | status=EvidenceProvenanceStatus.SUPPORTS.value, |
| 60 | ), |
| 61 | ], |
| 62 | ) |
| 63 | ] |
| 64 | |
| 65 | trace = completion_trace_from_workflow_timeline( |
| 66 | timeline, |
| 67 | last_decision_code="continuation_budget_exhausted", |
| 68 | ) |
| 69 | |
| 70 | assert len(trace) == 1 |
| 71 | assert trace[0].decision_code == "continuation_budget_exhausted" |
| 72 | assert trace[0].evidence_summary == [ |
| 73 | "verification evidence was still missing for `pytest -q`", |
| 74 | "recorded work already showed the requested edit happened", |
| 75 | ] |
| 76 | assert [item.status for item in trace[0].evidence_provenance] == [ |
| 77 | EvidenceProvenanceStatus.MISSING.value, |
| 78 | EvidenceProvenanceStatus.SUPPORTS.value, |
| 79 | ] |