Skip to content

Commit e10f695

Browse files
Fix Python subagent hooks test to scope env var to client instance
Instead of polluting global os.environ at module import time, create a dedicated client with the feature flag in its env dict. This matches how the .NET and Go tests scope the env var to the client instance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 025931c commit e10f695

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

python/e2e/test_subagent_hooks_e2e.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import os
77

8-
os.environ["COPILOT_EXP_COPILOT_CLI_SESSION_BASED_SUBAGENTS"] = "true"
9-
108
import pytest
119

10+
from copilot.client import CopilotClient, SubprocessConfig
1211
from copilot.session import PermissionHandler
1312

1413
from .testharness import E2ETestContext
@@ -40,7 +39,22 @@ async def on_post_tool_use(input_data, invocation):
4039
})
4140
return None
4241

43-
session = await ctx.client.create_session(
42+
# Create a client with the session-based subagents feature flag
43+
env = ctx.get_env()
44+
env["COPILOT_EXP_COPILOT_CLI_SESSION_BASED_SUBAGENTS"] = "true"
45+
github_token = (
46+
"fake-token-for-e2e-tests" if os.environ.get("GITHUB_ACTIONS") == "true" else None
47+
)
48+
client = CopilotClient(
49+
SubprocessConfig(
50+
cli_path=ctx.cli_path,
51+
cwd=ctx.work_dir,
52+
env=env,
53+
github_token=github_token,
54+
)
55+
)
56+
57+
session = await client.create_session(
4458
on_permission_request=PermissionHandler.approve_all,
4559
hooks={
4660
"on_pre_tool_use": on_pre_tool_use,
@@ -73,3 +87,4 @@ async def on_post_tool_use(input_data, invocation):
7387
)
7488

7589
await session.disconnect()
90+
await client.stop()

0 commit comments

Comments
 (0)