Files
phronesis/test/test_cli.py
T
nvaldez 196df53a9b phronesis v0.2.0: the CLI app per SPEC.md - list, filter, install, update
- SPEC.md sectionized with stable ids (sectionize-markdown conventions)
- src/phronesis: cli, registry, harnesses (modular, vibe first), state,
  formatting, completions; argcomplete completion; exit codes per SPEC
- phronesis              -> version line + skill table (name, version, category,
  description wrapped below, daedalus-style)
- phronesis <category>   -> filtered table; close-match typos for skills+categories
- phronesis <skill> --install | --project  [--harness <name>] [-f]
  installs whole skill dir; prompt when present; EOF/default = skip; -f no prompt
- phronesis --update     -> refresh every state entry; warns unbundled; reinstalls missing
- state: <config>/phronesis/installed.json, unique by (name, harness, scope)
- skill/python-tdd bumped 1.2.0 with category: development
- test/ (56 tests, 92% cov) + autotest pytest check with 75% floor;
  all 7 autotest checks green

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-11-19 09:50:45 +01:00

216 lines
7.1 KiB
Python

"""CLI tests: list, filter, install, prompt, force, and update (SPEC sections 3, 6, 7)."""
import json
import pytest
from phronesis import cli
from phronesis import harnesses
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()
state.save([{"name": "python-tdd", "version": "1.0.0", "harness": "vibe",
"scope": "global",
"path": str(config.parent / "home" / ".vibe" / "skills" / "python-tdd" / "SKILL.md"),
"installed": "2026-01-01"}], path)
code, out, _ = run(capsys, "--update")
assert code == 0
assert "1.0.0 -> 1.2.0" in out
assert state.load(path)[0]["version"] == "1.2.0"
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()
state.save([{"name": "python-tdd", "version": "1.1.0", "harness": "vibe",
"scope": "global",
"path": str(config.parent / "home" / ".vibe" / "skills" / "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
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"}