Files
rune/tests/test_spine_language.py
T
Nick d8ce21b76d
Auto-version and Release / release (push) Successful in 4s
CI Pipeline / go-surface (push) Successful in 2s
CI Pipeline / best-practices (push) Successful in 2s
CI Pipeline / documentation (push) Successful in 2s
CI Pipeline / lint (push) Successful in 38s
CI Pipeline / canary (push) Successful in 41s
CI Pipeline / gitea-offline (push) Successful in 14s
CI Pipeline / type-check (push) Successful in 30s
CI Pipeline / unit-tests (push) Successful in 4m57s
CI Pipeline / required-checks (push) Successful in 1s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Successful in 2s
deploy / deploy (push) Successful in 5m54s
fix(spine): the measured dichotomy decides — hints demoted to labeled fallbacks (#2461, Nick correction)
Nick caught the deviation: module verdicts were substring-guessed from names (memory→rust, gitea→go) with a silent rust default. Authority order now: the measured classification map (import-evidence) decides FIRST for every module; hint hits are labeled "(name hint)" so provenance is visible; unmeasured+unhinted modules are "unclassified" (12), never a guessed rust. Store rebuilt: 106 rust / 45 go measured, 33+7 hint-labeled, 23 test-infra, 12 honest unclassified. Battery 95 green (test updated to pin the authority contract).
2026-10-06 02:28:16 +01:00

144 lines
6.1 KiB
Python

"""spine_language — the #2465 doc-level transforms (T5.15 keep-green:
the new-module henxel demands these ship WITH tests; they were carved
from spine.py whose battery covered them, but the carved module is the
unit under test now)."""
from __future__ import annotations
import json
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
from rune import spine_language as sl # noqa: E402
@pytest.fixture
def doc():
return sl.new_doc()
def test_classification_sides_reads_the_measured_map():
sides = sl._classification_sides()
assert sides, "classification.json must be readable in-repo"
assert sides.get("spine") == "RUST"
assert sides.get("spine_language") == "RUST"
def test_classification_sides_degrades_to_empty_when_unreadable(tmp_path, monkeypatch):
monkeypatch.setattr(sl, "ROOT", tmp_path)
assert sl._classification_sides() == {}
def test_language_verdicts_kind_defaults(doc):
sl.add_entity(doc, id="rust-crate:cognition_core", kind="rust-crate")
sl.add_entity(doc, id="go-surface:rune-entry", kind="go-surface")
sl.add_entity(doc, id="workflow:ci.yml", kind="workflow")
sl.add_entity(doc, id="contract:BUILDER-x", kind="contract")
sl._place_languages(doc)
by = {e["id"]: e["identities"]["language"] for e in doc["entities"]}
assert by["rust-crate:cognition_core"] == "rust"
assert by["go-surface:rune-entry"] == "go"
assert by["workflow:ci.yml"] == "n/a"
assert by["contract:BUILDER-x"] == "n/a"
def test_language_verdicts_measured_authoritative_then_hints(doc):
"""Nick's dichotomy correction: the measured map decides; hints only
label UNMEASURED entities and say so; nothing silently defaults."""
sl.add_entity(doc, id="module:rune_tui", kind="module") # TUI-LAST measured
sl.add_entity(doc, id="module:spine", kind="module") # RUST measured
sl.add_entity(doc, id="module:totally_unknown_name", kind="module")
sl._place_languages(doc)
by = {e["id"]: e["identities"]["language"] for e in doc["entities"]}
assert by["module:rune_tui"] == "python-tui (Wave 6)" # from the MAP
assert by["module:spine"] == "rust" # from the MAP
assert by["module:totally_unknown_name"] == "unclassified"
def test_subsystem_language_from_member_majority(doc):
"""identity: 7 RUST / 3 GO members per classification.json → mixed with
counts carried in the verdict text (never a silent guess)."""
for m in ("behavior", "identity_anchors", "persona_definition",
"persona_gate", "prompt_sync", "voice_hybrid", "voice_injector",
"voice_sync", "voicebox", "safety_override"):
sl.add_entity(doc, id=f"module:{m}", kind="module")
sl.add_relationship(doc, type="belongs_to",
from_id=f"module:{m}", to_id="subsystem:identity",
evidence_refs=["t"])
sl.add_entity(doc, id="subsystem:identity", kind="subsystem")
sl._place_languages(doc)
e = sl.entity(doc, "subsystem:identity")
lang = e["identities"]["language"]
assert lang.startswith("mixed (rust ")
assert "go" in lang
def test_unqualified_discovery_becomes_construction_surface(doc):
"""A bare file path from a closed contract is NOT a module — provenance
preserved, kind honest, candidate stays DECLARED."""
monkey_specs = [("example", [("src/rune/audit_ledger.py",
"construction-surface", "candidate")])]
original = sl._contract_discoveries
sl._contract_discoveries = lambda: monkey_specs
try:
placed = sl._apply_contract_discoveries(doc)
finally:
sl._contract_discoveries = original
assert placed == 1
e = doc["entities"][0]
assert e["id"] == "construction-surface:src/rune/audit_ledger.py"
assert e["kind"] == "construction-surface"
assert e["maturity"] == "DECLARED"
assert e["evidence_refs"] == ["contract-discovery:example"]
def test_legacy_unqualified_module_normalized_with_edges(doc):
sl.add_entity(doc, id="src/rune/claim_audit.py", kind="module",
maturity="PRESENT",
evidence_refs=["contract-discovery:old"])
sl.add_relationship(doc, type="depends_on",
from_id="src/rune/claim_audit.py",
to_id="module:other", evidence_refs=["t"])
sl._normalize_discovery_ids(doc)
assert doc["entities"][0]["id"] == \
"construction-surface:src/rune/claim_audit.py"
assert doc["entities"][0]["kind"] == "construction-surface"
assert doc["relationships"][0]["from"] == \
"construction-surface:src/rune/claim_audit.py"
# Not in the observed set (no closed contract recorded it) → the
# unsupported PRESENT claim is demoted to DECLARED; evidence survives.
assert doc["entities"][0]["maturity"] == "DECLARED"
assert doc["entities"][0]["evidence_refs"] == ["contract-discovery:old"]
def test_discoveries_gather_reads_real_scaffold_store(tmp_path, monkeypatch):
"""The gatherer only trusts CLOSED contracts' ext.contract_quality."""
store = tmp_path / "scaffold"
store.mkdir()
doc = sl.new_doc()
sl.add_entity(doc, id="contract:C1", kind="contract",
ext={"contract_quality": {
"expected_new_observed": ["rust-crate:kernel_x"],
"candidate_corrections": [
{"entity": "suite"}]}})
sl.add_entity(doc, id="contract:C2", kind="contract",
ext={"contract_quality": {
"expected_new_observed": ["rust-crate:never"]}})
for e in doc["entities"]:
if e["id"] == "contract:C1":
e["phase"] = "closed"
if e["id"] == "contract:C2":
e["phase"] = "building"
monkeypatch.setattr(sl, "ROOT", tmp_path)
(tmp_path / "store" / "scaffold").mkdir(parents=True, exist_ok=True)
(tmp_path / "store" / "scaffold" / "current.json").write_text(
json.dumps(doc))
got = sl._contract_discoveries()
assert got == [("C1", [("rust-crate:kernel_x", "rust-crate", "observed"),
("suite", "construction-surface", "candidate")])]