Skip to content

Commit 7d6e120

Browse files
committed
Fix Python same-client resume tests
Mark Python test sessions inactive before same-client resume so the duplicate active-session guard is preserved without destroying the server-side session. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0baebaf commit 7d6e120

9 files changed

Lines changed: 34 additions & 7 deletions

python/e2e/test_client_e2e.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from copilot.session import PermissionHandler
1515

16-
from .testharness import CLI_PATH
16+
from .testharness import CLI_PATH, mark_inactive_for_resume
1717

1818

1919
class TestClient:
@@ -270,6 +270,7 @@ async def test_should_resume_session_without_permission_handler(self):
270270
try:
271271
await client.start()
272272
session = await client.create_session()
273+
mark_inactive_for_resume(session)
273274
resumed = await client.resume_session(session.session_id)
274275

275276
assert resumed.session_id == session.session_id

python/e2e/test_commands_e2e.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from copilot.session import CommandDefinition, PermissionHandler
2121

2222
from .testharness.context import SNAPSHOTS_DIR, get_cli_path_for_tests
23+
from .testharness.helper import mark_inactive_for_resume
2324
from .testharness.proxy import CapiProxy
2425

2526
pytestmark = pytest.mark.asyncio(loop_scope="module")
@@ -258,6 +259,7 @@ async def test_session_with_commands_resumes_successfully(self, ctx):
258259
)
259260
session_id = session1.session_id
260261

262+
mark_inactive_for_resume(session1)
261263
session2 = await ctx.client.resume_session(
262264
session_id,
263265
on_permission_request=PermissionHandler.approve_all,

python/e2e/test_mcp_and_agents_e2e.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from copilot.session import CustomAgentConfig, MCPServerConfig, PermissionHandler
1010

11-
from .testharness import E2ETestContext, get_final_assistant_message
11+
from .testharness import E2ETestContext, get_final_assistant_message, mark_inactive_for_resume
1212

1313
TEST_MCP_SERVER = str(
1414
(Path(__file__).parents[2] / "test" / "harness" / "test-mcp-server.mjs").resolve()
@@ -64,6 +64,7 @@ async def test_should_accept_mcp_server_configuration_on_session_resume(
6464
}
6565
}
6666

67+
mark_inactive_for_resume(session1)
6768
session2 = await ctx.client.resume_session(
6869
session_id,
6970
on_permission_request=PermissionHandler.approve_all,
@@ -157,6 +158,7 @@ async def test_should_accept_custom_agent_configuration_on_session_resume(
157158
}
158159
]
159160

161+
mark_inactive_for_resume(session1)
160162
session2 = await ctx.client.resume_session(
161163
session_id,
162164
on_permission_request=PermissionHandler.approve_all,

python/e2e/test_permissions_e2e.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from copilot.session import PermissionHandler, PermissionRequestResult
1515

16-
from .testharness import E2ETestContext
16+
from .testharness import E2ETestContext, mark_inactive_for_resume
1717
from .testharness.helper import read_file, write_file
1818

1919
pytestmark = pytest.mark.asyncio(loop_scope="module")
@@ -140,6 +140,7 @@ async def test_should_deny_tool_operations_when_handler_explicitly_denies_after_
140140
def deny_all(request, invocation):
141141
return PermissionRequestResult()
142142

143+
mark_inactive_for_resume(session1)
143144
session2 = await ctx.client.resume_session(session_id, on_permission_request=deny_all)
144145

145146
denied_events = []
@@ -218,6 +219,7 @@ def on_permission_request(
218219
permission_requests.append(request)
219220
return PermissionRequestResult(kind="approve-once")
220221

222+
mark_inactive_for_resume(session1)
221223
session2 = await ctx.client.resume_session(
222224
session_id, on_permission_request=on_permission_request
223225
)

python/e2e/test_session_config_e2e.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from copilot import ModelCapabilitiesOverride, ModelSupportsOverride
1010
from copilot.session import PermissionHandler
1111

12-
from .testharness import E2ETestContext
12+
from .testharness import E2ETestContext, mark_inactive_for_resume
1313

1414
pytestmark = pytest.mark.asyncio(loop_scope="module")
1515

@@ -217,6 +217,7 @@ async def test_should_forward_custom_provider_headers_on_resume(self, ctx: E2ETe
217217
)
218218
session_id = session1.session_id
219219

220+
mark_inactive_for_resume(session1)
220221
session2 = await ctx.client.resume_session(
221222
session_id,
222223
on_permission_request=PermissionHandler.approve_all,
@@ -314,6 +315,7 @@ async def test_should_apply_workingdirectory_on_session_resume(self, ctx: E2ETes
314315
)
315316
session_id = session1.session_id
316317

318+
mark_inactive_for_resume(session1)
317319
session2 = await ctx.client.resume_session(
318320
session_id,
319321
on_permission_request=PermissionHandler.approve_all,
@@ -335,6 +337,7 @@ async def test_should_apply_systemmessage_on_session_resume(self, ctx: E2ETestCo
335337
session_id = session1.session_id
336338

337339
resume_instruction = "End the response with RESUME_SYSTEM_MESSAGE_SENTINEL."
340+
mark_inactive_for_resume(session1)
338341
session2 = await ctx.client.resume_session(
339342
session_id,
340343
on_permission_request=PermissionHandler.approve_all,
@@ -394,6 +397,7 @@ async def test_should_apply_instruction_directories_on_resume(self, ctx: E2ETest
394397
working_directory=project_dir,
395398
)
396399

400+
mark_inactive_for_resume(session1)
397401
session2 = await ctx.client.resume_session(
398402
session1.session_id,
399403
on_permission_request=PermissionHandler.approve_all,
@@ -416,6 +420,7 @@ async def test_should_apply_availabletools_on_session_resume(self, ctx: E2ETestC
416420
)
417421
session_id = session1.session_id
418422

423+
mark_inactive_for_resume(session1)
419424
session2 = await ctx.client.resume_session(
420425
session_id,
421426
on_permission_request=PermissionHandler.approve_all,

python/e2e/test_session_e2e.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from copilot.session import PermissionHandler
1212
from copilot.tools import Tool, ToolResult
1313

14-
from .testharness import E2ETestContext, get_final_assistant_message, get_next_event_of_type
14+
from .testharness import (
15+
E2ETestContext,
16+
get_final_assistant_message,
17+
get_next_event_of_type,
18+
mark_inactive_for_resume,
19+
)
1520

1621
pytestmark = pytest.mark.asyncio(loop_scope="module")
1722

@@ -31,7 +36,7 @@ async def test_should_create_and_disconnect_sessions(self, ctx: E2ETestContext):
3136

3237
await session.disconnect()
3338

34-
with pytest.raises(Exception, match="Session not found"):
39+
with pytest.raises(Exception, match="Session has been disconnected"):
3540
await session.get_messages()
3641

3742
async def test_should_have_stateful_conversation(self, ctx: E2ETestContext):
@@ -216,6 +221,7 @@ async def test_should_resume_a_session_using_the_same_client(self, ctx: E2ETestC
216221
assert "2" in answer.data.content
217222

218223
# Resume using the same client
224+
mark_inactive_for_resume(session1)
219225
session2 = await ctx.client.resume_session(
220226
session_id, on_permission_request=PermissionHandler.approve_all
221227
)
@@ -457,6 +463,7 @@ async def test_should_resume_session_with_custom_provider(self, ctx: E2ETestCont
457463
session_id = session.session_id
458464

459465
# Resume the session with a provider
466+
mark_inactive_for_resume(session)
460467
session2 = await ctx.client.resume_session(
461468
session_id,
462469
on_permission_request=PermissionHandler.approve_all,

python/e2e/testharness/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test harness for E2E tests."""
22

33
from .context import CLI_PATH, DEFAULT_GITHUB_TOKEN, E2ETestContext
4-
from .helper import get_final_assistant_message, get_next_event_of_type
4+
from .helper import get_final_assistant_message, get_next_event_of_type, mark_inactive_for_resume
55
from .proxy import CapiProxy
66

77
__all__ = [
@@ -11,4 +11,5 @@
1111
"CapiProxy",
1212
"get_final_assistant_message",
1313
"get_next_event_of_type",
14+
"mark_inactive_for_resume",
1415
]

python/e2e/testharness/helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def read_file(work_dir: str, filename: str) -> str:
139139
return f.read()
140140

141141

142+
def mark_inactive_for_resume(session: CopilotSession) -> None:
143+
"""Clear local active-session tracking without destroying the server session."""
144+
session._mark_disconnected()
145+
146+
142147
async def get_next_event_of_type(session: CopilotSession, event_type: str, timeout: float = 30.0):
143148
"""
144149
Wait for and return the next event of a specific type from a session.

python/test_commands_and_elicitation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ async def mock_request(method, params):
107107

108108
client._client.request = mock_request
109109

110+
session._mark_disconnected()
110111
await client.resume_session(
111112
session.session_id,
112113
on_permission_request=PermissionHandler.approve_all,
@@ -525,6 +526,7 @@ async def mock_request(method, params):
525526

526527
client._client.request = mock_request
527528

529+
session._mark_disconnected()
528530
await client.resume_session(
529531
session.session_id,
530532
on_permission_request=PermissionHandler.approve_all,

0 commit comments

Comments
 (0)