-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_manuscript_variables.py
More file actions
109 lines (76 loc) · 4.11 KB
/
Copy pathtest_manuscript_variables.py
File metadata and controls
109 lines (76 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""Tests for the deterministic manuscript-variable producer.
Real objects only: every assertion recomputes the expected value from the live repository
and compares it against :func:`src.manuscript_variables.generate_variables`, so the
test fails if the producer drifts from the source surfaces it claims to read.
"""
from __future__ import annotations
import json
import re
import sys
from pathlib import Path
import pytest
# Import the producer by its canonical top-level name (src/ on path), matching the
# repo convention (`from pipeline.X import ...`). Importing it as `src.manuscript_variables`
# makes mypy (mypy_path=src) resolve the same file under two module names and fail.
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from manuscript_variables import generate_variables, save_variables # noqa: E402
_PROJECT_ROOT = Path(__file__).resolve().parents[2]
@pytest.fixture(scope="module")
def variables() -> dict[str, str]:
return generate_variables(_PROJECT_ROOT)
def test_all_values_are_strings(variables: dict[str, str]) -> None:
assert variables, "producer returned an empty token map"
assert all(isinstance(k, str) and isinstance(v, str) for k, v in variables.items())
def test_token_keys_are_injector_compatible(variables: dict[str, str]) -> None:
# Template injector regex: {{[A-Z][A-Z0-9_]*}}
key_re = re.compile(r"^[A-Z][A-Z0-9_]*$")
bad = [k for k in variables if not key_re.match(k)]
assert not bad, f"keys not matchable by injector regex: {bad}"
def test_minimum_token_coverage(variables: dict[str, str]) -> None:
# ISC-3: at least 20 distinct tokens.
assert len(variables) >= 20, f"only {len(variables)} tokens"
def test_determinism(variables: dict[str, str]) -> None:
# ISC-4: a second invocation yields an identical map.
again = generate_variables(_PROJECT_ROOT)
assert again == variables
def test_version_matches_pyproject(variables: dict[str, str]) -> None:
text = (_PROJECT_ROOT / "pyproject.toml").read_text(encoding="utf-8")
match = re.search(r'^\s*version\s*=\s*"([^"]+)"', text, re.MULTILINE)
assert match is not None
assert variables["GNN_VERSION"] == match.group(1)
def test_step_count_matches_step_modules(variables: dict[str, str]) -> None:
step_modules = list((_PROJECT_ROOT / "src").glob("[0-9]*_*.py"))
assert variables["GNN_STEP_COUNT"] == str(len(step_modules))
assert int(variables["GNN_STEP_COUNT"]) >= 1
def test_family_count_matches_manifest(variables: dict[str, str]) -> None:
manifest = json.loads(
(_PROJECT_ROOT / "input" / "model_family_manifest.json").read_text(
encoding="utf-8"
)
)
assert variables["GNN_FAMILY_COUNT"] == str(len(manifest["families"]))
def test_backend_count_matches_registry(variables: dict[str, str]) -> None:
registry = (_PROJECT_ROOT / "src" / "render" / "framework_registry.py").read_text(
encoding="utf-8"
)
names = re.findall(r'"name"\s*:\s*"([^"]+)"', registry)
assert variables["GNN_BACKEND_COUNT"] == str(len(names))
assert int(variables["GNN_BACKEND_COUNT"]) >= 2
def test_mcp_tool_count_matches_audit(variables: dict[str, str]) -> None:
audit = json.loads(
(_PROJECT_ROOT / "src" / "mcp" / "audit_report.json").read_text(
encoding="utf-8"
)
)
assert variables["GNN_MCP_TOOL_COUNT"] == str(audit["tools_total"])
def test_tables_are_multiline_markdown(variables: dict[str, str]) -> None:
for key in ("GNN_STEP_TABLE", "GNN_FAMILY_TABLE", "GNN_BACKEND_TABLE"):
assert "\n" in variables[key], f"{key} should be a multi-line markdown table"
assert variables[key].lstrip().startswith("|"), f"{key} should be a pipe table"
def test_license_value_is_resolved(variables: dict[str, str]) -> None:
# ISC-23 guard: config completion removes the scaffold 'TBD'/empty license.
assert variables["GNN_LICENSE"] and variables["GNN_LICENSE"] != "TBD"
def test_save_variables_roundtrip(tmp_path: Path, variables: dict[str, str]) -> None:
out = save_variables(variables, tmp_path / "vars.json")
reloaded = json.loads(out.read_text(encoding="utf-8"))
assert reloaded == variables