Skip to content

Commit beed12a

Browse files
committed
test(gateway): preserve rebased protocol contracts
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 0a17604d-e1a5-47ae-bdb5-54ff34887ae7
1 parent 1a36d8e commit beed12a

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎tests/OpenClaw.Shared.Tests/ConnectEnvelopeBuilderTests.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public async Task OperatorClient_SignerThrow_ReachesExistingSafeHandler()
234234
var unsafeTask = InvokePrivateTask(client, "SendConnectMessageAsync", Nonce);
235235
await Assert.ThrowsAsync<InvalidOperationException>(() => unsafeTask);
236236

237-
await InvokePrivateTask(client, "SendConnectSafeAsync", Nonce);
237+
await InvokePrivateTask(client, "SendConnectSafeAsync", Nonce, 0L);
238238
Assert.Contains(
239239
logger.Errors,
240240
message => message.Contains("SendConnectMessageAsync threw", StringComparison.Ordinal));
@@ -263,8 +263,13 @@ public void NodeClient_SignerThrow_LogsAndOmitsSignature()
263263
var method = typeof(WindowsNodeClient).GetMethod(
264264
"BuildNodeConnectMessage",
265265
BindingFlags.Instance | BindingFlags.NonPublic);
266-
var json = (string)method!.Invoke(client, [Nonce, ChallengeTimestamp])!;
266+
var json = (string)method!.Invoke(
267+
client,
268+
[Nonce, ChallengeTimestamp, "node-connect-request"])!;
267269
using var document = JsonDocument.Parse(json);
270+
Assert.Equal(
271+
"node-connect-request",
272+
document.RootElement.GetProperty("id").GetString());
268273
var device = document.RootElement.GetProperty("params").GetProperty("device");
269274

270275
Assert.False(device.TryGetProperty("signature", out _));

‎tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ public async Task SendWizardRequestAsync_TransportDisconnect_DrainsPendingReques
706706

707707
await server.CloseSocketAsync(0);
708708

709-
var exception = await Assert.ThrowsAsync<OperationCanceledException>(
709+
var exception = await Assert.ThrowsAsync<GatewayConnectionLostException>(
710710
async () => await responseTask.WaitAsync(TimeSpan.FromSeconds(2)));
711711
Assert.Equal(
712-
"Gateway connection lost while waiting for wizard response",
713-
exception.Message);
712+
(int)WebSocketCloseStatus.NormalClosure,
713+
exception.CloseStatusCode);
714714
Assert.Equal(0, helper.GetPendingRequestCount());
715715
}
716716

‎tests/OpenClaw.Shared.Tests/PendingRequestRegistryTests.cs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,33 @@ public async Task Drain_FaultsEachWaiterExactlyAndClearsTracked_DoubleDrainIsIde
204204
Assert.Equal(0, registry.Count);
205205
}
206206

207+
[Fact]
208+
public async Task Drain_WithConnectionLoss_PreservesWizardCloseMetadataOnly()
209+
{
210+
var registry = OpenRegistry();
211+
var chat = registry.RegisterChatSend("chat", "chat.send");
212+
var wizard = registry.RegisterWizard("wizard", "wizard.status");
213+
var approval = registry.RegisterApproval("approval", "exec.approval.resolve");
214+
var connectionLoss = new GatewayConnectionLostException(1012, "service restart");
215+
216+
registry.Drain(connectionLoss);
217+
218+
var chatException = await Assert.ThrowsAsync<OperationCanceledException>(
219+
async () => await chat.Task);
220+
var wizardException = await Assert.ThrowsAsync<GatewayConnectionLostException>(
221+
async () => await wizard.Task);
222+
var approvalException = await Assert.ThrowsAsync<OperationCanceledException>(
223+
async () => await approval.Task);
224+
Assert.Equal("Request canceled", chatException.Message);
225+
Assert.Same(connectionLoss, wizardException);
226+
Assert.Equal(1012, wizardException.CloseStatusCode);
227+
Assert.Equal("service restart", wizardException.CloseStatusDescription);
228+
Assert.Equal(
229+
"Gateway connection lost before exec.approval.resolve response",
230+
approvalException.Message);
231+
Assert.Equal(0, registry.Count);
232+
}
233+
207234
[Fact]
208235
public async Task ResponseVersusDrain_ExactlyOneTerminalOutcomeWins()
209236
{

0 commit comments

Comments
 (0)