Skip to content

Commit fa3c232

Browse files
mareursclaude
andcommitted
chore: apply cargo fmt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 491c073 commit fa3c232

3 files changed

Lines changed: 141 additions & 35 deletions

File tree

src/tools/file.rs

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,25 +1228,43 @@ mod tests {
12281228

12291229
// Baseline: valid 1-indexed range succeeds and returns content
12301230
let result = ReadFile
1231-
.call(json!({ "path": path, "start_line": 1, "end_line": 2 }), &ctx)
1231+
.call(
1232+
json!({ "path": path, "start_line": 1, "end_line": 2 }),
1233+
&ctx,
1234+
)
12321235
.await
12331236
.unwrap();
1234-
assert!(!result["content"].as_str().unwrap().is_empty(), "valid range must return content");
1237+
assert!(
1238+
!result["content"].as_str().unwrap().is_empty(),
1239+
"valid range must return content"
1240+
);
12351241

12361242
// Stale (the bug): old code passed start_line=0 through to extract_lines, which
12371243
// silently returned an empty string — indistinguishable from an empty file.
12381244
// Fixed: start_line=0 is now rejected with a RecoverableError.
12391245
let result = ReadFile
1240-
.call(json!({ "path": path, "start_line": 0, "end_line": 3 }), &ctx)
1246+
.call(
1247+
json!({ "path": path, "start_line": 0, "end_line": 3 }),
1248+
&ctx,
1249+
)
12411250
.await;
1242-
assert!(result.is_err(), "start_line=0 must be rejected (lines are 1-indexed)");
1251+
assert!(
1252+
result.is_err(),
1253+
"start_line=0 must be rejected (lines are 1-indexed)"
1254+
);
12431255

12441256
// Fresh: valid range is unaffected — the guard is narrow and precise
12451257
let result = ReadFile
1246-
.call(json!({ "path": path, "start_line": 2, "end_line": 3 }), &ctx)
1258+
.call(
1259+
json!({ "path": path, "start_line": 2, "end_line": 3 }),
1260+
&ctx,
1261+
)
12471262
.await
12481263
.unwrap();
1249-
assert!(!result["content"].as_str().unwrap().is_empty(), "valid range after error cases must still return content");
1264+
assert!(
1265+
!result["content"].as_str().unwrap().is_empty(),
1266+
"valid range after error cases must still return content"
1267+
);
12501268
}
12511269

12521270
#[tokio::test]
@@ -1259,25 +1277,40 @@ mod tests {
12591277

12601278
// Baseline: valid range succeeds
12611279
let result = ReadFile
1262-
.call(json!({ "path": path, "start_line": 2, "end_line": 4 }), &ctx)
1280+
.call(
1281+
json!({ "path": path, "start_line": 2, "end_line": 4 }),
1282+
&ctx,
1283+
)
12631284
.await
12641285
.unwrap();
1265-
assert!(!result["content"].as_str().unwrap().is_empty(), "valid range must return content");
1286+
assert!(
1287+
!result["content"].as_str().unwrap().is_empty(),
1288+
"valid range must return content"
1289+
);
12661290

12671291
// Stale (the bug): old code passed end < start through to extract_lines, which
12681292
// computed a negative/empty slice and silently returned "".
12691293
// Fixed: end_line < start_line is now rejected with a RecoverableError.
12701294
let result = ReadFile
1271-
.call(json!({ "path": path, "start_line": 5, "end_line": 2 }), &ctx)
1295+
.call(
1296+
json!({ "path": path, "start_line": 5, "end_line": 2 }),
1297+
&ctx,
1298+
)
12721299
.await;
12731300
assert!(result.is_err(), "end_line < start_line must be rejected");
12741301

12751302
// Fresh: equal start/end (single line) is valid, not rejected
12761303
let result = ReadFile
1277-
.call(json!({ "path": path, "start_line": 3, "end_line": 3 }), &ctx)
1304+
.call(
1305+
json!({ "path": path, "start_line": 3, "end_line": 3 }),
1306+
&ctx,
1307+
)
12781308
.await
12791309
.unwrap();
1280-
assert!(!result["content"].as_str().unwrap().is_empty(), "start_line == end_line (single line) must succeed");
1310+
assert!(
1311+
!result["content"].as_str().unwrap().is_empty(),
1312+
"start_line == end_line (single line) must succeed"
1313+
);
12811314
}
12821315

12831316
#[tokio::test]
@@ -2595,17 +2628,31 @@ mod tests {
25952628
// but old code still set total=2 (line count) — inconsistent with matches.len()=1.
25962629
// Fixed: total now equals the number of merged blocks returned.
25972630
let with_ctx = SearchPattern
2598-
.call(json!({ "pattern": "MATCH_", "path": path, "context_lines": 2 }), &ctx)
2631+
.call(
2632+
json!({ "pattern": "MATCH_", "path": path, "context_lines": 2 }),
2633+
&ctx,
2634+
)
25992635
.await
26002636
.unwrap();
26012637
let matches = with_ctx["matches"].as_array().unwrap();
26022638
let total = with_ctx["total"].as_u64().unwrap();
26032639

26042640
// Sandwich assertion: the two matches must have merged into exactly one block
2605-
assert_eq!(matches.len(), 1, "adjacent matches with context_lines=2 must merge into one block");
2641+
assert_eq!(
2642+
matches.len(),
2643+
1,
2644+
"adjacent matches with context_lines=2 must merge into one block"
2645+
);
26062646
// Fresh: total now tracks blocks, not lines — so it equals 1, not 2
2607-
assert_eq!(total, 1, "total must be block count (1), not line count (2)");
2608-
assert_eq!(total, matches.len() as u64, "total must always equal matches.len()");
2647+
assert_eq!(
2648+
total, 1,
2649+
"total must be block count (1), not line count (2)"
2650+
);
2651+
assert_eq!(
2652+
total,
2653+
matches.len() as u64,
2654+
"total must always equal matches.len()"
2655+
);
26092656
}
26102657

26112658
#[tokio::test]

src/tools/output_buffer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ impl OutputBuffer {
452452
// of our own injected temp files. Relative paths without a ./ prefix (e.g.
453453
// "src/main.rs") are also treated as non-buffer-only.
454454
let is_buffer_only = !shell_words(&result).iter().any(|word| {
455-
let is_temp = temp_path_strings.iter().any(|tp| word.contains(tp.as_str()));
455+
let is_temp = temp_path_strings
456+
.iter()
457+
.any(|tp| word.contains(tp.as_str()));
456458
if is_temp {
457459
return false;
458460
}
@@ -791,7 +793,10 @@ mod tests {
791793
// Baseline: command with only a buffer ref → IS buffer-only (safe to skip checks)
792794
let (_, files, is_buf_only, _) = buf.resolve_refs(&format!("cat {id}")).unwrap();
793795
OutputBuffer::cleanup_temp_files(&files);
794-
assert!(is_buf_only, "command with only buffer refs must be buffer-only");
796+
assert!(
797+
is_buf_only,
798+
"command with only buffer refs must be buffer-only"
799+
);
795800

796801
// Stale (the bug): old resolve_refs also classified 'grep foo @cmd src/main.rs'
797802
// as buffer-only because it only checked '/' and './' prefixes on real args.

tests/symbol_lsp.rs

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,14 @@ async fn replace_symbol_works_for_python() {
779779
.unwrap();
780780

781781
let result = std::fs::read_to_string(dir.path().join("greet.py")).unwrap();
782-
assert!(result.contains("'new'"), "new body must be present; got:\n{result}");
783-
assert!(!result.contains("'old'"), "old body must be gone; got:\n{result}");
782+
assert!(
783+
result.contains("'new'"),
784+
"new body must be present; got:\n{result}"
785+
);
786+
assert!(
787+
!result.contains("'old'"),
788+
"old body must be gone; got:\n{result}"
789+
);
784790
}
785791

786792
/// TypeScript: `function` was not in the Rust keyword allowlist → old code rejected it.
@@ -806,8 +812,14 @@ async fn replace_symbol_works_for_typescript() {
806812
.unwrap();
807813

808814
let result = std::fs::read_to_string(dir.path().join("greet.ts")).unwrap();
809-
assert!(result.contains("'new'"), "new body must be present; got:\n{result}");
810-
assert!(!result.contains("'old'"), "old body must be gone; got:\n{result}");
815+
assert!(
816+
result.contains("'new'"),
817+
"new body must be present; got:\n{result}"
818+
);
819+
assert!(
820+
!result.contains("'old'"),
821+
"old body must be gone; got:\n{result}"
822+
);
811823
}
812824

813825
/// JavaScript: `function` keyword → same Rust-allowlist rejection as TypeScript.
@@ -830,8 +842,14 @@ async fn replace_symbol_works_for_javascript() {
830842
.unwrap();
831843

832844
let result = std::fs::read_to_string(dir.path().join("greet.js")).unwrap();
833-
assert!(result.contains("'new'"), "new body must be present; got:\n{result}");
834-
assert!(!result.contains("'old'"), "old body must be gone; got:\n{result}");
845+
assert!(
846+
result.contains("'new'"),
847+
"new body must be present; got:\n{result}"
848+
);
849+
assert!(
850+
!result.contains("'old'"),
851+
"old body must be gone; got:\n{result}"
852+
);
835853
}
836854

837855
/// Go: `func` was not in the Rust keyword allowlist → old code rejected it.
@@ -854,8 +872,14 @@ async fn replace_symbol_works_for_go() {
854872
.unwrap();
855873

856874
let result = std::fs::read_to_string(dir.path().join("greet.go")).unwrap();
857-
assert!(result.contains("\"new\""), "new body must be present; got:\n{result}");
858-
assert!(!result.contains("\"old\""), "old body must be gone; got:\n{result}");
875+
assert!(
876+
result.contains("\"new\""),
877+
"new body must be present; got:\n{result}"
878+
);
879+
assert!(
880+
!result.contains("\"old\""),
881+
"old body must be gone; got:\n{result}"
882+
);
859883
}
860884

861885
/// Java: `public` at the start of a method was not in the allowlist → rejected.
@@ -879,8 +903,14 @@ async fn replace_symbol_works_for_java() {
879903
.unwrap();
880904

881905
let result = std::fs::read_to_string(dir.path().join("Greet.java")).unwrap();
882-
assert!(result.contains("\"new\""), "new body must be present; got:\n{result}");
883-
assert!(!result.contains("\"old\""), "old body must be gone; got:\n{result}");
906+
assert!(
907+
result.contains("\"new\""),
908+
"new body must be present; got:\n{result}"
909+
);
910+
assert!(
911+
!result.contains("\"old\""),
912+
"old body must be gone; got:\n{result}"
913+
);
884914
}
885915

886916
/// Kotlin: `fun` was not in the Rust keyword allowlist → old code rejected it.
@@ -903,8 +933,14 @@ async fn replace_symbol_works_for_kotlin() {
903933
.unwrap();
904934

905935
let result = std::fs::read_to_string(dir.path().join("Greet.kt")).unwrap();
906-
assert!(result.contains("\"new\""), "new body must be present; got:\n{result}");
907-
assert!(!result.contains("\"old\""), "old body must be gone; got:\n{result}");
936+
assert!(
937+
result.contains("\"new\""),
938+
"new body must be present; got:\n{result}"
939+
);
940+
assert!(
941+
!result.contains("\"old\""),
942+
"old body must be gone; got:\n{result}"
943+
);
908944
}
909945

910946
/// C: return-type-first signatures were not in the Rust keyword allowlist → rejected.
@@ -927,8 +963,14 @@ async fn replace_symbol_works_for_c() {
927963
.unwrap();
928964

929965
let result = std::fs::read_to_string(dir.path().join("greet.c")).unwrap();
930-
assert!(result.contains("return 1"), "new body must be present; got:\n{result}");
931-
assert!(!result.contains("return 0"), "old body must be gone; got:\n{result}");
966+
assert!(
967+
result.contains("return 1"),
968+
"new body must be present; got:\n{result}"
969+
);
970+
assert!(
971+
!result.contains("return 0"),
972+
"old body must be gone; got:\n{result}"
973+
);
932974
}
933975

934976
/// C++: same as C — return-type-first → rejected by old allowlist.
@@ -951,8 +993,14 @@ async fn replace_symbol_works_for_cpp() {
951993
.unwrap();
952994

953995
let result = std::fs::read_to_string(dir.path().join("greet.cpp")).unwrap();
954-
assert!(result.contains("\"new\""), "new body must be present; got:\n{result}");
955-
assert!(!result.contains("\"old\""), "old body must be gone; got:\n{result}");
996+
assert!(
997+
result.contains("\"new\""),
998+
"new body must be present; got:\n{result}"
999+
);
1000+
assert!(
1001+
!result.contains("\"old\""),
1002+
"old body must be gone; got:\n{result}"
1003+
);
9561004
}
9571005

9581006
/// Ruby: `def` (without parens) was not in the Rust keyword allowlist → rejected.
@@ -979,6 +1027,12 @@ async fn replace_symbol_works_for_ruby() {
9791027
.unwrap();
9801028

9811029
let result = std::fs::read_to_string(dir.path().join("greet.rb")).unwrap();
982-
assert!(result.contains("'new'"), "new body must be present; got:\n{result}");
983-
assert!(!result.contains("'old'"), "old body must be gone; got:\n{result}");
1030+
assert!(
1031+
result.contains("'new'"),
1032+
"new body must be present; got:\n{result}"
1033+
);
1034+
assert!(
1035+
!result.contains("'old'"),
1036+
"old body must be gone; got:\n{result}"
1037+
);
9841038
}

0 commit comments

Comments
 (0)