"""N17: one case- and accent-insensitive fold, kept identical where it is copied (each skill's scripts stand alone), and lint check 20 built on it.""" import importlib.util import shutil import subprocess import sys import tempfile import unicodedata import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[2] LINT = ROOT / ".agents/skills/ckb-lint/scripts/lint_report.py" RETRIEVE = ROOT / ".agents/skills/ckb-retrieve/scripts/retrieve_candidates.py" START = ROOT / ".agents/skills/ckb-lint/scripts/session_start.py" def load(path): spec = importlib.util.spec_from_file_location(path.stem, str(path)) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod class Fold(unittest.TestCase): @classmethod def setUpClass(cls): cls.lint, cls.retrieve, cls.start = load(LINT), load(RETRIEVE), load(START) def test_maps_are_identical(self): self.assertEqual(self.lint.FOLD_MAP, self.retrieve.FOLD_MAP) self.assertEqual(self.lint.FOLD_MAP, self.start.SLUG_MAP) def test_fold_equates_case_accents_and_composition(self): decomposed = unicodedata.normalize("NFD", "Michał Kopeć") for fold in (self.lint.fold, self.retrieve.fold): self.assertEqual(fold("Michał Kopeć"), "michal kopec") self.assertEqual(fold(decomposed), "michal kopec") self.assertEqual(fold("ŁÓDŹ"), "lodz") def test_lint_reports_names_that_collide_after_folding(self): with tempfile.TemporaryDirectory() as tmp: kb = Path(tmp) / "kb" shutil.copytree(str(ROOT / "tests/fixtures/minimal-kb"), str(kb)) page = "---\ntype: person\n---\n\n# X\n" (kb / "wiki/entities/Kopeć.md").write_text(page, encoding="utf-8") (kb / "wiki/entities/kopec.md").write_text(page, encoding="utf-8") out = subprocess.run([sys.executable, str(LINT), "--today", "2026-11-23"], cwd=str(kb), capture_output=True, text=True, encoding="utf-8").stdout self.assertIn("names differ only by case or accents", out) def test_retrieve_matches_a_title_without_its_accents(self): with tempfile.TemporaryDirectory() as tmp: kb = Path(tmp) / "kb" shutil.copytree(str(ROOT / "tests/fixtures/minimal-kb"), str(kb)) (kb / "wiki/entities/branch-a.md").write_text( "---\ntype: place\ntldr: Łódź office opening hours\n---\n\n# Łódź office\n", encoding="utf-8") out = subprocess.run([sys.executable, str(RETRIEVE), "lodz", "--root", str(kb), "--no-bm25", "--today", "2026-11-23"], capture_output=True, text=True, encoding="utf-8").stdout # Only the folded tldr signal can find it: the query has no accent, # the page text has no "lodz" for grep, and the file name doesn't either. self.assertIn("wiki/entities/branch-a.md", out) self.assertIn("tldr:", out.split("wiki/entities/branch-a.md", 1)[1].split("\n", 1)[0]) if __name__ == "__main__": unittest.main()