fix(okf): fail-closed ingest-stempel-sjekk paa YAML-1.1-sannhetsformer [skip-docs]
_carries_complete_ingest_stamp sammenlignet generated kun mot literalen "true" og
feilet AAPENT: en pinnet ingest-writer som skrev "yes"/"on" ville sluppet det
komplette eierskaps-stempelet forbi write_concept_file uten en eneste lokal diff.
_YAML_TRUE_LITERALS ({"true","yes","on"}, case-insensitivt) er naa ENESTE vokabular,
malt mot PyYAML sin safe_load-resolver; "1"/bare "y"/"n" er bevisst utelatt siden en
YAML-leser aldri leser dem som bool. Halv-stempel forblir lovlig.
RED-foerst (tests/test_ingest_stamp_fail_closed_loadbearing.py), fire mutasjoner
alle roede mot hele suiten (904 passed/5 skipped): revert til literalen "true"
(2 roede) - over-widen til aa inkludere 1/y (1 roed) - and->or paa halv-stempel
(4 roede) - detach gaten helt (4 roede).
Ordre: 20260821T152153Z-432035430-from-portfolio-optimiser
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UhxZ7XNjAFHFenWX5j9pev
This commit is contained in:
parent
56c48f6f65
commit
ed696d2650
3 changed files with 109 additions and 8 deletions
|
|
@ -326,17 +326,30 @@ class IngestStampError(ValueError):
|
|||
forged it could be silently deleted by a later ingest run."""
|
||||
|
||||
|
||||
def _carries_complete_ingest_stamp(frontmatter: dict[str, str]) -> bool:
|
||||
"""Whether ``frontmatter`` carries BOTH halves of the ingest ownership stamp: ``generated:
|
||||
true`` together with a non-empty ``ingest_manifest`` reference (ingest-spec §7).
|
||||
_YAML_TRUE_LITERALS = frozenset({"true", "yes", "on"})
|
||||
"""Every scalar a real YAML reader parses to boolean ``True`` (measured with PyYAML's ``safe_load``
|
||||
core-schema resolver: ``true``/``yes``/``on``, any case, are bool; the same resolver reads bare
|
||||
``y``/``n`` and ``1``/``0`` as string/int, never bool — so those are deliberately EXCLUDED here.
|
||||
Widening past what a YAML reader actually resolves would over-block curated content no ingest
|
||||
pipeline ever produces, on a form nothing downstream would honour as the stamp either."""
|
||||
|
||||
The test is on the COMPLETE stamp, never on the individual field names — curated content may
|
||||
legitimately carry a single provenance field, and a verbatim round-trip of one half must keep
|
||||
working. Values are compared the way ``parse_frontmatter`` yields them (line-oriented strings,
|
||||
quotes retained), so surrounding quotes and case are normalised away here."""
|
||||
|
||||
def _carries_complete_ingest_stamp(frontmatter: dict[str, str]) -> bool:
|
||||
"""Whether ``frontmatter`` carries BOTH halves of the ingest ownership stamp: a ``generated``
|
||||
value a YAML reader would read as boolean ``True`` (``_YAML_TRUE_LITERALS``) together with a
|
||||
non-empty ``ingest_manifest`` reference (ingest-spec §7).
|
||||
|
||||
FAIL-CLOSED on the value literal: the field previously matched only the exact string ``"true"``,
|
||||
so a pinned ingest writer emitting any other YAML-1.1 truthy form (``yes``, ``on``) would have
|
||||
slipped the stamp past this gate undetected — inert only by the accident of the pinned writer's
|
||||
current output, per the CLAUDE.md ingest-stamp invariant. The test is on the COMPLETE stamp,
|
||||
never on the individual field names — curated content may legitimately carry a single provenance
|
||||
field, and a verbatim round-trip of one half must keep working. Values are compared the way
|
||||
``parse_frontmatter`` yields them (line-oriented strings, quotes retained), so surrounding quotes
|
||||
and case are normalised away here."""
|
||||
generated = str(frontmatter.get("generated", "")).strip().strip('"').lower()
|
||||
manifest = str(frontmatter.get("ingest_manifest", "")).strip().strip('"')
|
||||
return generated == "true" and bool(manifest)
|
||||
return generated in _YAML_TRUE_LITERALS and bool(manifest)
|
||||
|
||||
|
||||
def write_concept_file(bundle_dir: str, name: str, frontmatter: dict[str, str], body: str) -> Path:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue