feat(harness): tht session set-name/set-group/archive/unarchive/delete commands
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -67,3 +67,63 @@ def test_delete_session(tmp_path):
|
||||
def test_delete_missing_raises(tmp_path):
|
||||
with pytest.raises(SessionError):
|
||||
delete_session("nope", tmp_path)
|
||||
|
||||
|
||||
import json
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from tht.cli.session_cmd import session_app
|
||||
|
||||
|
||||
def _patch_cfg(monkeypatch, tmp_path):
|
||||
from tht.cli import session_cmd
|
||||
|
||||
class FakePaths:
|
||||
sessions = tmp_path
|
||||
|
||||
class FakeCfg:
|
||||
paths = FakePaths()
|
||||
database = _db()
|
||||
|
||||
monkeypatch.setattr(session_cmd, "_load_config_or_exit", lambda _: FakeCfg())
|
||||
|
||||
|
||||
def test_cli_set_name(tmp_path, monkeypatch):
|
||||
m = create_session("q", _db(), tmp_path)
|
||||
_patch_cfg(monkeypatch, tmp_path)
|
||||
res = CliRunner().invoke(session_app, ["set-name", m.id, "--name", "Mio nome"])
|
||||
assert res.exit_code == 0, res.output
|
||||
assert load_session(m.id, tmp_path).name == "Mio nome"
|
||||
|
||||
|
||||
def test_cli_set_group(tmp_path, monkeypatch):
|
||||
m = create_session("q", _db(), tmp_path)
|
||||
_patch_cfg(monkeypatch, tmp_path)
|
||||
res = CliRunner().invoke(session_app, ["set-group", m.id, "--group", "G1"])
|
||||
assert res.exit_code == 0, res.output
|
||||
assert load_session(m.id, tmp_path).group == "G1"
|
||||
|
||||
|
||||
def test_cli_archive_unarchive(tmp_path, monkeypatch):
|
||||
m = create_session("q", _db(), tmp_path)
|
||||
_patch_cfg(monkeypatch, tmp_path)
|
||||
assert CliRunner().invoke(session_app, ["archive", m.id]).exit_code == 0
|
||||
assert load_session(m.id, tmp_path).archived is True
|
||||
assert CliRunner().invoke(session_app, ["unarchive", m.id]).exit_code == 0
|
||||
assert load_session(m.id, tmp_path).archived is False
|
||||
|
||||
|
||||
def test_cli_delete(tmp_path, monkeypatch):
|
||||
m = create_session("q", _db(), tmp_path)
|
||||
_patch_cfg(monkeypatch, tmp_path)
|
||||
res = CliRunner().invoke(session_app, ["delete", m.id])
|
||||
assert res.exit_code == 0, res.output
|
||||
assert not (tmp_path / m.id).exists()
|
||||
|
||||
|
||||
def test_cli_list_includes_new_fields(tmp_path, monkeypatch):
|
||||
from tht.cli.session_cmd import _list_sessions
|
||||
|
||||
create_session("q", _db(), tmp_path)
|
||||
rows = _list_sessions(tmp_path)
|
||||
assert {"name", "group", "archived"}.issubset(rows[0].keys())
|
||||
|
||||
Reference in New Issue
Block a user