test_store.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from pathlib import Path
  2. from visualization.web.store import FileRunStore
  3. PROJECT_ROOT = Path(__file__).resolve().parents[2]
  4. def test_discovers_current_global_and_production_runs() -> None:
  5. store = FileRunStore(PROJECT_ROOT / "demo_output")
  6. refs = store.discover()
  7. kinds = {ref.kind for ref in refs}
  8. assert "global_data" in kinds
  9. assert "segment" in kinds
  10. def test_global_run_projects_upstream_compatible_views() -> None:
  11. store = FileRunStore(PROJECT_ROOT / "demo_output")
  12. ref = next(
  13. item for item in store.discover()
  14. if item.key == "global-data-stage-live-v22"
  15. )
  16. brief = store.brief(ref)
  17. detail = store.detail(ref)
  18. snapshots = store.snapshots(ref)
  19. flat = store.flat(ref, 0)
  20. assert brief["status"] == "success"
  21. assert brief["raw_status"] == "COMPLETED"
  22. assert brief["cost_status"] in {"reported", "unavailable"}
  23. assert detail["steps"]
  24. assert detail["overview"] == {
  25. "plan_rounds": 1,
  26. "execute_rounds": 4,
  27. "task_count": 4,
  28. "passed": 4,
  29. "failed": 0,
  30. "retries": 0,
  31. }
  32. assert snapshots["snapshots"]
  33. assert flat["root"]["module_key"] == "production.global_data.workflow"
  34. assert flat["round_count"] >= 1
  35. assert flat["rounds"][0]["instances"]
  36. executor = next(
  37. item
  38. for item in flat["rounds"][0]["instances"]
  39. if item["module_key"] == "production.global_data.execute"
  40. and item["task_id"] == "Task1"
  41. )
  42. assert executor["output"]["images"]
  43. def test_production_run_reads_latest_versioned_plan_without_terminal_report() -> None:
  44. store = FileRunStore(PROJECT_ROOT / "demo_output")
  45. ref = next(
  46. item for item in store.discover()
  47. if item.key == "v22-production-v06-live-v3"
  48. )
  49. detail = store.detail(ref)
  50. flat = store.flat(ref, 0)
  51. assert detail["agent_name"] == "segment_production"
  52. assert detail["input_payload"]["schema_version"] == "0.6"
  53. assert detail["overview"]["plan_rounds"] == 1
  54. assert detail["overview"]["task_count"] == 4
  55. assert detail["overview"]["execute_rounds"] > 0
  56. assert flat["round_count"] == 1
  57. assert flat["rounds"][0]["instances"][0]["module_key"] == (
  58. "production.segment.execute"
  59. )
  60. assert (
  61. flat["rounds"][0]["instances"][0]["input"]["blocks"][0]["source"]
  62. == "segment_packages/Segment1.v1.json"
  63. )
  64. def test_completed_global_run_without_summary_uses_stage_delivery_status() -> None:
  65. store = FileRunStore(PROJECT_ROOT / "demo_output")
  66. ref = next(
  67. item for item in store.discover()
  68. if item.key == "global-data-stage-live-v19"
  69. )
  70. brief = store.brief(ref)
  71. assert brief["raw_status"] == "GLOBAL_DATA_COMPLETED"
  72. assert brief["status"] == "success"
  73. def test_media_path_cannot_escape_run_directory() -> None:
  74. store = FileRunStore(PROJECT_ROOT / "demo_output")
  75. ref = next(
  76. item for item in store.discover()
  77. if item.key == "global-data-stage-live-v22"
  78. )
  79. try:
  80. store.media_path(ref, "../v22-production-plan.v1.json")
  81. except FileNotFoundError:
  82. pass
  83. else:
  84. raise AssertionError("media path traversal must be rejected")