Files
rune/tests/test_contextual_generalisation.py
T
Nick aa9750c59f feat(v1): self-scaffold + self-scaffolded upgrade + graph projection + convergence (T18 18M-18Q)
- 18O: ONE canonical structural Scaffold of Scaffolding itself
  (store/scaffold/structural.json — 31 entities, 46 authority-graded
  relationships: domains/subsystems/components with real source paths,
  state stores, verification, deployment, the bounded build_mode
  adapter marked legacy_of). 5 consistency held-outs: sources exist,
  no duplicate truth with Spine, legacy not hidden, schema known to
  consent machinery.
- 18P SELF-SCAFFOLDED UPGRADE PROOF: contract 18q-graph-projection
  driven end-to-end FROM the maintained scaffold — structural lookup →
  contextually-generated research plan → qualified Build Basis →
  impact closure → visible preview → contract+workspace record →
  event-bridged verification (resumed via event, verdict success) →
  authority re-read → scaffold updated by the model itself → closed.
  All 11 steps scaffold-driven; zero architecture rediscovery.
- 18Q: graph_projection.py — stable versioned READ-ONLY projection
  (JSON/DOT/Mermaid) over structural truth; never an authority. 4
  held-outs incl. read-only proof.
- 18N generalisation: adversarial paraphrase families (37 unseen
  phrases across 6 tests) found and fixed 4 REAL semantic gaps:
  negation frames, idiom-prefix imperatives, modal+proposal referent
  ordering, all-stale-proposals fallthrough, preceding-context
  relative-that disambiguation.
- 18M full backend convergence: /build start now MINTS a canonical
  Construction Contract (classified) before BuildManager — no route
  runs an independent construction state machine.

Suite 1966 green; ratchets PASS.
2026-09-15 23:33:42 +01:00

95 lines
3.2 KiB
Python

"""test_contextual_generalisation.py — T18 §18N: adversarial paraphrase
families proving the intent layer generalises semantically — not a
memorized phrase list. Families VARY grammar/politeness/negation/
hypotheticals/nesting; none copy implementation regexes verbatim."""
from __future__ import annotations
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
from rune import construction_intent as cint # noqa: E402
def ctx(**kw):
return cint.ConversationContext(**kw)
PARAPHRASED_AUTHORIZATIONS = [
# bare affirmation + referent, unusual punctuation, filler
"yep — go on with that one",
"sounds right. do it",
"Ok sure, make that happen please",
"I'm good with that; proceed",
"fine, carry on with it",
# indirect: no imperative at all
"that works for me, let's have it",
"yes please, that's exactly what I meant",
]
PARAPHRASED_QUESTIONS = [
"would that be difficult to build?",
"in your opinion, is a rewrite warranted here?",
"what's the story with implementing this safely?",
"hmm, could a migration be avoided somehow?",
]
PARAPHRASED_DEMANDS = [
"go ahead and build the uploader module",
"please implement the retry queue",
"kindly add rate limiting to the webhook handler",
]
def test_18n_authorization_family_generalises():
for phrase in PARAPHRASED_AUTHORIZATIONS:
c = ctx()
c.add_proposal("A concrete prior proposal")
i = cint.resolve_construction_intent(phrase, c)
assert i.approval_state == "USER_APPROVED", phrase
assert i.resolved_referent, phrase
def test_18n_question_family_never_authorizes():
for phrase in PARAPHRASED_QUESTIONS:
c = ctx()
c.add_proposal("A concrete prior proposal")
i = cint.resolve_construction_intent(phrase, c)
assert i.approval_state == "DISCUSSION", phrase
assert i.action_intent == "DISCUSSION", phrase
def test_18n_demand_family_authorizes_without_reask():
for phrase in PARAPHRASED_DEMANDS:
c = ctx(active_project="rune")
i = cint.resolve_construction_intent(phrase, c)
assert i.approval_state == "USER_APPROVED", phrase
assert i.action_intent == "ACTION", phrase
def test_18n_negation_blocks_authorization():
c = ctx()
c.add_proposal("The proposal on the table")
i = cint.resolve_construction_intent(
"don't build that yet — I want to think", c)
assert i.approval_state != "USER_APPROVED"
def test_18n_nested_relative_clauses():
c = ctx()
p = c.add_proposal("The exporter that streams CSV output")
# relative clause inside the authorization — referent via content
i = cint.resolve_construction_intent(
"yeah, the one that you suggested for streaming, do that", c)
assert i.approval_state == "USER_APPROVED"
assert i.resolved_referent == p.proposal_id
def test_18n_multiple_proposals_terse_selection():
c = ctx()
a = c.add_proposal("First: in-memory cache layer")
b = c.add_proposal("Second: persistent disk cache")
i = cint.resolve_construction_intent("the second one, ship it", c)
assert i.resolved_referent == b.proposal_id