a907e7da79
Rename the template skill to the <name>/SKILL.md convention, add the frontmatter description fmlint requires (FML004), point every reference at the new path (SPEC 3.4.2), and add template tests. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
216 lines
8.2 KiB
Python
216 lines
8.2 KiB
Python
"""Tests for the deployed-wiki rules in the llm-wiki template (SPEC 3.3).
|
|
|
|
Generated by AI/LLM: 2026-09-30 - the template is self-contained and
|
|
tells a deployed wiki to commit after ingest and housekeeping.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import re
|
|
|
|
import pytest
|
|
|
|
from fiona.paths import llm_wiki_template
|
|
|
|
TEMPLATE = llm_wiki_template()
|
|
AGENTS = TEMPLATE / "AGENTS.md"
|
|
SKILL = TEMPLATE / "utils" / "skills" / "fiona" / "SKILL.md"
|
|
LOG = TEMPLATE / "wiki" / "log.md"
|
|
MEMORY = TEMPLATE / "MEMORY.md"
|
|
MEMORY_SKILL = TEMPLATE / "utils" / "skills" / "memory" / "SKILL.md"
|
|
MEMORIES = TEMPLATE / "utils" / "skills" / "memory" / "MEMORIES.md"
|
|
SKILLS_README = TEMPLATE / "utils" / "skills" / "README.md"
|
|
SECTIONIZE_SKILL = TEMPLATE / "utils" / "skills" / "sectionize-markdown" / "SKILL.md"
|
|
MEMORY_FILES = pytest.mark.parametrize("path", [MEMORY, MEMORIES], ids=["MEMORY", "MEMORIES"])
|
|
HEADING = re.compile(r"^(#{2,6}) (\S+) ")
|
|
LIST_ITEM = re.compile(r"^\s*- (\[[ x]\] )?(\*\*([\d.]+)\*\*)?")
|
|
|
|
|
|
def _body(path: pathlib.Path) -> str:
|
|
"""Return the markdown text after the frontmatter block.
|
|
|
|
Generated by AI/LLM: 2026-09-30 - drop frontmatter before content checks.
|
|
"""
|
|
text = path.read_text(encoding="utf-8")
|
|
return text.split("---", 2)[2] if text.startswith("---") else text
|
|
|
|
|
|
@pytest.mark.parametrize("path", sorted(TEMPLATE.rglob("*.md")), ids=str)
|
|
@pytest.mark.parametrize("needle", ["SPEC", "project agent rule", "scripts/run_"])
|
|
def test_template_markdown_has_no_outside_reference(path: pathlib.Path, needle: str) -> None:
|
|
"""SPEC 3.3.1: template markdown never cites files outside the template.
|
|
|
|
Generated by AI/LLM: 2026-09-30 - a deployed wiki only has the template.
|
|
"""
|
|
assert needle not in path.read_text(encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.parametrize("link", ["./utils/skills/fiona/SKILL.md", "./utils/skills/fiona/llm-wiki-mod.md"])
|
|
def test_agents_links_skill_and_concept(link: str) -> None:
|
|
"""SPEC 3.3.2: the entry point links the Fiona skill and llm-wiki-mod.
|
|
|
|
Generated by AI/LLM: 2026-09-30 - AGENTS.md is the wiki entry point.
|
|
"""
|
|
assert f"]({link})" in AGENTS.read_text(encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.parametrize("path", [AGENTS, SKILL], ids=["AGENTS", "SKILL"])
|
|
def test_deployed_wiki_commits_after_ingest(path: pathlib.Path) -> None:
|
|
"""SPEC 3.3.3: save after ingest and housekeeping, not only when asked.
|
|
|
|
Generated by AI/LLM: 2026-09-30 - commits are the wiki's history.
|
|
"""
|
|
text = " ".join(path.read_text(encoding="utf-8").split())
|
|
assert "git save" in text
|
|
assert not re.search(r"(commit|Run them)[^.]*only when the user asked", text)
|
|
assert "Do not commit" not in text
|
|
|
|
|
|
def test_seed_log_has_one_entry() -> None:
|
|
"""SPEC 3.3.4: a new wiki's log starts with one seed bullet.
|
|
|
|
Generated by AI/LLM: 2026-09-30 - no product history in a new wiki.
|
|
"""
|
|
bullets = [line for line in _body(LOG).splitlines() if line.startswith("- ")]
|
|
assert bullets == ["- DATE_PLACEHOLDER - Initialized the llm-wiki."]
|
|
|
|
|
|
def _memory_lines(path: pathlib.Path = MEMORY) -> list[str]:
|
|
"""Return memory body lines outside the TOC block and code fences.
|
|
|
|
Generated by AI/LLM: 2026-10-14 - sectionize ids skip TOC and code.
|
|
Modified by AI/LLM: 2026-10-15 - any memory file (SPEC 3.5.2).
|
|
"""
|
|
lines, skip = [], False
|
|
for line in _body(path).splitlines():
|
|
if line.startswith(("<!-- toc-start", "```")):
|
|
skip = not skip if line.startswith("```") else True
|
|
continue
|
|
if line.startswith("<!-- toc-end"):
|
|
skip = False
|
|
continue
|
|
if not skip:
|
|
lines.append(line)
|
|
return lines
|
|
|
|
|
|
def test_memory_frontmatter() -> None:
|
|
"""SPEC 3.4.1: the template ships MEMORY.md named memory with a version.
|
|
|
|
Generated by AI/LLM: 2026-10-14 - the file wiki init copies.
|
|
"""
|
|
head = MEMORY.read_text(encoding="utf-8").split("---", 2)[1]
|
|
assert re.search(r"^name: memory$", head, re.MULTILINE)
|
|
assert re.search(r"^version: \d+\.\d+\.\d+$", head, re.MULTILINE)
|
|
|
|
|
|
@MEMORY_FILES
|
|
def test_memory_is_sectionized(path: pathlib.Path) -> None:
|
|
"""SPEC 3.4.2, 3.5.2: numbered headings, an id on every item, ids unique and in section.
|
|
|
|
Generated by AI/LLM: 2026-10-14 - sectionize-markdown sections 1 and 2.
|
|
Modified by AI/LLM: 2026-10-15 - also the skill memory template.
|
|
"""
|
|
section, seen = "", []
|
|
for line in _memory_lines(path):
|
|
heading = HEADING.match(line)
|
|
if heading:
|
|
section = heading.group(2).rstrip(".")
|
|
assert re.fullmatch(r"\d+(\.\d+)*", section), line
|
|
assert section.count(".") == len(heading.group(1)) - 2, line
|
|
continue
|
|
item = LIST_ITEM.match(line)
|
|
if item:
|
|
assert item.group(3), line
|
|
assert item.group(3).startswith(f"{section}."), line
|
|
seen.append(item.group(3))
|
|
assert seen
|
|
assert len(seen) == len(set(seen))
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"heading",
|
|
["1.1 When to read", "1.2 When to write", "1.3 How to write", "1.4 How the memory evolves"],
|
|
)
|
|
@MEMORY_FILES
|
|
def test_memory_states_its_rules(heading: str, path: pathlib.Path) -> None:
|
|
"""SPEC 3.4.3, 3.5.2: section 1 says when to read, write, and evolve entries.
|
|
|
|
Generated by AI/LLM: 2026-10-14 - the four subsections of section 1.
|
|
Modified by AI/LLM: 2026-10-15 - also the skill memory template.
|
|
"""
|
|
assert f"### {heading}" in _memory_lines(path)
|
|
|
|
|
|
def test_skill_memories_frontmatter() -> None:
|
|
"""SPEC 3.5.2: the skill memory template has a name and a version.
|
|
|
|
Generated by AI/LLM: 2026-10-15 - the file a skill copies.
|
|
"""
|
|
head = MEMORIES.read_text(encoding="utf-8").split("---", 2)[1]
|
|
assert re.search(r"^name: \S+$", head, re.MULTILINE)
|
|
assert re.search(r"^version: \d+\.\d+\.\d+$", head, re.MULTILINE)
|
|
|
|
|
|
def test_memory_skill_frontmatter_and_links() -> None:
|
|
"""SPEC 3.5.1: the memory skill is named memory and links both memory files.
|
|
|
|
Generated by AI/LLM: 2026-10-15 - instructions for a skill with memory.
|
|
"""
|
|
text = MEMORY_SKILL.read_text(encoding="utf-8")
|
|
head = text.split("---", 2)[1]
|
|
assert re.search(r"^name: memory$", head, re.MULTILINE)
|
|
assert re.search(r"^version: \d+\.\d+\.\d+$", head, re.MULTILINE)
|
|
assert "](./MEMORIES.md)" in text
|
|
assert "](../../../MEMORY.md)" in text
|
|
|
|
|
|
def test_agents_links_memory() -> None:
|
|
"""SPEC 3.4.5: the entry point links MEMORY.md.
|
|
|
|
Generated by AI/LLM: 2026-10-14 - the agent reads memory after the skill.
|
|
"""
|
|
assert "](./MEMORY.md)" in AGENTS.read_text(encoding="utf-8")
|
|
|
|
|
|
def test_agents_says_when_to_update_memory() -> None:
|
|
"""SPEC 3.4.6: update memory on an important memory or an explicit request.
|
|
|
|
Generated by AI/LLM: 2026-10-14 - the write triggers live in the entry point.
|
|
"""
|
|
text = " ".join(AGENTS.read_text(encoding="utf-8").split())
|
|
assert "Update `MEMORY.md` whenever an important memory comes up" in text
|
|
assert "whenever the user explicitly asks" in text
|
|
|
|
|
|
def test_sectionize_skill_is_skill_md() -> None:
|
|
"""SPEC 3.4.2: the sectionize skill ships as SKILL.md, like every skill.
|
|
|
|
Generated by AI/LLM: 2026-10-21 - a proper skill is <name>/SKILL.md.
|
|
"""
|
|
head = SECTIONIZE_SKILL.read_text(encoding="utf-8").split("---", 2)[1]
|
|
assert re.search(r"^name: sectionize-markdown$", head, re.MULTILINE)
|
|
assert re.search(r"^version: \d+\.\d+\.\d+$", head, re.MULTILINE)
|
|
assert re.search(r"^description: \S", head, re.MULTILINE)
|
|
assert not (SECTIONIZE_SKILL.parent / "sectionize-markdown.md").exists()
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"path, link",
|
|
[
|
|
(MEMORY, "./utils/skills/sectionize-markdown/SKILL.md"),
|
|
(MEMORY_SKILL, "../sectionize-markdown/SKILL.md"),
|
|
(MEMORIES, "../../skills/sectionize-markdown/SKILL.md"),
|
|
(SKILLS_README, "./sectionize-markdown/SKILL.md"),
|
|
],
|
|
ids=["MEMORY", "memory-SKILL", "MEMORIES", "skills-README"],
|
|
)
|
|
def test_files_link_sectionize_skill_md(path: pathlib.Path, link: str) -> None:
|
|
"""SPEC 3.4.2: every reference to the sectionize skill points at its SKILL.md.
|
|
|
|
Generated by AI/LLM: 2026-10-21 - the skill moved from
|
|
sectionize-markdown.md to SKILL.md.
|
|
"""
|
|
assert f"]({link})" in path.read_text(encoding="utf-8")
|