from pathlib import Path
import hashlib
import re

base = Path(__file__).resolve().parent
part1 = (base / ".part1.md").read_bytes()
part2 = (base / ".part2.md").read_bytes()
part3 = (base / ".part3.md").read_bytes()
out_path = base / "Королевство 5 — глубокий анализ и разбор.md"
out = out_path.read_bytes()
expected = part1 + part2 + part3
assert out == expected, "Итог не равен механической конкатенации частей"
text = out.decode("utf-8")
heads = re.findall(r"^## ([1-9])\.", text, flags=re.M)
assert heads == [str(i) for i in range(1, 10)], heads
assert text.rstrip().endswith("границами компетенции."), "Возможный обрыв конца"
for i, data in enumerate((part1, part2, part3), 1):
    print(f"part{i}: lines={len(data.splitlines())}, bytes={len(data)}, sha256={hashlib.sha256(data).hexdigest()}")
print(f"final: lines={len(out.splitlines())}, bytes={len(out)}, sha256={hashlib.sha256(out).hexdigest()}")
print("sections:", ",".join(heads))
print("exact_concat: yes")
print("ending_complete: yes")
