Commons ratified V1 2026-08-02 and executed it at `54e0ec7`; verified
against their tree rather than taken on report. ingest-spec.md:217 now
defines `generated` as `{ by: process:okf-ingest, at: <ingested_at> }`,
unquoted, `at` repeating `ingested_at` verbatim. `generated: true` no
longer appears in the spec.
`DEFAULT` states commons' §5 layer, so its stamp is theirs to decide.
`DEFAULT.ownership` gains the actor; the four goldens this repo's plan
named in advance were regenerated by RUNNING the materializer, each on
its own case's `ingested-at.txt`. The v0.2 golden was untouched, as
predicted -- it has carried the O2 form since D5.
Not a migration onto OKF v0.2: `DEFAULT` stays v0.1 on every axis
upstream owns and still emits no `sources`. Commons' spec and the Google
version are independent axes, and comments that narrated them as one
were rewritten rather than left to mislead. README and CLAUDE.md said
the additive rule without that boundary, which would have told a
consumer their DEFAULT bytes can never move; both now state it.
V-A3 is amended, not dropped. `DEFAULT` must OWN the mapping it now
writes -- a profile refusing its own output fires the collision gate on
files its own previous run wrote -- while a mapping naming a foreign
actor, or §7's `human:` actor on curated content, stays unowned. That
half is what carried the safety and it is asserted directly.
§11's stamp-integrity condition moved with the value: the forgeable
stamp was `true` and is now the mapping naming the ingest actor. The
defence was never the value -- the §3 scan globs `ingest-*.md`, so a
Door C import is unreachable however well it forges. Second spoof test
added; both were hand-mutated (glob widened to `*.md`) to confirm they
can fail.
The characterization test derived its foreign-stamp fixture from the
literal `generated: true`, which V1 leaves without a referent -- a
silent no-op waiting to happen. It now derives the needle from the
profile and asserts the substitution occurred.
Door B is deliberately untouched: not the ingest-spec's, marker is
`generated` + `source_file`, disjoint from Door A's `ingest_manifest`,
and the divergence predates V1.
Nothing released or notified. The pilot set pins `v0.5.0a2`, not `main`,
so this is invisible to portfolio-optimiser's freeze and demo; the
consumer exposure report is owed at the release that carries this.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwcjUXbKySLbEG5WqTNkta
133 lines
5.7 KiB
Python
133 lines
5.7 KiB
Python
"""The remaining load-bearing seams of the §11 table, plus the public API.
|
|
|
|
Every seam in the spec §11 table has one named test that MUST fail when its
|
|
seam is detached (verified by hand-mutation, noted per docstring):
|
|
|
|
| Seam | Named test |
|
|
|---|---|
|
|
| Provenance stamping | test_provenance_layer_on_every_generated_file (here) |
|
|
| Navigability | test_every_generated_file_reachable_via_index_links (here) |
|
|
| Verdict reservation | test_verdict_okf_type_rejected (test_manifest.py) |
|
|
| Re-ingest layer safety | test_promoted_verdict_and_its_link_survive_reingest (test_index.py) |
|
|
| Golden regression | test_golden_case_byte_for_byte (test_golden.py) |
|
|
| Network gate | test_network_gate_blocks_before_any_transport_call (test_http_connector.py) |
|
|
|
|
(The spec-integrity seam belongs to commons, which owns the spec.)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from llm_ingestion_okf.materialize import materialize_bundle
|
|
|
|
INGESTED_AT = "2026-07-16T12:00:00Z"
|
|
|
|
# Independent §7 parsing — deliberately NOT the library's own frontmatter
|
|
# parser, so a symmetric render/parse defect cannot mask a missing layer.
|
|
_FM_LINE = re.compile(r"^(?P<key>[a-z_]+): (?P<value>.*)$")
|
|
_INDEX_LINK = re.compile(r"^- \[[^\]]*\]\((?P<target>[^)]+)\)$", re.MULTILINE)
|
|
|
|
|
|
def parse_frontmatter_independently(path: Path) -> dict[str, str]:
|
|
lines = path.read_text(encoding="utf-8").split("\n")
|
|
assert lines[0] == "---", f"{path.name} does not start with a frontmatter block"
|
|
frontmatter: dict[str, str] = {}
|
|
for line in lines[1:]:
|
|
if line == "---":
|
|
return frontmatter
|
|
match = _FM_LINE.match(line)
|
|
assert match, f"malformed frontmatter line in {path.name}: {line!r}"
|
|
frontmatter[match.group("key")] = match.group("value")
|
|
raise AssertionError(f"{path.name} frontmatter block never closes")
|
|
|
|
|
|
def materialized_bundle(tmp_path: Path) -> tuple[Path, tuple[Path, ...]]:
|
|
data: dict[str, Any] = {
|
|
"manifest_version": 1,
|
|
"source": {"type": "file", "id": "catalogue-1", "root": "data"},
|
|
"bundle_summary": "A test bundle.",
|
|
"extractions": [
|
|
{
|
|
"id": "orders",
|
|
"title": "Orders",
|
|
"query": "orders.csv",
|
|
"okf_type": "dataset",
|
|
"max_rows": 10,
|
|
},
|
|
{
|
|
"id": "refunds",
|
|
"title": "Refunds",
|
|
"query": "refunds.csv",
|
|
"okf_type": "dataset",
|
|
"max_rows": 10,
|
|
},
|
|
],
|
|
}
|
|
src = tmp_path / "src"
|
|
(src / "data").mkdir(parents=True)
|
|
(src / "data" / "orders.csv").write_text("a\n1\n", encoding="utf-8", newline="")
|
|
(src / "data" / "refunds.csv").write_text("b\n2\n", encoding="utf-8", newline="")
|
|
manifest_path = src / "manifest.json"
|
|
manifest_path.write_text(json.dumps(data), encoding="utf-8")
|
|
bundle = tmp_path / "bundle"
|
|
result = materialize_bundle(manifest_path, bundle, INGESTED_AT)
|
|
return bundle, result.written
|
|
|
|
|
|
def test_provenance_layer_on_every_generated_file(tmp_path: Path) -> None:
|
|
"""Load-bearing (spec §11, seam: provenance stamping).
|
|
|
|
MUST fail when a generated file no longer carries the §7 layer.
|
|
Hand-mutation check 2026-07-16: dropping any of the five §7 keys from
|
|
_render_concept_file turns this test red.
|
|
|
|
`generated` is spelled out here rather than read from the profile, for the
|
|
same reason the frontmatter parser is: a seam that asks the library what it
|
|
should have written cannot catch the library writing the wrong thing. §7
|
|
fixes both sub-keys — the actor is the constant `process:okf-ingest`, and
|
|
`at` repeats `ingested_at` verbatim — so the expected value is derivable by
|
|
hand, which is what makes stating it independently possible at all.
|
|
"""
|
|
_, written = materialized_bundle(tmp_path)
|
|
assert written
|
|
for path in written:
|
|
frontmatter = parse_frontmatter_independently(path)
|
|
assert frontmatter["source_system"] == "catalogue-1"
|
|
assert frontmatter["source_query"]
|
|
assert frontmatter["ingested_at"] == INGESTED_AT
|
|
assert re.fullmatch(r"manifest@[0-9a-f]{16}", frontmatter["ingest_manifest"])
|
|
assert frontmatter["generated"] == f"{{ by: process:okf-ingest, at: {INGESTED_AT} }}"
|
|
|
|
|
|
def test_every_generated_file_reachable_via_index_links(tmp_path: Path) -> None:
|
|
"""Load-bearing (spec §11, seam: navigability).
|
|
|
|
Navigation follows ONLY index cross-links — a generated concept file
|
|
without an index link is unreachable, so every written file must have a
|
|
link whose target resolves. Hand-mutation check 2026-07-16: skipping the
|
|
_link_in_index call in materialize_bundle turns this test red.
|
|
"""
|
|
bundle, written = materialized_bundle(tmp_path)
|
|
index = (bundle / "index.md").read_text(encoding="utf-8")
|
|
targets = {match.group("target") for match in _INDEX_LINK.finditer(index)}
|
|
for target in targets:
|
|
assert (bundle / target).is_file(), f"index link target {target!r} does not resolve"
|
|
for path in written:
|
|
assert path.name in targets, f"generated file {path.name!r} has no index link"
|
|
|
|
|
|
def test_public_api_importable_from_package_root() -> None:
|
|
"""The library's public surface: one entry point plus the typed errors."""
|
|
import llm_ingestion_okf as pkg
|
|
|
|
assert callable(pkg.materialize_bundle)
|
|
assert issubclass(pkg.ManifestError, pkg.IngestError)
|
|
assert issubclass(pkg.SourceError, pkg.IngestError)
|
|
assert issubclass(pkg.RenderError, pkg.IngestError)
|
|
assert issubclass(pkg.MaterializationError, pkg.IngestError)
|
|
assert issubclass(pkg.NetworkGateError, pkg.IngestError)
|
|
assert pkg.IngestResult is not None
|