Template 1.28.7: backport 2.0.6 frontmatter contract and lint tests to the 1.x line
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e557fd1eb1
commit
a41893ec2e
12 changed files with 221 additions and 27 deletions
|
|
@ -41,15 +41,19 @@ class Author:
|
||||||
return f"{self.name} <{self.email}>"
|
return f"{self.name} <{self.email}>"
|
||||||
|
|
||||||
|
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def parse_frontmatter(text):
|
def parse_frontmatter(text):
|
||||||
"""Flat key: value frontmatter, the same deliberately simple reading as the rest of the template."""
|
"""Flat key: value frontmatter, the same deliberately simple reading as the rest of the template."""
|
||||||
if not text.startswith("---\n"):
|
if not text.startswith("---\n"):
|
||||||
return {}, text
|
return {}, text
|
||||||
end = text.find("\n---", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
if end < 0:
|
if close is None:
|
||||||
return {}, text
|
return {}, text
|
||||||
|
end = close.start() - 1
|
||||||
fm = {}
|
fm = {}
|
||||||
for line in text[4:end].splitlines():
|
for line in text[4:max(end, 4)].splitlines():
|
||||||
m = re.match(r"^([A-Za-z_][\w-]*):\s*(.*)$", line)
|
m = re.match(r"^([A-Za-z_][\w-]*):\s*(.*)$", line)
|
||||||
if m:
|
if m:
|
||||||
fm[m.group(1)] = m.group(2).strip().strip('"').strip("'")
|
fm[m.group(1)] = m.group(2).strip().strip('"').strip("'")
|
||||||
|
|
|
||||||
|
|
@ -85,11 +85,14 @@ def identity(root, author):
|
||||||
return name or user, email or f"{user}@localhost"
|
return name or user, email or f"{user}@localhost"
|
||||||
|
|
||||||
|
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def split_frontmatter(text):
|
def split_frontmatter(text):
|
||||||
if text.startswith("---\n"):
|
if text.startswith("---\n"):
|
||||||
end = text.find("\n---\n", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
if end != -1:
|
if close is not None:
|
||||||
return text[4:end], text[end + 5:]
|
return text[4:close.start()].rstrip("\n"), text[close.end() + 1:]
|
||||||
return "", text
|
return "", text
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,18 +44,21 @@ MIN_SCOPE_CLUSTER = 2
|
||||||
OLD_LOG_DAYS = 90
|
OLD_LOG_DAYS = 90
|
||||||
|
|
||||||
|
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def parse(text):
|
def parse(text):
|
||||||
if not text.startswith("---\n"):
|
if not text.startswith("---\n"):
|
||||||
return {}, text
|
return {}, text
|
||||||
end = text.find("\n---\n", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
if end == -1:
|
if close is None:
|
||||||
return {}, text
|
return {}, text
|
||||||
fm = {}
|
fm = {}
|
||||||
for line in text[4:end].split("\n"):
|
for line in text[4:close.start()].split("\n"):
|
||||||
k, sep, v = line.partition(":")
|
k, sep, v = line.partition(":")
|
||||||
if sep and not line[:1].isspace():
|
if sep and not line[:1].isspace() and not line.lstrip().startswith("#"):
|
||||||
fm[k.strip()] = v.strip().strip("\"'")
|
fm[k.strip()] = v.strip().strip("\"'")
|
||||||
return fm, text[end + 5:]
|
return fm, text[close.end() + 1:]
|
||||||
|
|
||||||
|
|
||||||
def words(s):
|
def words(s):
|
||||||
|
|
|
||||||
|
|
@ -71,16 +71,19 @@ VERB_MAP = {
|
||||||
PRIVATE_RE = re.compile(r"<private>.*?(?:</private>|\Z)", re.S | re.I)
|
PRIVATE_RE = re.compile(r"<private>.*?(?:</private>|\Z)", re.S | re.I)
|
||||||
|
|
||||||
|
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def parse_frontmatter(text):
|
def parse_frontmatter(text):
|
||||||
"""Return (dict, body). Flat `key: value` YAML only — that is all the
|
"""Return (dict, body). Flat `key: value` YAML only — that is all the
|
||||||
schema uses. Unparseable or absent frontmatter yields ({}, text)."""
|
schema uses. Unparseable or absent frontmatter yields ({}, text)."""
|
||||||
if not text.startswith("---\n"):
|
if not text.startswith("---\n"):
|
||||||
return {}, text
|
return {}, text
|
||||||
end = text.find("\n---\n", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
if end == -1:
|
if close is None:
|
||||||
return {}, text
|
return {}, text
|
||||||
raw = text[4:end]
|
raw = text[4:close.start()]
|
||||||
body = text[end + 5 :]
|
body = text[close.end() + 1 :]
|
||||||
fm = {}
|
fm = {}
|
||||||
for line in raw.split("\n"):
|
for line in raw.split("\n"):
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
|
|
|
||||||
|
|
@ -63,15 +63,18 @@ def yaml_quote(s):
|
||||||
return f'"{s}"'
|
return f'"{s}"'
|
||||||
|
|
||||||
|
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def parse_frontmatter(text):
|
def parse_frontmatter(text):
|
||||||
"""Minimal parser for this repo's flat key: value frontmatter (no lists/nesting)."""
|
"""Minimal parser for this repo's flat key: value frontmatter (no lists/nesting)."""
|
||||||
if not text.startswith("---\n"):
|
if not text.startswith("---\n"):
|
||||||
return {}, text
|
return {}, text
|
||||||
end = text.find("\n---", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
if end == -1:
|
if close is None:
|
||||||
return {}, text
|
return {}, text
|
||||||
fm_block = text[4:end]
|
fm_block = text[4:close.start()]
|
||||||
body = text[end + 4 :].lstrip("\n")
|
body = text[close.end() + 1 :].lstrip("\n")
|
||||||
fm = {}
|
fm = {}
|
||||||
for line in fm_block.splitlines():
|
for line in fm_block.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
|
||||||
|
|
@ -96,11 +96,14 @@ def files_under(base):
|
||||||
if p.is_file() and not any(part.startswith(".") for part in p.relative_to(base).parts)]
|
if p.is_file() and not any(part.startswith(".") for part in p.relative_to(base).parts)]
|
||||||
|
|
||||||
|
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def frontmatter_value(text, key):
|
def frontmatter_value(text, key):
|
||||||
if not text.startswith("---\n"):
|
if not text.startswith("---\n"):
|
||||||
return ""
|
return ""
|
||||||
end = text.find("\n---\n", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
for line in text[4:end if end != -1 else 0].split("\n"):
|
for line in text[4:close.start() if close else 4].split("\n"):
|
||||||
if line.startswith(f"{key}:"):
|
if line.startswith(f"{key}:"):
|
||||||
return line.split(":", 1)[1].strip().strip("\"'")
|
return line.split(":", 1)[1].strip().strip("\"'")
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,18 @@ MD_EXCLUDE = {"index.md", "log.md"}
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- parsing ---
|
# ---------------------------------------------------------------- parsing ---
|
||||||
|
FM_CLOSE_RE = re.compile(r"^---[ \t]*$", re.M) # the closing line; may end the file
|
||||||
|
|
||||||
|
|
||||||
def parse_frontmatter(text):
|
def parse_frontmatter(text):
|
||||||
if not text.startswith("---\n"):
|
if not text.startswith("---\n"):
|
||||||
return {}, text
|
return {}, text
|
||||||
end = text.find("\n---", 4)
|
close = FM_CLOSE_RE.search(text, 4)
|
||||||
if end < 0:
|
if close is None:
|
||||||
return {}, text
|
return {}, text
|
||||||
|
end = close.start() - 1
|
||||||
fm = {}
|
fm = {}
|
||||||
for line in text[4:end].splitlines():
|
for line in text[4:max(end, 4)].splitlines():
|
||||||
m = re.match(r"^([A-Za-z_][\w-]*):\s*(.*)$", line)
|
m = re.match(r"^([A-Za-z_][\w-]*):\s*(.*)$", line)
|
||||||
if m:
|
if m:
|
||||||
fm[m.group(1)] = m.group(2).strip().strip('"').strip("'")
|
fm[m.group(1)] = m.group(2).strip().strip('"').strip("'")
|
||||||
|
|
|
||||||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
1.28.6
|
1.28.7
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,8 @@ docs. Independent of the content schema above.
|
||||||
|
|
||||||
| Version | Date | What landed | Schema |
|
| Version | Date | What landed | Schema |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| **1.28.6** | 2026-11-11 | `1.x` backport of the 2.0.5 fixes, no new features: `routines.py` zero-indent lists, escaped `--do`, `--remove` continuation lines; `<private>` redaction across content blocks; OKF quoting and code-fence titles; Unicode search tokens; workload date guard, frontmatter at end of file, `wiki/` refs without a slash, Starlight route collisions, labelled wikilinks, splash sections, `<private>` dropped from exports. Same tests as 2.0.5 | 1.7 |
|
| **1.28.7** | 2026-11-11 | `1.x` backport of 2.0.6: all eight frontmatter readers close at a `---` line, including one at end of file; frontmatter contract test and dirty-KB lint test | 1.7 |
|
||||||
|
| 1.28.6 | 2026-11-11 | `1.x` backport of the 2.0.5 fixes, no new features: `routines.py` zero-indent lists, escaped `--do`, `--remove` continuation lines; `<private>` redaction across content blocks; OKF quoting and code-fence titles; Unicode search tokens; workload date guard, frontmatter at end of file, `wiki/` refs without a slash, Starlight route collisions, labelled wikilinks, splash sections, `<private>` dropped from exports. Same tests as 2.0.5 | 1.7 |
|
||||||
| 1.28.5 | 2026-11-11 | `1.x` backport of the 2.0.4 fixes, no new features: wider secret scan (hidden folders, key files, dotfiles, extensionless text, unquoted secret-looking assignments, oversized files reported); mcp search filtered by the read policy, case-insensitive `.local.yaml` refusal, verified OAuth email only, DNS-rebinding protection on by default, single-use confirmation codes; capture refuses link-local/metadata always and private networks without `--allow-private`, total download limit, charset fallback, `<form>` pages, safe binary names. The PowerShell fallback's reduced secret set is unchanged. Same tests as 2.0.4 | 1.7 |
|
| 1.28.5 | 2026-11-11 | `1.x` backport of the 2.0.4 fixes, no new features: wider secret scan (hidden folders, key files, dotfiles, extensionless text, unquoted secret-looking assignments, oversized files reported); mcp search filtered by the read policy, case-insensitive `.local.yaml` refusal, verified OAuth email only, DNS-rebinding protection on by default, single-use confirmation codes; capture refuses link-local/metadata always and private networks without `--allow-private`, total download limit, charset fallback, `<form>` pages, safe binary names. The PowerShell fallback's reduced secret set is unchanged. Same tests as 2.0.4 | 1.7 |
|
||||||
| 1.28.4 | 2026-11-11 | `1.x` backport of the 2.0.3 Windows fixes, no new features: UTF-8 output and subprocess decoding in every script, UTF-8 hook stdin, `utf-8-sig` reads for BOM files, fingerprints that match LF or CRLF checkouts and short prefixes (`lint_report.py`, `lint_quick.sh`, `consolidate.py`, and on this line `lint_quick.ps1`, which is not run in CI), POSIX paths in lint output and `rg --path-separator /`, hook installers that default to the running interpreter, quote paths and check that it still exists. Same tests as 2.0.3 | 1.7 |
|
| 1.28.4 | 2026-11-11 | `1.x` backport of the 2.0.3 Windows fixes, no new features: UTF-8 output and subprocess decoding in every script, UTF-8 hook stdin, `utf-8-sig` reads for BOM files, fingerprints that match LF or CRLF checkouts and short prefixes (`lint_report.py`, `lint_quick.sh`, `consolidate.py`, and on this line `lint_quick.ps1`, which is not run in CI), POSIX paths in lint output and `rg --path-separator /`, hook installers that default to the running interpreter, quote paths and check that it still exists. Same tests as 2.0.3 | 1.7 |
|
||||||
| 1.28.3 | 2026-11-11 | `1.x` backport of the 2.0.2 fixes, no new features: `share` message names and identifiers validated (no `ckb.yaml` injection, no writes outside `raw/inbox/`), every commit on a message must be by a mailbox owner, duplicate `members.yaml` entries unown a mailbox, only verified retractions hide mail, channel branch/url validated before git, received copies always `untrusted: true`, `<private>` stripped from title and `tldr`, no send without the secret scan; `capture` frontmatter quoting and one-line titles; lint check 13 accepts a chat-attributed Crux without `## Sources`. Same tests as 2.0.2 | 1.7 |
|
| 1.28.3 | 2026-11-11 | `1.x` backport of the 2.0.2 fixes, no new features: `share` message names and identifiers validated (no `ckb.yaml` injection, no writes outside `raw/inbox/`), every commit on a message must be by a mailbox owner, duplicate `members.yaml` entries unown a mailbox, only verified retractions hide mail, channel branch/url validated before git, received copies always `untrusted: true`, `<private>` stripped from title and `tldr`, no send without the secret scan; `capture` frontmatter quoting and one-line titles; lint check 13 accepts a chat-attributed Crux without `## Sources`. Same tests as 2.0.2 | 1.7 |
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,8 @@ Niezależna od schematu treści powyżej.
|
||||||
|
|
||||||
| Wersja | Data | Co weszło | Schemat |
|
| Wersja | Data | Co weszło | Schemat |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| **1.28.6** | 2026-11-11 | Przeniesienie poprawek 2.0.5 na `1.x`, bez nowych funkcji: listy rutyn od kolumny 0, `--do` z escape'ami, `--remove` z wierszami kontynuacji; redakcja `<private>` przez bloki wiadomości; cytowanie w OKF i tytuły poza blokami kodu; tokeny Unicode w wyszukiwaniu; ochrona przed złą datą w workload, frontmatter na końcu pliku, odwołania `wiki/` bez ukośnika, kolizje ścieżek w Starlight, wikilinki z etykietą, sekcje strony startowej, `<private>` usuwane z eksportów. Te same testy co w 2.0.5 | 1.7 |
|
| **1.28.7** | 2026-11-11 | Przeniesienie 2.0.6 na `1.x`: wszystkie osiem czytników frontmattera kończy go na linii `---`, także na końcu pliku; test kontraktu frontmattera i test lintu na zabrudzonej KB | 1.7 |
|
||||||
|
| 1.28.6 | 2026-11-11 | Przeniesienie poprawek 2.0.5 na `1.x`, bez nowych funkcji: listy rutyn od kolumny 0, `--do` z escape'ami, `--remove` z wierszami kontynuacji; redakcja `<private>` przez bloki wiadomości; cytowanie w OKF i tytuły poza blokami kodu; tokeny Unicode w wyszukiwaniu; ochrona przed złą datą w workload, frontmatter na końcu pliku, odwołania `wiki/` bez ukośnika, kolizje ścieżek w Starlight, wikilinki z etykietą, sekcje strony startowej, `<private>` usuwane z eksportów. Te same testy co w 2.0.5 | 1.7 |
|
||||||
| 1.28.5 | 2026-11-11 | Przeniesienie poprawek 2.0.4 na `1.x`, bez nowych funkcji: szerszy skan sekretów (ukryte foldery, pliki kluczy, pliki z kropką, tekst bez rozszerzenia, niecytowane przypisania wyglądające na sekret, zgłaszanie zbyt dużych plików); wyszukiwanie mcp filtrowane polityką odczytu, odmowa `.local.yaml` niezależna od wielkości liter, tylko zweryfikowany e-mail z OAuth, ochrona przed DNS rebinding domyślnie włączona, jednorazowe kody potwierdzenia; capture zawsze odrzuca link-local i metadane, a sieci prywatne bez `--allow-private`, limit całego pobierania, zapas kodowania, strony z `<form>`, bezpieczne nazwy plików binarnych. Zredukowany zestaw sekretów w zapasowym skrypcie PowerShell bez zmian. Te same testy co w 2.0.4 | 1.7 |
|
| 1.28.5 | 2026-11-11 | Przeniesienie poprawek 2.0.4 na `1.x`, bez nowych funkcji: szerszy skan sekretów (ukryte foldery, pliki kluczy, pliki z kropką, tekst bez rozszerzenia, niecytowane przypisania wyglądające na sekret, zgłaszanie zbyt dużych plików); wyszukiwanie mcp filtrowane polityką odczytu, odmowa `.local.yaml` niezależna od wielkości liter, tylko zweryfikowany e-mail z OAuth, ochrona przed DNS rebinding domyślnie włączona, jednorazowe kody potwierdzenia; capture zawsze odrzuca link-local i metadane, a sieci prywatne bez `--allow-private`, limit całego pobierania, zapas kodowania, strony z `<form>`, bezpieczne nazwy plików binarnych. Zredukowany zestaw sekretów w zapasowym skrypcie PowerShell bez zmian. Te same testy co w 2.0.4 | 1.7 |
|
||||||
| 1.28.4 | 2026-11-11 | Przeniesienie poprawek dla Windows z 2.0.3 na `1.x`, bez nowych funkcji: wyjście UTF-8 i dekodowanie podprocesów w każdym skrypcie, stdin hooka w UTF-8, odczyt `utf-8-sig` dla plików z BOM, odciski pasujące do checkoutu z LF albo CRLF i do krótkich prefiksów (`lint_report.py`, `lint_quick.sh`, `consolidate.py`, a na tej linii także `lint_quick.ps1`, którego CI nie uruchamia), ścieżki POSIX w wyjściu lintu i `rg --path-separator /`, instalatory hooków domyślnie wpisujące uruchamiający je interpreter, ze ścieżką w cudzysłowie i sprawdzeniem, czy nadal istnieje. Te same testy co w 2.0.3 | 1.7 |
|
| 1.28.4 | 2026-11-11 | Przeniesienie poprawek dla Windows z 2.0.3 na `1.x`, bez nowych funkcji: wyjście UTF-8 i dekodowanie podprocesów w każdym skrypcie, stdin hooka w UTF-8, odczyt `utf-8-sig` dla plików z BOM, odciski pasujące do checkoutu z LF albo CRLF i do krótkich prefiksów (`lint_report.py`, `lint_quick.sh`, `consolidate.py`, a na tej linii także `lint_quick.ps1`, którego CI nie uruchamia), ścieżki POSIX w wyjściu lintu i `rg --path-separator /`, instalatory hooków domyślnie wpisujące uruchamiający je interpreter, ze ścieżką w cudzysłowie i sprawdzeniem, czy nadal istnieje. Te same testy co w 2.0.3 | 1.7 |
|
||||||
| 1.28.3 | 2026-11-11 | Przeniesienie poprawek 2.0.2 na `1.x`, bez nowych funkcji: w `share` nazwy i identyfikatory wiadomości są sprawdzane (bez wstrzykiwania do `ckb.yaml`, bez zapisu poza `raw/inbox/`), każdy commit wiadomości musi pochodzić od właściciela skrzynki, podwójny wpis w `members.yaml` odbiera skrzynce właściciela, tylko zweryfikowane wycofanie ukrywa pocztę, gałąź i URL kanału są sprawdzane przed gitem, odebrane kopie zawsze mają `untrusted: true`, `<private>` usuwane z tytułu i `tldr`, bez skanu sekretów nie ma wysyłki; w `capture` cytowanie frontmattera i jednoliniowe tytuły; sprawdzenie 13 lintu przyjmuje Crux przypisany rozmowie bez `## Sources`. Te same testy co w 2.0.2 | 1.7 |
|
| 1.28.3 | 2026-11-11 | Przeniesienie poprawek 2.0.2 na `1.x`, bez nowych funkcji: w `share` nazwy i identyfikatory wiadomości są sprawdzane (bez wstrzykiwania do `ckb.yaml`, bez zapisu poza `raw/inbox/`), każdy commit wiadomości musi pochodzić od właściciela skrzynki, podwójny wpis w `members.yaml` odbiera skrzynce właściciela, tylko zweryfikowane wycofanie ukrywa pocztę, gałąź i URL kanału są sprawdzane przed gitem, odebrane kopie zawsze mają `untrusted: true`, `<private>` usuwane z tytułu i `tldr`, bez skanu sekretów nie ma wysyłki; w `capture` cytowanie frontmattera i jednoliniowe tytuły; sprawdzenie 13 lintu przyjmuje Crux przypisany rozmowie bez `## Sources`. Te same testy co w 2.0.2 | 1.7 |
|
||||||
|
|
|
||||||
65
tests/unit/test_frontmatter_contract.py
Normal file
65
tests/unit/test_frontmatter_contract.py
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
"""Eight scripts read page frontmatter, each with its own small parser (a
|
||||||
|
skill must stand alone when copied into a KB, so they can't share a module).
|
||||||
|
They must agree on what a page says. Inputs here are already decoded text:
|
||||||
|
BOM and CRLF are handled when the file is read (utf-8-sig, read_text)."""
|
||||||
|
import importlib.util
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
|
||||||
|
|
||||||
|
def load(rel, name):
|
||||||
|
spec = importlib.util.spec_from_file_location(name, str(ROOT / rel))
|
||||||
|
mod = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(mod)
|
||||||
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
lint = load(".agents/skills/ckb-lint/scripts/lint_report.py", "fm_lint")
|
||||||
|
retrieve = load(".agents/skills/ckb-retrieve/scripts/retrieve_candidates.py", "fm_retrieve")
|
||||||
|
consolidate = load(".agents/skills/ckb-consolidate/scripts/consolidate.py", "fm_consolidate")
|
||||||
|
okf = load(".agents/skills/ckb-export-okf/scripts/export_okf.py", "fm_okf")
|
||||||
|
starlight = load(".agents/skills/ckb-export-starlight/scripts/export_starlight.py", "fm_starlight")
|
||||||
|
dedup = load(".agents/skills/ckb-ingest/scripts/dedup_inbox.py", "fm_dedup")
|
||||||
|
share = load(".agents/modules/share/skills/ckb-share/scripts/share.py", "fm_share")
|
||||||
|
sys.path.insert(0, str(ROOT / ".agents/modules/mcp/server"))
|
||||||
|
kb = load(".agents/modules/mcp/server/kb.py", "fm_kb")
|
||||||
|
|
||||||
|
READERS = {
|
||||||
|
"lint": lambda t, k: lint.parse_frontmatter(t)[0].get(k),
|
||||||
|
"retrieve": lambda t, k: retrieve.parse_frontmatter(t)[0].get(k),
|
||||||
|
"consolidate": lambda t, k: consolidate.parse(t)[0].get(k),
|
||||||
|
"okf": lambda t, k: okf.parse_frontmatter(t)[0].get(k),
|
||||||
|
"starlight": lambda t, k: starlight.parse_frontmatter(t)[0].get(k),
|
||||||
|
"dedup": lambda t, k: dedup.frontmatter_value(t, k) or None,
|
||||||
|
"share": lambda t, k: share.parse_fm(t).get(k),
|
||||||
|
"mcp": lambda t, k: kb.parse_frontmatter(t)[0].get(k),
|
||||||
|
}
|
||||||
|
|
||||||
|
CASES = {
|
||||||
|
"plain": ("---\ntype: entity\ntldr: A page\n---\n\n# T\n", {"type": "entity", "tldr": "A page"}),
|
||||||
|
"ends at end of file": ("---\ntype: entity\ntldr: A page\n---", {"type": "entity", "tldr": "A page"}),
|
||||||
|
"comment line": ("---\n# note\ntype: entity\ntldr: A page\n---\n", {"type": "entity", "tldr": "A page"}),
|
||||||
|
"colon in value": ("---\ntype: entity\ntldr: Ratio 3: 1\n---\n", {"type": "entity", "tldr": "Ratio 3: 1"}),
|
||||||
|
"double-quoted": ('---\ntype: entity\ntldr: "Quoted: yes"\n---\n', {"type": "entity", "tldr": "Quoted: yes"}),
|
||||||
|
"dashes inside": ("---\ntype: entity\ntldr: a --- b\n---\n", {"type": "entity", "tldr": "a --- b"}),
|
||||||
|
"dash line in body": ("---\ntype: entity\n---\n\n---more\n", {"type": "entity", "tldr": None}),
|
||||||
|
"empty block": ("---\n---\n\n# T\n", {"type": None, "tldr": None}),
|
||||||
|
"no frontmatter": ("# Just a page\n\ntype: entity\n", {"type": None, "tldr": None}),
|
||||||
|
"unclosed": ("---\ntype: entity\ntldr: x\n", {"type": None, "tldr": None}),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Contract(unittest.TestCase):
|
||||||
|
def test_every_reader_agrees(self):
|
||||||
|
for case, (text, want) in CASES.items():
|
||||||
|
for name, read in READERS.items():
|
||||||
|
for key, value in want.items():
|
||||||
|
with self.subTest(case=case, reader=name, key=key):
|
||||||
|
self.assertEqual(read(text, key), value)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
104
tests/unit/test_lint_dirty.py
Normal file
104
tests/unit/test_lint_dirty.py
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
"""Every lint check must fire on its own fault. The golden lint.json of the
|
||||||
|
clean fixture has every category at zero, which proves only that the checks
|
||||||
|
stay quiet; this plants one fault per check and asserts exactly which files
|
||||||
|
each check reports."""
|
||||||
|
import hashlib
|
||||||
|
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"
|
||||||
|
TODAY = "2026-11-11"
|
||||||
|
SOURCE = "raw/archive/2026-09-01/kickoff-notes.md"
|
||||||
|
|
||||||
|
FM = "---\ntype: concept\ntldr: {name}\nlast_updated: 2026-11-01\nfreshness_window_days: 90\n{extra}---\n\n# {name}\n\n{body}\n"
|
||||||
|
|
||||||
|
|
||||||
|
def page(name, extra="", body="Text."):
|
||||||
|
return FM.format(name=name, extra=extra, body=body)
|
||||||
|
|
||||||
|
|
||||||
|
class DirtyKB(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
cls.tmp = tempfile.TemporaryDirectory()
|
||||||
|
kb = Path(cls.tmp.name) / "kb"
|
||||||
|
shutil.copytree(str(FIX), str(kb))
|
||||||
|
digest = hashlib.sha256((kb / SOURCE).read_bytes()).hexdigest()[:8]
|
||||||
|
bed = kb / "wiki" / "lintbed"
|
||||||
|
listed = {
|
||||||
|
"notype.md": "---\ntldr: no type here\n---\n\n# No type\n",
|
||||||
|
"stale.md": page("Stale", "").replace("last_updated: 2026-11-01", "last_updated: 2020-01-01"),
|
||||||
|
"lowconf.md": page("Low confidence", "confidence: 0.1\n"),
|
||||||
|
"archive.md": page("Archive me", "retention: low\n").replace("last_updated: 2026-11-01", "last_updated: 2020-01-01"),
|
||||||
|
"0099-undecided.md": "---\ntype: decision\ntldr: x\ndecided_by: A\n---\n\n# D-0099\n",
|
||||||
|
"drifted.md": page("Drifted", body=f"## Sources\n\n- `{SOURCE}` — sha256:00000000 (checked 2026-09-01)\n"),
|
||||||
|
"misquoted.md": page("Misquoted", body=f"## Sources\n\n- `{SOURCE}` — sha256:{digest} (checked 2026-09-01)\n\n"
|
||||||
|
"## Crux\n\n> This sentence was never in the kickoff notes at all.\n— "
|
||||||
|
f"`{SOURCE}`, under \"Notes\"\n"),
|
||||||
|
"unreviewed.md": page("Unreviewed", "review: reviewed\nreviewed_on: 2026-11-05\n"),
|
||||||
|
"contested.md": page("Contested", body="> CONTRADICTION: 3 retries (`a.md`) vs 5 retries (`b.md`) — found 2026-11-01\n"),
|
||||||
|
"tagged.md": page("Tagged", "tags: made-up-tag\n"),
|
||||||
|
}
|
||||||
|
bed.mkdir()
|
||||||
|
for name, text in listed.items():
|
||||||
|
(bed / name).write_text(text, encoding="utf-8")
|
||||||
|
(bed / "orphan.md").write_text(page("Orphan"), encoding="utf-8") # linked from nowhere
|
||||||
|
(bed / "nested").mkdir()
|
||||||
|
(bed / "nested" / "child.md").write_text(page("Child"), encoding="utf-8") # folder without index.md
|
||||||
|
(bed / "index.md").write_text("# Lint bed\n\n" + "".join(f"- [{n}]({n})\n" for n in listed)
|
||||||
|
+ "- [child](nested/child.md)\n", encoding="utf-8")
|
||||||
|
with (kb / "wiki" / "index.md").open("a", encoding="utf-8") as fh:
|
||||||
|
fh.write("\n- [Lint bed](lintbed/index.md)\n")
|
||||||
|
edges = kb / "wiki/graph/edges.json"
|
||||||
|
data = json.loads(edges.read_text(encoding="utf-8"))
|
||||||
|
data["edges"].append({"from": "entities/maria-nowak", "to": "entities/nobody", "type": "knows"})
|
||||||
|
edges.write_text(json.dumps(data), encoding="utf-8")
|
||||||
|
r = subprocess.run([sys.executable, str(LINT), "--json", "--today", TODAY], cwd=str(kb),
|
||||||
|
capture_output=True, text=True, encoding="utf-8")
|
||||||
|
cls.tree = json.loads(r.stdout)["trees"][0]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
cls.tmp.cleanup()
|
||||||
|
|
||||||
|
def files(self, category):
|
||||||
|
return {f.split(":", 1)[0] for f in self.tree[category]}
|
||||||
|
|
||||||
|
def test_each_check_reports_exactly_its_planted_files(self):
|
||||||
|
expected = {
|
||||||
|
"conformance": {"lintbed/notype.md"},
|
||||||
|
"freshness": {"lintbed/stale.md", "lintbed/archive.md"}, # an archive candidate is also stale
|
||||||
|
"confidence": {"lintbed/lowconf.md"},
|
||||||
|
"retention": {"lintbed/archive.md"},
|
||||||
|
"decisions": {"lintbed/0099-undecided.md"},
|
||||||
|
"orphans": {"lintbed/orphan.md"},
|
||||||
|
"graph": {"graph/edges.json"},
|
||||||
|
"index_log": {"lintbed/index.md", "lintbed/nested/index.md"}, # lists no orphan; nested has none
|
||||||
|
"evidence": {"lintbed/drifted.md"},
|
||||||
|
"crux": {"lintbed/misquoted.md"},
|
||||||
|
"review": {"lintbed/unreviewed.md"},
|
||||||
|
"contradictions": {"lintbed/contested.md"},
|
||||||
|
"tags": {"lintbed/tagged.md"},
|
||||||
|
}
|
||||||
|
for category, files in expected.items():
|
||||||
|
with self.subTest(check=category):
|
||||||
|
self.assertEqual(self.files(category), files, "\n".join(self.tree[category]))
|
||||||
|
|
||||||
|
def test_findings_say_what_is_wrong(self):
|
||||||
|
text = json.dumps(self.tree, ensure_ascii=False)
|
||||||
|
for phrase in ("missing or empty `type`", "stale —", "below 0.3", "archive candidate", "no `status`",
|
||||||
|
"no inbound links", "does not resolve to a page", "does not list lintbed/orphan.md",
|
||||||
|
"CHANGED since this page was built", "not found verbatim", "no `reviewed_by`",
|
||||||
|
"open contradiction", "tags.md"):
|
||||||
|
self.assertIn(phrase, text)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
Add table
Reference in a new issue