fix(corpus): harden canonical chunk and frontmatter invariants

This commit is contained in:
2026-07-12 03:50:32 +02:00
parent 015715d092
commit 11e7ee9ea6
5 changed files with 186 additions and 53 deletions
+23
View File
@@ -52,6 +52,29 @@ def test_frontmatter_can_end_at_eof_without_inventing_content():
assert document.content == ""
@pytest.mark.parametrize(
"frontmatter",
[
"title: first\ntitle: second",
"title: &shared value\ncopy: *shared",
"nested: " + "[" * 25 + "x" + "]" * 25,
"items: [" + ",".join("x" for _ in range(1100)) + "]",
"api_key: secret",
],
)
def test_rejects_unsafe_frontmatter_as_typed_permanent_error(frontmatter):
raw = f"---\n{frontmatter}\n---\nbody".encode()
with pytest.raises(PermanentNormalizationError) as caught:
normalize(acquired(raw), "pipe:v1")
assert caught.value.reason == "invalid_frontmatter"
def test_pipeline_policy_errors_are_not_misclassified_as_bad_frontmatter():
with pytest.raises(ValueError, match="pipeline_version") as caught:
normalize(acquired(b"---\ntitle: valid\n---\nbody"), "")
assert not isinstance(caught.value, PermanentNormalizationError)
@pytest.mark.parametrize(
("content", "media_type", "reason"),
[