Dianel555/DSkills / skills/agent-wiki
agent-wiki
UnverifiedIncremental LLM-friendly wiki generator for Obsidian note vaults. Use when: (1) Building wiki from notes, (2) Ingesting notes to wiki, (3) Obsidian LLM wiki, (4) Incremental knowledge base management. Triggers: 'build wiki from notes', 'ingest notes to wiki', 'Obsidian LLM wiki', 'incremental knowledge base'.
tests/test_cli.py
View on GitHubimport json
import os
import subprocess
import sys
from pathlib import Path
from agent_wiki import frontmatter
ROOT = Path(__file__).resolve().parents[1]
CLI = ROOT / "scripts" / "agent_wiki_cli.py"
def run_cli(*args, env=None):
full_env = os.environ.copy()
if env:
full_env.update(env)
return subprocess.run(
[sys.executable, str(CLI), *args],
text=True,
encoding="utf-8",
capture_output=True,
env=full_env,
)
def test_cli_missing_vault_returns_json_error(monkeypatch, tmp_path):
# Create an isolated environment without vault config
env = os.environ.copy()
env.pop("AGENT_WIKI_VAULT", None)
env["DOTENV_DISABLE"] = "1" # Disable .env loading for this test
result = subprocess.run(
[sys.executable, str(CLI), "status"],
text=True,
encoding="utf-8",
capture_output=True,
env=env,
cwd=tmp_path, # Run from temp dir
)
assert result.returncode == 2
assert json.loads(result.stderr)["error"] == "vault path required"
def test_cli_version():
result = run_cli("--version")
assert result.returncode == 0
assert result.stdout.strip() == "agent-wiki 0.1.0"
def test_init_fresh_partial_and_idempotent(tmp_path):
result = run_cli("init", "--vault", str(tmp_path))
assert result.returncode == 0, result.stderr
payload = json.loads(result.stdout)
assert payload["status"] == "ok"
assert (tmp_path / "wiki" / "index.md").exists()
assert (tmp_path / "wiki" / "log.md").exists()
assert (tmp_path / "wiki" / "topics").is_dir()
second = run_cli("init", "--vault", str(tmp_path))
assert json.loads(second.stdout) == {"status": "already_initialized", "created": []}
def test_cache_put_get_round_trip(tmp_path):
(tmp_path / "note.md").write_text("hello", encoding="utf-8")
assert run_cli("init", "--vault", str(tmp_path)).returncode == 0
put = run_cli("cache-put", "note.md", "--topics", "topic.md, other.md ", "--vault", str(tmp_path))
assert put.returncode == 0, put.stderr
put_payload = json.loads(put.stdout)
assert put_payload["ok"] is True
assert put_payload["path"] == "note.md"
get = run_cli("cache-get", "note.md", "--vault", str(tmp_path))
payload = json.loads(get.stdout)
assert payload["path"] == "note.md"
assert payload["derived_topics"] == ["topic.md", "other.md"]
def test_scan_reports_new_modified_deleted(tmp_path):
(tmp_path / "a.md").write_text("a", encoding="utf-8")
run_cli("init", "--vault", str(tmp_path))
run_cli("cache-put", "a.md", "--topics", "A.md", "--vault", str(tmp_path))
(tmp_path / "a.md").write_text("a2", encoding="utf-8")
(tmp_path / "中文.md").write_text("new", encoding="utf-8")
scan = run_cli("scan", "--vault", str(tmp_path))
payload = json.loads(scan.stdout)
assert [item["path"] for item in payload["modified"]] == ["a.md"]
assert [item["path"] for item in payload["new"]] == ["中文.md"]
(tmp_path / "a.md").unlink()
deleted = json.loads(run_cli("scan", "--vault", str(tmp_path)).stdout)
assert deleted["deleted"] == [{"path": "a.md", "derived_topics": ["A.md"]}]
def test_cleanup_archives_orphaned_topic_and_updates_cache(tmp_path):
(tmp_path / "a.md").write_text("a", encoding="utf-8")
run_cli("init", "--vault", str(tmp_path))
topic = tmp_path / "wiki" / "topics" / "A.md"
topic.write_text(frontmatter.dump({"title": "A", "sources": ["a.md"]}, "# A\n"), encoding="utf-8")
run_cli("cache-put", "a.md", "--topics", "A.md", "--vault", str(tmp_path))
(tmp_path / "a.md").unlink()
result = run_cli("cleanup", "--vault", str(tmp_path))
payload = json.loads(result.stdout)
assert payload["removed"] == 1
assert payload["archived"] == 1
assert (tmp_path / "wiki" / "_archived").exists()
assert json.loads(run_cli("cache-get", "a.md", "--vault", str(tmp_path)).stdout)["status"] == "absent"
second = json.loads(run_cli("cleanup", "--vault", str(tmp_path)).stdout)
assert second["removed"] == 0
assert second["archived"] == 0
def test_status_reports_health(tmp_path):
run_cli("init", "--vault", str(tmp_path))
topic = tmp_path / "wiki" / "topics" / "orphan.md"
topic.write_text(frontmatter.dump({"sources": []}, "body"), encoding="utf-8")
result = run_cli("status", "--vault", str(tmp_path))
payload = json.loads(result.stdout)
assert payload["topics_total"] == 1
assert payload["topics_orphaned"] == 1
assert payload["sources_tracked"] == 0
assert "last_log_entry" in payload
def test_plan_resume_reuses_existing_state(tmp_path):
(tmp_path / "a.md").write_text("a", encoding="utf-8")
run_cli("init", "--vault", str(tmp_path))
first = json.loads(run_cli("plan", "--batch-size", "5", "--vault", str(tmp_path)).stdout)
assert first["resumed"] is False and first["total"] == 1
resumed = json.loads(run_cli("plan", "--resume", "--vault", str(tmp_path)).stdout)
assert resumed["resumed"] is True
assert resumed["batches"] == first["batches"]
(tmp_path / "wiki" / ".wiki-batch.json").unlink()
missing = run_cli("plan", "--resume", "--vault", str(tmp_path))
assert missing.returncode == 1
assert json.loads(missing.stderr)["error"] == "no_existing_plan"
def test_normalize_source_type_backfills_from_sources(tmp_path):
run_cli("init", "--vault", str(tmp_path))
topic = tmp_path / "wiki" / "topics" / "T.md"
topic.write_text(frontmatter.dump({"title": "T", "sources": ["paper.pdf"]}, "body"), encoding="utf-8")
payload = json.loads(run_cli("normalize-source-type", "--vault", str(tmp_path)).stdout)
assert payload["changed"] == [{"path": "T.md", "source_type": "pdf"}]
assert frontmatter.parse(topic.read_text(encoding="utf-8"))[0]["source_type"] == "pdf"
again = json.loads(run_cli("normalize-source-type", "--vault", str(tmp_path)).stdout)
assert again["changed"] == [] and again["skipped"] == 1
def test_verbose_writes_progress_to_stderr_only(tmp_path):
run_cli("init", "--vault", str(tmp_path))
result = run_cli("--verbose", "scan", "--vault", str(tmp_path))
assert result.returncode == 0
assert "[agent-wiki]" in result.stderr
assert json.loads(result.stdout)["stats"]["total_sources"] == 0
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |