feat: validate Anwarpy publication metadata

This commit is contained in:
AHMED
2026-10-09 15:52:08 +03:00
parent 00f8e4aee7
commit 4aeb747d56
8 changed files with 457 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import unittest
from page_state import MarkerError, find_marker
VALID = "anwarpy: status=pending | access=free | category=نماذج | queued_at=2026-10-09T15:12:00+03:00"
class PageStateTests(unittest.TestCase):
def test_finds_one_exact_marker_after_unrelated_blocks(self):
result = find_marker([
{"id": "a", "text": "ملاحظات"},
{"id": "b", "text": VALID},
{"id": "c", "text": "مصدر عام"},
])
self.assertEqual(result.block_id, "b")
self.assertEqual(result.meta["status"], "pending")
def test_returns_none_when_anwarpy_is_never_mentioned(self):
self.assertIsNone(find_marker([{"id": "a", "text": "لا توجد علامة"}]))
def test_reports_every_near_miss(self):
for text in (
VALID.replace("anwarpy:", "Anwarpy:"),
"prefix " + VALID,
"documentation mentions anwarpy but has no marker",
VALID.replace("anwarpy:", "anwarpy ="),
):
with self.subTest(text=text):
with self.assertRaisesRegex(MarkerError, "near-miss"):
find_marker([{"id": "bad", "text": text}])
def test_scans_all_blocks_and_rejects_ambiguity(self):
with self.assertRaisesRegex(MarkerError, "multiple"):
find_marker([
{"id": "first", "text": VALID},
{"id": "middle", "text": "unrelated"},
{"id": "last", "text": VALID.replace("category=نماذج", "category=أدوات")},
])
def test_exact_plus_near_miss_is_ambiguous(self):
with self.assertRaisesRegex(MarkerError, "ambiguous"):
find_marker([
{"id": "good", "text": VALID},
{"id": "bad", "text": "Anwarpy: pending"},
])
if __name__ == "__main__":
unittest.main()