test_p4_graph_integration.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from content_agent.run_service import RunService
  2. from content_agent.schemas import RunStartRequest
  3. from tests.p1_helpers import FakeQueryVariantClient, REAL_SOURCE_FIXTURE
  4. from tests.p4_helpers import (
  5. FailingDecodeClient,
  6. FakeCategoryMatchClient,
  7. FakeDecodeClient,
  8. fake_decode_pending,
  9. )
  10. def test_p4_mock_run_writes_pattern_recall_evidence_and_matched_items(tmp_path):
  11. service = RunService(
  12. runtime_root=tmp_path / "runtime" / "v1",
  13. query_variant_client=FakeQueryVariantClient(),
  14. decode_client=FakeDecodeClient(),
  15. category_match_client=FakeCategoryMatchClient(),
  16. )
  17. state = service.start_run(
  18. RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
  19. )
  20. assert state["status"] == "success"
  21. assert state["current_step"] == "review_strategy"
  22. evidence_rows = service.read_jsonl(state["run_id"], "pattern_recall_evidence.jsonl")
  23. items = service.read_jsonl(state["run_id"], "discovered_content_items.jsonl")
  24. assert evidence_rows
  25. assert all(row["recall_status"] == "matched" for row in evidence_rows)
  26. assert all(item["pattern_match_result"]["pattern_recall"] == "matched" for item in items)
  27. assert service.validate_run(state["run_id"])["status"] == "pass"
  28. def test_p4_pending_content_does_not_fail_run(tmp_path):
  29. service = RunService(
  30. runtime_root=tmp_path / "runtime" / "v1",
  31. query_variant_client=FakeQueryVariantClient(),
  32. decode_client=FakeDecodeClient(fake_decode_pending()),
  33. category_match_client=FakeCategoryMatchClient(),
  34. pattern_recall_max_wait_seconds=0,
  35. pattern_recall_poll_interval_seconds=0,
  36. )
  37. state = service.start_run(
  38. RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
  39. )
  40. assert state["status"] == "success"
  41. evidence_rows = service.read_jsonl(state["run_id"], "pattern_recall_evidence.jsonl")
  42. decisions = service.read_jsonl(state["run_id"], "rule_decisions.jsonl")
  43. assert all(row["recall_status"] == "pending" for row in evidence_rows)
  44. assert all(
  45. decision["decision_reason_code"] == "content_pattern_recall_required"
  46. for decision in decisions
  47. )
  48. assert service.validate_run(state["run_id"])["status"] == "pass"
  49. def test_p4_decode_client_failure_is_content_failed_not_run_failed(tmp_path):
  50. service = RunService(
  51. runtime_root=tmp_path / "runtime" / "v1",
  52. query_variant_client=FakeQueryVariantClient(),
  53. decode_client=FailingDecodeClient(),
  54. category_match_client=FakeCategoryMatchClient(),
  55. )
  56. state = service.start_run(
  57. RunStartRequest(platform_mode="mock", source=str(REAL_SOURCE_FIXTURE))
  58. )
  59. assert state["status"] == "success"
  60. evidence_rows = service.read_jsonl(state["run_id"], "pattern_recall_evidence.jsonl")
  61. assert all(row["recall_status"] == "failed" for row in evidence_rows)
  62. assert all(
  63. row["evidence_summary"]["failure_reason"] == "decode_client_error"
  64. for row in evidence_rows
  65. )
  66. assert service.validate_run(state["run_id"])["status"] == "pass"