"""Motor step 2 (A6): the skill, the helpers and the tools reach a session started in a folder of documents. The repository is a Claude Code plugin: `.claude-plugin/plugin.json` names it, `skills/` and `agents/` sit at the root where a plugin's components are looked for, `.claude-plugin/marketplace.json` lets it be installed once from the local clone, and `bin/okf-wiki` (on the Bash tool's PATH while the plugin is enabled) runs `python3 -m okfwiki.` from any folder. Run: python3 -m unittest discover -s tests -p 'test_plugin.py' """ from __future__ import annotations import json import os import subprocess import sys import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) LAUNCHER = ROOT / "bin" / "okf-wiki" SKILL = ROOT / "skills" / "okf-wiki" / "SKILL.md" AGENTS = ("okf-wiki-compiler", "okf-wiki-linker", "okf-wiki-reader", "okf-wiki-merger", "okf-wiki-repairer") class PluginTest(unittest.TestCase): def test_the_manifest_names_the_plugin(self) -> None: doc = json.loads((ROOT / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8")) self.assertEqual(doc["name"], "okf-wiki") self.assertNotIn("skills", doc) # the default places hold them self.assertNotIn("agents", doc) self.assertTrue(SKILL.is_file()) for agent in AGENTS: self.assertTrue((ROOT / "agents" / f"{agent}.md").is_file(), agent) def test_the_marketplace_offers_the_plugin_from_its_own_root(self) -> None: doc = json.loads((ROOT / ".claude-plugin" / "marketplace.json").read_text(encoding="utf-8")) self.assertEqual([(p["name"], p["source"]) for p in doc["plugins"]], [("okf-wiki", "./")]) self.assertTrue(doc["name"] and doc["owner"]["name"]) def test_the_agents_the_repository_sessions_use_are_the_plugins_agents(self) -> None: for agent in AGENTS: self.assertEqual((ROOT / "agents" / f"{agent}.md").read_bytes(), (ROOT / ".claude" / "agents" / f"{agent}.md").read_bytes(), agent) def test_the_launcher_is_executable_ascii_and_runs_a_module_from_another_folder(self) -> None: data = LAUNCHER.read_bytes() self.assertTrue(os.access(LAUNCHER, os.X_OK)) self.assertTrue(data.startswith(b"#!/bin/bash\n")) data.decode("ascii") with tempfile.TemporaryDirectory() as tmp: folder = Path(tmp) / "docs" folder.mkdir() (folder / "a.md").write_text("# A\n\nOne.\n", encoding="utf-8") env = {k: v for k, v in os.environ.items() if k != "PYTHONPATH"} done = subprocess.run([str(LAUNCHER), "sources", "folder", "docs", "--collection", "x", "--out", "root"], cwd=tmp, env=env, capture_output=True, text=True, timeout=60) self.assertEqual(done.returncode, 0, done.stderr) self.assertIn("folder: 1 sources -> root", done.stdout) done = subprocess.run([str(LAUNCHER)], cwd=tmp, env=env, capture_output=True, text=True, timeout=60) self.assertEqual(done.returncode, 2) self.assertIn("usage: okf-wiki MODULE", done.stderr) def test_the_skill_says_how_a_session_in_a_document_folder_runs_the_tools_and_names_the_helpers(self) -> None: text = SKILL.read_text(encoding="utf-8") self.assertIn("python3 -m okfwiki.sources folder", text) self.assertIn("`okf-wiki `", text) self.assertIn("okf-wiki:okf-wiki-compiler", text) if __name__ == "__main__": unittest.main()