Skip to content

Commit e84e4b9

Browse files
rojiCopilot
andcommitted
fix(python): avoid nested PowerShell in shell RPC test
Use the Windows shell's built-in echo command and a relative marker path so the test avoids a flaky child-process launch while continuing to validate shell execution and cwd handling. Ensure the session is disconnected on assertion failures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent ed1c2ea commit e84e4b9

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

‎python/e2e/test_rpc_shell_and_fleet_e2e.py‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737

3838
def _write_file_command(marker_path: Path, marker: str) -> str:
3939
if sys.platform == "win32":
40-
return (
41-
f"powershell -NoLogo -NoProfile -Command "
42-
f"\"Set-Content -LiteralPath '{marker_path}' -Value '{marker}'\""
43-
)
40+
# shell.exec already runs through cmd.exe on Windows. Use its built-in echo
41+
# instead of spawning a nested PowerShell process just to write the marker.
42+
return f'echo {marker}>"{marker_path.name}"'
4443
return f"sh -c \"printf '%s' '{marker}' > '{marker_path}'\""
4544

4645

@@ -57,19 +56,17 @@ async def _wait_for_file_text(path: Path, expected: str, *, timeout: float = 30.
5756

5857
class TestRpcShellAndFleet:
5958
async def test_should_execute_shell_command(self, ctx: E2ETestContext):
60-
session = await ctx.client.create_session(
59+
async with await ctx.client.create_session(
6160
on_permission_request=PermissionHandler.approve_all,
62-
)
63-
marker_path = Path(ctx.work_dir) / f"shell-rpc-{uuid.uuid4().hex}.txt"
64-
marker = "copilot-sdk-shell-rpc"
65-
66-
result = await session.rpc.shell.exec(
67-
ShellExecRequest(command=_write_file_command(marker_path, marker), cwd=ctx.work_dir)
68-
)
69-
assert (result.process_id or "").strip()
70-
await _wait_for_file_text(marker_path, marker)
61+
) as session:
62+
marker_path = Path(ctx.work_dir) / f"shell-rpc-{uuid.uuid4().hex}.txt"
63+
marker = "copilot-sdk-shell-rpc"
7164

72-
await session.disconnect()
65+
result = await session.rpc.shell.exec(
66+
ShellExecRequest(command=_write_file_command(marker_path, marker), cwd=ctx.work_dir)
67+
)
68+
assert (result.process_id or "").strip()
69+
await _wait_for_file_text(marker_path, marker)
7370

7471
async def test_should_kill_shell_process(self, ctx: E2ETestContext):
7572
session = await ctx.client.create_session(

0 commit comments

Comments
 (0)