Stevesolun commited on
Commit
b015319
·
verified ·
1 Parent(s): 482a9b2

Sync ctx b62b78d (part 5)

Browse files

GitHub commit: b62b78d704ec54b3ff43e333982eef713a33c8df

src/tests/test_release_graph_count_sync.py CHANGED
@@ -2,12 +2,12 @@ from __future__ import annotations
2
 
3
  import json
4
  from pathlib import Path
5
- import subprocess
6
  from urllib.parse import quote
7
 
8
  import yaml # type: ignore[import-untyped]
9
 
10
  import update_repo_stats as urs
 
11
  from scripts.ci_preflight import GRAPH_VALIDATE_ARGS
12
 
13
 
@@ -51,21 +51,6 @@ def _workflow_job_steps(path: str, job_name: str) -> list[dict[str, object]]:
51
  return steps
52
 
53
 
54
- def _head_lfs_pointer(path: str) -> dict[str, int | str]:
55
- pointer = subprocess.check_output(
56
- ["git", "cat-file", "-p", f"HEAD:{path}"],
57
- text=True,
58
- )
59
- values: dict[str, int | str] = {}
60
- for line in pointer.splitlines():
61
- if line.startswith("oid sha256:"):
62
- values["sha256"] = line.split(":", 1)[1].strip()
63
- elif line.startswith("size "):
64
- values["size"] = int(line.split(" ", 1)[1].strip())
65
- assert values.keys() == {"sha256", "size"}
66
- return values
67
-
68
-
69
  def _graph_contract_counts() -> dict[str, int]:
70
  flags = _flag_values(GRAPH_VALIDATE_ARGS[1:])
71
  return {
@@ -115,12 +100,26 @@ def test_pr_graph_check_runs_repo_stats_after_artifact_validation() -> None:
115
  assert steps[stats_index]["run"] == "python src/update_repo_stats.py --check"
116
 
117
 
118
- def test_graph_release_metadata_matches_committed_lfs_pointers() -> None:
119
- full = _head_lfs_pointer("graph/wiki-graph.tar.gz")
120
- runtime = _head_lfs_pointer("graph/wiki-graph-runtime.tar.gz")
121
  stats = json.loads(Path("graph/wiki-graph-stats.json").read_text(encoding="utf-8"))
 
122
 
123
- assert stats["artifact"] == {"path": "graph/wiki-graph.tar.gz", **full}
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  for workflow_path in (
126
  ".github/workflows/test.yml",
@@ -128,9 +127,9 @@ def test_graph_release_metadata_matches_committed_lfs_pointers() -> None:
128
  ".github/workflows/huggingface-sync.yml",
129
  ):
130
  workflow = Path(workflow_path).read_text(encoding="utf-8")
131
- for pointer in (full, runtime):
132
- assert f'"sha256": "{pointer["sha256"]}"' in workflow
133
- assert f'"size": {pointer["size"]}' in workflow
134
 
135
 
136
  def test_public_docs_and_readmes_expose_current_graph_counts() -> None:
 
2
 
3
  import json
4
  from pathlib import Path
 
5
  from urllib.parse import quote
6
 
7
  import yaml # type: ignore[import-untyped]
8
 
9
  import update_repo_stats as urs
10
+ from ctx.core.graph import release_artifacts
11
  from scripts.ci_preflight import GRAPH_VALIDATE_ARGS
12
 
13
 
 
51
  return steps
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  def _graph_contract_counts() -> dict[str, int]:
55
  flags = _flag_values(GRAPH_VALIDATE_ARGS[1:])
56
  return {
 
100
  assert steps[stats_index]["run"] == "python src/update_repo_stats.py --check"
101
 
102
 
103
+ def test_graph_release_metadata_matches_strict_release_manifest() -> None:
104
+ manifest_path = Path("graph/release-artifacts.json")
105
+ manifest = release_artifacts.load_manifest(manifest_path)
106
  stats = json.loads(Path("graph/wiki-graph-stats.json").read_text(encoding="utf-8"))
107
+ full = manifest.artifact_for_path("graph/wiki-graph.tar.gz")
108
 
109
+ assert manifest.repository == "stevesolun/ctx"
110
+ assert manifest.source_release_tag == "v1.0.21"
111
+ assert (
112
+ tuple(
113
+ (artifact.path, artifact.asset_name, artifact.hydrate)
114
+ for artifact in manifest.artifacts
115
+ )
116
+ == release_artifacts.GRAPH_RELEASE_ARTIFACT_SPECS
117
+ )
118
+ assert stats["artifact"] == {
119
+ "path": full.path,
120
+ "size": full.size,
121
+ "sha256": full.sha256,
122
+ }
123
 
124
  for workflow_path in (
125
  ".github/workflows/test.yml",
 
127
  ".github/workflows/huggingface-sync.yml",
128
  ):
129
  workflow = Path(workflow_path).read_text(encoding="utf-8")
130
+ assert "graph/release-artifacts.json" in workflow
131
+ assert "scripts/graph_release_manifest.py" in workflow
132
+ assert "git lfs" not in workflow.lower()
133
 
134
 
135
  def test_public_docs_and_readmes_expose_current_graph_counts() -> None:
src/tests/test_release_supply_chain.py CHANGED
@@ -614,6 +614,7 @@ def test_attestation_covers_every_published_artifact_and_blocks_publish() -> Non
614
  assert graph_download["with"]["name"] == "graph-release-assets"
615
  assert graph_attest["if"] == "needs.build.outputs.graph_assets_available == 'true'"
616
  published_graph_paths = {
 
617
  "wiki-graph.tar.gz",
618
  "wiki-graph-runtime.tar.gz",
619
  "skills-sh-catalog.json.gz",
 
614
  assert graph_download["with"]["name"] == "graph-release-assets"
615
  assert graph_attest["if"] == "needs.build.outputs.graph_assets_available == 'true'"
616
  published_graph_paths = {
617
+ "release-artifacts.json",
618
  "wiki-graph.tar.gz",
619
  "wiki-graph-runtime.tar.gz",
620
  "skills-sh-catalog.json.gz",
src/tests/test_reproducible_dist.py CHANGED
@@ -431,7 +431,7 @@ def test_git_tree_export_disables_lfs_smudging(
431
  "HEAD",
432
  ]
433
  assert isinstance(captured["env"], dict)
434
- assert captured["env"]["GIT_LFS_SKIP_SMUDGE"] == "1"
435
 
436
 
437
  def test_dev_dependencies_include_no_isolation_build_backend() -> None:
 
431
  "HEAD",
432
  ]
433
  assert isinstance(captured["env"], dict)
434
+ assert "GIT_LFS_SKIP_SMUDGE" not in captured["env"]
435
 
436
 
437
  def test_dev_dependencies_include_no_isolation_build_backend() -> None:
src/tests/test_review_findings.py CHANGED
@@ -25,6 +25,7 @@ import pack_full_wiki_tar # noqa: E402
25
  import sync_huggingface # noqa: E402
26
  import validate_graph_artifacts as vga # noqa: E402
27
  from ctx import dashboard_entities # noqa: E402
 
28
  from ctx.core.wiki import wiki_queue_worker # noqa: E402
29
  from ctx.utils._secret_scan import find_inline_secret_arg # noqa: E402
30
 
@@ -225,54 +226,47 @@ def test_graph_markdown_host_path_scan_covers_key_value_delimiters(payload: byte
225
 
226
 
227
  @pytest.mark.parametrize(
228
- "workflow_path",
229
  [
230
- ".github/workflows/huggingface-sync.yml",
231
- ".github/workflows/publish.yml",
232
- ".github/workflows/test.yml",
233
  ],
234
  )
235
- def test_graph_workflow_searches_release_cache_before_lfs_fallback(
236
  workflow_path: str,
 
237
  ) -> None:
238
  workflow = (ROOT / workflow_path).read_text(encoding="utf-8")
239
- resolve_script = workflow[workflow.index("def hydrate_from_release") :]
240
-
241
- release_search = resolve_script.index("for release in load_releases():")
242
- lfs_fallback = resolve_script.rindex(
243
- "hydrate_from_lfs(path_name, expected_oid, expected_size, hydrated_min_size)"
244
  )
245
 
246
- assert release_search < lfs_fallback
247
- assert (
248
- "hydrate_from_lfs(path_name, expected_oid, expected_size, hydrated_min_size)"
249
- not in resolve_script[:release_search]
250
- )
251
- assert 'if expected_oid != fallback["sha256"]' not in resolve_script
252
 
253
 
254
- def test_preflight_refuses_oversized_graph_lfs_pointer_before_pull(
255
- monkeypatch: Any,
256
- tmp_path: Path,
257
- capsys: Any,
258
- ) -> None:
259
- monkeypatch.setattr(ci_preflight, "REPO_ROOT", tmp_path)
260
- artifact = tmp_path / "graph" / "wiki-graph.tar.gz"
261
- artifact.parent.mkdir()
262
- max_size = ci_preflight.GRAPH_LFS_MAX_FALLBACK_SIZES["graph/wiki-graph.tar.gz"]
263
- artifact.write_text(
264
- f"version https://git-lfs.github.com/spec/v1\noid sha256:{'a' * 64}\nsize {max_size + 1}\n",
265
- encoding="utf-8",
 
 
 
 
 
 
 
266
  )
267
- monkeypatch.setattr(ci_preflight.shutil, "which", lambda _name: "/usr/bin/git")
268
-
269
- def fail_run(*_args: Any, **_kwargs: Any) -> None:
270
- raise AssertionError("git lfs pull should not run")
271
-
272
- monkeypatch.setattr(ci_preflight.subprocess, "run", fail_run)
273
-
274
- assert ci_preflight.hydrate_graph_lfs_artifacts() == 1
275
- assert "exceeds cap" in capsys.readouterr().err
276
 
277
 
278
  def test_hf_card_export_uploads_docs_and_changelog(
@@ -666,7 +660,7 @@ def test_entity_search_fallback_returns_wiki_relative_path(tmp_path: Path) -> No
666
  assert str(tmp_path) not in results[0]["path"]
667
 
668
 
669
- def test_lfs_pointer_probe_does_not_full_read_hydrated_artifact(
670
  monkeypatch: Any,
671
  tmp_path: Path,
672
  ) -> None:
@@ -679,4 +673,7 @@ def test_lfs_pointer_probe_does_not_full_read_hydrated_artifact(
679
 
680
  monkeypatch.setattr(Path, "read_bytes", fail_read_bytes)
681
 
682
- assert ci_preflight._read_lfs_pointer(artifact) is None
 
 
 
 
25
  import sync_huggingface # noqa: E402
26
  import validate_graph_artifacts as vga # noqa: E402
27
  from ctx import dashboard_entities # noqa: E402
28
+ from ctx.core.graph import release_artifacts # noqa: E402
29
  from ctx.core.wiki import wiki_queue_worker # noqa: E402
30
  from ctx.utils._secret_scan import find_inline_secret_arg # noqa: E402
31
 
 
226
 
227
 
228
  @pytest.mark.parametrize(
229
+ ("workflow_path", "expected_invocations"),
230
  [
231
+ (".github/workflows/huggingface-sync.yml", 1),
232
+ (".github/workflows/publish.yml", 1),
233
+ (".github/workflows/test.yml", 3),
234
  ],
235
  )
236
+ def test_graph_workflows_use_one_strict_release_manifest_resolver(
237
  workflow_path: str,
238
+ expected_invocations: int,
239
  ) -> None:
240
  workflow = (ROOT / workflow_path).read_text(encoding="utf-8")
241
+ resolver = (
242
+ "python scripts/graph_release_manifest.py hydrate --manifest graph/release-artifacts.json"
 
 
 
243
  )
244
 
245
+ assert workflow.count(resolver) == expected_invocations
246
+ assert "git lfs" not in workflow.lower()
247
+ assert "GIT_LFS_" not in workflow
 
 
 
248
 
249
 
250
+ def test_preflight_hydrates_strict_manifest_before_graph_validation() -> None:
251
+ checks, _notes = ci_preflight.select_checks(
252
+ base_ref="origin/main",
253
+ files=["graph/release-artifacts.json"],
254
+ profile="pr",
255
+ python="python",
256
+ )
257
+ names = [check.name for check in checks]
258
+ hydrate = next(check for check in checks if check.name == "hydrate graph release assets")
259
+
260
+ assert names.index("hydrate graph release assets") < names.index("graph artifact validation")
261
+ assert hydrate.argv == (
262
+ "python",
263
+ "scripts/graph_release_manifest.py",
264
+ "hydrate",
265
+ "--manifest",
266
+ "graph/release-artifacts.json",
267
+ "--repo-root",
268
+ ".",
269
  )
 
 
 
 
 
 
 
 
 
270
 
271
 
272
  def test_hf_card_export_uploads_docs_and_changelog(
 
660
  assert str(tmp_path) not in results[0]["path"]
661
 
662
 
663
+ def test_release_manifest_hash_probe_does_not_full_read_artifact(
664
  monkeypatch: Any,
665
  tmp_path: Path,
666
  ) -> None:
 
673
 
674
  monkeypatch.setattr(Path, "read_bytes", fail_read_bytes)
675
 
676
+ assert release_artifacts.file_sha256_and_size(artifact) == (
677
+ sha256(b"hydrated graph payload").hexdigest(),
678
+ len(b"hydrated graph payload"),
679
+ )
src/tests/test_update_repo_stats.py CHANGED
@@ -11,6 +11,7 @@ import pytest
11
  sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
12
 
13
  import update_repo_stats as urs # noqa: E402
 
14
 
15
 
16
  def _add_bytes(tf: tarfile.TarFile, name: str, body: bytes) -> None:
@@ -65,6 +66,27 @@ def _write_graph_stats_sidecar(
65
  )
66
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  def test_tarball_stats_only_trust_safe_regular_members(
69
  tmp_path: Path,
70
  monkeypatch: pytest.MonkeyPatch,
@@ -167,6 +189,28 @@ def test_graph_artifact_stats_sidecar_rejects_size_drift(
167
  assert urs._read_graph_artifact_stats() is None
168
 
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  def test_read_graph_stats_prefers_artifact_sidecar_without_tarball_scan(
171
  tmp_path: Path,
172
  monkeypatch: pytest.MonkeyPatch,
@@ -446,17 +490,7 @@ def test_published_inventory_prose_uses_exact_graph_counts(
446
  ) -> None:
447
  graph_dir = tmp_path / "graph"
448
  graph_dir.mkdir()
449
- (graph_dir / "wiki-graph.tar.gz").write_text(
450
- "\n".join(
451
- (
452
- "version https://git-lfs.github.com/spec/v1",
453
- "oid sha256:" + ("a" * 64),
454
- f"size {314 * 1024 * 1024}",
455
- "",
456
- )
457
- ),
458
- encoding="utf-8",
459
- )
460
  text = "\n".join(
461
  [
462
  "badge/Graph-79%2C958_nodes_/_1.8M_edges-red",
 
11
  sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
12
 
13
  import update_repo_stats as urs # noqa: E402
14
+ from ctx.core.graph import release_artifacts # noqa: E402
15
 
16
 
17
  def _add_bytes(tf: tarfile.TarFile, name: str, body: bytes) -> None:
 
66
  )
67
 
68
 
69
+ def _write_graph_release_manifest(root: Path, *, full_size: int) -> None:
70
+ artifacts = tuple(
71
+ release_artifacts.GraphReleaseArtifact(
72
+ path=path,
73
+ asset_name=asset_name,
74
+ size=full_size if path == "graph/wiki-graph.tar.gz" else 1,
75
+ sha256="a" * 64,
76
+ hydrate=hydrate,
77
+ )
78
+ for path, asset_name, hydrate in release_artifacts.GRAPH_RELEASE_ARTIFACT_SPECS
79
+ )
80
+ release_artifacts.write_manifest(
81
+ root / "graph" / "release-artifacts.json",
82
+ release_artifacts.GraphReleaseManifest(
83
+ repository="stevesolun/ctx",
84
+ source_release_tag="v1.0.21",
85
+ artifacts=artifacts,
86
+ ),
87
+ )
88
+
89
+
90
  def test_tarball_stats_only_trust_safe_regular_members(
91
  tmp_path: Path,
92
  monkeypatch: pytest.MonkeyPatch,
 
189
  assert urs._read_graph_artifact_stats() is None
190
 
191
 
192
+ def test_graph_artifact_stats_use_manifest_when_archive_is_not_checked_in(
193
+ tmp_path: Path,
194
+ monkeypatch: pytest.MonkeyPatch,
195
+ ) -> None:
196
+ monkeypatch.setattr(urs, "REPO_ROOT", tmp_path)
197
+ _write_graph_stats_sidecar(
198
+ tmp_path,
199
+ {"nodes": 100, "edges": 200, "skills": 30},
200
+ file_size=4,
201
+ artifact_size=4,
202
+ )
203
+ _write_graph_release_manifest(tmp_path, full_size=4)
204
+ (tmp_path / "graph" / "wiki-graph.tar.gz").unlink()
205
+
206
+ stats = urs._read_graph_artifact_stats()
207
+
208
+ assert stats is not None
209
+ assert stats["nodes"] == 100
210
+ assert stats["edges"] == 200
211
+ assert stats["skills"] == 30
212
+
213
+
214
  def test_read_graph_stats_prefers_artifact_sidecar_without_tarball_scan(
215
  tmp_path: Path,
216
  monkeypatch: pytest.MonkeyPatch,
 
490
  ) -> None:
491
  graph_dir = tmp_path / "graph"
492
  graph_dir.mkdir()
493
+ _write_graph_release_manifest(tmp_path, full_size=314 * 1024 * 1024)
 
 
 
 
 
 
 
 
 
 
494
  text = "\n".join(
495
  [
496
  "badge/Graph-79%2C958_nodes_/_1.8M_edges-red",
src/tests/test_validate_graph_artifacts.py CHANGED
@@ -1697,20 +1697,20 @@ def test_validator_default_floors_match_preflight_contract() -> None:
1697
  assert values["--min-semantic-edges"] == str(DEFAULT_MIN_SEMANTIC_EDGES)
1698
 
1699
 
1700
- def test_graph_only_workflow_uses_release_cache_or_targeted_lfs() -> None:
1701
  workflow = yaml.safe_load(Path(".github/workflows/test.yml").read_text(encoding="utf-8"))
1702
  steps = workflow["jobs"]["graph-check"]["steps"]
1703
  resolve_step = next(
1704
  step
1705
  for step in steps
1706
- if step.get("name") == "Resolve graph artifacts from release assets or targeted LFS"
1707
  )
1708
- script = resolve_step["run"]
 
 
 
1709
 
1710
- assert "release_asset_wait_seconds = 300" in script
1711
- assert "while True:" in script
1712
- assert "Waiting for matching release asset" in script
1713
- assert "time.sleep(release_asset_poll_seconds)" in script
1714
- assert "Pointer for {path_name} is not in release cache" in script
1715
- assert '"git", "lfs", "pull", "--include", path_name' in script
1716
- assert "verify_hydrated_file(graph_tar, expected_oid, expected_size)" in script
 
1697
  assert values["--min-semantic-edges"] == str(DEFAULT_MIN_SEMANTIC_EDGES)
1698
 
1699
 
1700
+ def test_graph_only_workflow_uses_exact_release_manifest_resolver() -> None:
1701
  workflow = yaml.safe_load(Path(".github/workflows/test.yml").read_text(encoding="utf-8"))
1702
  steps = workflow["jobs"]["graph-check"]["steps"]
1703
  resolve_step = next(
1704
  step
1705
  for step in steps
1706
+ if step.get("name") == "Resolve graph artifacts from exact release manifest"
1707
  )
1708
+ validate_step = next(
1709
+ step for step in steps if step.get("name") == "Validate shipped graph artifacts"
1710
+ )
1711
+ names = [step.get("name") for step in steps]
1712
 
1713
+ assert resolve_step["run"].strip() == (
1714
+ "python scripts/graph_release_manifest.py hydrate --manifest graph/release-artifacts.json"
1715
+ )
1716
+ assert names.index(resolve_step["name"]) < names.index(validate_step["name"])
 
 
 
src/tests/test_workflow_lfs_caps.py CHANGED
@@ -3,45 +3,79 @@ from __future__ import annotations
3
  from pathlib import Path
4
 
5
  import pytest
 
6
 
7
  ROOT = Path(__file__).resolve().parents[2]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
- def _resolve_script(workflow_path: str) -> str:
11
- workflow = (ROOT / workflow_path).read_text(encoding="utf-8")
12
- start = workflow.index("def hydrate_from_lfs")
13
- end = workflow.index(" PY", start)
14
- return workflow[start:end]
15
-
16
-
17
- @pytest.mark.parametrize(
18
- "workflow_path",
19
- [
20
- ".github/workflows/huggingface-sync.yml",
21
- ".github/workflows/publish.yml",
22
- ".github/workflows/test.yml",
23
- ],
24
- )
25
- def test_targeted_lfs_fallback_checks_pointer_size_before_pull(workflow_path: str) -> None:
26
  workflow = (ROOT / workflow_path).read_text(encoding="utf-8")
27
- script = _resolve_script(workflow_path)
28
 
29
- assert '"graph/wiki-graph.tar.gz": 350_000_000' in workflow
30
- assert '"graph/wiki-graph-runtime.tar.gz": 150_000_000' in workflow
31
- size_check = script.index("if expected_size > max_size:")
32
- lfs_pull = script.index('["git", "lfs", "pull", "--include", path_name, "--exclude", ""]')
33
- missing_cap_check = script.index("no size cap configured")
34
 
35
- assert "max_size = max_lfs_fallback_sizes.get(path_name)" in script
36
- assert missing_cap_check < lfs_pull
37
- assert "pointer size {expected_size} exceeds cap {max_size}" in script
38
- assert size_check < lfs_pull
 
 
39
 
 
 
 
 
40
 
41
- def test_huggingface_sync_catalog_lfs_fallback_has_explicit_cap() -> None:
42
- workflow = (ROOT / ".github" / "workflows" / "huggingface-sync.yml").read_text(encoding="utf-8")
43
 
44
- assert '"graph/skills-sh-catalog.json.gz": 15_000_000' in workflow
45
- assert workflow.index('"graph/skills-sh-catalog.json.gz": 15_000_000') < workflow.index(
46
- 'hydrate_from_release("graph/skills-sh-catalog.json.gz", 1_000_000)'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  )
 
3
  from pathlib import Path
4
 
5
  import pytest
6
+ import yaml # type: ignore[import-untyped]
7
 
8
  ROOT = Path(__file__).resolve().parents[2]
9
+ WORKFLOW_STEPS = {
10
+ ".github/workflows/huggingface-sync.yml": (
11
+ "sync",
12
+ "Hydrate required graph artifacts from exact release manifest",
13
+ "Set up Python",
14
+ ),
15
+ ".github/workflows/publish.yml": (
16
+ "build",
17
+ "Resolve release graph artifacts from exact release manifest",
18
+ "Validate release graph artifacts",
19
+ ),
20
+ ".github/workflows/test.yml": (
21
+ "graph-check",
22
+ "Resolve graph artifacts from exact release manifest",
23
+ "Validate shipped graph artifacts",
24
+ ),
25
+ }
26
+ RESOLVER_COMMAND = (
27
+ "python scripts/graph_release_manifest.py hydrate --manifest graph/release-artifacts.json"
28
+ )
29
 
30
 
31
+ def _workflow_steps(workflow_path: str) -> list[dict[str, object]]:
32
+ job_name, _, _ = WORKFLOW_STEPS[workflow_path]
33
+ workflow = yaml.safe_load((ROOT / workflow_path).read_text(encoding="utf-8"))
34
+ steps = workflow["jobs"][job_name]["steps"]
35
+ assert isinstance(steps, list)
36
+ return steps
37
+
38
+
39
+ @pytest.mark.parametrize("workflow_path", WORKFLOW_STEPS)
40
+ def test_graph_workflows_have_no_git_lfs_dependency(workflow_path: str) -> None:
 
 
 
 
 
 
41
  workflow = (ROOT / workflow_path).read_text(encoding="utf-8")
 
42
 
43
+ assert "git lfs" not in workflow.lower()
44
+ assert "GIT_LFS_" not in workflow
45
+ assert "git-lfs.github.com" not in workflow
46
+ assert "targeted LFS" not in workflow
47
+
48
 
49
+ @pytest.mark.parametrize("workflow_path", WORKFLOW_STEPS)
50
+ def test_graph_workflows_use_shared_exact_manifest_resolver(workflow_path: str) -> None:
51
+ _, step_name, _ = WORKFLOW_STEPS[workflow_path]
52
+ steps = _workflow_steps(workflow_path)
53
+ step = next(item for item in steps if item.get("name") == step_name)
54
+ run = str(step["run"])
55
 
56
+ assert RESOLVER_COMMAND in run
57
+ assert run.count("scripts/graph_release_manifest.py") == 1
58
+ assert "--manifest graph/release-artifacts.json" in run
59
+ assert "git" not in run.lower()
60
 
 
 
61
 
62
+ @pytest.mark.parametrize("workflow_path", WORKFLOW_STEPS)
63
+ def test_graph_workflows_resolve_before_consuming_artifacts(workflow_path: str) -> None:
64
+ _, resolver_name, consumer_name = WORKFLOW_STEPS[workflow_path]
65
+ names = [str(step.get("name", "")) for step in _workflow_steps(workflow_path)]
66
+
67
+ assert names.index(resolver_name) < names.index(consumer_name)
68
+
69
+
70
+ def test_huggingface_hydration_keeps_canonical_full_sync_guard() -> None:
71
+ steps = _workflow_steps(".github/workflows/huggingface-sync.yml")
72
+ step = next(
73
+ item
74
+ for item in steps
75
+ if item.get("name") == "Hydrate required graph artifacts from exact release manifest"
76
+ )
77
+
78
+ assert step["if"] == (
79
+ "${{ env.HF_TOKEN != '' && github.repository == 'stevesolun/ctx' "
80
+ "&& steps.scope.outputs.sync_mode == 'full' }}"
81
  )
src/update_repo_stats.py CHANGED
@@ -6,9 +6,9 @@ Run by the pre-commit hook so README/docs badges and inline counts never drift
6
  from reality. Reads only committed files and a live pytest collection.
7
 
8
  Sources of truth:
9
- - graph/wiki-graph.tar.gz -> graph/report/entity counts
 
10
  - scripts/ci_preflight.py GRAPH_VALIDATE_ARGS -> exact release fallback
11
- - graph/wiki-graph-runtime.tar.gz -> runtime graph/report counts
12
  - graph/communities.json -> current community export
13
  - graph/skills-sh-catalog.json.gz -> hydrated skill body counts
14
  - pytest --collect-only -q -> test inventory count
@@ -134,6 +134,19 @@ def _int_from_json(value: object) -> int | None:
134
  return None
135
 
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  def _read_graph_artifact_stats() -> dict[str, int | None] | None:
138
  """Read the shipped graph stats sidecar after checking artifact identity.
139
 
@@ -145,7 +158,7 @@ def _read_graph_artifact_stats() -> dict[str, int | None] | None:
145
  sidecar = graph_dir / _GRAPH_STATS_SIDECAR
146
  tarball = graph_dir / "wiki-graph.tar.gz"
147
  promotion = graph_dir / "wiki-graph.tar.gz.promotion.json"
148
- if not sidecar.exists() or not tarball.exists():
149
  return None
150
  try:
151
  payload = json.loads(sidecar.read_text(encoding="utf-8"))
@@ -157,7 +170,15 @@ def _read_graph_artifact_stats() -> dict[str, int | None] | None:
157
  expected_sha = str(artifact.get("sha256") or "").strip().lower()
158
  if expected_size is None or len(expected_sha) != 64:
159
  return None
160
- if tarball.stat().st_size != expected_size:
 
 
 
 
 
 
 
 
161
  return None
162
  if promotion.exists():
163
  promotion_payload = json.loads(promotion.read_text(encoding="utf-8"))
@@ -490,14 +511,14 @@ def read_graph_stats() -> dict:
490
  Priority:
491
  1. ``graph/wiki-graph-stats.json`` — the checked sidecar for the
492
  shipped graph artifact. This keeps docs/About updates fast while
493
- still tying counts to the promoted tarball hash and size.
494
- 2. ``graph/wiki-graph.tar.gz`` — the tarball that ships in
495
- releases. Pinned and canonical, but slow to enumerate.
496
  3. ``scripts/ci_preflight.py`` graph contract counts — fallback
497
- when a source checkout has not downloaded the release tarball.
498
  4. ``~/.claude/skill-wiki/graphify-out/graph.json`` — the user's
499
  live wiki. Used only when the tarball isn't present (e.g. a
500
- bare clone without the release asset downloaded).
501
 
502
  Without this priority the pre-commit hook can silently publish stale
503
  contract numbers or whatever the user last re-graphified instead of
@@ -754,29 +775,16 @@ def format_edges(n: int) -> str:
754
 
755
 
756
  def _full_wiki_tarball_mib() -> int | None:
757
- """Return the shipped full wiki tarball MiB, following Git LFS pointers."""
 
 
 
758
  tarball = REPO_ROOT / "graph" / "wiki-graph.tar.gz"
759
  if not tarball.exists():
760
  return None
761
- size = _git_lfs_pointer_size(tarball)
762
- if size is None:
763
- size = tarball.stat().st_size
764
- return round(size / (1024 * 1024))
765
-
766
-
767
- def _git_lfs_pointer_size(path: Path) -> int | None:
768
- try:
769
- if path.stat().st_size > 1024:
770
- return None
771
- text = path.read_text(encoding="utf-8", errors="replace")
772
- except OSError:
773
- return None
774
- if not text.startswith("version https://git-lfs.github.com/spec/v1\n"):
775
- return None
776
- match = re.search(r"^size (\d+)$", text, re.MULTILINE)
777
- if match is None:
778
  return None
779
- return int(match.group(1))
780
 
781
 
782
  Replacement = tuple[re.Pattern[str], str]
 
6
  from reality. Reads only committed files and a live pytest collection.
7
 
8
  Sources of truth:
9
+ - graph/release-artifacts.json -> exact release asset identities
10
+ - graph/wiki-graph-stats.json -> graph/report/entity counts
11
  - scripts/ci_preflight.py GRAPH_VALIDATE_ARGS -> exact release fallback
 
12
  - graph/communities.json -> current community export
13
  - graph/skills-sh-catalog.json.gz -> hydrated skill body counts
14
  - pytest --collect-only -q -> test inventory count
 
134
  return None
135
 
136
 
137
+ def _release_manifest_artifact_identity(path: str) -> tuple[str, int] | None:
138
+ manifest_path = REPO_ROOT / "graph" / "release-artifacts.json"
139
+ if not manifest_path.exists():
140
+ return None
141
+ try:
142
+ from ctx.core.graph.release_artifacts import load_manifest
143
+
144
+ artifact = load_manifest(manifest_path).artifact_for_path(path)
145
+ except (ImportError, KeyError, ValueError):
146
+ return None
147
+ return artifact.sha256, artifact.size
148
+
149
+
150
  def _read_graph_artifact_stats() -> dict[str, int | None] | None:
151
  """Read the shipped graph stats sidecar after checking artifact identity.
152
 
 
158
  sidecar = graph_dir / _GRAPH_STATS_SIDECAR
159
  tarball = graph_dir / "wiki-graph.tar.gz"
160
  promotion = graph_dir / "wiki-graph.tar.gz.promotion.json"
161
+ if not sidecar.exists():
162
  return None
163
  try:
164
  payload = json.loads(sidecar.read_text(encoding="utf-8"))
 
170
  expected_sha = str(artifact.get("sha256") or "").strip().lower()
171
  if expected_size is None or len(expected_sha) != 64:
172
  return None
173
+ manifest_identity = _release_manifest_artifact_identity("graph/wiki-graph.tar.gz")
174
+ if manifest_identity is not None and manifest_identity != (expected_sha, expected_size):
175
+ return None
176
+ if tarball.exists():
177
+ if tarball.is_symlink() or not tarball.is_file():
178
+ return None
179
+ if tarball.stat().st_size != expected_size:
180
+ return None
181
+ elif manifest_identity is None:
182
  return None
183
  if promotion.exists():
184
  promotion_payload = json.loads(promotion.read_text(encoding="utf-8"))
 
511
  Priority:
512
  1. ``graph/wiki-graph-stats.json`` — the checked sidecar for the
513
  shipped graph artifact. This keeps docs/About updates fast while
514
+ still tying counts to the release manifest's exact hash and size.
515
+ 2. ``graph/wiki-graph.tar.gz`` — the release-manifest-pinned tarball
516
+ when it has been hydrated locally. Canonical but slow to enumerate.
517
  3. ``scripts/ci_preflight.py`` graph contract counts — fallback
518
+ when a source checkout has not hydrated the release tarball.
519
  4. ``~/.claude/skill-wiki/graphify-out/graph.json`` — the user's
520
  live wiki. Used only when the tarball isn't present (e.g. a
521
+ bare clone without the release asset hydrated).
522
 
523
  Without this priority the pre-commit hook can silently publish stale
524
  contract numbers or whatever the user last re-graphified instead of
 
775
 
776
 
777
  def _full_wiki_tarball_mib() -> int | None:
778
+ """Return the full release wiki tarball size from its pinned manifest."""
779
+ identity = _release_manifest_artifact_identity("graph/wiki-graph.tar.gz")
780
+ if identity is not None:
781
+ return round(identity[1] / (1024 * 1024))
782
  tarball = REPO_ROOT / "graph" / "wiki-graph.tar.gz"
783
  if not tarball.exists():
784
  return None
785
+ if tarball.is_symlink() or not tarball.is_file():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
  return None
787
+ return round(tarball.stat().st_size / (1024 * 1024))
788
 
789
 
790
  Replacement = tuple[re.Pattern[str], str]