"""Unit tests — Phase 9A-4 F7 overseer-run provenance enrichment (issue #144).""" from __future__ import annotations import pytest from musehub.services import musehub_overseer_provenance as enrichment def test_fixture_run_ref_returns_content_free_envelope() -> None: payload = enrichment.get_overseer_run_provenance("flow_run:fixture-overseer-001") assert payload is not None assert payload["schema"] == "musehub.overseer_run_provenance_envelope/v0" record = payload["record"] assert record["runRef"] == "flow_run:fixture-overseer-001" assert record["reviewTrayOutcomeRef"] == "outcome:flow_run:fixture-overseer-001" assert record["outcome"] == "pass" assert record["untrusted"] is True # content-free: no prompt/body fields assert "prompt" not in record assert "completion" not in record def test_unknown_run_ref_returns_none() -> None: assert enrichment.get_overseer_run_provenance("flow_run:missing-run") is None def test_invalid_run_ref_returns_none() -> None: assert enrichment.get_overseer_run_provenance("not-a-run-ref") is None def test_gate_off_when_env_disabled(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr( enrichment.settings, "musehub_overseer_provenance_enrichment_enabled", "disabled", ) assert enrichment.is_overseer_provenance_enrichment_enabled() is False def test_gate_on_when_env_enabled(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr( enrichment.settings, "musehub_overseer_provenance_enrichment_enabled", "enabled", ) assert enrichment.is_overseer_provenance_enrichment_enabled() is True def test_seed_rejects_invalid_record() -> None: bad = enrichment.OverseerRunProvenanceRecord( run_ref="bad ref with spaces", review_tray_outcome_ref="outcome:bad", outcome="pass", constitution_version="0.1.0", agent_version_ref="agent:x", worker_model_family="family:ollama", checker_model_family="family:llama_cpp", external_ref=None, actor_hash="a" * 64, produced_at="2026-07-09T12:00:00Z", ) with pytest.raises(ValueError, match="provenance_record_invalid"): enrichment.seed_overseer_provenance_record(bad)