Add page identity and frontmatter domain types

PageId (UUIDv7) and PageTitle validate on construction; frontmatter is
split losslessly, read as text-only YAML without anchors or duplicate
keys, and written canonically. All page errors live in domain/errors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
torbenandClaude Sonnet 5.5 committed 2026-12-04 12:58:10 +01:00
1 parent 931b1dcc5f
commit 308d68ad8c
5 files changed
+492

No files matched your search

+117
View File
@@ -0,0 +1,117 @@
import pytest
from chemenu.domain.errors import InvalidPageIdError, InvalidTitleError
from chemenu.domain.identity import PageId, PageTitle
VALID_ID = "01a238ea-2e6d-7157-ba55-5da7405095ff"
def test_valid_id() -> None:
assert PageId(VALID_ID).value == VALID_ID
assert PageId(VALID_ID.replace("ba55", "8a55")).value.startswith("01a2")
@pytest.mark.parametrize(
"value",
[
"",
VALID_ID + "\n",
VALID_ID.upper(),
VALID_ID.replace("-7157", "-4157"),
VALID_ID.replace("ba55", "ca55"),
VALID_ID.replace("-", ""),
VALID_ID[:-1],
VALID_ID[:-1] + "g",
VALID_ID[:-1] + chr(0xFF10),
" " + VALID_ID,
],
)
def test_invalid_id_raises(value: str) -> None:
with pytest.raises(InvalidPageIdError):
PageId(value)
@pytest.mark.parametrize(
"value",
[
"Ordnungs-, Wisch- und Sanitätsdienst",
"Äpfel 🍎",
"a" * 252,
"CONSOLE",
"Aux-Plan",
"a.b",
"x%y",
"md",
"notes.mdx",
"a.md b",
"Familie 👨" + chr(0x200D) + "👩",
"Mi" + chr(0x200C) + "zan",
"🏴" + "".join(chr(0xE0000 + ord(c)) for c in "gbeng") + chr(0xE007F),
],
)
def test_title_with_comma(value: str) -> None:
assert PageTitle(value).value == value
@pytest.mark.parametrize(
"value",
[
"",
" ",
"a<b",
"a>b",
"a:b",
'a"b',
"a/b",
"a\\b",
"a|b",
"a?b",
"a*b",
"a[b",
"a]b",
"a#b",
"a^b",
"a%%b",
"a\tb",
"a\nb",
"a\x7fb",
"a\x85b",
f"a{chr(0x2028)}b",
f"a{chr(0x2029)}b",
".a",
"a.",
" a",
"a ",
f"a{chr(0xA0)}",
f"{chr(0x3000)}a",
"con",
"CON",
"Con.txt",
"con .txt",
"NUL",
"prn",
"conin$",
"CONOUT$",
"aux",
"COM1",
"lpt9.x",
"COM¹",
"LPT²",
"COM³.a",
"e\u0301",
"a" * 253,
"ä" * 127,
"a\ud800b",
"README.md",
"notes.MD",
"x.Md",
"a" + chr(0x200B) + "b",
chr(0xFEFF) + "a",
"a" + chr(0x202E) + "b",
"a" + chr(0x00AD) + "b",
"a" + chr(0x2060) + "b",
],
)
def test_invalid_title_raises(value: str) -> None:
with pytest.raises(InvalidTitleError):
PageTitle(value)