forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRpcServerRemoteControlE2ETests.cs
More file actions
105 lines (88 loc) · 4.35 KB
/
Copy pathRpcServerRemoteControlE2ETests.cs
File metadata and controls
105 lines (88 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Rpc;
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.Test.E2E;
/// <summary>
/// E2E coverage for the server-scoped remote-control RPC methods that were previously untested:
/// getRemoteControlStatus, setRemoteControlSteering, stopRemoteControl, transferRemoteControl, and
/// startRemoteControl. The remote-control singleton is per-runtime shared state, so every test uses
/// its own dedicated client process and leaves the singleton in the "off" state.
/// </summary>
public class RpcServerRemoteControlE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "rpc_server_remote_control", output)
{
[Fact]
public async Task Should_Report_Remote_Control_Status_As_Off()
{
await using var client = Ctx.CreateClient();
await client.StartAsync();
var result = await client.Rpc.Sessions.GetRemoteControlStatusAsync();
// A runtime that has never attached remote control reports the off singleton state.
Assert.IsType<RemoteControlStatusOff>(result.Status);
Assert.Equal("off", result.Status.State);
}
[Fact]
public async Task Should_Treat_Set_Steering_As_No_Op_When_Off()
{
await using var client = Ctx.CreateClient();
await client.StartAsync();
// Steering only applies to an active singleton; with remote control off it is a no-op that
// returns the unchanged off status rather than failing.
var result = await client.Rpc.Sessions.SetRemoteControlSteeringAsync(false);
Assert.IsType<RemoteControlStatusOff>(result.Status);
}
[Fact]
public async Task Should_Report_Not_Stopped_When_Remote_Control_Is_Off()
{
await using var client = Ctx.CreateClient();
await client.StartAsync();
var result = await client.Rpc.Sessions.StopRemoteControlAsync();
// Nothing is attached, so there is nothing to tear down.
Assert.False(result.Stopped);
Assert.IsType<RemoteControlStatusOff>(result.Status);
}
[Fact]
public async Task Should_Reject_Transfer_When_Off_With_Compare_And_Swap()
{
await using var client = Ctx.CreateClient();
await client.StartAsync();
// Compare-and-swap transfer is rejected because the singleton is off (it points at no
// session), so the expected-from guard can never match and nothing is rebound.
var result = await client.Rpc.Sessions.TransferRemoteControlAsync(
toSessionId: $"rc-to-{Guid.NewGuid():N}",
expectedFromSessionId: $"rc-from-{Guid.NewGuid():N}");
Assert.False(result.Transferred);
Assert.IsType<RemoteControlStatusOff>(result.Status);
}
[Fact]
public async Task Should_Reach_Runtime_When_Starting_Remote_Control_For_Unknown_Session()
{
await using var client = Ctx.CreateClient();
await client.StartAsync();
try
{
// startRemoteControl attaches the singleton to a local session. A well-formed session id
// that the runtime does not know is rejected at the runtime (not as an unhandled method),
// proving the method is wired through without requiring a live Mission Control backend.
var ex = await Assert.ThrowsAnyAsync<Exception>(
() => client.Rpc.Sessions.StartRemoteControlAsync(
$"missing-session-{Guid.NewGuid():N}",
new RemoteControlConfig { Remote = false, Explicit = false, Silent = true, Steerable = false }));
var message = ex.ToString();
Assert.DoesNotContain("Unhandled method", message, StringComparison.OrdinalIgnoreCase);
Assert.True(
message.Contains("session", StringComparison.OrdinalIgnoreCase)
|| message.Contains("remote", StringComparison.OrdinalIgnoreCase),
message);
}
finally
{
// Force the singleton back to off regardless of how the start attempt resolved.
try { await client.Rpc.Sessions.StopRemoteControlAsync(force: true); }
catch { /* best-effort reset */ }
}
}
}