llm-ingestion-okf/tests/test_asset_structure.py
Kjell Tore Guttormsen 9d1f4b14ed test(fixtures): replace sector-specific example material with generic, fictitious examples — green
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>
2026-09-23 14:52:02 +02:00

55 lines
2.5 KiB
Python

"""An image is not a cross-reference, and a carried image is counted (0.10.0).
Two door-level properties that the asset layer would otherwise get wrong in
opposite directions.
**A markdown image is not a pointer to another concept.** `structure._LINK`
reads `[...](target)` and does not care what stands in front of the bracket, so
every pointer this capability writes would arrive in the index as a `references`
edge to a concept that cannot exist. That is the same defect K3-21 hit when the
`Enclosing section:` line was read as body text and became a second, unresolved
edge; the repair there was to append after derivation, and the repair here is
that an image link is a different construct from a link.
**A concept says how many images it carries.** A bundle that holds an image and
says nothing about it is only half an improvement: the count is what lets a
consumer, or `okf quality`, tell "this document had no figures" from "this
build dropped them". The key is CONDITIONAL -- written only where the count is
non-zero -- so a bundle of documents without images is byte-identical to one
built before this existed.
"""
from __future__ import annotations
from llm_ingestion_okf.structure import derive_document_structure
POINTER = (
"# 84 Boller\n\n"
"Hevetidsklasse er gitt i tabell 84-2, jf. Q500.\n\n"
"![Tabell 84-2](/assets/e54e5f5da0e8-tabell-84-2.png)\n"
"Image: graphics/tabell-84-2.png (120x90 px) -- Tabell 84-2\n\n"
"Se ellers [Q100](q100.md).\n"
)
def test_an_image_pointer_is_not_a_reference() -> None:
structure = derive_document_structure(POINTER, source_file="p761.xml")
assert "/assets/e54e5f5da0e8-tabell-84-2.png" not in structure.references
def test_the_links_beside_it_still_are() -> None:
"""The known-positive in the same text: masking must not eat real edges."""
structure = derive_document_structure(POINTER, source_file="p761.xml")
assert "q100.md" in structure.references
def test_the_asset_name_does_not_leak_a_number_into_references() -> None:
"""A masked span is still masked: `84-2` inside the file name is not a subject.
The span is blanked rather than deleted for exactly this reason -- deleting
would move every later offset and break first-appearance order, and leaving
it would let the number scan read an identifier out of a file name.
"""
structure = derive_document_structure(POINTER, source_file="p761.xml")
assert all("ASSETS" not in subject.upper() for subject in structure.references)
assert "Q500" in structure.references