Three STS fixtures still carried the section titles and labels of one real reference document, and three identifiers were copies of its codes with a letter or a word swapped. They now describe an invented kitchen counter and cookbook series: the titles, labels and descriptions of sts-identity.xml, sts-inherit.xml and sts-empty-label.xml, the P350/P351 document codes, the 99-0001 delivery prefix and chapter 7 of the image and accounting corpora. Generated fixtures are regenerated and the witness inventory's per-document totals are identical before and after; only names and text move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
4.7 KiB
Python
128 lines
4.7 KiB
Python
"""Door C carries the assets its merged concepts point at (0.10.0).
|
|
|
|
Measured on 2026-09-17, before this was fixed: importing a bundle built with
|
|
`--assets` merged 6 of 6 concepts -- the guard cleared every pointer block as
|
|
ordinary body text -- and wrote **no `assets/` directory at all**. Every
|
|
`` in the imported bundle pointed at a file that was
|
|
not there.
|
|
|
|
That is the same defect one door over: a bundle that reads as complete and is
|
|
not. Door C's two invariants make the repair obvious rather than a new
|
|
mechanism -- a merged concept is written VERBATIM, so its pointer cannot be
|
|
rewritten to point somewhere else, and ownership is proven by CONTENT IDENTITY,
|
|
which is exactly the rule an asset name already encodes.
|
|
|
|
WHAT IS NOT CARRIED IS AS IMPORTANT: an asset no merged concept points at stays
|
|
behind. A concept the guard refused takes its pictures with it, or the import
|
|
would persist bytes the gate never cleared a reader for -- and an orphan in
|
|
`assets/` is a file nothing names and nothing retires.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import warnings
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from llm_ingestion_okf import cli
|
|
from llm_ingestion_okf.assets import ASSETS_DIR, IMAGE_POINTER
|
|
from llm_ingestion_okf.importer import import_bundle
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures" / "image-inbox"
|
|
INGESTED_AT = "2026-09-17T00:00:00Z"
|
|
|
|
|
|
def _source_bundle(tmp_path: Path) -> Path:
|
|
inbox = tmp_path / "inbox"
|
|
(inbox / "graphics").mkdir(parents=True)
|
|
for source in sorted(FIXTURES.rglob("*")):
|
|
if source.is_file():
|
|
(inbox / source.relative_to(FIXTURES)).write_bytes(source.read_bytes())
|
|
bundle = tmp_path / "source-bundle"
|
|
with warnings.catch_warnings():
|
|
warnings.simplefilter("ignore")
|
|
assert (
|
|
cli.main(
|
|
[
|
|
"build",
|
|
str(inbox),
|
|
"--bundle",
|
|
str(bundle),
|
|
"--bundle-id",
|
|
"asset-import-fixture",
|
|
"--okf-version",
|
|
"0.2",
|
|
]
|
|
)
|
|
== 0
|
|
)
|
|
return bundle
|
|
|
|
|
|
def _imported(tmp_path: Path) -> Path:
|
|
from llm_ingestion_okf.guard_adapter import import_gate
|
|
|
|
target = tmp_path / "imported"
|
|
import_bundle(
|
|
_source_bundle(tmp_path),
|
|
target,
|
|
INGESTED_AT,
|
|
origin="external",
|
|
channel="manual",
|
|
gate=import_gate,
|
|
)
|
|
return target
|
|
|
|
|
|
def test_every_pointer_a_merged_concept_carries_resolves(tmp_path: Path) -> None:
|
|
pytest.importorskip("pdfplumber")
|
|
pytest.importorskip("llm_ingestion_guard")
|
|
target = _imported(tmp_path)
|
|
pointers = 0
|
|
for concept in sorted(target.rglob("*.md")):
|
|
for match in IMAGE_POINTER.finditer(concept.read_text("utf-8")):
|
|
pointers += 1
|
|
asset = target / ASSETS_DIR / match.group("asset")
|
|
assert asset.is_file(), f"{concept.name} points at a missing {asset.name}"
|
|
assert pointers, "the fixture bundle carried no pointers at all"
|
|
|
|
|
|
def test_the_imported_bytes_are_the_senders_own(tmp_path: Path) -> None:
|
|
pytest.importorskip("pdfplumber")
|
|
pytest.importorskip("llm_ingestion_guard")
|
|
source = _source_bundle(tmp_path)
|
|
from llm_ingestion_okf.guard_adapter import import_gate
|
|
|
|
target = tmp_path / "imported"
|
|
import_bundle(
|
|
source, target, INGESTED_AT, origin="external", channel="manual", gate=import_gate
|
|
)
|
|
carried = sorted((target / ASSETS_DIR).glob("*"))
|
|
# The known-positive in the same test: a loop over an empty directory is
|
|
# green and proves nothing, which is exactly how a repair can empty the set
|
|
# a test iterates over and stay passing.
|
|
assert carried, "nothing was carried, so the comparison below ran over nothing"
|
|
for asset in carried:
|
|
assert asset.read_bytes() == (source / ASSETS_DIR / asset.name).read_bytes()
|
|
|
|
|
|
def test_an_asset_nothing_points_at_stays_behind(tmp_path: Path) -> None:
|
|
"""The negative control, and it is the security half of the rule.
|
|
|
|
An asset belonging to a concept the gate refused must not ride in on the
|
|
back of one it cleared.
|
|
"""
|
|
pytest.importorskip("pdfplumber")
|
|
pytest.importorskip("llm_ingestion_guard")
|
|
source = _source_bundle(tmp_path)
|
|
(source / ASSETS_DIR / "deadbeefdead-ingen-peker.png").write_bytes(
|
|
(source / ASSETS_DIR).glob("*.png").__next__().read_bytes() + b"\x00"
|
|
)
|
|
from llm_ingestion_okf.guard_adapter import import_gate
|
|
|
|
target = tmp_path / "imported"
|
|
import_bundle(
|
|
source, target, INGESTED_AT, origin="external", channel="manual", gate=import_gate
|
|
)
|
|
assert not (target / ASSETS_DIR / "deadbeefdead-ingen-peker.png").exists()
|