Skip to content

Commit a87442e

Browse files
ranjeshjCopilot
authored andcommitted
fix(setup): narrow device-pair plugin error detection
Require the missing-plugin classifier to identify device-pair before returning terminal setup guidance, and cover the pairing approval paths so unrelated plugin failures remain retriable. Co-authored-by: Copilot <[email protected]>
1 parent 8411830 commit a87442e

3 files changed

Lines changed: 90 additions & 2 deletions

File tree

‎src/OpenClaw.SetupEngine/ApprovalRequestHelper.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ internal static string ApprovalCommand(ApprovalRequestKind kind)
2424
// versions that ship without the device-pair plugin bundle or don't load it. Detecting this
2525
// lets callers return a Terminal (non-retriable) failure with actionable upgrade guidance.
2626
internal static bool IsPluginNotFoundError(string output)
27-
=> output.Contains("plugin not found", StringComparison.OrdinalIgnoreCase);
27+
=> output.Contains("plugin not found", StringComparison.OrdinalIgnoreCase)
28+
&& output.Contains("device-pair", StringComparison.OrdinalIgnoreCase);
2829

2930
internal const string PluginNotFoundMessage =
3031
"The gateway device-pair plugin is not loaded. " +

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void TryReadApprovedRequestId_ReadsApproveSuccessShape()
9898
[Theory]
9999
[InlineData("plugin not found: device-pair")]
100100
[InlineData("plugins.entries.device-pair: plugin not found: device-pair")]
101-
[InlineData("error: Plugin not found")]
101+
[InlineData("error: Plugin Not Found: Device-Pair")]
102102
public void IsPluginNotFoundError_ReturnsTrueForPluginNotFoundOutput(string output)
103103
{
104104
Assert.True(ApprovalRequestHelper.IsPluginNotFoundError(output));
@@ -109,6 +109,8 @@ public void IsPluginNotFoundError_ReturnsTrueForPluginNotFoundOutput(string outp
109109
[InlineData("{}")]
110110
[InlineData("approval failed: unknown error")]
111111
[InlineData("gateway connection refused")]
112+
[InlineData("error: Plugin not found")]
113+
[InlineData("plugins.entries.other-plugin: plugin not found: other-plugin")]
112114
public void IsPluginNotFoundError_ReturnsFalseForOtherOutput(string output)
113115
{
114116
Assert.False(ApprovalRequestHelper.IsPluginNotFoundError(output));

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class SetupStepsTests : IDisposable
1212
private readonly string _localTempDir;
1313
private readonly string? _prevDataDir;
1414
private readonly string? _prevLocalDataDir;
15+
private const string DevicePairPluginNotFoundOutput = "plugins.entries.device-pair: plugin not found: device-pair";
16+
private const string OtherPluginNotFoundOutput = "plugins.entries.other-plugin: plugin not found: other-plugin";
1517

1618
public SetupStepsTests()
1719
{
@@ -1180,6 +1182,75 @@ public void IsKeepaliveCommandLine_RequiresDistroAndSleepInfinity()
11801182
"OpenClawGateway"));
11811183
}
11821184

1185+
[Fact]
1186+
public async Task AutoApprovePairing_ReturnsTerminalForDevicePairPluginNotFound()
1187+
{
1188+
var ctx = CreatePairingContext(DevicePairPluginNotFoundOutput);
1189+
1190+
var result = await PairOperatorStep.AutoApprovePairing(ctx, "device-req-1", CancellationToken.None);
1191+
1192+
Assert.Equal(StepOutcome.FailedTerminal, result.Outcome);
1193+
Assert.Equal(ApprovalRequestHelper.PluginNotFoundMessage, result.Message);
1194+
}
1195+
1196+
[Fact]
1197+
public async Task AutoApprovePairing_KeepsOtherMissingPluginRetriable()
1198+
{
1199+
var ctx = CreatePairingContext(OtherPluginNotFoundOutput);
1200+
1201+
var result = await PairOperatorStep.AutoApprovePairing(ctx, "device-req-1", CancellationToken.None);
1202+
1203+
Assert.Equal(StepOutcome.Failed, result.Outcome);
1204+
Assert.Contains("Device approval failed", result.Message);
1205+
Assert.DoesNotContain(ApprovalRequestHelper.PluginNotFoundMessage, result.Message);
1206+
}
1207+
1208+
[Fact]
1209+
public async Task AutoApproveNodePairing_ReturnsTerminalWhenPendingListReportsDevicePairPluginNotFound()
1210+
{
1211+
var ctx = CreatePairingContext(DevicePairPluginNotFoundOutput);
1212+
1213+
var result = await PairNodeStep.AutoApproveNodePairing(ctx, requestId: null, CancellationToken.None);
1214+
1215+
Assert.Equal(StepOutcome.FailedTerminal, result.Outcome);
1216+
Assert.Equal(ApprovalRequestHelper.PluginNotFoundMessage, result.Message);
1217+
}
1218+
1219+
[Fact]
1220+
public async Task AutoApproveNodePairing_KeepsOtherPendingListMissingPluginRetriable()
1221+
{
1222+
var ctx = CreatePairingContext(OtherPluginNotFoundOutput);
1223+
1224+
var result = await PairNodeStep.AutoApproveNodePairing(ctx, requestId: null, CancellationToken.None);
1225+
1226+
Assert.Equal(StepOutcome.Failed, result.Outcome);
1227+
Assert.Contains("Could not list pending node pairing requests", result.Message);
1228+
Assert.DoesNotContain(ApprovalRequestHelper.PluginNotFoundMessage, result.Message);
1229+
}
1230+
1231+
[Fact]
1232+
public async Task AutoApproveNodePairing_ReturnsTerminalWhenApproveReportsDevicePairPluginNotFound()
1233+
{
1234+
var ctx = CreatePairingContext(DevicePairPluginNotFoundOutput);
1235+
1236+
var result = await PairNodeStep.AutoApproveNodePairing(ctx, "node-req-1", CancellationToken.None);
1237+
1238+
Assert.Equal(StepOutcome.FailedTerminal, result.Outcome);
1239+
Assert.Equal(ApprovalRequestHelper.PluginNotFoundMessage, result.Message);
1240+
}
1241+
1242+
[Fact]
1243+
public async Task AutoApproveNodePairing_KeepsOtherApproveMissingPluginRetriable()
1244+
{
1245+
var ctx = CreatePairingContext(OtherPluginNotFoundOutput);
1246+
1247+
var result = await PairNodeStep.AutoApproveNodePairing(ctx, "node-req-1", CancellationToken.None);
1248+
1249+
Assert.Equal(StepOutcome.Failed, result.Outcome);
1250+
Assert.Contains("Node approval failed", result.Message);
1251+
Assert.DoesNotContain(ApprovalRequestHelper.PluginNotFoundMessage, result.Message);
1252+
}
1253+
11831254
// ─── Bind validation ───
11841255

11851256
[Fact]
@@ -1279,9 +1350,23 @@ private static CommandResult Ok(string stdout = "", string stderr = "")
12791350
private static CommandResult Fail(string stderr = "")
12801351
=> new(1, "", stderr, TimeSpan.Zero, TimedOut: false);
12811352

1353+
private static CommandResult FailWithStdout(string stdout)
1354+
=> new(1, stdout, "", TimeSpan.Zero, TimedOut: false);
1355+
12821356
private static CommandResult TimedOut()
12831357
=> new(-1, "", "", TimeSpan.FromSeconds(30), TimedOut: true);
12841358

1359+
private SetupContext CreatePairingContext(string failureStdout)
1360+
{
1361+
var commands = new FakeCommandRunner(
1362+
_ => Ok(),
1363+
(_, _, _) => FailWithStdout(failureStdout));
1364+
var ctx = CreateContext(commands: commands);
1365+
ctx.DistroName = "test-distro";
1366+
ctx.SharedGatewayToken = "shared-token";
1367+
return ctx;
1368+
}
1369+
12851370
private sealed class FakeCommandRunner(
12861371
Func<string[], CommandResult> run,
12871372
Func<string, string, TimeSpan, CommandResult>? runInWsl = null) : ICommandRunner

0 commit comments

Comments
 (0)