Skip to content

Commit e9d571a

Browse files
bkudiessCopilot
andauthored
fix(setup): tolerate slow WSL version discovery (#1106)
Co-authored-by: Copilot App <[email protected]>
1 parent 2341450 commit e9d571a

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎src/OpenClaw.SetupEngine/SetupSteps.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ private static string DescribeBind(IPAddress address)
740740

741741
public sealed class CreateWslInstanceStep : SetupStep
742742
{
743+
private static readonly TimeSpan DistroVersionVerificationTimeout = TimeSpan.FromMinutes(1);
744+
743745
public override string Id => "wsl-create";
744746
public override string DisplayName => "Create WSL instance";
745747
public override bool CanRetry => false;
@@ -832,7 +834,11 @@ private static async Task<StepResult> VerifyFreshDistro(SetupContext ctx, string
832834
return StepResult.Fail(environmentIssue != null ? $"{baseMessage} {environmentIssue}" : baseMessage);
833835
}
834836

835-
var verbose = await ctx.Commands.RunAsync(WslConstants.WslExePath, ["--list", "--verbose"], TimeSpan.FromSeconds(15), ct: ct);
837+
var verbose = await ctx.Commands.RunAsync(
838+
WslConstants.WslExePath,
839+
["--list", "--verbose"],
840+
DistroVersionVerificationTimeout,
841+
ct: ct);
836842
if (verbose.ExitCode != 0 || !WslInstallSupport.TryGetDistroVersion(verbose.Stdout, distro, out var version))
837843
return StepResult.Fail($"Fresh WSL install registered '{distro}', but setup could not verify it is WSL2.");
838844

‎tests/OpenClaw.SetupEngine.Tests/SetupStepsTests.cs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,37 @@ public async Task CreateWslInstance_UsesDirectFreshInstallAndDoesNotExportBaseDi
10301030
Assert.Contains("--web-download", installCall.Arguments);
10311031
}
10321032

1033+
[Fact]
1034+
public async Task CreateWslInstance_AllowsWslServiceToSettleBeforeVersionVerification()
1035+
{
1036+
var installed = false;
1037+
var commands = new FakeCommandRunner(args =>
1038+
{
1039+
if (args.SequenceEqual(["--list", "--quiet"]))
1040+
return Ok(installed ? "OpenClawGateway\n" : "");
1041+
if (args.Contains("--install"))
1042+
{
1043+
installed = true;
1044+
return Ok("Installing Ubuntu-24.04\n");
1045+
}
1046+
if (args.SequenceEqual(["--list", "--verbose"]))
1047+
return Ok(" NAME STATE VERSION\n* OpenClawGateway Stopped 2\n");
1048+
if (args.SequenceEqual(["-d", "OpenClawGateway", "-u", "root", "--", "sh", "-lc", "id -u && test -d / && echo OPENCLAW_FRESH_WSL_READY"]))
1049+
return Ok("0\nOPENCLAW_FRESH_WSL_READY\n");
1050+
1051+
return Fail($"unexpected args: {string.Join(' ', args)}");
1052+
});
1053+
var ctx = CreateContext(commands: commands);
1054+
1055+
var result = await new CreateWslInstanceStep().ExecuteAsync(ctx, CancellationToken.None);
1056+
1057+
Assert.True(result.IsSuccess, result.Message);
1058+
var verboseCall = Assert.Single(
1059+
commands.TimedCalls,
1060+
call => call.Arguments.SequenceEqual(["--list", "--verbose"]));
1061+
Assert.Equal(TimeSpan.FromMinutes(1), verboseCall.Timeout);
1062+
}
1063+
10331064
[Fact]
10341065
public async Task CreateWslInstance_PartialCleanupAvoidsGlobalShutdownWhenUnregisterSucceeds()
10351066
{
@@ -3576,6 +3607,7 @@ private sealed class FakeCommandRunner(
35763607
Func<string, string, TimeSpan, CommandResult>? runInWsl = null) : ICommandRunner
35773608
{
35783609
public List<(string Executable, string[] Arguments)> Calls { get; } = [];
3610+
public List<(string Executable, string[] Arguments, TimeSpan Timeout)> TimedCalls { get; } = [];
35793611
public List<(string Executable, string[] Arguments, string? StdinInput)> DetailedCalls { get; } = [];
35803612
public List<(string DistroName, string Command, TimeSpan Timeout, string? User, bool InputViaStdin)> WslCalls { get; } = [];
35813613
public List<IReadOnlyDictionary<string, string>?> WslEnvironments { get; } = [];
@@ -3590,6 +3622,7 @@ public Task<CommandResult> RunAsync(
35903622
CancellationToken ct = default)
35913623
{
35923624
Calls.Add((executable, arguments));
3625+
TimedCalls.Add((executable, arguments, timeout));
35933626
DetailedCalls.Add((executable, arguments, stdinInput));
35943627
return Task.FromResult(run(arguments));
35953628
}

0 commit comments

Comments
 (0)