chore: uptick
This commit is contained in:
@@ -10,6 +10,7 @@ from gateway.platforms.base import MessageEvent
|
||||
from gateway.session import SessionEntry, SessionSource, build_session_key
|
||||
from tools import approval as approval_mod
|
||||
from tools.approval import (
|
||||
_ApprovalEntry,
|
||||
approve_session,
|
||||
enable_session_yolo,
|
||||
is_approved,
|
||||
@@ -172,6 +173,38 @@ async def test_branch_clears_session_scoped_approval_and_yolo_state():
|
||||
assert other_key in runner._update_prompt_pending
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_branch_preserves_persisted_assistant_metadata():
|
||||
runner, _session_key = _make_branch_runner()
|
||||
runner.session_store.load_transcript.return_value = [
|
||||
{"role": "user", "content": "hello"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "world",
|
||||
"finish_reason": "stop",
|
||||
"reasoning": "thinking",
|
||||
"reasoning_content": "provider scratchpad",
|
||||
"reasoning_details": [{"type": "summary", "text": "step"}],
|
||||
"codex_reasoning_items": [{"id": "r1", "type": "reasoning"}],
|
||||
"codex_message_items": [{"id": "m1", "type": "message"}],
|
||||
},
|
||||
]
|
||||
|
||||
result = await runner._handle_branch_command(_make_event("/branch"))
|
||||
|
||||
assert "Branched to" in result
|
||||
append_calls = runner._session_db.append_message.call_args_list
|
||||
assert len(append_calls) == 2
|
||||
assistant_kwargs = append_calls[1].kwargs
|
||||
assert assistant_kwargs["role"] == "assistant"
|
||||
assert assistant_kwargs["finish_reason"] == "stop"
|
||||
assert assistant_kwargs["reasoning"] == "thinking"
|
||||
assert assistant_kwargs["reasoning_content"] == "provider scratchpad"
|
||||
assert assistant_kwargs["reasoning_details"] == [{"type": "summary", "text": "step"}]
|
||||
assert assistant_kwargs["codex_reasoning_items"] == [{"id": "r1", "type": "reasoning"}]
|
||||
assert assistant_kwargs["codex_message_items"] == [{"id": "m1", "type": "message"}]
|
||||
|
||||
|
||||
def test_clear_session_boundary_security_state_is_scoped():
|
||||
"""The helper must wipe only the target session's approval/yolo state.
|
||||
|
||||
@@ -214,3 +247,30 @@ def test_clear_session_boundary_security_state_is_scoped():
|
||||
runner._clear_session_boundary_security_state("")
|
||||
assert is_approved(other_key, "recursive delete") is True
|
||||
assert other_key in runner._update_prompt_pending
|
||||
|
||||
|
||||
def test_clear_session_boundary_security_state_wakes_blocked_approvals():
|
||||
"""Boundary cleanup must cancel blocked approval waiters immediately."""
|
||||
from gateway.run import GatewayRunner
|
||||
|
||||
runner = object.__new__(GatewayRunner)
|
||||
runner._pending_approvals = {}
|
||||
runner._update_prompt_pending = {}
|
||||
|
||||
source = _make_source()
|
||||
session_key = build_session_key(source)
|
||||
other_key = "agent:main:telegram:dm:other-chat"
|
||||
|
||||
target_entry = _ApprovalEntry({"command": "rm -rf /tmp/demo"})
|
||||
other_entry = _ApprovalEntry({"command": "rm -rf /tmp/other"})
|
||||
approval_mod._gateway_queues[session_key] = [target_entry]
|
||||
approval_mod._gateway_queues[other_key] = [other_entry]
|
||||
|
||||
runner._clear_session_boundary_security_state(session_key)
|
||||
|
||||
assert target_entry.event.is_set()
|
||||
assert target_entry.result == "deny"
|
||||
assert other_entry.event.is_set() is False
|
||||
assert other_entry.result is None
|
||||
assert session_key not in approval_mod._gateway_queues
|
||||
assert other_key in approval_mod._gateway_queues
|
||||
|
||||
Reference in New Issue
Block a user