The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(skills): trim the salvaged exit-code tests to the invariants
Tekniumced2e89d6461
diff --git a/tests/hermes_cli/test_skills_failure_exit_code.py b/tests/hermes_cli/test_skills_failure_exit_code.pyindex bbf3adb016f..a9b724ca13d 100644--- a/tests/hermes_cli/test_skills_failure_exit_code.py+++ b/tests/hermes_cli/test_skills_failure_exit_code.py@@ -74,221 +74,6 @@ def test_scan_blocked_install_reports_failure(monkeypatch, tmp_path, verdict):assert audit and audit[0][0] == "BLOCKED"-def test_successful_install_reports_success(monkeypatch, tmp_path):- installs, _ = _scan_gate_env(monkeypatch, tmp_path, verdict="safe")- monkeypatch.setattr(cli_hub, "_finish_change", lambda *a, **k: None)- console, _ = _console()-- assert cli_hub.do_install("org/repo/risky-skill", console=console, skip_confirm=True) is True- assert installs == ["risky-skill"]---def test_already_installed_is_not_a_failure(monkeypatch, tmp_path):- """No-op the user owns: exits 0 (the Desktop never offers install on an installed row)."""- _scan_gate_env(monkeypatch, tmp_path, installed={"install_path": "risky-skill"})- console, _ = _console()-- assert cli_hub.do_install("org/repo/risky-skill", console=console, skip_confirm=True) is None---def test_declined_install_confirm_is_not_a_failure(monkeypatch, tmp_path):- """The user answering "no" at the install prompt is a no-op they own: None, exit 0."""- installs, _ = _scan_gate_env(monkeypatch, tmp_path, verdict="safe")- monkeypatch.setattr(cli_hub, "_confirm_install", lambda *a, **k: False)- console, _ = _console()-- assert cli_hub.do_install("org/repo/risky-skill", console=console, skip_confirm=False) is None- assert installs == []---def test_pinned_source_that_is_gone_reports_failure(monkeypatch):- """``do_update`` pins the lockfile's registry; when no adapter matches, the install is refused- ("Refusing to resolve ...") and must report False, not a success that over-counts the update."""- import tools.skills_hub as hub-- class _Source:- def source_id(self):- return "skills-sh"-- monkeypatch.setattr(hub, "ensure_hub_dirs", lambda: None)- monkeypatch.setattr(cli_hub, "_sources", lambda: [_Source()])- monkeypatch.setattr(cli_hub, "_record_skill_install", lambda *a, **k: None)- monkeypatch.setattr(cli_hub, "_resolve_source_meta_and_bundle",- lambda *a, **k: pytest.fail("a pinned-source refusal must not resolve elsewhere"))- console, sink = _console()-- assert cli_hub.do_install("org/x", console=console, skip_confirm=True, source_id="gone-registry") is False- assert "Refusing to resolve" in sink.getvalue()---def test_update_whose_registry_is_gone_is_not_updated(monkeypatch):- """End to end through the real do_install: the pinned-source refusal surfaces as Not updated."""- import tools.skills_hub as hub- import tools.skills_hub_install as hub_install-- class _Source:- def source_id(self):- return "skills-sh"-- monkeypatch.setattr(hub, "ensure_hub_dirs", lambda: None)- monkeypatch.setattr(cli_hub, "_sources", lambda: [_Source()])- monkeypatch.setattr(cli_hub, "_record_skill_install", lambda *a, **k: None)- monkeypatch.setattr(hub_install, "check_for_skill_updates", lambda **_k: [- {"name": "orphan", "identifier": "org/orphan", "source": "gone-registry", "status": "update_available"}])- monkeypatch.setattr(hub, "HubLockFile", lambda: type(- "Lock", (), {"get_installed": lambda self, n: None})())- console, sink = _console()-- assert cli_hub.do_update(console=console) is False- out = sink.getvalue()- assert "Not updated:" in out and "orphan" in out- assert "Updated 1 skill(s)" not in out---def test_unresolvable_source_reports_failure(monkeypatch):- import tools.skills_hub as hub-- monkeypatch.setattr(hub, "ensure_hub_dirs", lambda: None)- monkeypatch.setattr(cli_hub, "_sources", lambda: [object()])- monkeypatch.setattr(cli_hub, "_resolve_source_meta_and_bundle",- lambda identifier, sources: (None, None, None))- monkeypatch.setattr(cli_hub, "_record_skill_install", lambda *a, **k: None)- console, sink = _console()-- assert cli_hub.do_install("org/repo/gone", console=console, skip_confirm=True) is False- assert "Could not download" in sink.getvalue()---def _update_env(monkeypatch, outcomes):- import tools.skills_hub as hub- import tools.skills_hub_install as hub_install-- names = list(outcomes)- monkeypatch.setattr(hub_install, "check_for_skill_updates", lambda **_k: [- {"name": n, "identifier": f"org/{n}", "source": "github", "status": "update_available"}- for n in names])- monkeypatch.setattr(hub, "HubLockFile", lambda: type(- "Lock", (), {"get_installed": lambda self, n: None})())- monkeypatch.setattr(cli_hub, "do_install",- lambda identifier, **_k: outcomes[identifier.split("/", 1)[1]])---def test_update_reports_failure_when_a_new_version_is_refused(monkeypatch):- _update_env(monkeypatch, {"good": True, "blocked": False})- console, sink = _console()-- assert cli_hub.do_update(console=console) is False- out = sink.getvalue()- assert "Updated 1 skill(s)" in out- assert "Not updated:" in out and "blocked" in out---def test_update_all_succeeding_is_not_a_failure(monkeypatch):- _update_env(monkeypatch, {"good": True})- console, sink = _console()-- assert cli_hub.do_update(console=console) is None- assert "Not updated" not in sink.getvalue()---def test_uninstall_refusal_reports_failure(monkeypatch):- import tools.skills_hub_install as hub_install-- monkeypatch.setattr(hub_install, "uninstall_skill",- lambda name: (False, f"'{name}' is not a hub-installed skill (may be a builtin)"))- console, _ = _console()-- assert cli_hub.do_uninstall("builtin-skill", console=console, skip_confirm=True) is False--[email protected]("invalidate_cache", [True, False])-def test_uninstall_success_applies_the_change(monkeypatch, invalidate_cache):- """A removal reports True and still reaches the cache step (invalidate now, or defer)."""- import tools.skills_hub_install as hub_install-- monkeypatch.setattr(hub_install, "uninstall_skill", lambda name: (True, f"Uninstalled '{name}'"))- finished: list = []- monkeypatch.setattr(cli_hub, "_finish_change", lambda c, invalidate: finished.append(invalidate))- console, _ = _console()-- assert cli_hub.do_uninstall("hub-skill", console=console, skip_confirm=True,- invalidate_cache=invalidate_cache) is True- assert finished == [invalidate_cache]---def test_uninstall_refusal_does_not_touch_the_cache(monkeypatch):- import tools.skills_hub_install as hub_install-- monkeypatch.setattr(hub_install, "uninstall_skill", lambda name: (False, "not a hub skill"))- finished: list = []- monkeypatch.setattr(cli_hub, "_finish_change", lambda *a, **k: finished.append(a))- console, _ = _console()-- assert cli_hub.do_uninstall("builtin-skill", console=console, skip_confirm=True) is False- assert finished == []---def test_declined_uninstall_is_not_a_failure(monkeypatch):- import tools.skills_hub_install as hub_install-- monkeypatch.setattr(cli_hub, "_confirm_or_cancel", lambda *a, **k: False)- monkeypatch.setattr(hub_install, "uninstall_skill",- lambda name: pytest.fail("a declined prompt must not uninstall"))- console, _ = _console()-- assert cli_hub.do_uninstall("hub-skill", console=console, skip_confirm=False) is None---def _snapshot(tmp_path, names):- import json-- path = tmp_path / "snap.json"- path.write_text(json.dumps({"taps": [], "skills": [- {"name": n, "identifier": f"org/{n}"} for n in names]}), encoding="utf-8")- return str(path)---def test_snapshot_import_reports_refused_entries(monkeypatch, tmp_path):- """Restoring a snapshot whose entries the scan gate refuses must not end in "complete"."""- outcomes = {"good": True, "blocked": False}- monkeypatch.setattr(cli_hub, "do_install", lambda identifier, **_k: outcomes[identifier.split("/", 1)[1]])- console, sink = _console()-- assert cli_hub.do_snapshot_import(_snapshot(tmp_path, ["good", "blocked"]), console=console) is False- out = sink.getvalue()- assert "Snapshot import complete" not in out- assert "Not installed: blocked" in out---def test_snapshot_import_all_installed_is_not_a_failure(monkeypatch, tmp_path):- monkeypatch.setattr(cli_hub, "do_install", lambda identifier, **_k: True)- console, sink = _console()-- assert cli_hub.do_snapshot_import(_snapshot(tmp_path, ["good"]), console=console) is None- assert "Snapshot import complete" in sink.getvalue()---def test_snapshot_import_unreadable_file_is_a_failure(tmp_path):- console, _ = _console()-- assert cli_hub.do_snapshot_import(str(tmp_path / "missing.json"), console=console) is False---def test_snapshot_import_with_real_scan_gate_exits_non_zero(monkeypatch, tmp_path):- """Two snapshot entries, both refused by the real ``should_allow_install`` policy, through- the real ``hermes skills snapshot import`` entry point: exit 1, nothing installed."""- from hermes_cli.main import main-- installs, audit = _scan_gate_env(monkeypatch, tmp_path, verdict="dangerous")- monkeypatch.setattr(sys, "argv", ["hermes", "skills", "snapshot", "import",- _snapshot(tmp_path, ["risky-skill", "risky-skill-2"])])- with pytest.raises(SystemExit) as exc:- main()- assert exc.value.code == 1- assert installs == []- assert [row[0] for row in audit] == ["BLOCKED", "BLOCKED"]--# --- the process exit code, through the real `hermes` entry point ---diff --git a/tests/hermes_cli/test_skills_hub.py b/tests/hermes_cli/test_skills_hub.pyindex c5a0a8e729f..a57e803de4c 100644--- a/tests/hermes_cli/test_skills_hub.py+++ b/tests/hermes_cli/test_skills_hub.py@@ -691,51 +691,6 @@ def test_resolve_short_name_matches_identifier_slug(monkeypatch):assert "No exact match" not in sink.getvalue()-def test_resolve_short_name_keeps_display_name_precedence(monkeypatch):- """Display-name matching still decides first: another row merely ending in the same slug must- not turn a single exact display-name hit into the ambiguous list."""- from hermes_cli.skills_hub import _resolve_short_name-- _stub_search(monkeypatch, [- _meta("dream-loop", "official/creative/dream-loop", source="official"),- _meta("Something Else", "skills-sh/org/repo/dream-loop"),- ])- console, sink = _sink_console()-- assert _resolve_short_name("dream-loop", [], console) == "official/creative/dream-loop"- assert "Multiple skills" not in sink.getvalue()---def test_do_install_reports_unresolved_name_as_failure(monkeypatch):- """An unresolved short name is a real failure (False), not the None no-op."""- import hermes_cli.skills_hub as cli_hub- import tools.skills_hub as hub-- class _Source:- def source_id(self):- return "clawhub"-- monkeypatch.setattr(hub, "ensure_hub_dirs", lambda: None)- monkeypatch.setattr(cli_hub, "_sources", lambda: [_Source()])- monkeypatch.setattr(cli_hub, "_full_identifier", lambda identifier, sources, c: "")- console, _ = _sink_console()-- assert cli_hub.do_install("no-such-skill", console=console, skip_confirm=True) is False--[email protected]("verdict, expected_exit", [(False, 1), (None, None)])-def test_skills_command_exit_code_follows_install_verdict(monkeypatch, verdict, expected_exit):- """`hermes skills install` exits non-zero only on a real failure: the Desktop Hub keys its- failure toast off the spawned action's exit code, so an exit-0 failure reads as silence."""- import hermes_cli.skills_hub as cli_hub-- monkeypatch.setattr(cli_hub, "_CLI_ACTIONS", {"install": lambda args: verdict})- args = type("Args", (), {"skills_action": "install"})()-- # The router returns the code; `hermes` (main()) turns a handler's int into the exit status.- assert cli_hub.skills_command(args) == expected_exit--@pytest.mark.parametrize("identifier", ["computer-use", "NousResearch/hermes-agent/skills/productivity/pdf","skills-sh/nousresearch/hermes-agent/google-workspace"])