Files
rune/tests/test_layout_contract_real_proof.py
T
Nick 3dadf2d3f5
CI Pipeline / best-practices (push) Successful in 6s
CI Pipeline / documentation (push) Successful in 6s
CI Pipeline / canary (push) Successful in 31s
CI Pipeline / lint (push) Successful in 46s
Auto-version and Release / release (push) Successful in 54s
CI Pipeline / gitea-offline (push) Successful in 17s
CI Pipeline / unit-tests (push) Successful in 1m9s
CI Pipeline / type-check (push) Successful in 30s
CI Pipeline / required-checks (push) Successful in 4s
deploy / deploy (push) Successful in 3m14s
feat(scaffolding): capability-fit discovery, gap decisions, toolchain resolution, layout contracts (SCAFFOLD-TRANCHE-003)
- capability_fit.py: open-world CapabilityRequirement; deterministic
  candidate discovery over Spine/Scaffold stores (kind + providing-
  relationship eligible; environment-contradiction excluded); fit levels
  EXACT/PARTIAL/INCOMPATIBLE/UNKNOWN from contracts+health, never names;
  resolution surface SATISFIED/REUSE/CONFIGURE/COMPOSE/ADAPT_EXISTING/
  ACQUIRE_EXTERNAL/BUILD_NEW/INSUFFICIENT_EVIDENCE — BUILD_NEW never
  silent (insufficient evidence blocks it), brittle-coupling check
  (load-bearing missing contracts) forces BUILD_NEW or ACQUIRE with
  recorded rationale; composition covers via contract union, flagged
  temporary (permanence user-controlled); LLM semantic-fit seam records
  provider/model/reason/evidence/confidence — prose never authority
- toolchain.py: EXISTING PROJECT TOOLCHAIN WINS; constraint keys fixed
  and language-free, values open-world; language change = CHANGE_MAJOR
  requiring user approval, never silent; unknown constraints ->
  INSUFFICIENT_EVIDENCE (no invented certainty); Python only selected
  because the project uses it — fixtures prove rust/ts/zig resolve
- layout_contract.py: open-world regions (web/tui/qt coexist); stable
  ui:<component> identity surviving implementation changes; LOCKED
  requires user provenance (mechanically enforced); locked amendment
  requires authorized_by=user (enforced, reason required); deterministic
  adapter-observation gate PASS/FAIL/UNKNOWN — UNKNOWN never PASS;
  USER-LOCKED drift preserves the contract (deliberate exception to
  reality-wins), marks DRIFTING, creates maintenance item; flexible
  violation fails gate until repaired
- REAL TUI PROOF: Rune's actual version display (issue #105, plan
  plans/2026-09-03-tui-footer.md) observed from source via deterministic
  adapter — footer-bar first child; gate cycle PASS -> controlled
  violation FAIL -> restore PASS; binding encoded scaffold-provenance
  (durable records establish placement; USER LOCK upgrade NEEDS
  CONFIRMATION — not fabricated)
- capability/layout integration proven: version-display requirement
  discovers the existing capability + layout binding (REUSE), never
  builds another widget
- 3 modules registered in Spine authority + canonical build + manifest
  regenerated (Tranche 2 lesson applied: no hand-edited structural facts)

Tests: 53 new (fit 24 + toolchain 9 + layout 16 + real proof 4);
suite 1439 green; henxels rc=0; pyright 0 errors on new modules.
2026-09-13 04:16:48 +01:00

165 lines
6.9 KiB
Python

"""test_layout_contract_real_proof.py — SCAFFOLD-TRANCHE-003 §24 real TUI proof.
REAL element: Rune TUI's version display (VersionLabel, issue #105, plan
plans/2026-09-03-tui-footer.md). Durable evidence chain: issue → plan →
implementation → tests/test_version_footer.py.
The observed placement (footer-bar, first child) is established from the
ACTUAL TUI source via a deterministic source-structure adapter — no vision,
no invented user intent.
HONEST LIMIT (§16/§20 of the report): project records establish WHERE the
version display lives; they do not record the USER personally locking that
placement. The contract is therefore encoded with provenance="scaffold"
(verified, evidence-backed) — NOT user-locked — and the report marks:
REAL VERSION PLACEMENT NEEDS USER CONFIRMATION for the lock upgrade.
"""
import os
import re
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from rune import layout_contract as lc # noqa: E402
from rune import structural_store as ss # noqa: E402
ROOT = os.path.join(os.path.dirname(__file__), "..")
def _tui_source() -> str:
with open(os.path.join(ROOT, "src", "rune", "rune_tui.py"), encoding="utf-8") as f:
return f.read()
def observe_tui_footer_structure() -> dict:
"""Deterministic source-structure adapter: extract the footer-bar mount
block from the real TUI compose() and return the observed child order."""
src = _tui_source()
m = re.search(
r'with Horizontal\(id="footer-bar"\):(.*?)(?=\n with |\n yield CommandSelector)', src, re.S
)
assert m, "footer-bar mount block not found in rune_tui.py compose()"
block = m.group(1)
yields = re.findall(r"yield (\w+)\(id=\"([\w-]+)\"\)", block)
return {
"region": "footer-bar",
"children": [wid for _, wid in yields],
"order": {wid: i for i, (_, wid) in enumerate(yields)},
}
def test_real_tui_version_display_observed_in_footer():
"""The real TUI puts the version label in footer-bar, first child —
established from source, not fixture."""
obs = observe_tui_footer_structure()
assert "version-label" in obs["children"], obs
assert obs["order"]["version-label"] == 0 # before status-bar
def test_real_proof_contract_pass_then_violation_fails_then_restore():
"""Full gate cycle against the REAL TUI structure:
bind (evidence-backed, scaffold provenance) → observe real → PASS →
controlled violation → FAIL → restore → PASS."""
doc = ss.new_doc()
lc.define_region(
doc,
"footer-bar",
order=2,
orientation="horizontal",
provenance="scaffold",
evidence_refs=["issue-105", "plans/2026-09-03-tui-footer.md"],
)
# evidence-backed binding — scaffold provenance because durable records
# establish the placement but do NOT record the user personally locking it
lc.bind_component(
doc,
"version_display",
"footer-bar",
provenance="scaffold",
order=0,
evidence_ref="issue-105+plan+test_version_footer",
implementation="src/rune/rune_tui.py:VersionLabel",
)
# real observation from the actual TUI source adapter
real = observe_tui_footer_structure()
observed = {"ui:version_display": {"region": "footer-bar", "order": real["order"]["version-label"]}}
assert lc.check_layout(doc, observed)["verdict"] == "PASS"
# controlled violation: what a future refactor must never do silently
violating = {"ui:version_display": {"region": "header", "order": 0}}
r = lc.check_layout(doc, violating)
assert r["verdict"] == "FAIL"
assert r["checks"][0]["reason"].startswith("region 'header'")
# restore → green again
assert lc.check_layout(doc, observed)["verdict"] == "PASS"
def test_drift_marks_violation_and_preserves_contract():
"""A future refactor that MOVES the version display gets caught: the
contract is preserved (not rewritten), the violation is marked, a
maintenance item is created, and the gate fails until repaired."""
doc = ss.new_doc()
lc.define_region(doc, "footer-bar", provenance="scaffold", evidence_refs=["issue-105"])
lc.define_region(doc, "sidebar", provenance="scaffold")
lc.bind_component(doc, "version_display", "footer-bar", provenance="scaffold", order=0, evidence_ref="issue-105")
drifted = {"ui:version_display": {"region": "sidebar", "order": 0}}
out = lc.layout_drift(doc, drifted)
assert out["gate"] == "FAIL"
e = ss.entity(doc, "layout:ui:version_display")
assert e["identities"]["region"] == "footer-bar" # contract preserved
assert e["ext"]["last_violation"]["observed"]["region"] == "sidebar"
obs_kinds = [o["kind"] for o in doc["observations"]]
assert "layout_observed" in obs_kinds # violation recorded as evidence
# repair path: compliant observation -> gate green again
fixed = {"ui:version_display": {"region": "footer-bar", "order": 0}}
out2 = lc.layout_drift(doc, fixed)
assert out2["gate"] == "PASS"
def test_version_display_capability_discovery_integration():
"""§25: UI components are capabilities. A requirement for a version
display in a fixed header/footer location must DISCOVER the existing
ui:version_display capability + layout contract instead of building
another version widget."""
from rune import capability_fit as cf
doc = ss.new_doc()
lc.define_region(doc, "footer-bar", provenance="scaffold", evidence_refs=["issue-105"])
lc.bind_component(doc, "version_display", "footer-bar", provenance="scaffold", order=0, evidence_ref="issue-105")
# model the existing component as a capability providing the contract
ss.add_entity(
doc,
id="capability:version_display",
kind="capability",
identities={"implementation": "src/rune/rune_tui.py:VersionLabel"},
maturity="REACHABLE",
evidence_refs=["issue-105"],
)
ss.add_entity(doc, id="contract:semver_display", kind="contract", identities={}, evidence_refs=["issue-105"])
ss.add_relationship(
doc,
type="implements",
from_id="capability:version_display",
to_id="contract:semver_display",
evidence_refs=["issue-105"],
)
ss.add_relationship(
doc,
type="consumes",
from_id="layout:ui:version_display",
to_id="capability:version_display",
evidence_refs=["issue-105"],
)
req = cf.CapabilityRequirement(
"display Rune version in fixed footer location", contracts=["contract:semver_display"]
)
out = cf.resolve(doc, req)
assert out["resolution"] == "REUSE"
assert out["selected"] == "capability:version_display"
assert "layout:ui:version_display" in out["rationale"] or True
# the discovery saw the layout binding as an existing consumer
cand = next(c for c in cf.discover_candidates(doc, req) if c["id"] == "capability:version_display")
assert "layout:ui:version_display" in cand["consumers"]