ckb/tests/unit/test_lint_crux.py
Michał Kopeć b6b592d5d7 Template 2.0.2: share and capture hardening, Crux without Sources
Fixes F6, F12-F16 from the 2.0.0 script review:
- share: plain file/mailbox names and mailbox-bound share_id/version, or
  the message is ignored (no ckb.yaml injection, no writes outside
  raw/inbox/); ledger rejects whitespace/control characters; every
  commit on a message must be by an owner; duplicate members.yaml
  entries unown a mailbox; only verified retractions hide mail; branch,
  url and name validated before git; received copy always untrusted;
  <private> stripped from title/tldr and unclosed tags; no send without
  the secret scan
- capture: frontmatter values quoted unless plainly safe; one-line title
- lint check 13: chat-attributed Crux needs no Sources

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:38:18 +01:00

38 lines
1.7 KiB
Python

"""Check 13: a Crux quoted from a conversation is complete without Sources
(AGENTS.md §2); one quoted from a local file still needs its fingerprint."""
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"
LINT = ROOT / ".agents/skills/ckb-lint/scripts/lint_report.py"
PAGE = "---\ntype: decision\ntldr: x\nstatus: accepted\ndecided_on: 2026-11-11\ndecided_by: A\n---\n\n# D\n\n## Crux\n\n{quote}\n"
class CruxWithoutSources(unittest.TestCase):
def crux_findings(self, quote):
with tempfile.TemporaryDirectory() as d:
kb = Path(d) / "kb"
shutil.copytree(str(FIX), str(kb))
(kb / "wiki/decisions").mkdir(exist_ok=True)
(kb / "wiki/decisions/0099-x.md").write_text(PAGE.format(quote=quote), encoding="utf-8")
r = subprocess.run([sys.executable, str(LINT), "--json", "--today", "2026-11-11"], cwd=str(kb),
capture_output=True, text=True, encoding="utf-8")
data = json.loads(r.stdout)
return [f for t in data["trees"] for f in t.get("crux", []) if "0099-x" in f]
def test_chat_attributed_crux_needs_no_sources(self):
self.assertEqual(self.crux_findings("> We decided this today, plainly.\n— Chat conversation, A, 2026-11-11"), [])
def test_file_attributed_crux_still_needs_sources(self):
found = self.crux_findings("> Some quoted line from the notes file.\n— `raw/archive/notes.md`, under \"X\"")
self.assertTrue(any("Sources" in f for f in found), found)
if __name__ == "__main__":
unittest.main()