Skip to content

Commit c870de2

Browse files
committed
Fix Windows cancellation fixture environment
1 parent 249af31 commit c870de2

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎ClaudeCodeSharpSDK.Tests/Unit/ProcessRunnerCancellationTests.cs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class ProcessRunnerCancellationTests
1212
private const string PosixFixtureSkipReason = "The public CLI yield-boundary fixture currently uses a POSIX executable script.";
1313
private const string LinuxFixtureSkipReason = "The detached stderr-retention fixture requires Linux setsid.";
1414
private const string StderrClosureFailure = "stderr stream closed";
15+
private const string WindowsLongRunningCommand = "Write-Output $PID; Start-Sleep -Seconds 30";
1516

1617
[Test]
1718
public async Task PublicExec_PreCanceledTokenDoesNotStartCliProcess()
@@ -130,7 +131,7 @@ public async Task Cancellation_WaitsForStartedProcessToExit()
130131
{
131132
using var cancellation = new CancellationTokenSource();
132133
var invocation = OperatingSystem.IsWindows()
133-
? new ClaudeProcessInvocation("powershell.exe", Environment.CurrentDirectory, ["-NoProfile", "-NonInteractive", "-Command", "Write-Output $PID; Start-Sleep -Seconds 30"], CreateEnvironment(), string.Empty, TimeSpan.FromSeconds(5))
134+
? new ClaudeProcessInvocation("powershell.exe", Environment.CurrentDirectory, ["-NoProfile", "-NonInteractive", "-Command", WindowsLongRunningCommand], CreateWindowsProcessEnvironment(), string.Empty, TimeSpan.FromSeconds(5))
134135
: new ClaudeProcessInvocation("/bin/sh", Environment.CurrentDirectory, ["-c", "echo $$; exec /bin/sleep 30"], CreateEnvironment(), string.Empty, TimeSpan.FromSeconds(5));
135136
var runner = new DefaultClaudeProcessRunner();
136137

@@ -155,6 +156,21 @@ private static Dictionary<string, string> CreateEnvironment()
155156
return new Dictionary<string, string>(StringComparer.Ordinal);
156157
}
157158

159+
private static Dictionary<string, string> CreateWindowsProcessEnvironment()
160+
{
161+
var environment = CreateEnvironment();
162+
foreach (var variableName in new[] { "SystemRoot", "WINDIR", "PATH", "PATHEXT" })
163+
{
164+
var value = Environment.GetEnvironmentVariable(variableName);
165+
if (!string.IsNullOrEmpty(value))
166+
{
167+
environment[variableName] = value;
168+
}
169+
}
170+
171+
return environment;
172+
}
173+
158174
private static string CreateLongRunningCliScript()
159175
{
160176
var scriptPath = Path.Combine(GetTestSandboxDirectory(), $"claude-cli-{Guid.NewGuid():N}.sh");

0 commit comments

Comments
 (0)