llm-ingestion-okf/tests/test_depth_seven.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

83 lines
2.9 KiB
Python

"""A declared section below markdown's sixth level keeps its own level in the plan.
K3-21 D. The NISO-STS reader wrote ONE clipped level into two places: the ATX
heading it emits, where markdown has six levels and the clip is the grammar's,
and the `OutlineMark` the declared route builds its plan from, where nothing
clips and the source's own depth is the point (`OutlineMark`'s docstring:
the level is what the tree declares, "reported rather than fixed up"). On one
standard 9 of its N titled sections sit at depth 7, and the plan read them at
6 -- so `--shell-parent` gave its two depth-7 shells the ancestor one level
too high.
The heading stays clipped: `#######` matches nothing, and the extracted TEXT
does not move one character. Only the mark's level does.
`sts-deep.xml` is hand-written in an invented setting and carries no sentence
from any source.
"""
from __future__ import annotations
from pathlib import Path
from llm_ingestion_okf import extract, propose
FIXTURE = Path(__file__).parent / "fixtures" / "sts-deep.xml"
#: Every flag `okf build` turns on by default.
BUILD_DEFAULTS = dict(
outline_run=3,
table_grid=True,
unit_fold=True,
keep_table_heading=True,
sheet_section_rows=True,
drop_wrapped_outline=True,
outline_gate=True,
first_span_from_zero=True,
close_span_gaps=True,
contents_name=True,
)
#: The extracted headings, as they were before this rule and after it.
HEADINGS = [
"# 1 Nivaa en",
"## 1.1 Nivaa to",
"### 1.11 Nivaa tre",
"#### 1.111 Nivaa fire",
"##### 1.1111 Nivaa fem",
"###### 1.11111 Nivaa seks",
"###### 1.111111 Nivaa sju foerste",
"###### 1.111112 Nivaa sju andre",
]
def test_the_mark_carries_the_declared_depth() -> None:
marks = extract.xml_outline(FIXTURE.name, FIXTURE.read_bytes())
assert [mark.level for mark in marks] == [1, 2, 3, 4, 5, 6, 7, 7]
def test_the_heading_stays_markdown_and_the_text_does_not_move() -> None:
data = FIXTURE.read_bytes()
text = extract.extract_text(FIXTURE.name, data)
lines = text.split("\n")
assert [line for line in lines if line.startswith("#")] == HEADINGS
for mark in extract.xml_outline(FIXTURE.name, data):
assert lines[mark.line] == "#" * min(mark.level, 6) + " " + mark.title
def test_a_depth_seven_shell_points_at_its_depth_six_ancestor() -> None:
data = FIXTURE.read_bytes()
text = extract.extract_text(FIXTURE.name, data)
plan = propose.build_plan(
FIXTURE,
text,
data,
okf_type="reference",
proposed_at="2026-01-01T00:00:00Z",
shell_parent=True,
**BUILD_DEFAULTS, # type: ignore[arg-type]
)
titles = {entry["segment_id"]: entry["title"] for entry in plan["entries"]}
parents = {entry["title"]: titles.get(entry.get("parent_id", "")) for entry in plan["entries"]}
assert parents["Nivaa sju foerste"] == "Nivaa seks"
assert parents["Nivaa sju andre"] == "Nivaa seks"