llm-ingestion-okf/tests/test_asset_structure.py
Kjell Tore Guttormsen 88cf67f12e test(fixtures): the STS fixtures and fixture codes are fictitious
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>
2026-09-23 14:52:03 +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 = (
"# 7 Boller\n\n"
"Hevetidsklasse er gitt i tabell 7-2, jf. Q500.\n\n"
"![Tabell 7-2](/assets/e54e5f5da0e8-tabell-7-2.png)\n"
"Image: graphics/tabell-7-2.png (120x90 px) -- Tabell 7-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="p350.xml")
assert "/assets/e54e5f5da0e8-tabell-7-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="p350.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: `7-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="p350.xml")
assert all("ASSETS" not in subject.upper() for subject in structure.references)
assert "Q500" in structure.references