test_wp09_repository_contract.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from __future__ import annotations
  2. from pathlib import Path
  3. ROOT = Path(__file__).resolve().parents[2]
  4. MIGRATION = ROOT / "migrations/versions/20260813_496_model_gateway_agent_runtime.py"
  5. DEPLOYMENT_MIGRATION = ROOT / "deployment/migrations/versions/20260813_496_model_gateway_agent_runtime.py"
  6. def test_wp09_migration_is_chained_after_current_head_has_fenced_budget_and_no_raw_payload_columns():
  7. source = MIGRATION.read_text(encoding="utf-8")
  8. assert 'revision = "20260813_496"' in source
  9. assert 'down_revision = "20260811_495"' in source
  10. for table in (
  11. "model_gateway_routes", "agent_runtime_budgets", "agent_runtime_reservations",
  12. "agent_runtime_capabilities", "agent_runtime_states", "agent_generation_canaries",
  13. "agent_invocation_audits",
  14. ):
  15. assert table in source
  16. for column in ("lease_fence", "idempotency_key", "input_hash", "evidence_digests"):
  17. assert column in source
  18. for forbidden in ("raw_prompt", "raw_input", "raw_output", "secret_value", "api_key"):
  19. assert forbidden not in source
  20. assert "DROP TABLE IF EXISTS public.agent_invocation_audits" in source
  21. assert MIGRATION.read_bytes() == DEPLOYMENT_MIGRATION.read_bytes()
  22. def test_wp09_source_and_deployment_runtime_contracts_are_byte_identical():
  23. for relative_path in (
  24. "app/core/llm/runtime_governance.py",
  25. "app/core/llm/runtime_governance_repository.py",
  26. "app/core/mcp/governed_invocation.py",
  27. ):
  28. source = ROOT / relative_path
  29. deployment = ROOT / "deployment" / relative_path
  30. assert source.read_bytes() == deployment.read_bytes()