-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathrpc_server_misc.rs
More file actions
170 lines (149 loc) · 5.14 KB
/
Copy pathrpc_server_misc.rs
File metadata and controls
170 lines (149 loc) · 5.14 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
use github_copilot_sdk::Client;
use github_copilot_sdk::rpc::{
AgentRegistrySpawnRequest, SendAttachmentsToMessageParams, SessionsOpenStatus,
};
use super::support::{wait_for_condition, with_e2e_context};
#[tokio::test]
async fn should_reload_user_settings() {
with_e2e_context("rpc_server_misc", "should_reload_user_settings", |ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
client
.rpc()
.user()
.settings()
.reload()
.await
.expect("reload user settings");
client.stop().await.expect("stop client");
})
})
.await;
}
#[tokio::test]
async fn should_report_agent_registry_spawn_gate_closed() {
with_e2e_context(
"rpc_server_misc",
"should_report_agent_registry_spawn_gate_closed",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let err = client
.rpc()
.agent_registry()
.spawn(AgentRegistrySpawnRequest {
agent_name: None,
cwd: ctx.work_dir().to_string_lossy().to_string(),
initial_prompt: None,
model: None,
name: None,
permission_mode: None,
})
.await
.expect_err("agent registry spawn should be gated");
let message = err.to_string();
assert_not_unhandled(&message);
let lower = message.to_ascii_lowercase();
assert!(lower.contains("agentregistry.spawn"), "{message}");
assert!(
lower.contains("not enabled") || lower.contains("no delegate"),
"{message}"
);
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_shut_down_owned_runtime() {
with_e2e_context("rpc_server_misc", "should_shut_down_owned_runtime", |ctx| {
Box::pin(async move {
let client = Client::start(ctx.client_options())
.await
.expect("start dedicated client");
client
.rpc()
.user()
.settings()
.reload()
.await
.expect("runtime should start live");
client
.rpc()
.runtime()
.shutdown()
.await
.expect("shut down runtime");
wait_for_condition("runtime to stop serving RPCs", || async {
client.rpc().user().settings().reload().await.is_err()
})
.await;
let _ = client.stop().await;
})
})
.await;
}
#[tokio::test]
async fn should_report_not_found_when_opening_session_without_context() {
with_e2e_context(
"rpc_server_misc",
"should_report_not_found_when_opening_session_without_context",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let result = client
.rpc()
.sessions()
.open()
.await
.expect("open session without context");
assert_eq!(result.status, SessionsOpenStatus::NotFound);
assert!(result.session_id.is_none());
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_reject_send_attachments_from_non_extension_connection() {
with_e2e_context(
"rpc_server_misc",
"should_reject_send_attachments_from_non_extension_connection",
|ctx| {
Box::pin(async move {
ctx.set_default_copilot_user();
let client = ctx.start_client().await;
let session = client
.create_session(ctx.approve_all_session_config())
.await
.expect("create session");
let err = session
.rpc()
.extensions()
.send_attachments_to_message(SendAttachmentsToMessageParams {
attachments: Vec::new(),
instance_id: None,
})
.await
.expect_err("normal session connection should be rejected");
let message = err.to_string();
assert_not_unhandled(&message);
assert!(
message.to_ascii_lowercase().contains("extension"),
"{message}"
);
session.disconnect().await.expect("disconnect session");
client.stop().await.expect("stop client");
})
},
)
.await;
}
fn assert_not_unhandled(message: &str) {
assert!(
!message.to_ascii_lowercase().contains("unhandled method"),
"{message}"
);
}