Skip to content

Commit 337074d

Browse files
committed
fix ests
1 parent 7d25860 commit 337074d

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

tests/ai_tab.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ use git_ai::{
1616
fn run_ai_tab_checkpoint(repo: &TestRepo, hook_payload: serde_json::Value) {
1717
let hook_input = hook_payload.to_string();
1818
let args: Vec<&str> = vec!["checkpoint", "ai_tab", "--hook-input", hook_input.as_str()];
19-
match repo.git_ai(&args) {
20-
Ok(output) => {
21-
println!("git_ai checkpoint output: {}", output);
22-
}
23-
Err(err) => {
24-
panic!("ai_tab checkpoint failed: {}", err);
25-
}
19+
if let Err(err) = repo.git_ai(&args) {
20+
panic!("ai_tab checkpoint failed: {}", err);
2621
}
2722
}
2823

@@ -135,10 +130,7 @@ fn test_ai_tab_after_edit_checkpoint_includes_dirty_files_and_paths() {
135130
let edited = result
136131
.edited_filepaths
137132
.expect("after_edit should include edited filepaths");
138-
assert_eq!(
139-
edited,
140-
vec!["/Users/test/project/src/main.rs".to_string()]
141-
);
133+
assert_eq!(edited, vec!["/Users/test/project/src/main.rs".to_string()]);
142134

143135
let dirty_files = result
144136
.dirty_files
@@ -173,7 +165,10 @@ fn test_ai_tab_rejects_invalid_hook_event() {
173165
message
174166
);
175167
}
176-
other => panic!("expected PresetError for invalid hook_event_name, got {:?}", other),
168+
other => panic!(
169+
"expected PresetError for invalid hook_event_name, got {:?}",
170+
other
171+
),
177172
}
178173
}
179174

@@ -228,7 +223,7 @@ fn test_ai_tab_requires_non_empty_tool_and_model() {
228223
fn test_ai_tab_e2e_marks_ai_lines() {
229224
let repo = TestRepo::new();
230225
let relative_path = "notes_test.ts";
231-
let file_path = repo.canonical_path().join(relative_path);
226+
let file_path = repo.path().join(relative_path);
232227

233228
let base_content = "console.log(\"hello world\");\n".to_string();
234229
fs::write(&file_path, &base_content).unwrap();
@@ -243,7 +238,7 @@ fn test_ai_tab_e2e_marks_ai_lines() {
243238
"hook_event_name": "before_edit",
244239
"tool": "github-copilot-tab",
245240
"model": "default",
246-
"repo_working_dir": repo.canonical_path().to_string_lossy(),
241+
"repo_working_dir": repo.path().to_string_lossy(),
247242
"will_edit_filepaths": [file_path_str.clone()],
248243
"dirty_files": {
249244
file_path_str.clone(): base_content.clone()
@@ -252,7 +247,9 @@ fn test_ai_tab_e2e_marks_ai_lines() {
252247
);
253248

254249
// AI tab inserts new lines alongside the existing content
255-
let ai_content = "console.log(\"hello world\");\n// Log hello world\nconsole.log(\"hello from ai\");\n".to_string();
250+
let ai_content =
251+
"console.log(\"hello world\");\n// Log hello world\nconsole.log(\"hello from ai\");\n"
252+
.to_string();
256253
fs::write(&file_path, &ai_content).unwrap();
257254

258255
run_ai_tab_checkpoint(
@@ -261,15 +258,16 @@ fn test_ai_tab_e2e_marks_ai_lines() {
261258
"hook_event_name": "after_edit",
262259
"tool": "github-copilot-tab",
263260
"model": "default",
264-
"repo_working_dir": repo.canonical_path().to_string_lossy(),
261+
"repo_working_dir": repo.path().to_string_lossy(),
265262
"edited_filepaths": [file_path_str.clone()],
266263
"dirty_files": {
267264
file_path_str.clone(): ai_content.clone()
268265
}
269266
}),
270267
);
271268

272-
repo.stage_all_and_commit("Accept AI tab completion").unwrap();
269+
repo.stage_all_and_commit("Accept AI tab completion")
270+
.unwrap();
273271

274272
let mut file = repo.filename(relative_path);
275273
file.assert_lines_and_blame(lines![
@@ -283,13 +281,13 @@ fn test_ai_tab_e2e_marks_ai_lines() {
283281
fn test_ai_tab_e2e_handles_dirty_files_map() {
284282
let repo = TestRepo::new();
285283
let lib_relative_path = std::path::Path::new("src").join("lib.rs");
286-
let lib_file_path = repo.canonical_path().join(lib_relative_path);
284+
let lib_file_path = repo.path().join(lib_relative_path);
287285
// Create parent directory - handle Windows paths safely
288286
if let Some(parent) = lib_file_path.parent() {
289287
fs::create_dir_all(parent).unwrap();
290288
}
291289
let readme_relative_path = "README.md";
292-
let readme_file_path = repo.canonical_path().join(readme_relative_path);
290+
let readme_file_path = repo.path().join(readme_relative_path);
293291

294292
let base_lib_content = "fn greet() {\n println!(\"hello\");\n}\n".to_string();
295293
fs::write(&lib_file_path, &base_lib_content).unwrap();
@@ -304,17 +302,14 @@ fn test_ai_tab_e2e_handles_dirty_files_map() {
304302
let lib_file_path_str = lib_file_path.to_string_lossy().to_string();
305303
let readme_file_path_str = readme_file_path.to_string_lossy().to_string();
306304

307-
println!("lib_file_path_str: {}", lib_file_path_str);
308-
println!("readme_file_path_str: {}", readme_file_path_str);
309-
310305
// Before edit snapshot includes all dirty files (AI target plus unrelated human edits)
311306
run_ai_tab_checkpoint(
312307
&repo,
313308
json!({
314309
"hook_event_name": "before_edit",
315310
"tool": "github-copilot-tab",
316311
"model": "default",
317-
"repo_working_dir": repo.canonical_path().to_string_lossy(),
312+
"repo_working_dir": repo.path().to_string_lossy(),
318313
"will_edit_filepaths": [lib_file_path_str.clone()],
319314
"dirty_files": {
320315
lib_file_path_str.clone(): base_lib_content.clone(),
@@ -335,7 +330,7 @@ fn test_ai_tab_e2e_handles_dirty_files_map() {
335330
"hook_event_name": "after_edit",
336331
"tool": "github-copilot-tab",
337332
"model": "default",
338-
"repo_working_dir": repo.canonical_path().to_string_lossy(),
333+
"repo_working_dir": repo.path().to_string_lossy(),
339334
"edited_filepaths": [lib_file_path_str.clone()],
340335
"dirty_files": {
341336
lib_file_path_str.clone(): ai_content.clone(),
@@ -344,19 +339,8 @@ fn test_ai_tab_e2e_handles_dirty_files_map() {
344339
}),
345340
);
346341

347-
// Debug: Check working logs before commit
348-
let working_logs = repo.current_working_logs();
349-
if let Ok(checkpoints) = working_logs.read_all_checkpoints() {
350-
println!("Checkpoints before commit: {}", checkpoints.len());
351-
for (i, cp) in checkpoints.iter().enumerate() {
352-
println!("Checkpoint {}: kind={:?}, entries={}", i, cp.kind, cp.entries.len());
353-
for entry in &cp.entries {
354-
println!(" File: {}, attributions={}", entry.file, entry.attributions.len());
355-
}
356-
}
357-
}
358-
359-
repo.stage_all_and_commit("Record AI tab completion while other files dirty").unwrap();
342+
repo.stage_all_and_commit("Record AI tab completion while other files dirty")
343+
.unwrap();
360344

361345
let mut file = repo.filename(&std::path::Path::new("src").join("lib.rs").to_string_lossy());
362346
file.assert_lines_and_blame(lines![
@@ -367,4 +351,4 @@ fn test_ai_tab_e2e_handles_dirty_files_map() {
367351
" println!(\"from ai\");".ai(),
368352
"}".ai(),
369353
]);
370-
}
354+
}

0 commit comments

Comments
 (0)