ckb/tests/unit/test_low_severity.py
Michał Kopeć 45d2830aed Template 2.0.5: routines, redaction, OKF quoting, Unicode search, low-severity fixes
Fixes F20-F24 from the 2.0.0 script review: zero-indent routine lists,
escaped --do values, --remove continuation lines; <private> redaction
across content blocks; OKF scalar quoting and code-fence titles; Unicode
tokens in retrieve and consolidate; bad workload dates, frontmatter at
EOF, `wiki/` refs without a slash, Starlight route collisions, labelled
wikilinks, string source_files, real splash sections, <private> dropped
from both exports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 17:19:48 +01:00

95 lines
4 KiB
Python

"""The low-severity findings of the 2.0.0 review (F24), one test each."""
import json
import shutil
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
FIX = ROOT / "tests/fixtures/minimal-kb"
S = ROOT / ".agents/skills"
LINT = S / "ckb-lint/scripts/lint_report.py"
START = S / "ckb-lint/scripts/session_start.py"
OKF = S / "ckb-export-okf/scripts/export_okf.py"
STARLIGHT = S / "ckb-export-starlight/scripts/export_starlight.py"
TODAY = "2026-11-11"
def run(cwd, *cmd):
return subprocess.run([str(c) for c in cmd], cwd=str(cwd), capture_output=True, text=True, encoding="utf-8")
class KB(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.kb = Path(self.tmp.name) / "kb"
shutil.copytree(str(FIX), str(self.kb))
def tearDown(self):
self.tmp.cleanup()
def page(self, rel, text):
p = self.kb / "wiki" / rel
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(text, encoding="utf-8")
def lint(self):
r = run(self.kb, sys.executable, LINT, "--json", "--today", TODAY)
return json.loads(r.stdout)["trees"][0]
class Lint(KB):
def test_frontmatter_only_page_without_final_newline_is_closed(self):
self.page("entities/bare.md", "---\ntype: entity\ntldr: x\n---")
self.assertEqual([f for f in self.lint()["conformance"] if "bare.md" in f], [])
def test_wiki_prefix_without_slash_resolves(self):
edges = self.kb / "wiki/graph/edges.json"
data = json.loads(edges.read_text(encoding="utf-8"))
known = next(p.relative_to(self.kb).as_posix() for p in (self.kb / "wiki/entities").glob("*.md")
if p.name != "index.md")
data["edges"] = (data.get("edges") or []) + [{"from": known, "to": known, "type": "related_to"}]
edges.write_text(json.dumps(data), encoding="utf-8")
self.assertEqual([f for f in self.lint()["graph"] if "does not resolve" in f], [])
class SessionStart(KB):
def test_impossible_date_in_a_workload_name_is_skipped(self):
(self.kb / "workload").mkdir(exist_ok=True)
(self.kb / "workload/2026-02-30_x_summary.md").write_text("### Open threads\n- [ ] a\n", encoding="utf-8")
r = run(self.kb, sys.executable, START, "--today", TODAY, "--no-git")
self.assertEqual(r.returncode, 0, r.stderr)
self.assertNotIn("Traceback", r.stderr)
class Exports(KB):
def setUp(self):
super().setUp()
self.page("routing-table.md", "---\ntype: concept\ntldr: mine\n---\n\n# My routing notes\n\nMINE\n")
self.page("entities/linker.md", "---\ntype: entity\ntldr: links\n---\n\n# Linker\n\n"
"See [[Linker|the linker page]]. Kept <private>hidden-bit</private> out.\n")
def test_starlight(self):
r = run(self.kb, sys.executable, STARLIGHT, "--mode", "full", "--today", TODAY)
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
docs = self.kb / "outputs/starlight/src/content/docs"
self.assertNotIn("MINE", (docs / "routing-table.md").read_text(encoding="utf-8"))
self.assertIn("MINE", (docs / "routing-table-page.md").read_text(encoding="utf-8"))
linker = (docs / "entities/linker.md").read_text(encoding="utf-8")
self.assertIn("[the linker page](/entities/linker/)", linker)
self.assertNotIn("hidden-bit", linker)
splash = (docs / "index.mdx").read_text(encoding="utf-8")
for link in [l.split("link:", 1)[1].strip() for l in splash.splitlines() if "link:" in l]:
if link != "/routing-table/":
self.assertTrue((docs / link.strip("/")).is_dir(), f"splash links to missing {link}")
def test_okf_strips_private(self):
self.assertIn(run(self.kb, sys.executable, OKF).returncode, (0, 1))
text = "".join(p.read_text(encoding="utf-8") for p in (self.kb / "outputs/okf").rglob("*.md"))
self.assertNotIn("hidden-bit", text)
if __name__ == "__main__":
unittest.main()