Add files using upload-large-folder tool
Browse files- src/__init__.py +1 -1
- src/ctx/__init__.py +1 -1
- src/tests/test_ci_classifier.py +7 -2
- src/tests/test_ctx_init.py +83 -5
- src/tests/test_ctx_monitor.py +6 -4
- src/tests/test_validate_graph_artifacts.py +65 -0
- src/validate_graph_artifacts.py +88 -11
src/__init__.py
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
"""ctx — skill and agent recommendation for Claude Code."""
|
| 2 |
|
| 3 |
-
__version__ = "1.0.
|
|
|
|
| 1 |
"""ctx — skill and agent recommendation for Claude Code."""
|
| 2 |
|
| 3 |
+
__version__ = "1.0.1"
|
src/ctx/__init__.py
CHANGED
|
@@ -30,7 +30,7 @@ Package layout:
|
|
| 30 |
ctx.utils - low-level primitives (safe names, atomic IO)
|
| 31 |
"""
|
| 32 |
|
| 33 |
-
__version__ = "1.0.
|
| 34 |
|
| 35 |
|
| 36 |
# Public library surface — anything listed here is safe for third-
|
|
|
|
| 30 |
ctx.utils - low-level primitives (safe names, atomic IO)
|
| 31 |
"""
|
| 32 |
|
| 33 |
+
__version__ = "1.0.1"
|
| 34 |
|
| 35 |
|
| 36 |
# Public library surface — anything listed here is safe for third-
|
src/tests/test_ci_classifier.py
CHANGED
|
@@ -45,7 +45,11 @@ def test_docs_tooling_changes_are_docs_only() -> None:
|
|
| 45 |
|
| 46 |
|
| 47 |
def test_graph_artifacts_are_graph_only_not_docs_only() -> None:
|
| 48 |
-
flags = classify_paths([
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
assert flags["docs_changed"] is False
|
| 51 |
assert flags["docs_only"] is False
|
|
@@ -154,7 +158,8 @@ def test_graph_artifact_job_uses_release_asset_fallback_for_lfs_budget() -> None
|
|
| 154 |
assert "Resolve graph LFS artifacts" in workflow
|
| 155 |
assert "Git LFS download failed; trying matching prior release asset." in workflow
|
| 156 |
assert "sha256:{expected_oid} size:{expected_size}" in workflow
|
| 157 |
-
assert "Hydrated
|
|
|
|
| 158 |
assert "python src/validate_graph_artifacts.py" in workflow
|
| 159 |
assert "validating pointer metadata only" not in workflow
|
| 160 |
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
def test_graph_artifacts_are_graph_only_not_docs_only() -> None:
|
| 48 |
+
flags = classify_paths([
|
| 49 |
+
"graph/wiki-graph.tar.gz",
|
| 50 |
+
"graph/wiki-graph-runtime.tar.gz",
|
| 51 |
+
"graph/communities.json",
|
| 52 |
+
])
|
| 53 |
|
| 54 |
assert flags["docs_changed"] is False
|
| 55 |
assert flags["docs_only"] is False
|
|
|
|
| 158 |
assert "Resolve graph LFS artifacts" in workflow
|
| 159 |
assert "Git LFS download failed; trying matching prior release asset." in workflow
|
| 160 |
assert "sha256:{expected_oid} size:{expected_size}" in workflow
|
| 161 |
+
assert "Hydrated {path_name} from" in workflow
|
| 162 |
+
assert "graph/wiki-graph-runtime.tar.gz" in workflow
|
| 163 |
assert "python src/validate_graph_artifacts.py" in workflow
|
| 164 |
assert "validating pointer metadata only" not in workflow
|
| 165 |
|
src/tests/test_ctx_init.py
CHANGED
|
@@ -309,7 +309,12 @@ def test_main_with_graph_flag_installs_prebuilt_graph(
|
|
| 309 |
archive = _write_graph_archive(tmp_path)
|
| 310 |
monkeypatch.setattr(ci, "_claude_dir", lambda: claude)
|
| 311 |
monkeypatch.setattr(ci, "seed_toolboxes", lambda force=False: 0)
|
| 312 |
-
monkeypatch.setattr(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
monkeypatch.setattr(
|
| 314 |
ci,
|
| 315 |
"_download_graph_archive",
|
|
@@ -335,6 +340,9 @@ def test_main_with_graph_flag_installs_prebuilt_graph(
|
|
| 335 |
graph_json = claude / "skill-wiki" / "graphify-out" / "graph.json"
|
| 336 |
graph_payload = json.loads(graph_json.read_text(encoding="utf-8"))
|
| 337 |
assert graph_payload["graph"]["export_id"] == "test-export"
|
|
|
|
|
|
|
|
|
|
| 338 |
assert not any("ctx.core.wiki.wiki_graphify" in c for c in calls)
|
| 339 |
assert not any(c == "wiki_graphify" for call in calls for c in call)
|
| 340 |
|
|
@@ -355,12 +363,67 @@ def test_graph_install_rejects_incomplete_archive(
|
|
| 355 |
tf.add(graph_out / "graph.json", arcname="graphify-out/graph.json")
|
| 356 |
|
| 357 |
claude = tmp_path / "home"
|
| 358 |
-
monkeypatch.setattr(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
assert ci.build_graph(claude) == 1
|
| 361 |
assert not (claude / "skill-wiki" / "graphify-out" / "graph.json").exists()
|
| 362 |
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
def test_graph_install_force_prunes_stale_generated_files(
|
| 365 |
tmp_path: Path,
|
| 366 |
monkeypatch,
|
|
@@ -370,9 +433,20 @@ def test_graph_install_force_prunes_stale_generated_files(
|
|
| 370 |
stale = claude / "skill-wiki" / "entities" / "skills" / "stale.md"
|
| 371 |
stale.parent.mkdir(parents=True)
|
| 372 |
stale.write_text("# Stale\n", encoding="utf-8")
|
| 373 |
-
monkeypatch.setattr(ci, "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
-
assert ci.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
assert not stale.exists()
|
| 377 |
assert (claude / "skill-wiki" / "entities" / "skills" / "current.md").is_file()
|
| 378 |
|
|
@@ -389,7 +463,11 @@ def test_graph_install_rejects_path_traversal_archive(
|
|
| 389 |
tf.addfile(info, io.BytesIO(payload))
|
| 390 |
|
| 391 |
claude = tmp_path / "home"
|
| 392 |
-
monkeypatch.setattr(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
assert ci.build_graph(claude) == 1
|
| 395 |
assert not (tmp_path / "evil.txt").exists()
|
|
|
|
| 309 |
archive = _write_graph_archive(tmp_path)
|
| 310 |
monkeypatch.setattr(ci, "_claude_dir", lambda: claude)
|
| 311 |
monkeypatch.setattr(ci, "seed_toolboxes", lambda force=False: 0)
|
| 312 |
+
monkeypatch.setattr(
|
| 313 |
+
ci,
|
| 314 |
+
"_find_local_graph_archive",
|
| 315 |
+
lambda _install_mode="runtime": archive,
|
| 316 |
+
raising=False,
|
| 317 |
+
)
|
| 318 |
monkeypatch.setattr(
|
| 319 |
ci,
|
| 320 |
"_download_graph_archive",
|
|
|
|
| 340 |
graph_json = claude / "skill-wiki" / "graphify-out" / "graph.json"
|
| 341 |
graph_payload = json.loads(graph_json.read_text(encoding="utf-8"))
|
| 342 |
assert graph_payload["graph"]["export_id"] == "test-export"
|
| 343 |
+
assert not (
|
| 344 |
+
claude / "skill-wiki" / "entities" / "skills" / "current.md"
|
| 345 |
+
).exists()
|
| 346 |
assert not any("ctx.core.wiki.wiki_graphify" in c for c in calls)
|
| 347 |
assert not any(c == "wiki_graphify" for call in calls for c in call)
|
| 348 |
|
|
|
|
| 363 |
tf.add(graph_out / "graph.json", arcname="graphify-out/graph.json")
|
| 364 |
|
| 365 |
claude = tmp_path / "home"
|
| 366 |
+
monkeypatch.setattr(
|
| 367 |
+
ci,
|
| 368 |
+
"_find_local_graph_archive",
|
| 369 |
+
lambda _install_mode="runtime": archive,
|
| 370 |
+
)
|
| 371 |
|
| 372 |
assert ci.build_graph(claude) == 1
|
| 373 |
assert not (claude / "skill-wiki" / "graphify-out" / "graph.json").exists()
|
| 374 |
|
| 375 |
|
| 376 |
+
def test_graph_install_validation_does_not_parse_full_graph_json(
|
| 377 |
+
tmp_path: Path,
|
| 378 |
+
monkeypatch,
|
| 379 |
+
) -> None:
|
| 380 |
+
wiki = tmp_path / "wiki"
|
| 381 |
+
graph_out = wiki / "graphify-out"
|
| 382 |
+
graph_out.mkdir(parents=True)
|
| 383 |
+
(wiki / "index.md").write_text("# Wiki\n", encoding="utf-8")
|
| 384 |
+
(graph_out / "graph.json").write_text(
|
| 385 |
+
json.dumps({"graph": {"export_id": "test-export"}, "nodes": [], "links": []}),
|
| 386 |
+
encoding="utf-8",
|
| 387 |
+
)
|
| 388 |
+
(graph_out / "graph-delta.json").write_text(
|
| 389 |
+
json.dumps({"export_id": "test-export", "nodes": [], "edges": []}),
|
| 390 |
+
encoding="utf-8",
|
| 391 |
+
)
|
| 392 |
+
(graph_out / "communities.json").write_text(
|
| 393 |
+
json.dumps({"export_id": "test-export", "total_communities": 0}),
|
| 394 |
+
encoding="utf-8",
|
| 395 |
+
)
|
| 396 |
+
(graph_out / "graph-report.md").write_text(
|
| 397 |
+
"# Graph Report\n\n> Export ID: test-export\n",
|
| 398 |
+
encoding="utf-8",
|
| 399 |
+
)
|
| 400 |
+
(graph_out / "graph-export-manifest.json").write_text(
|
| 401 |
+
json.dumps({
|
| 402 |
+
"version": 1,
|
| 403 |
+
"export_id": "test-export",
|
| 404 |
+
"artifacts": {
|
| 405 |
+
"graph": "graph.json",
|
| 406 |
+
"delta": "graph-delta.json",
|
| 407 |
+
"communities": "communities.json",
|
| 408 |
+
"report": "graph-report.md",
|
| 409 |
+
},
|
| 410 |
+
}),
|
| 411 |
+
encoding="utf-8",
|
| 412 |
+
)
|
| 413 |
+
external = wiki / "external-catalogs" / "skills-sh"
|
| 414 |
+
external.mkdir(parents=True)
|
| 415 |
+
(external / "catalog.json").write_text("{}", encoding="utf-8")
|
| 416 |
+
|
| 417 |
+
def guarded_read(path: Path) -> object:
|
| 418 |
+
if path.name == "graph.json":
|
| 419 |
+
raise AssertionError("install validation must not parse full graph.json")
|
| 420 |
+
return json.loads(path.read_text(encoding="utf-8"))
|
| 421 |
+
|
| 422 |
+
monkeypatch.setattr(ci, "_read_json_file", guarded_read)
|
| 423 |
+
|
| 424 |
+
ci._validate_graph_install_tree(wiki)
|
| 425 |
+
|
| 426 |
+
|
| 427 |
def test_graph_install_force_prunes_stale_generated_files(
|
| 428 |
tmp_path: Path,
|
| 429 |
monkeypatch,
|
|
|
|
| 433 |
stale = claude / "skill-wiki" / "entities" / "skills" / "stale.md"
|
| 434 |
stale.parent.mkdir(parents=True)
|
| 435 |
stale.write_text("# Stale\n", encoding="utf-8")
|
| 436 |
+
monkeypatch.setattr(ci, "_claude_dir", lambda: claude)
|
| 437 |
+
monkeypatch.setattr(ci, "seed_toolboxes", lambda force=False: 0)
|
| 438 |
+
monkeypatch.setattr(
|
| 439 |
+
ci,
|
| 440 |
+
"_find_local_graph_archive",
|
| 441 |
+
lambda _install_mode="runtime": archive,
|
| 442 |
+
)
|
| 443 |
|
| 444 |
+
assert ci.main([
|
| 445 |
+
"--graph",
|
| 446 |
+
"--graph-install-mode", "full",
|
| 447 |
+
"--force",
|
| 448 |
+
"--model-mode", "skip",
|
| 449 |
+
]) == 0
|
| 450 |
assert not stale.exists()
|
| 451 |
assert (claude / "skill-wiki" / "entities" / "skills" / "current.md").is_file()
|
| 452 |
|
|
|
|
| 463 |
tf.addfile(info, io.BytesIO(payload))
|
| 464 |
|
| 465 |
claude = tmp_path / "home"
|
| 466 |
+
monkeypatch.setattr(
|
| 467 |
+
ci,
|
| 468 |
+
"_find_local_graph_archive",
|
| 469 |
+
lambda _install_mode="runtime": archive,
|
| 470 |
+
)
|
| 471 |
|
| 472 |
assert ci.build_graph(claude) == 1
|
| 473 |
assert not (tmp_path / "evil.txt").exists()
|
src/tests/test_ctx_monitor.py
CHANGED
|
@@ -360,7 +360,11 @@ def test_artifact_status_reads_promotion_metadata(
|
|
| 360 |
repo_graph = tmp_path / "repo-graph"
|
| 361 |
repo_graph.mkdir()
|
| 362 |
(repo_graph / "wiki-graph.tar.gz").write_bytes(b"tar")
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
monkeypatch.setattr(cm, "_repo_graph_dir", lambda: repo_graph)
|
| 365 |
(graph_dir / "graph.json.promotion.json").write_text(
|
| 366 |
json.dumps({
|
|
@@ -378,9 +382,7 @@ def test_artifact_status_reads_promotion_metadata(
|
|
| 378 |
assert status["graph_json"]["exists"] is True
|
| 379 |
assert status["graph_json"]["size"] == graph.stat().st_size
|
| 380 |
assert status["wiki_graph_tar"]["path"] == str(repo_graph / "wiki-graph.tar.gz")
|
| 381 |
-
assert status["skills_sh_catalog"]["path"] == str(
|
| 382 |
-
repo_graph / "skills-sh-catalog.json.gz",
|
| 383 |
-
)
|
| 384 |
assert status["promotion_count"] == 1
|
| 385 |
assert status["promotions"][0]["status"] == "promoted"
|
| 386 |
assert status["promotions"][0]["current_sha256"] == "new"
|
|
|
|
| 360 |
repo_graph = tmp_path / "repo-graph"
|
| 361 |
repo_graph.mkdir()
|
| 362 |
(repo_graph / "wiki-graph.tar.gz").write_bytes(b"tar")
|
| 363 |
+
runtime_catalog = (
|
| 364 |
+
fake_claude / "skill-wiki" / "external-catalogs" / "skills-sh" / "catalog.json"
|
| 365 |
+
)
|
| 366 |
+
runtime_catalog.parent.mkdir(parents=True)
|
| 367 |
+
runtime_catalog.write_text("{}", encoding="utf-8")
|
| 368 |
monkeypatch.setattr(cm, "_repo_graph_dir", lambda: repo_graph)
|
| 369 |
(graph_dir / "graph.json.promotion.json").write_text(
|
| 370 |
json.dumps({
|
|
|
|
| 382 |
assert status["graph_json"]["exists"] is True
|
| 383 |
assert status["graph_json"]["size"] == graph.stat().st_size
|
| 384 |
assert status["wiki_graph_tar"]["path"] == str(repo_graph / "wiki-graph.tar.gz")
|
| 385 |
+
assert status["skills_sh_catalog"]["path"] == str(runtime_catalog)
|
|
|
|
|
|
|
| 386 |
assert status["promotion_count"] == 1
|
| 387 |
assert status["promotions"][0]["status"] == "promoted"
|
| 388 |
assert status["promotions"][0]["current_sha256"] == "new"
|
src/tests/test_validate_graph_artifacts.py
CHANGED
|
@@ -11,6 +11,7 @@ import pytest
|
|
| 11 |
import yaml # type: ignore[import-untyped]
|
| 12 |
|
| 13 |
from validate_graph_artifacts import (
|
|
|
|
| 14 |
GraphArtifactError,
|
| 15 |
_safe_tar_name,
|
| 16 |
_scan_graph_json,
|
|
@@ -51,6 +52,59 @@ def _write_catalog(graph_dir: Path, *, converted_path: str | None = None) -> Non
|
|
| 51 |
json.dump(catalog, f)
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def _write_archive(
|
| 55 |
graph_dir: Path,
|
| 56 |
*,
|
|
@@ -150,6 +204,17 @@ def _write_archive(
|
|
| 150 |
]),
|
| 151 |
encoding="utf-8",
|
| 152 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
def test_validate_graph_artifacts_checks_catalog_paths_and_deep_graph_stats(
|
|
|
|
| 11 |
import yaml # type: ignore[import-untyped]
|
| 12 |
|
| 13 |
from validate_graph_artifacts import (
|
| 14 |
+
DEFAULT_HARNESSES,
|
| 15 |
GraphArtifactError,
|
| 16 |
_safe_tar_name,
|
| 17 |
_scan_graph_json,
|
|
|
|
| 52 |
json.dump(catalog, f)
|
| 53 |
|
| 54 |
|
| 55 |
+
def _write_runtime_archive(
|
| 56 |
+
graph_dir: Path,
|
| 57 |
+
*,
|
| 58 |
+
graph: dict[str, Any],
|
| 59 |
+
include_delta: bool = True,
|
| 60 |
+
include_report: bool = True,
|
| 61 |
+
include_manifest: bool = True,
|
| 62 |
+
delta_export_id: str = "export-test",
|
| 63 |
+
communities_export_id: str = "export-test",
|
| 64 |
+
report_export_id: str = "export-test",
|
| 65 |
+
manifest_export_id: str = "export-test",
|
| 66 |
+
) -> None:
|
| 67 |
+
with tarfile.open(graph_dir / "wiki-graph-runtime.tar.gz", "w:gz") as tf:
|
| 68 |
+
_add_text(tf, "index.md", "# Wiki\n")
|
| 69 |
+
_add_text(tf, "graphify-out/graph.json", json.dumps(graph, separators=(",", ":")))
|
| 70 |
+
if include_delta:
|
| 71 |
+
_add_text(
|
| 72 |
+
tf,
|
| 73 |
+
"graphify-out/graph-delta.json",
|
| 74 |
+
json.dumps({"export_id": delta_export_id, "nodes": [], "edges": []}),
|
| 75 |
+
)
|
| 76 |
+
_add_text(
|
| 77 |
+
tf,
|
| 78 |
+
"graphify-out/communities.json",
|
| 79 |
+
json.dumps({"export_id": communities_export_id, "total_communities": 1}),
|
| 80 |
+
)
|
| 81 |
+
if include_report:
|
| 82 |
+
_add_text(
|
| 83 |
+
tf,
|
| 84 |
+
"graphify-out/graph-report.md",
|
| 85 |
+
f"# Graph Report\n\n> Export ID: {report_export_id}\n",
|
| 86 |
+
)
|
| 87 |
+
if include_manifest:
|
| 88 |
+
_add_text(
|
| 89 |
+
tf,
|
| 90 |
+
"graphify-out/graph-export-manifest.json",
|
| 91 |
+
json.dumps({
|
| 92 |
+
"version": 1,
|
| 93 |
+
"export_id": manifest_export_id,
|
| 94 |
+
"artifacts": {
|
| 95 |
+
"graph": "graph.json",
|
| 96 |
+
"delta": "graph-delta.json",
|
| 97 |
+
"communities": "communities.json",
|
| 98 |
+
"report": "graph-report.md",
|
| 99 |
+
},
|
| 100 |
+
"counts": {"nodes": 2, "edges": 1, "communities": 1},
|
| 101 |
+
}),
|
| 102 |
+
)
|
| 103 |
+
_add_text(tf, "external-catalogs/skills-sh/catalog.json", "{}")
|
| 104 |
+
for slug in sorted(DEFAULT_HARNESSES):
|
| 105 |
+
_add_text(tf, f"entities/harnesses/{slug}.md", f"# {slug}\n")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
def _write_archive(
|
| 109 |
graph_dir: Path,
|
| 110 |
*,
|
|
|
|
| 204 |
]),
|
| 205 |
encoding="utf-8",
|
| 206 |
)
|
| 207 |
+
_write_runtime_archive(
|
| 208 |
+
graph_dir,
|
| 209 |
+
graph=graph,
|
| 210 |
+
include_delta=include_delta,
|
| 211 |
+
include_report=include_report,
|
| 212 |
+
include_manifest=include_manifest,
|
| 213 |
+
delta_export_id=delta_export_id,
|
| 214 |
+
communities_export_id=communities_export_id,
|
| 215 |
+
report_export_id=report_export_id,
|
| 216 |
+
manifest_export_id=manifest_export_id,
|
| 217 |
+
)
|
| 218 |
|
| 219 |
|
| 220 |
def test_validate_graph_artifacts_checks_catalog_paths_and_deep_graph_stats(
|
src/validate_graph_artifacts.py
CHANGED
|
@@ -49,6 +49,15 @@ _PREVIEW_HTML_FILES = (
|
|
| 49 |
"viz-python.html",
|
| 50 |
"viz-security.html",
|
| 51 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
class GraphArtifactError(RuntimeError):
|
|
@@ -236,11 +245,17 @@ def validate_graph_artifacts(
|
|
| 236 |
) -> GraphArtifactStats:
|
| 237 |
graph_dir = Path(graph_dir)
|
| 238 |
tarball = graph_dir / "wiki-graph.tar.gz"
|
|
|
|
| 239 |
catalog_path = graph_dir / "skills-sh-catalog.json.gz"
|
| 240 |
communities_path = graph_dir / "communities.json"
|
| 241 |
-
for path in (tarball, catalog_path, communities_path):
|
| 242 |
_require_real_file(path)
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
catalog = _load_gzip_json(catalog_path)
|
| 245 |
_load_json(communities_path)
|
| 246 |
skills = _catalog_skills(catalog)
|
|
@@ -269,7 +284,6 @@ def validate_graph_artifacts(
|
|
| 269 |
graph_nodes = graph_edges = graph_semantic_edges = skills_sh_nodes = 0
|
| 270 |
harness_nodes = 0
|
| 271 |
skill_pages = agent_pages = mcp_pages = harness_pages = skills_sh_converted = 0
|
| 272 |
-
expected_harnesses = DEFAULT_HARNESSES if expected_harnesses is None else expected_harnesses
|
| 273 |
export_ids: dict[str, str] = {}
|
| 274 |
manifest: dict[str, Any] | None = None
|
| 275 |
|
|
@@ -341,15 +355,7 @@ def validate_graph_artifacts(
|
|
| 341 |
f"{member.name} has {lines} lines, above limit {limit}",
|
| 342 |
)
|
| 343 |
|
| 344 |
-
required_names =
|
| 345 |
-
"index.md",
|
| 346 |
-
"graphify-out/graph.json",
|
| 347 |
-
"graphify-out/graph-delta.json",
|
| 348 |
-
"graphify-out/communities.json",
|
| 349 |
-
"graphify-out/graph-report.md",
|
| 350 |
-
"graphify-out/graph-export-manifest.json",
|
| 351 |
-
"external-catalogs/skills-sh/catalog.json",
|
| 352 |
-
}
|
| 353 |
missing_required = sorted(required_names - names)
|
| 354 |
if missing_required:
|
| 355 |
raise GraphArtifactError(f"wiki graph archive is missing: {missing_required}")
|
|
@@ -440,6 +446,77 @@ def validate_graph_artifacts(
|
|
| 440 |
return stats
|
| 441 |
|
| 442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
def _validate_graph_previews(
|
| 444 |
graph_dir: Path,
|
| 445 |
*,
|
|
|
|
| 49 |
"viz-python.html",
|
| 50 |
"viz-security.html",
|
| 51 |
)
|
| 52 |
+
_GRAPH_RUNTIME_REQUIRED_NAMES = {
|
| 53 |
+
"index.md",
|
| 54 |
+
"graphify-out/graph.json",
|
| 55 |
+
"graphify-out/graph-delta.json",
|
| 56 |
+
"graphify-out/communities.json",
|
| 57 |
+
"graphify-out/graph-report.md",
|
| 58 |
+
"graphify-out/graph-export-manifest.json",
|
| 59 |
+
"external-catalogs/skills-sh/catalog.json",
|
| 60 |
+
}
|
| 61 |
|
| 62 |
|
| 63 |
class GraphArtifactError(RuntimeError):
|
|
|
|
| 245 |
) -> GraphArtifactStats:
|
| 246 |
graph_dir = Path(graph_dir)
|
| 247 |
tarball = graph_dir / "wiki-graph.tar.gz"
|
| 248 |
+
runtime_tarball = graph_dir / "wiki-graph-runtime.tar.gz"
|
| 249 |
catalog_path = graph_dir / "skills-sh-catalog.json.gz"
|
| 250 |
communities_path = graph_dir / "communities.json"
|
| 251 |
+
for path in (tarball, runtime_tarball, catalog_path, communities_path):
|
| 252 |
_require_real_file(path)
|
| 253 |
|
| 254 |
+
expected_harnesses = DEFAULT_HARNESSES if expected_harnesses is None else expected_harnesses
|
| 255 |
+
_validate_runtime_graph_archive(
|
| 256 |
+
runtime_tarball,
|
| 257 |
+
expected_harnesses=expected_harnesses,
|
| 258 |
+
)
|
| 259 |
catalog = _load_gzip_json(catalog_path)
|
| 260 |
_load_json(communities_path)
|
| 261 |
skills = _catalog_skills(catalog)
|
|
|
|
| 284 |
graph_nodes = graph_edges = graph_semantic_edges = skills_sh_nodes = 0
|
| 285 |
harness_nodes = 0
|
| 286 |
skill_pages = agent_pages = mcp_pages = harness_pages = skills_sh_converted = 0
|
|
|
|
| 287 |
export_ids: dict[str, str] = {}
|
| 288 |
manifest: dict[str, Any] | None = None
|
| 289 |
|
|
|
|
| 355 |
f"{member.name} has {lines} lines, above limit {limit}",
|
| 356 |
)
|
| 357 |
|
| 358 |
+
required_names = _GRAPH_RUNTIME_REQUIRED_NAMES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
missing_required = sorted(required_names - names)
|
| 360 |
if missing_required:
|
| 361 |
raise GraphArtifactError(f"wiki graph archive is missing: {missing_required}")
|
|
|
|
| 446 |
return stats
|
| 447 |
|
| 448 |
|
| 449 |
+
def _validate_runtime_graph_archive(
|
| 450 |
+
tarball: Path,
|
| 451 |
+
*,
|
| 452 |
+
expected_harnesses: set[str],
|
| 453 |
+
) -> None:
|
| 454 |
+
names: set[str] = set()
|
| 455 |
+
export_ids: dict[str, str] = {}
|
| 456 |
+
manifest: dict[str, Any] | None = None
|
| 457 |
+
with tarfile.open(tarball, "r:gz") as tf:
|
| 458 |
+
for member in tf:
|
| 459 |
+
name = _safe_tar_name(member.name)
|
| 460 |
+
names.add(name)
|
| 461 |
+
if not (member.isfile() or member.isdir()):
|
| 462 |
+
raise GraphArtifactError(
|
| 463 |
+
f"runtime archive member is not a regular file/dir: {member.name}",
|
| 464 |
+
)
|
| 465 |
+
if name.endswith(".original"):
|
| 466 |
+
raise GraphArtifactError(
|
| 467 |
+
f"runtime archive contains raw backup member: {member.name}",
|
| 468 |
+
)
|
| 469 |
+
if name.endswith(".lock"):
|
| 470 |
+
raise GraphArtifactError(
|
| 471 |
+
f"runtime archive contains lock member: {member.name}",
|
| 472 |
+
)
|
| 473 |
+
if member.isfile() and name == "graphify-out/graph.json":
|
| 474 |
+
f = tf.extractfile(member)
|
| 475 |
+
if f is None:
|
| 476 |
+
raise GraphArtifactError("runtime graph.json could not be read")
|
| 477 |
+
_record_export_id(export_ids, name, _scan_graph_export_id(f))
|
| 478 |
+
elif member.isfile() and name == "graphify-out/graph-delta.json":
|
| 479 |
+
data = _read_tar_json(tf, member, name)
|
| 480 |
+
_record_export_id(export_ids, name, _export_id_from_json(data, name))
|
| 481 |
+
elif member.isfile() and name == "graphify-out/communities.json":
|
| 482 |
+
data = _read_tar_json(tf, member, name)
|
| 483 |
+
_record_export_id(export_ids, name, _export_id_from_json(data, name))
|
| 484 |
+
elif member.isfile() and name == "graphify-out/graph-export-manifest.json":
|
| 485 |
+
data = _read_tar_json(tf, member, name)
|
| 486 |
+
if not isinstance(data, dict):
|
| 487 |
+
raise GraphArtifactError(f"{name} did not contain a JSON object")
|
| 488 |
+
manifest = data
|
| 489 |
+
elif member.isfile() and name == "graphify-out/graph-report.md":
|
| 490 |
+
f = tf.extractfile(member)
|
| 491 |
+
if f is None:
|
| 492 |
+
raise GraphArtifactError(f"{member.name} could not be read")
|
| 493 |
+
_record_export_id(export_ids, name, _export_id_from_report(f.read()))
|
| 494 |
+
|
| 495 |
+
missing_required = sorted(_GRAPH_RUNTIME_REQUIRED_NAMES - names)
|
| 496 |
+
if missing_required:
|
| 497 |
+
raise GraphArtifactError(
|
| 498 |
+
f"runtime graph archive is missing: {missing_required}",
|
| 499 |
+
)
|
| 500 |
+
missing_harnesses = sorted(
|
| 501 |
+
f"entities/harnesses/{slug}.md"
|
| 502 |
+
for slug in expected_harnesses
|
| 503 |
+
if f"entities/harnesses/{slug}.md" not in names
|
| 504 |
+
)
|
| 505 |
+
if missing_harnesses:
|
| 506 |
+
raise GraphArtifactError(
|
| 507 |
+
f"runtime graph archive is missing harness pages: {missing_harnesses}",
|
| 508 |
+
)
|
| 509 |
+
manifest_export_id = _validate_graph_export_manifest(manifest, names)
|
| 510 |
+
_record_export_id(
|
| 511 |
+
export_ids,
|
| 512 |
+
"graphify-out/graph-export-manifest.json",
|
| 513 |
+
manifest_export_id,
|
| 514 |
+
)
|
| 515 |
+
if "graphify-out/graph.json" not in export_ids:
|
| 516 |
+
raise GraphArtifactError("runtime graph.json is missing export_id")
|
| 517 |
+
_validate_export_ids(export_ids, expected=manifest_export_id)
|
| 518 |
+
|
| 519 |
+
|
| 520 |
def _validate_graph_previews(
|
| 521 |
graph_dir: Path,
|
| 522 |
*,
|