Skip to content

Commit d339ec7

Browse files
committed
python/core: enforce single-use request-info token behavior (#4618)
1 parent 18e433f commit d339ec7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

python/packages/core/tests/workflow/test_request_info_event_rehydrate.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from dataclasses import dataclass, field
55
from datetime import datetime, timezone
66

7+
import pytest
8+
79
from agent_framework import (
810
FileCheckpointStorage,
911
InMemoryCheckpointStorage,
@@ -47,6 +49,25 @@ class TimedApproval:
4749
issued_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
4850

4951

52+
async def test_send_request_info_response_rejects_replay_for_same_request_id() -> None:
53+
"""Request IDs should be single-use once a response has been accepted."""
54+
runner_context = InProcRunnerContext(InMemoryCheckpointStorage())
55+
request_info_event = WorkflowEvent.request_info(
56+
request_id="request-123",
57+
source_executor_id="review_gateway",
58+
request_data=MockRequest(),
59+
response_type=bool,
60+
)
61+
await runner_context.add_request_info_event(request_info_event)
62+
63+
await runner_context.send_request_info_response("request-123", True)
64+
pending_requests = await runner_context.get_pending_request_info_events()
65+
assert "request-123" not in pending_requests
66+
67+
with pytest.raises(ValueError, match="No pending request found for request_id: request-123"):
68+
await runner_context.send_request_info_response("request-123", False)
69+
70+
5071
async def test_rehydrate_request_info_event() -> None:
5172
"""Rehydration should succeed for valid request info events."""
5273
request_info_event = WorkflowEvent.request_info(

0 commit comments

Comments
 (0)