feat(acp): add session-scoped edit auto-approval

This commit is contained in:
HenkDz
2026-05-16 12:06:21 +01:00
committed by Teknium
parent 49b28d1646
commit f70e0b85dd
4 changed files with 166 additions and 5 deletions

View File

@@ -3,12 +3,14 @@
from __future__ import annotations
import json
from pathlib import Path
from acp_adapter.edit_approval import (
EditProposal,
build_acp_edit_tool_call,
clear_edit_approval_requester,
set_edit_approval_requester,
should_auto_approve_edit,
)
from model_tools import handle_function_call
@@ -177,3 +179,25 @@ def test_patch_replace_approval_request_includes_full_file_diff(tmp_path):
assert proposals[0].tool_name == "patch"
assert proposals[0].old_text == "alpha\nbeta\n"
assert proposals[0].new_text == "alpha\ngamma\n"
def test_workspace_auto_approval_allows_workspace_and_tmp_but_not_sensitive(tmp_path):
workspace_file = tmp_path / "src.py"
tmp_file = Path("/tmp/hermes-acp-auto-approve-test.txt")
env_file = tmp_path / ".env"
assert should_auto_approve_edit(
EditProposal("write_file", str(workspace_file), None, "x", {}),
"workspace_session",
str(tmp_path),
)
assert should_auto_approve_edit(
EditProposal("write_file", str(tmp_file), None, "x", {}),
"workspace_session",
str(tmp_path),
)
assert not should_auto_approve_edit(
EditProposal("write_file", str(env_file), None, "SECRET=x", {}),
"session",
str(tmp_path),
)

View File

@@ -52,6 +52,32 @@ def agent(mock_manager):
"""HermesACPAgent backed by a mock session manager."""
return HermesACPAgent(session_manager=mock_manager)
@pytest.mark.asyncio
async def test_new_session_includes_edit_approval_config_option(self, agent):
resp = await agent.new_session(cwd="/tmp")
assert resp.config_options
option = resp.config_options[0]
assert option.id == "edit_approval_policy"
assert option.current_value == "ask"
assert {choice.value for choice in option.options} == {
"ask",
"workspace_session",
"session",
}
@pytest.mark.asyncio
async def test_set_config_option_persists_edit_approval_policy(self, agent):
resp = await agent.new_session(cwd="/tmp")
update = await agent.set_config_option(
"edit_approval_policy",
resp.session_id,
"workspace_session",
)
assert isinstance(update, SetSessionConfigOptionResponse)
assert update.config_options[0].current_value == "workspace_session"
# ---------------------------------------------------------------------------
# initialize
@@ -892,7 +918,8 @@ class TestSessionConfiguration:
)
assert mode_result == {}
assert config_result == {"configOptions": []}
assert config_result["configOptions"]
assert config_result["configOptions"][0]["id"] == "edit_approval_policy"
@pytest.mark.asyncio
async def test_router_accepts_unstable_model_switch_when_enabled(self, agent):