Every fixture, test document, tool example and document now uses an invented kitchen-and-baking handbook series, written in this repository. The package's behaviour is unchanged; src/ changes are comments and help text only. - Generated fixtures are regenerated from their generators. Their structural counts are identical before and after: elements, images, rows, cells, headings, bookmarks and the witness inventory's per-document totals. The image-inbox and accounting documents are renamed kapittel-84-*. - tools/okf_accounting_gate.py: the two options that named one real corpus each are replaced by a generic, repeatable --corpus PATH with no default. Row 5 compares the PDF pair alone. Gate verdict unchanged: RED rows 2, 3, 6. - tools/okf_witness.py: the STS JSON reader for one publisher's delivery is removed, along with its three twins and five tests. The mutation harness loses W09. - docs/: 13 dated reports that documented runs on a retired reference corpus are removed, and 40 are neutralized. Dead links are removed, and no new dangling path is introduced. - The synthetic MCP-gate corpus and the residual probe words are neutral. Valgt: keep the `okf quality --fasit` bar value (the measured fraction, one corpus) and rewrite only its provenance, because the verdict stays unchanged and the number names nothing. Term check with the local list: 0 of 411 tracked files, 0 file names, 0 of 27 binary fixtures. Suite after git add: 2457 passed, 1 skipped. The base tree had 2460 passed and 2 skipped; five tests went with the JSON reader and four were added by the term check. ruff, ruff format and mypy --strict src/ are clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
164 lines
6 KiB
Python
164 lines
6 KiB
Python
"""The SEGMENTED_V1 golden: bytes, pinned.
|
|
|
|
A NEW golden directory, never an edit to the four that exist. That is how
|
|
`2504011` shipped `OKF_V0_2`'s golden -- zero bytes changed in the three that
|
|
were already there -- and it is what makes "additive" a measured claim rather
|
|
than an intention. The second test below is the measurement.
|
|
|
|
The fixture is synthetic throughout. No consumer content, no real regulatory or
|
|
procurement prose: this repository is public, and a golden is the most durable
|
|
place a leak could land.
|
|
|
|
Door B shaped, unlike the four Door A goldens: the inputs are an inbox, a
|
|
segmentation plan and a `bundle_id`, because those are exactly what a rebuild
|
|
replays. Re-materializing them into an empty directory must reproduce the
|
|
shipped tree file for file -- which is S7 stated as a fixture instead of as a
|
|
property test.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from llm_ingestion_okf.inbox import GateDecision, process_inbox
|
|
from llm_ingestion_okf.profiles import SEGMENTED_V1
|
|
from llm_ingestion_okf.segmentation import parse_segmentation_plan
|
|
|
|
EXAMPLES = Path(__file__).resolve().parents[1] / "examples"
|
|
CASE = EXAMPLES / "ingest-golden-segmented"
|
|
|
|
EXISTING_GOLDENS = (
|
|
"ingest-golden-file",
|
|
"ingest-golden-sql",
|
|
"ingest-golden-http",
|
|
"ingest-golden-okf-v0-2",
|
|
)
|
|
|
|
|
|
def gate(text: str) -> GateDecision:
|
|
return GateDecision(sanitized_text=text, disposition="warn")
|
|
|
|
|
|
def materialize(out_dir: Path) -> None:
|
|
plan = parse_segmentation_plan(json.loads((CASE / "segmentation-plan.json").read_text("utf-8")))
|
|
process_inbox(
|
|
CASE / "fixture" / "inbox",
|
|
out_dir,
|
|
(CASE / "ingested-at.txt").read_text(encoding="utf-8").strip(),
|
|
okf_type="reference",
|
|
gate=gate,
|
|
profile=SEGMENTED_V1,
|
|
root_frontmatter_values={
|
|
"bundle_id": (CASE / "bundle-id.txt").read_text(encoding="utf-8").strip()
|
|
},
|
|
segmentation=plan,
|
|
)
|
|
|
|
|
|
def tree(root: Path) -> dict[str, bytes]:
|
|
return {
|
|
path.relative_to(root).as_posix(): path.read_bytes()
|
|
for path in sorted(root.rglob("*"))
|
|
if path.is_file()
|
|
}
|
|
|
|
|
|
def test_the_golden_rematerializes_byte_for_byte(tmp_path: Path) -> None:
|
|
out_dir = tmp_path / "bundle"
|
|
materialize(out_dir)
|
|
expected = tree(CASE / "expected-bundle")
|
|
actual = tree(out_dir)
|
|
assert sorted(actual) == sorted(expected)
|
|
for name in sorted(expected):
|
|
assert actual[name] == expected[name], f"{name} diverges from the golden bytes"
|
|
|
|
|
|
def test_the_golden_covers_the_shape_the_profile_exists_for(tmp_path: Path) -> None:
|
|
# A golden that happened to be flat would pin nothing this profile adds.
|
|
expected = tree(CASE / "expected-bundle")
|
|
concepts = [name for name in expected if not name.endswith(SEGMENTED_V1.index.name)]
|
|
assert len(concepts) >= 3
|
|
assert any("/" in name for name in concepts)
|
|
assert len([name for name in expected if name.endswith(SEGMENTED_V1.index.name)]) >= 3
|
|
assert expected["index.md"].startswith(b"---\nbundle_id: ")
|
|
|
|
|
|
def test_the_four_existing_goldens_are_untouched() -> None:
|
|
# Measured against the baseline commit, not asserted. `git status` covers
|
|
# an uncommitted edit; `git diff` against the baseline covers a committed
|
|
# one -- and this voyage makes commits, so the second is the one that bites.
|
|
if not (Path(__file__).resolve().parents[1] / ".git").exists():
|
|
# A `git archive` extract is not a repository, so BOTH arms below have
|
|
# nothing to ask: each measures the CHECKOUT with `git`, and there is
|
|
# none. Measured 2026-09-19, this was the single failure of the whole
|
|
# suite run from a clean extract, and it read as a defect in whichever
|
|
# round happened to be under review. Stated rather than silent -- an
|
|
# extract cannot answer the question, and a checkout still must.
|
|
pytest.skip("not a git checkout: the goldens can only be compared inside one")
|
|
baseline = (
|
|
Path(__file__).resolve().parents[1]
|
|
/ ".claude/projects/2026-08-30-door-b-concept-granularity/baseline/sha"
|
|
)
|
|
if not baseline.is_file():
|
|
# The baseline is LOCAL-ONLY and gitignored, so a fresh clone has none.
|
|
# Skipping silently would make this test vacuous where it matters most,
|
|
# so the weaker check still runs.
|
|
result = subprocess.run(
|
|
[
|
|
"git",
|
|
"status",
|
|
"--porcelain",
|
|
"--",
|
|
*(f"examples/{name}" for name in EXISTING_GOLDENS),
|
|
],
|
|
cwd=Path(__file__).resolve().parents[1],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
assert result.stdout == ""
|
|
return
|
|
|
|
result = subprocess.run(
|
|
[
|
|
"git",
|
|
"diff",
|
|
"--exit-code",
|
|
baseline.read_text(encoding="utf-8").strip(),
|
|
"--",
|
|
*(f"examples/{name}" for name in EXISTING_GOLDENS),
|
|
],
|
|
cwd=Path(__file__).resolve().parents[1],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
assert result.returncode == 0, f"an existing golden moved:\n{result.stdout}"
|
|
|
|
|
|
def test_the_new_golden_was_absent_at_the_baseline() -> None:
|
|
# Without this, the exclusion above could be hiding churn inside an
|
|
# existing golden that had been renamed into the new directory.
|
|
baseline = (
|
|
Path(__file__).resolve().parents[1]
|
|
/ ".claude/projects/2026-08-30-door-b-concept-granularity/baseline/sha"
|
|
)
|
|
if not baseline.is_file():
|
|
return
|
|
result = subprocess.run(
|
|
[
|
|
"git",
|
|
"cat-file",
|
|
"-e",
|
|
f"{baseline.read_text(encoding='utf-8').strip()}:examples/ingest-golden-segmented",
|
|
],
|
|
cwd=Path(__file__).resolve().parents[1],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
assert result.returncode != 0, "the new golden already existed at the baseline"
|