Files
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

67 lines
2.3 KiB
Python

"""State tests: config path, roundtrip, record, and refresh (SPEC section 8)."""
import json
import pathlib
import pytest
from phronesis import registry
from phronesis import state
def test_config_home_honors_override():
env = {"PHRONESIS_CONFIG": "/tmp/cfg"}
assert state.config_home(env) == pathlib.Path("/tmp/cfg")
def test_config_home_uses_xdg_when_set(monkeypatch):
monkeypatch.setenv("XDG_CONFIG_HOME", "/home/me/.xdg")
assert state.config_home() == pathlib.Path("/home/me/.xdg")
def test_state_path_lands_in_phronesis_dir(tmp_path):
env = {"PHRONESIS_CONFIG": str(tmp_path)}
assert state.state_path(env) == tmp_path / "phronesis" / "installed.json"
def test_load_missing_file_is_empty(tmp_path):
assert state.load(tmp_path / "none.json") == []
def test_save_then_load_roundtrip(tmp_path):
path = tmp_path / "installed.json"
entries = [{"name": "python-tdd", "version": "1.2.0", "harness": "vibe",
"scope": "global", "path": "/x/SKILL.md", "installed": "2026-11-19"}]
state.save(entries, path)
assert state.load(path) == entries
data = json.loads(path.read_text(encoding="utf-8"))
assert data["skills"] == entries
def test_load_rejects_garbage(tmp_path):
path = tmp_path / "installed.json"
path.write_text("{oops", encoding="utf-8")
with pytest.raises(state.StateError):
state.load(path)
def test_record_replaces_same_entry_keeps_others():
skill = registry.SKILLS["python-tdd"]
old = {"name": "python-tdd", "version": "1.0.0", "harness": "vibe",
"scope": "project", "path": "/p/SKILL.md", "installed": "2026-01-01"}
other = {"name": "other", "version": "9.9.9", "harness": "vibe",
"scope": "global", "path": "/o/SKILL.md", "installed": "2026-01-02"}
entries = state.record([old, other], skill, "vibe", "project",
pathlib.Path("/p/SKILL.md"))
assert len(entries) == 2
entry = next(e for e in entries if e["name"] == "python-tdd")
assert entry["version"] == "1.2.0"
assert entry["harness"] == "vibe"
assert entry["scope"] == "project"
def test_refresh_version_updates_in_place():
entry = {"name": "python-tdd", "version": "1.0.0"}
entries = [entry]
state.refresh_version(entries, entry, "1.2.0")
assert entry["version"] == "1.2.0"