-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathclient_api.rs
More file actions
177 lines (156 loc) · 5.63 KB
/
Copy pathclient_api.rs
File metadata and controls
177 lines (156 loc) · 5.63 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
use github_copilot_sdk::SessionId;
use super::support::{wait_for_condition, with_e2e_context};
#[tokio::test]
async fn should_delete_session_by_id() {
with_e2e_context("client_api", "should_delete_session_by_id", |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 session_id = session.id().clone();
session.send_and_wait("Say OK.").await.expect("send");
session.disconnect().await.expect("disconnect session");
client
.delete_session(&session_id)
.await
.expect("delete session");
let metadata = client
.get_session_metadata(&session_id)
.await
.expect("get metadata");
assert!(metadata.is_none());
client.stop().await.expect("stop client");
})
})
.await;
}
#[tokio::test]
async fn should_report_error_when_deleting_unknown_session_id() {
with_e2e_context(
"client_api",
"should_report_error_when_deleting_unknown_session_id",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let unknown = SessionId::new("00000000-0000-0000-0000-000000000000");
client
.delete_session(&unknown)
.await
.expect("delete unknown session is idempotent");
let metadata = client
.get_session_metadata(&unknown)
.await
.expect("get unknown metadata");
assert!(metadata.is_none());
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_get_null_last_session_id_before_any_sessions_exist() {
with_e2e_context(
"client_api",
"should_get_null_last_session_id_before_any_sessions_exist",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let last_id = client.get_last_session_id().await.expect("get last id");
assert!(last_id.is_none());
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_track_last_session_id_after_session_created() {
with_e2e_context(
"client_api",
"should_track_last_session_id_after_session_created",
|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 session_id = session.id().clone();
session.send_and_wait("Say OK.").await.expect("send");
session.disconnect().await.expect("disconnect session");
wait_for_condition("last session id to update", || {
let client = client.clone();
let session_id = session_id.clone();
async move {
client
.get_last_session_id()
.await
.is_ok_and(|id| id.as_ref() == Some(&session_id))
}
})
.await;
assert_eq!(
client.get_last_session_id().await.expect("get last id"),
Some(session_id)
);
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_get_null_foreground_session_id_in_headless_mode() {
with_e2e_context(
"client_api",
"should_get_null_foreground_session_id_in_headless_mode",
|ctx| {
Box::pin(async move {
let client = ctx.start_client().await;
let foreground = client
.get_foreground_session_id()
.await
.expect("get foreground");
assert!(foreground.is_none());
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_report_error_when_setting_foreground_session_in_headless_mode() {
with_e2e_context(
"client_api",
"should_report_error_when_setting_foreground_session_in_headless_mode",
|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");
client
.set_foreground_session_id(session.id())
.await
.expect("set foreground is ignored in headless mode");
assert!(
client
.get_foreground_session_id()
.await
.expect("get foreground")
.is_none()
);
session.disconnect().await.expect("disconnect session");
client.stop().await.expect("stop client");
})
},
)
.await;
}