Merge branch 'main' of github.com:NousResearch/hermes-agent into bb/gui
This commit is contained in:
@@ -104,6 +104,44 @@ class TestWriteFileHandler:
|
||||
assert result["error"] == "boom"
|
||||
assert any("write_file error" in r.getMessage() for r in caplog.records)
|
||||
|
||||
def test_missing_content_key_returns_error(self):
|
||||
"""#19096 — handler must reject tool calls where 'content' key is absent."""
|
||||
from tools.file_tools import _handle_write_file
|
||||
|
||||
result = json.loads(_handle_write_file({"path": "/tmp/oops.md"}))
|
||||
assert "error" in result
|
||||
assert "content" in result["error"]
|
||||
assert "path" not in result.get("error", "").lower() or "missing" not in result.get("error", "").lower() or True # just check error present
|
||||
|
||||
def test_missing_path_key_returns_error(self):
|
||||
"""#19096 — handler must reject tool calls where 'path' key is absent."""
|
||||
from tools.file_tools import _handle_write_file
|
||||
|
||||
result = json.loads(_handle_write_file({"content": "hello"}))
|
||||
assert "error" in result
|
||||
|
||||
def test_explicit_empty_content_is_allowed(self):
|
||||
"""#19096 — explicit empty string content (file truncation) must still work."""
|
||||
from tools.file_tools import _handle_write_file
|
||||
|
||||
with patch("tools.file_tools._get_file_ops") as mock_get:
|
||||
mock_ops = MagicMock()
|
||||
result_obj = MagicMock()
|
||||
result_obj.to_dict.return_value = {"status": "ok", "path": "/tmp/empty.txt", "bytes": 0}
|
||||
mock_ops.write_file.return_value = result_obj
|
||||
mock_get.return_value = mock_ops
|
||||
|
||||
result = json.loads(_handle_write_file({"path": "/tmp/empty.txt", "content": ""}))
|
||||
assert result["status"] == "ok"
|
||||
|
||||
def test_non_string_content_returns_error(self):
|
||||
"""#19096 — content must be a string, not a dict or list."""
|
||||
from tools.file_tools import _handle_write_file
|
||||
|
||||
result = json.loads(_handle_write_file({"path": "/tmp/x.txt", "content": {"nested": "dict"}}))
|
||||
assert "error" in result
|
||||
assert "string" in result["error"].lower() or "content" in result["error"].lower()
|
||||
|
||||
|
||||
class TestPatchHandler:
|
||||
@patch("tools.file_tools._get_file_ops")
|
||||
|
||||
@@ -371,6 +371,57 @@ class TestDeleteSkill:
|
||||
_delete_skill("my-skill")
|
||||
assert not (tmp_path / "devops").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_valid_target(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("umbrella", VALID_SKILL_CONTENT)
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into="umbrella")
|
||||
assert result["success"] is True
|
||||
assert "absorbed into 'umbrella'" in result["message"]
|
||||
assert not (tmp_path / "narrow").exists()
|
||||
assert (tmp_path / "umbrella").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_empty_string_means_pruned(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("stale-skill", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("stale-skill", absorbed_into="")
|
||||
assert result["success"] is True
|
||||
# Empty absorbed_into is explicit prune — no "absorbed into" suffix in message
|
||||
assert "absorbed into" not in result["message"]
|
||||
|
||||
def test_delete_with_absorbed_into_nonexistent_target_rejected(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into="ghost-umbrella")
|
||||
assert result["success"] is False
|
||||
assert "does not exist" in result["error"]
|
||||
# Skill must NOT have been deleted on validation failure
|
||||
assert (tmp_path / "narrow").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_equals_self_rejected(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into="narrow")
|
||||
assert result["success"] is False
|
||||
assert "cannot equal" in result["error"]
|
||||
assert (tmp_path / "narrow").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_whitespace_only_treated_as_prune(self, tmp_path):
|
||||
# Leading/trailing whitespace only: .strip() → "" → pruned path
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into=" ")
|
||||
assert result["success"] is True
|
||||
assert "absorbed into" not in result["message"]
|
||||
|
||||
def test_delete_without_absorbed_into_backward_compat(self, tmp_path):
|
||||
# Legacy callers that don't pass the arg still work — the curator
|
||||
# reconciler falls back to its heuristic+YAML logic for such deletes.
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("my-skill", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("my-skill")
|
||||
assert result["success"] is True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# write_file / remove_file
|
||||
@@ -485,6 +536,25 @@ class TestSkillManageDispatcher:
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is True
|
||||
|
||||
def test_delete_via_dispatcher_threads_absorbed_into(self, tmp_path):
|
||||
# Dispatcher must plumb absorbed_into through to _delete_skill so the
|
||||
# validation + message suffix paths are exercised end-to-end.
|
||||
with _skill_dir(tmp_path):
|
||||
skill_manage(action="create", name="umbrella", content=VALID_SKILL_CONTENT)
|
||||
skill_manage(action="create", name="narrow", content=VALID_SKILL_CONTENT)
|
||||
raw = skill_manage(action="delete", name="narrow", absorbed_into="umbrella")
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is True
|
||||
assert "absorbed into 'umbrella'" in result["message"]
|
||||
|
||||
def test_delete_via_dispatcher_rejects_missing_absorbed_target(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
skill_manage(action="create", name="narrow", content=VALID_SKILL_CONTENT)
|
||||
raw = skill_manage(action="delete", name="narrow", absorbed_into="ghost")
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is False
|
||||
assert "does not exist" in result["error"]
|
||||
|
||||
|
||||
class TestSecurityScanGate:
|
||||
"""_security_scan_skill is gated by skills.guard_agent_created config flag."""
|
||||
|
||||
Reference in New Issue
Block a user