main
py 83 lines 3.25 KB
Raw
1 from pathlib import Path
2
3 WORKFLOW = Path(".github/workflows/sync-publish-to-main.yml")
4 RESTORE_WORKFLOW = Path(".github/workflows/restore-publish-backup.yml")
5 CRAWL_WORKFLOW = Path(".github/workflows/crawl-and-publish.yml")
6
7
8 def test_publish_sync_only_checks_out_generated_content_paths() -> None:
9 workflow = WORKFLOW.read_text(encoding="utf-8")
10
11 for path in (
12 "data/raw/",
13 "data/analyzed/",
14 "data/metrics/",
15 "content/weekly/",
16 "content/monthly/",
17 "content/yearly/",
18 ):
19 assert path in workflow
20
21 assert "git checkout origin/publish -- .squad" not in workflow
22 assert "git ls-tree -r --name-only origin/publish -- .squad" not in workflow
23 assert "squad learnings" not in workflow.lower()
24 assert "python3 scripts/generate_rollups.py" in workflow
25 assert "data/raw-store/" not in workflow
26
27
28 def test_publish_sync_refuses_staged_squad_changes() -> None:
29 workflow = WORKFLOW.read_text(encoding="utf-8")
30
31 assert "Refusing to sync .squad state from publish to main" in workflow
32 assert "git diff --cached --name-only | grep -E '^\\.squad/'" in workflow
33 assert "data/raw/" in workflow
34 assert ".squad/**" in workflow
35
36
37 def test_restore_publish_backup_workflow_uses_immutable_backup_manifest() -> None:
38 workflow = RESTORE_WORKFLOW.read_text(encoding="utf-8")
39
40 assert "backup_manifest" in workflow
41 assert "python3 ../workflow-source/scripts/publish_safety.py restore-backup" in workflow
42 assert "--force-with-lease" in workflow
43 assert "ref: publish" in workflow
44
45
46 def test_restore_publish_backup_workflow_keeps_helper_available_after_publish_checkout() -> None:
47 workflow = RESTORE_WORKFLOW.read_text(encoding="utf-8")
48
49 assert "path: workflow-source" in workflow
50 assert "ref: ${{ github.sha }}" in workflow
51 assert "path: publish" in workflow
52 assert "cd publish" in workflow
53 assert "python3 scripts/publish_safety.py restore-backup" not in workflow
54 assert "python3 ../workflow-source/scripts/publish_safety.py restore-backup" in workflow
55
56
57 def test_publish_sync_stages_before_cached_diff_evaluation() -> None:
58 workflow = WORKFLOW.read_text(encoding="utf-8")
59
60 assert workflow.index("git add -A") < workflow.index("if git diff --cached --quiet; then")
61
62
63 def test_crawl_workflow_stores_and_restores_source_bound_raw_evidence() -> None:
64 workflow = CRAWL_WORKFLOW.read_text(encoding="utf-8")
65
66 assert "source_run_id:" in workflow
67 assert "run_mode=restore and source_run_id" in workflow
68 assert workflow.count("python3 scripts/publish_safety.py restore-raw") == 2
69 assert "python3 publish-safety-tool.py store-raw" in workflow
70 assert 'RAW_STORE_DIR="data/raw-store/${REBUILD_WEEK}/${SOURCE_RUN_ID}"' in workflow
71 assert (
72 '--raw-store-manifest "data/raw-store/${WEEK}/${SOURCE_RUN_ID}/manifest.json"' in workflow
73 )
74 assert 'source-artifact-id "$RAW_ARTIFACT_ID"' in workflow
75 assert "retention-days: 90" in workflow
76
77
78 def test_crawl_workflow_stages_raw_store_before_cached_diff_evaluation() -> None:
79 workflow = CRAWL_WORKFLOW.read_text(encoding="utf-8")
80
81 stage = workflow.index("git add data/raw/ data/snapshots/ data/raw-store/")
82 cached_diff = workflow.index("if git diff --cached --quiet; then", stage)
83 assert stage < cached_diff