-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathrpc_workspace_checkpoints.rs
More file actions
184 lines (168 loc) · 6.51 KB
/
Copy pathrpc_workspace_checkpoints.rs
File metadata and controls
184 lines (168 loc) · 6.51 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 std::path::Path;
use std::process::Command;
use github_copilot_sdk::rpc::{
WorkspaceDiffFileChangeType, WorkspaceDiffMode, WorkspacesDiffRequest,
WorkspacesReadCheckpointRequest, WorkspacesReadFileRequest, WorkspacesSaveLargePasteRequest,
};
use super::support::with_e2e_context;
#[tokio::test]
async fn should_list_no_checkpoints_for_fresh_session() {
with_e2e_context(
"rpc_workspace_checkpoints",
"should_list_no_checkpoints_for_fresh_session",
|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 checkpoints = session
.rpc()
.workspaces()
.list_checkpoints()
.await
.expect("list checkpoints");
assert!(checkpoints.checkpoints.is_empty());
session.disconnect().await.expect("disconnect session");
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_return_null_or_empty_content_for_unknown_checkpoint() {
with_e2e_context(
"rpc_workspace_checkpoints",
"should_return_null_or_empty_content_for_unknown_checkpoint",
|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 checkpoint = session
.rpc()
.workspaces()
.read_checkpoint(WorkspacesReadCheckpointRequest { number: i64::MAX })
.await
.expect("read missing checkpoint");
assert!(checkpoint.content.as_deref().unwrap_or_default().is_empty());
session.disconnect().await.expect("disconnect session");
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_return_typed_workspace_diff_result() {
with_e2e_context(
"rpc_workspace_checkpoints",
"should_return_typed_workspace_diff_result",
|ctx| {
Box::pin(async move {
ctx.set_default_copilot_user();
init_git_repository(ctx.work_dir());
let changed_path = ctx.work_dir().join("rust-workspace-diff.txt");
std::fs::write(&changed_path, "diff content\n").expect("write diff file");
let client = ctx.start_client().await;
let session = client
.create_session(ctx.approve_all_session_config())
.await
.expect("create session");
let diff = session
.rpc()
.workspaces()
.diff(WorkspacesDiffRequest {
mode: WorkspaceDiffMode::Unstaged,
..Default::default()
})
.await
.expect("workspace diff");
assert_eq!(diff.requested_mode, WorkspaceDiffMode::Unstaged);
assert!(matches!(
diff.mode,
WorkspaceDiffMode::Unstaged | WorkspaceDiffMode::Branch
));
if let Some(change) = diff.changes.iter().find(|change| {
normalize_path(&change.path).ends_with("rust-workspace-diff.txt")
}) {
assert_eq!(change.change_type, WorkspaceDiffFileChangeType::Added);
assert!(change.diff.contains("diff content") || change.diff.is_empty());
} else {
assert!(
diff.changes.is_empty(),
"unexpected diff changes: {:?}",
diff.changes
);
}
session.disconnect().await.expect("disconnect session");
client.stop().await.expect("stop client");
})
},
)
.await;
}
#[tokio::test]
async fn should_save_large_paste_and_expose_readable_content() {
with_e2e_context(
"rpc_workspace_checkpoints",
"should_save_large_paste_and_expose_readable_content",
|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 content = "large paste rust content\n".repeat(512);
let saved = session
.rpc()
.workspaces()
.save_large_paste(WorkspacesSaveLargePasteRequest {
content: content.clone(),
})
.await
.expect("save large paste")
.saved
.expect("saved paste descriptor");
assert!(saved.filename.ends_with(".txt"));
assert_eq!(saved.size_bytes, content.len() as i64);
assert_eq!(
std::fs::read_to_string(&saved.file_path).expect("read saved paste"),
content
);
let read = session
.rpc()
.workspaces()
.read_file(WorkspacesReadFileRequest {
path: saved.filename,
})
.await
.expect("read saved paste through workspace");
assert_eq!(read.content, content);
session.disconnect().await.expect("disconnect session");
client.stop().await.expect("stop client");
})
},
)
.await;
}
fn normalize_path(path: &str) -> String {
path.replace('\\', "/")
}
fn init_git_repository(path: &Path) {
let status = Command::new("git")
.arg("init")
.arg("--quiet")
.current_dir(path)
.status()
.expect("run git init");
assert!(status.success(), "git init should succeed");
}