fix(letta): harden official Python hook integration
This commit is contained in:
1 parent
231cda604e
commit
909f3dd106
19 files changed
+2443
-212
No files matched your search
@@ -1,15 +1,39 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from elydora.plugins.letta import _is_elydora_hook as is_letta_hook
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from elydora.plugins.letta_command import build_letta_command
|
||||
from elydora.plugins.letta_contract import managed_letta_removals
|
||||
|
||||
|
||||
def test_hook_detection_handles_only_string_commands() -> None:
|
||||
assert is_letta_hook({"command": 42}, "") is False
|
||||
assert is_letta_hook({"hooks": [{"command": None}]}, "") is False
|
||||
assert is_letta_hook(
|
||||
{"hooks": [{"command": "run .elydora/agent-1/hook.py"}]}, ""
|
||||
) is True
|
||||
assert is_letta_hook(
|
||||
{"hooks": [{"command": "run .elydora/agent-1/hook.py"}]},
|
||||
"agent-2",
|
||||
) is False
|
||||
def test_letta_hook_detection_requires_exact_owned_commands(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
home = tmp_path / "home"
|
||||
guard = home / ".elydora" / "agent-1" / "guard.py"
|
||||
monkeypatch.setenv("HOME", str(home))
|
||||
monkeypatch.setenv("USERPROFILE", str(home))
|
||||
hooks = {
|
||||
"PreToolUse": [{
|
||||
"matcher": "*",
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": build_letta_command(str(guard)),
|
||||
"timeout": 10_000,
|
||||
}],
|
||||
}],
|
||||
}
|
||||
assert len(managed_letta_removals(hooks)) == 1
|
||||
|
||||
hooks["PreToolUse"][0]["hooks"][0]["quiet"] = True
|
||||
assert managed_letta_removals(hooks) == []
|
||||
|
||||
hooks["PreToolUse"][0]["hooks"][0] = {
|
||||
"type": "command",
|
||||
"command": f'"{sys.executable}" {guard}',
|
||||
}
|
||||
assert len(managed_letta_removals(hooks, "agent-1")) == 1
|
||||
assert managed_letta_removals(hooks, "agent-2") == []
|
||||
Reference in new issue
Block a user