| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- from content_agent.run_service import RunService
- from content_agent.schemas import RunStartRequest
- from tests.p1_helpers import FakeQueryVariantClient, REAL_SOURCE_FIXTURE
- from tests.p4_helpers import (
- FailingDecodeClient,
- FakeCategoryMatchClient,
- FakeDecodeClient,
- fake_decode_pending,
- )
- def test_p4_mock_run_writes_pattern_recall_evidence_and_matched_items(tmp_path):
- service = RunService(
- runtime_root=tmp_path / "runtime" / "v1",
- query_variant_client=FakeQueryVariantClient(),
- decode_client=FakeDecodeClient(),
- category_match_client=FakeCategoryMatchClient(),
- )
- state = service.start_run(
- RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
- )
- assert state["status"] == "success"
- assert state["current_step"] == "review_strategy"
- evidence_rows = service.read_jsonl(state["run_id"], "pattern_recall_evidence.jsonl")
- items = service.read_jsonl(state["run_id"], "discovered_content_items.jsonl")
- assert evidence_rows
- assert all(row["recall_status"] == "matched" for row in evidence_rows)
- assert all(item["pattern_match_result"]["pattern_recall"] == "matched" for item in items)
- assert service.validate_run(state["run_id"])["status"] == "pass"
- def test_p4_pending_content_does_not_fail_run(tmp_path):
- service = RunService(
- runtime_root=tmp_path / "runtime" / "v1",
- query_variant_client=FakeQueryVariantClient(),
- decode_client=FakeDecodeClient(fake_decode_pending()),
- category_match_client=FakeCategoryMatchClient(),
- pattern_recall_max_wait_seconds=0,
- pattern_recall_poll_interval_seconds=0,
- )
- state = service.start_run(
- RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
- )
- assert state["status"] == "success"
- evidence_rows = service.read_jsonl(state["run_id"], "pattern_recall_evidence.jsonl")
- decisions = service.read_jsonl(state["run_id"], "rule_decisions.jsonl")
- assert all(row["recall_status"] == "pending" for row in evidence_rows)
- assert all(
- decision["decision_reason_code"] == "content_pattern_recall_required"
- for decision in decisions
- )
- assert service.validate_run(state["run_id"])["status"] == "pass"
- def test_p4_decode_client_failure_is_content_failed_not_run_failed(tmp_path):
- service = RunService(
- runtime_root=tmp_path / "runtime" / "v1",
- query_variant_client=FakeQueryVariantClient(),
- decode_client=FailingDecodeClient(),
- category_match_client=FakeCategoryMatchClient(),
- )
- state = service.start_run(
- RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
- )
- assert state["status"] == "success"
- evidence_rows = service.read_jsonl(state["run_id"], "pattern_recall_evidence.jsonl")
- assert all(row["recall_status"] == "failed" for row in evidence_rows)
- assert all(
- row["evidence_summary"]["failure_reason"] == "decode_client_error"
- for row in evidence_rows
- )
- assert service.validate_run(state["run_id"])["status"] == "pass"
|