fix(okf): one unquoting rule for frontmatter scalars (kø-(a)/(i))

Two rules existed. verdicts._unquote took quotes off correctly; the
bundle_context title renderer stripped only `"`. Measured before the fix:
`title: "  Spaced  "` rendered as `## concept:   Spaced  ` (the whitespace
half kø-(a) named), and `title: 'Single'` rendered its quotes verbatim —
both ordinary YAML a hand-authoring curator writes, and both reach the
agent's read-context.

The (p) defect class: a duplicated conversion drifts, and the drifted copy
decides something. Same fix shape — ONE source, owned by the module that
owns parse_frontmatter. okf.unquote_scalar is now the rule; verdicts
delegates by identity, so the structural key that _mint_id hashes is
unchanged.

The commons-owned nav-goldens could never have caught this: every golden
title is double-quoted with no inner whitespace, so both rules render them
byte-identically. That is asserted as a control, and it goes RED if a
future golden gains a discriminating title.

Load-bearing MEASURED against the whole suite, three mutations:
- weaken the renderer back to .strip('"') -> ONLY the 2 new rows red,
  643 others green (incl. nav-goldens) = it covers ground nothing did
- reintroduce a private _unquote copy in verdicts -> only the identity
  test red, 644 green (the copy is behaviourally identical TODAY, which
  is exactly why identity is the only thing that catches the class)
- (control, kø-(n)) add `import numpy` to a second src module -> the
  existing test_semretrieval_is_the_sole_numpy_importer goes red alone,
  confirming that gate is live rather than green-but-dead

638 -> 645 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DVMsih6tXx39VMyq6wJ5H7
This commit is contained in:
Kjell Tore Guttormsen 2026-08-04 21:23:18 +02:00
commit fbc7a6120a
3 changed files with 130 additions and 5 deletions

View file

@ -41,6 +41,20 @@ _COST_BASELINE = "cost-baseline.json"
_LINK_RE = re.compile(r"\]\(([^)]+\.md)\)")
def unquote_scalar(raw: str) -> str:
"""The ONE unquoting rule for a frontmatter scalar — ``parse_frontmatter`` preserves quotes
(OKF SPEC §4), so every consumer of a scalar has to take them off, and they must all take them
off the SAME way.
It lives here because this module owns ``parse_frontmatter``. It was a private copy in
``verdicts`` (structural key) while ``bundle_context`` stripped only ``"`` (rendered title) —
two rules, and the weaker one in the path that becomes the agent's read-context. Both quote
styles, and whitespace on either side of them, are ordinary YAML a hand-authoring curator
writes. Mirrors the (p) precedent: a duplicated conversion drifts, and the drifted copy decides
something. Gated by ``tests/test_frontmatter_unquote_loadbearing.py``."""
return raw.strip().strip('"').strip("'").strip()
def parse_frontmatter(path: str | Path) -> dict[str, str]:
"""Read the leading ``---``-delimited YAML frontmatter block as key:value strings.
@ -213,7 +227,7 @@ def bundle_context(bundle: Bundle, *, dimension: str | None = None) -> str:
file_dim = f.frontmatter.get("dimension")
if file_dim is not None and file_dim != dimension:
continue
title = f.frontmatter.get("title", f.name).strip('"')
title = unquote_scalar(f.frontmatter.get("title", f.name))
body = f.body.strip("\n")
sections.append(f"## {f.type or 'document'}: {title}\n\n{body}")
return "\n\n".join(s for s in sections if s.strip())

View file

@ -488,10 +488,12 @@ class VerdictFrontmatterError(ValueError):
malformed files because anyone may drop anything there."""
def _unquote(raw: str) -> str:
"""``parse_frontmatter`` preserves quotes (OKF SPEC §4); the structural fields are compared and
hashed against the IR projection's RAW JSON values, so the quotes have to come off here."""
return raw.strip().strip('"').strip("'").strip()
# ``parse_frontmatter`` preserves quotes (OKF SPEC §4); the structural fields are compared and
# hashed against the IR projection's RAW JSON values, so the quotes have to come off. DELEGATED,
# not copied: this was a private implementation while ``okf.bundle_context`` stripped only ``"``,
# and a duplicated conversion drifts (the (p) precedent). ``okf`` owns ``parse_frontmatter``, so it
# owns the unquoting rule. Gated by ``tests/test_frontmatter_unquote_loadbearing.py``.
_unquote = okf.unquote_scalar
def _parse_affected_codes(raw: str) -> frozenset[str]: