Repository navigation
Expand file tree
/
Copy pathrpc_server_remote_control.rs
More file actions
184 lines (165 loc) · 5.91 KB
/
Copy pathrpc_server_remote_control.rs
File metadata and controls
184 lines (165 loc) · 5.91 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
use github_copilot_sdk::SessionId;
use github_copilot_sdk::rpc::{
RemoteControlConfig, SessionsSetRemoteControlSteeringRequest,
SessionsStartRemoteControlRequest, SessionsStopRemoteControlRequest,
SessionsTransferRemoteControlRequest,
};
use serde_json::Value;
#[tokio::test]
async fn should_report_remote_control_status_as_off() {
super::support::with_shared_e2e_context(
&E2E,
"rpc_server_remote_control",
"should_report_remote_control_status_as_off",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let result = client
.rpc()
.sessions()
.get_remote_control_status()
.await
.expect("get remote control status");
assert_status_off(&result.status);
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_treat_set_steering_as_no_op_when_off() {
super::support::with_shared_e2e_context(
&E2E,
"rpc_server_remote_control",
"should_treat_set_steering_as_no_op_when_off",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let result = client
.rpc()
.sessions()
.set_remote_control_steering(SessionsSetRemoteControlSteeringRequest {
enabled: false,
})
.await
.expect("set remote control steering");
assert_status_off(&result.status);
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_report_not_stopped_when_remote_control_is_off() {
super::support::with_shared_e2e_context(
&E2E,
"rpc_server_remote_control",
"should_report_not_stopped_when_remote_control_is_off",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let result = client
.rpc()
.sessions()
.stop_remote_control()
.await
.expect("stop remote control");
assert!(!result.stopped);
assert_status_off(&result.status);
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_reject_transfer_when_off_with_compare_and_swap() {
super::support::with_shared_e2e_context(
&E2E,
"rpc_server_remote_control",
"should_reject_transfer_when_off_with_compare_and_swap",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let result = client
.rpc()
.sessions()
.transfer_remote_control(SessionsTransferRemoteControlRequest {
expected_from_session_id: Some(format!(
"rc-from-{}",
uuid::Uuid::new_v4().simple()
)),
to_session_id: format!("rc-to-{}", uuid::Uuid::new_v4().simple()),
})
.await
.expect("transfer remote control");
assert!(!result.transferred);
assert_status_off(&result.status);
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_reach_runtime_when_starting_remote_control_for_unknown_session() {
super::support::with_shared_e2e_context(
&E2E,
"rpc_server_remote_control",
"should_reach_runtime_when_starting_remote_control_for_unknown_session",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let result = client
.rpc()
.sessions()
.start_remote_control(SessionsStartRemoteControlRequest {
session_id: SessionId::from(format!(
"missing-session-{}",
uuid::Uuid::new_v4().simple()
)),
config: RemoteControlConfig {
existing_mc_session: None,
explicit: false,
remote: false,
silent: true,
steerable: false,
task_id: None,
},
})
.await;
let _ = client
.rpc()
.sessions()
.stop_remote_control_with_params(SessionsStopRemoteControlRequest {
expected_session_id: None,
force: Some(true),
})
.await;
let err = result.expect_err("unknown session should fail");
let message = err.to_string();
assert_not_unhandled(&message);
let lower = message.to_ascii_lowercase();
assert!(
lower.contains("session") || lower.contains("remote"),
"{message}"
);
client.stop().await.expect("stop client");
})
},
)
.await;
}
fn assert_status_off(status: &Value) {
assert_eq!(status.get("state").and_then(Value::as_str), Some("off"));
}
fn assert_not_unhandled(message: &str) {
assert!(
!message.to_ascii_lowercase().contains("unhandled method"),
"{message}"
);
}
static E2E: super::support::SharedE2eGroup =
super::support::SharedE2eGroup::standard("rpc_server_remote_control", 5);