Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tools/analyze_pedagogical_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Any, Iterable, Mapping, Sequence

SCHEMA = "CONTENT_NODE_SCHEMA_v1.2"
GOSPEL_SCHEMA = "GW_CANONICAL_NODE_FILESET_v1.2"
HINT_KEYS = tuple(f"H{i}" for i in range(1, 8))
BLOCKER = "BLOCKER"
WARN = "WARN"
Expand Down Expand Up @@ -139,6 +140,21 @@ def _discover_json(roots: Sequence[str]) -> list[Path]:
return sorted(found, key=lambda p: p.as_posix())


def _recognized_node_schema(doc: Mapping[str, Any]) -> str | None:
"""Return an explicitly supported canonical node-envelope schema.

LN/PA use CONTENT_NODE_SCHEMA_v1.2 in schema_version. The independently
qualified Gospel corpus uses GW_CANONICAL_NODE_FILESET_v1.2 in schema while
preserving the same pedagogical node fields consumed below. Explicit
recognition prevents unrelated JSON from being silently reclassified.
"""
if doc.get("schema_version") == SCHEMA:
return SCHEMA
if doc.get("schema") == GOSPEL_SCHEMA:
return GOSPEL_SCHEMA
return None


def _load_schema_nodes(paths: Iterable[Path]) -> tuple[list[NodeRecord], int, Counter[str]]:
records: list[NodeRecord] = []
schema_files = 0
Expand All @@ -148,7 +164,7 @@ def _load_schema_nodes(paths: Iterable[Path]) -> tuple[list[NodeRecord], int, Co
doc = json.loads(path.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
continue
if not isinstance(doc, dict) or doc.get("schema_version") != SCHEMA:
if not isinstance(doc, dict) or _recognized_node_schema(doc) is None:
continue
nodes = doc.get("nodes")
if not isinstance(nodes, list):
Expand Down
27 changes: 27 additions & 0 deletions tools/test_analyze_pedagogical_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def _write_pack(root: Path, nodes: list[dict], *, status: str = "AUTHOR_COMPLETE
return path


def _write_gospel_pack(root: Path, nodes: list[dict]) -> Path:
path = root / "gospel-nodes.json"
path.write_text(
json.dumps(
{
"schema": "GW_CANONICAL_NODE_FILESET_v1.2",
"mission_id": "GW-T",
"node_count": len(nodes),
"nodes": nodes,
},
ensure_ascii=False,
),
encoding="utf-8",
)
return path


class PedagogicalQualityAnalyzerTests(unittest.TestCase):
def test_substantive_node_has_no_blocker(self):
with tempfile.TemporaryDirectory() as tmp:
Expand Down Expand Up @@ -154,6 +171,16 @@ def test_report_keeps_canonical_status_inventory_without_audit_promotion(self):
self.assertEqual(payload["canonical_status_counts"], {status: 1})
self.assertIn("independent audit acceptance", payload["interpretation"]["not_claimed"])

def test_gospel_canonical_envelope_is_analyzed_without_status_promotion(self):
with tempfile.TemporaryDirectory() as tmp:
_write_gospel_pack(Path(tmp), [_node("GW-T-N01")])
result = analyze([tmp])
blockers = [f for f in result.findings if f.severity == BLOCKER]
self.assertEqual(blockers, [])
self.assertEqual(result.schema_files, 1)
self.assertEqual(result.nodes_analyzed, 1)
self.assertEqual(result.canonical_status_counts, {"<unspecified>": 1})

def test_non_schema_json_is_ignored_not_reclassified(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
Expand Down
Loading