ed3d21fd54
- every bundled skill ships MEMORIES.md (memory-skill template, name substituted); autotest frontmatter check enforces its presence (SPEC 4.7) - copy_skill: MEMORIES.md is add-only - installed from the bundle when missing, never overwritten, on both install and update; --force does not change this (SPEC 4.7, 6.8, 7.6); uninstall removes it with the directory (SPEC 6.9, sad by design) - FIX bug in --update: it passed the skill directory where the skills root was expected, copying the bundle into skills/<name>/<name>/ and never refreshing the real SKILL.md; now updates the real files and heals the legacy nested directory on the next copy (SPEC 7.7) - tests strengthened to assert file contents, not just output: 84 total, all checks green; e2e-verified via the installed pipx CLI Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
380 lines
13 KiB
Python
380 lines
13 KiB
Python
"""CLI tests: list, filter, install, prompt, force, and update (SPEC sections 3, 6, 7)."""
|
|
import json
|
|
import shutil
|
|
|
|
import pytest
|
|
|
|
from phronesis import cli
|
|
from phronesis import harnesses
|
|
from phronesis import registry
|
|
from phronesis import state
|
|
|
|
|
|
@pytest.fixture
|
|
def config(tmp_path, monkeypatch):
|
|
"""An isolated state file and an isolated vibe home."""
|
|
monkeypatch.setenv("PHRONESIS_CONFIG", str(tmp_path / "cfg"))
|
|
harnesses.HARNESS_REGISTRY["vibe"].home = tmp_path / "home"
|
|
yield tmp_path / "cfg"
|
|
harnesses.HARNESS_REGISTRY["vibe"].home = None
|
|
|
|
|
|
def run(capsys, *argv):
|
|
code = cli.main(list(argv))
|
|
out = capsys.readouterr()
|
|
return code, out.out, out.err
|
|
|
|
|
|
def test_bare_call_lists_every_skill(config, capsys):
|
|
code, out, err = run(capsys)
|
|
assert code == 0
|
|
assert out.startswith("Phronesis Version:")
|
|
assert "python-tdd" in out and "1.2.0" in out and "development" in out
|
|
|
|
|
|
def test_list_flag_matches_bare_call(config, capsys):
|
|
assert run(capsys, "--list")[0] == 0
|
|
|
|
|
|
def test_version_flag(config, capsys):
|
|
code, out, _ = run(capsys, "--version")
|
|
assert code == 0
|
|
assert out.startswith("phronesis ")
|
|
|
|
|
|
def test_category_filters_the_table(config, capsys):
|
|
code, out, _ = run(capsys, "development")
|
|
assert code == 0
|
|
assert "python-tdd" in out
|
|
|
|
|
|
def test_unknown_category_prompts_close_matches(config, capsys):
|
|
code, out, err = run(capsys, "developmint")
|
|
assert code == 2
|
|
assert "did you mean" in err
|
|
|
|
|
|
def test_unknown_skill_suggests(config, capsys):
|
|
code, _, err = run(capsys, "python-tb", "--install")
|
|
assert code == 2
|
|
assert "python-tdd" in err
|
|
|
|
|
|
def test_show_one_skill_prints_install_hint(config, capsys):
|
|
code, out, _ = run(capsys, "python-tdd")
|
|
assert code == 0
|
|
assert out.count("python-tdd") >= 2
|
|
assert "install: phronesis python-tdd --install --harness vibe" in out
|
|
|
|
|
|
def test_install_and_project_reject_each_other(config, capsys):
|
|
code, _, err = run(capsys, "python-tdd", "--install", "--project")
|
|
assert code == 2
|
|
|
|
|
|
def test_unknown_harness_exits_two(config, capsys):
|
|
code, _, err = run(capsys, "python-tdd", "--install", "--harness", "colossus")
|
|
assert code == 2
|
|
assert "vibe" in err
|
|
|
|
|
|
def test_install_needs_one_skill_word(config, capsys):
|
|
code, _, err = run(capsys, "--install")
|
|
assert code == 2
|
|
|
|
|
|
def test_install_writes_skill_and_state(config, capsys):
|
|
code, out, _ = run(capsys, "python-tdd", "--install")
|
|
assert code == 0
|
|
target = config.parent / "home" / ".vibe" / "skills" / "python-tdd" / "SKILL.md"
|
|
assert target.is_file()
|
|
assert str(target) in out
|
|
entries = state.load(state.state_path())
|
|
assert [e["name"] for e in entries] == ["python-tdd"]
|
|
assert entries[0]["version"] == "1.2.0"
|
|
assert entries[0]["scope"] == "global"
|
|
|
|
|
|
def test_project_install_lands_in_the_project(config, capsys, tmp_path, monkeypatch):
|
|
work = tmp_path / "work"
|
|
work.mkdir()
|
|
monkeypatch.chdir(work)
|
|
code, _, _ = run(capsys, "python-tdd", "--project")
|
|
assert code == 0
|
|
target = tmp_path / "work" / ".vibe" / "skills" / "python-tdd" / "SKILL.md"
|
|
assert target.is_file()
|
|
assert state.load(state.state_path())[0]["scope"] == "project"
|
|
|
|
|
|
def test_prompt_shown_when_installed(config, capsys, monkeypatch, tmp_path):
|
|
answers = iter(["y"])
|
|
monkeypatch.setattr("builtins.input", lambda prompt: answers.__next__())
|
|
run(capsys, "python-tdd", "--install")
|
|
asked = run(capsys, "python-tdd", "--install")
|
|
assert asked[0] == 0
|
|
|
|
|
|
def test_prompt_no_leaves_target_untouched(config, capsys, monkeypatch):
|
|
monkeypatch.setattr("builtins.input", lambda prompt: "n")
|
|
run(capsys, "python-tdd", "--install")
|
|
target = config.parent / "home" / ".vibe" / "skills" / "python-tdd" / "SKILL.md"
|
|
before = target.read_text(encoding="utf-8")
|
|
code, out, err = run(capsys, "python-tdd", "--install")
|
|
assert code == 0
|
|
assert "skipped" in out
|
|
assert target.read_text(encoding="utf-8") == before
|
|
|
|
|
|
def test_prompt_accepts_default_no(config, capsys, monkeypatch):
|
|
monkeypatch.setattr("builtins.input", lambda prompt: "")
|
|
run(capsys, "python-tdd", "--install")
|
|
code, out, _ = run(capsys, "python-tdd", "--install")
|
|
assert code == 0
|
|
assert "skipped" in out
|
|
|
|
|
|
def test_prompt_eof_on_stdin_means_no(config, capsys, monkeypatch):
|
|
def eof(prompt):
|
|
raise EOFError
|
|
|
|
monkeypatch.setattr("builtins.input", eof)
|
|
run(capsys, "python-tdd", "--install")
|
|
code, out, _ = run(capsys, "python-tdd", "--install")
|
|
assert code == 0
|
|
assert "skipped" in out
|
|
|
|
|
|
def test_force_overwrites_without_prompt(config, capsys, monkeypatch):
|
|
def fail(prompt):
|
|
raise AssertionError("force must not prompt")
|
|
|
|
monkeypatch.setattr("builtins.input", fail)
|
|
run(capsys, "python-tdd", "--install")
|
|
code, out, _ = run(capsys, "python-tdd", "--install", "--force")
|
|
assert code == 0
|
|
assert "installed" in out
|
|
|
|
|
|
def test_short_force_flag_matches_long(config, capsys):
|
|
code, out, _ = run(capsys, "python-tdd", "--install", "-f")
|
|
assert code == 0
|
|
|
|
|
|
def test_update_refreshes_installed_skills(config, capsys):
|
|
path = state.state_path()
|
|
skills_root = config.parent / "home" / ".vibe" / "skills"
|
|
state.save([{"name": "python-tdd", "version": "1.0.0", "harness": "vibe",
|
|
"scope": "global",
|
|
"path": str(skills_root / "python-tdd" / "SKILL.md"),
|
|
"installed": "2026-01-01"}], path)
|
|
(skills_root / "python-tdd").mkdir(parents=True)
|
|
(skills_root / "python-tdd" / "SKILL.md").write_text("-old one-\n",
|
|
encoding="utf-8")
|
|
code, out, err = run(capsys, "--update")
|
|
assert code == 0
|
|
assert "1.0.0 -> 1.2.0" in out
|
|
assert state.load(path)[0]["version"] == "1.2.0"
|
|
installed = (skills_root / "python-tdd" / "SKILL.md").read_text(
|
|
encoding="utf-8")
|
|
assert "-old one-" not in installed
|
|
assert installed == registry.SKILLS["python-tdd"].skill_md.read_text(
|
|
encoding="utf-8")
|
|
|
|
|
|
def test_update_heals_a_legacy_nested_copy(config, capsys):
|
|
skills_root = config.parent / "home" / ".vibe" / "skills"
|
|
run(capsys, "python-tdd", "--install")
|
|
legacy = skills_root / "python-tdd" / "python-tdd"
|
|
shutil.copytree(registry.SKILLS["python-tdd"].source_dir, legacy)
|
|
code, _, _ = run(capsys, "--update")
|
|
assert code == 0
|
|
assert not legacy.exists()
|
|
assert (skills_root / "python-tdd" / "SKILL.md").is_file()
|
|
|
|
|
|
def test_update_nothing_installed(config, capsys):
|
|
code, out, _ = run(capsys, "--update")
|
|
assert code == 0
|
|
assert "nothing installed" in out
|
|
|
|
|
|
def test_update_warns_for_unbundled_skill(config, capsys):
|
|
path = state.state_path()
|
|
state.save([{"name": "ghost", "version": "1.0.0", "harness": "vibe",
|
|
"scope": "global", "path": "/tmp/ghost/SKILL.md",
|
|
"installed": "2026-01-01"}], path)
|
|
code, out, err = run(capsys, "--update")
|
|
assert code == 0
|
|
assert "no longer bundled" in err
|
|
|
|
|
|
def test_update_reinstalls_a_missing_target(config, capsys, tmp_path):
|
|
path = state.state_path()
|
|
skills_root = config.parent / "home" / ".vibe" / "skills"
|
|
state.save([{"name": "python-tdd", "version": "1.1.0", "harness": "vibe",
|
|
"scope": "global",
|
|
"path": str(skills_root / "python-tdd" / "SKILL.md"),
|
|
"installed": "2026-01-01"}], path)
|
|
code, out, _ = run(capsys, "--update")
|
|
assert code == 0
|
|
assert "1.1.0 -> 1.2.0" in out
|
|
assert (skills_root / "python-tdd" / "SKILL.md").is_file()
|
|
|
|
|
|
def test_state_entries_unique_by_scope(config, capsys, tmp_path, monkeypatch):
|
|
run(capsys, "python-tdd", "--install")
|
|
work = tmp_path / "work2"
|
|
work.mkdir()
|
|
monkeypatch.chdir(work)
|
|
run(capsys, "python-tdd", "--project")
|
|
entries = state.load(state.state_path())
|
|
assert sorted(e["scope"] for e in entries) == ["global", "project"]
|
|
|
|
|
|
def test_installed_json_is_plain_json(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
data = json.loads(state.state_path().read_text(encoding="utf-8"))
|
|
assert set(data) == {"skills"}
|
|
assert set(data["skills"][0]) == {"name", "version", "harness", "scope",
|
|
"path", "installed"}
|
|
|
|
|
|
# --- uninstall (SPEC items 6.6, 6.7, 8.4)
|
|
|
|
|
|
def test_uninstall_removes_skill_and_state(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
target = config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
code, out, _ = run(capsys, "python-tdd", "--uninstall")
|
|
assert code == 0
|
|
assert "removed python-tdd 1.2.0 (vibe, global)" in out
|
|
assert not target.exists()
|
|
assert state.load(state.state_path()) == []
|
|
|
|
|
|
def test_uninstall_project_scoped(config, capsys, tmp_path, monkeypatch):
|
|
work = tmp_path / "work"
|
|
work.mkdir()
|
|
monkeypatch.chdir(work)
|
|
run(capsys, "python-tdd", "--project")
|
|
code, _, _ = run(capsys, "python-tdd", "--uninstall", "--project")
|
|
assert code == 0
|
|
assert not (work / ".vibe" / "skills" / "python-tdd").exists()
|
|
assert state.load(state.state_path()) == []
|
|
|
|
|
|
def test_uninstall_needs_the_skill_installed(config, capsys):
|
|
code, _, err = run(capsys, "python-tdd", "--uninstall")
|
|
assert code == 2
|
|
assert "not installed" in err
|
|
|
|
|
|
def test_uninstall_refuses_a_non_skill_directory(config, capsys):
|
|
target = config.parent / "home" / ".vibe" / "skills" / "not-a-skill"
|
|
target.mkdir(parents=True)
|
|
(target / "SKILL.md").write_text("random notes, no front matter",
|
|
encoding="utf-8")
|
|
code, _, err = run(capsys, "not-a-skill", "--uninstall")
|
|
assert code == 2
|
|
assert "refusing to remove" in err
|
|
assert (target / "SKILL.md").is_file()
|
|
|
|
|
|
def test_uninstall_refuses_a_name_mismatch(config, capsys):
|
|
skill_md_run = run(capsys, "python-tdd", "--install")
|
|
target_dir = config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
other = target_dir.parent / "other-name"
|
|
other.mkdir()
|
|
shutil.copytree(target_dir, other, dirs_exist_ok=True)
|
|
code, _, err = run(capsys, "other-name", "--uninstall")
|
|
assert code == 2
|
|
assert "does not match the directory" in err
|
|
assert (other / "SKILL.md").is_file()
|
|
|
|
|
|
def test_uninstall_works_without_a_state_entry(config, capsys):
|
|
target = config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
target.mkdir(parents=True)
|
|
body = registry.SKILLS["python-tdd"].skill_md.read_text(encoding="utf-8")
|
|
(target / "SKILL.md").write_text(body, encoding="utf-8")
|
|
code, out, _ = run(capsys, "python-tdd", "--uninstall")
|
|
assert code == 0
|
|
assert "removed" in out
|
|
assert not target.exists()
|
|
|
|
|
|
def test_install_and_uninstall_are_exclusive(config, capsys):
|
|
code, _, err = run(capsys, "python-tdd", "--install", "--uninstall")
|
|
assert code == 2
|
|
assert "pick one of --install or --uninstall" in err
|
|
|
|
|
|
def test_uninstall_of_unbundled_name_is_allowed(config, capsys):
|
|
target = config.parent / "home" / ".vibe" / "skills" / "retired-skill"
|
|
target.mkdir(parents=True)
|
|
(target / "SKILL.md").write_text(
|
|
"---\nname: retired-skill\nversion: 0.9.0\ndescription: gone\n"
|
|
"category: misc\n---\n", encoding="utf-8")
|
|
code, out, _ = run(capsys, "retired-skill", "--uninstall")
|
|
assert code == 0
|
|
assert not target.exists()
|
|
|
|
|
|
# --- MEMORIES.md is add-only (SPEC items 4.7, 6.8, 6.9, 7.6)
|
|
|
|
|
|
def test_every_bundled_skill_ships_a_memory_template():
|
|
for name, skill in registry.SKILLS.items():
|
|
assert (skill.source_dir / "MEMORIES.md").is_file(), name
|
|
|
|
|
|
def test_install_adds_the_memory_template(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
memories = (config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
/ "MEMORIES.md")
|
|
assert memories.is_file()
|
|
assert "python-tdd Memories" in memories.read_text(encoding="utf-8")
|
|
|
|
|
|
def test_reinstall_preserves_a_locally_edited_memory(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
memories = (config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
/ "MEMORIES.md")
|
|
memories.write_text("my precious local notes\n", encoding="utf-8")
|
|
code, _, _ = run(capsys, "python-tdd", "--install", "--force")
|
|
assert code == 0
|
|
assert memories.read_text(encoding="utf-8") == "my precious local notes\n"
|
|
|
|
|
|
def test_update_preserves_a_locally_edited_memory(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
memories = (config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
/ "MEMORIES.md")
|
|
memories.write_text("keep me\n", encoding="utf-8")
|
|
state_path = state.state_path()
|
|
entries = state.load(state_path)
|
|
entries[0]["version"] = "1.0.0"
|
|
state.save(entries, state_path)
|
|
run(capsys, "--update")
|
|
assert memories.read_text(encoding="utf-8") == "keep me\n"
|
|
assert state.load(state_path)[0]["version"] == "1.2.0"
|
|
|
|
|
|
def test_update_adds_a_missing_memory_file(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
memories = (config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
/ "MEMORIES.md")
|
|
memories.unlink()
|
|
run(capsys, "--update")
|
|
assert memories.is_file()
|
|
assert "python-tdd Memories" in memories.read_text(encoding="utf-8")
|
|
|
|
|
|
def test_uninstall_takes_the_memory_with_it(config, capsys):
|
|
run(capsys, "python-tdd", "--install")
|
|
memories = (config.parent / "home" / ".vibe" / "skills" / "python-tdd"
|
|
/ "MEMORIES.md")
|
|
assert memories.is_file()
|
|
run(capsys, "python-tdd", "--uninstall")
|
|
assert not memories.exists()
|