Skip to content

Commit 6d4c211

Browse files
hyperpolymathclaude
andcommitted
Revert 35 .expect("TODO: handle error") sites in state.rs (batch 4/N)
Smallest of the big-4 remaining `impl/rust-cli/src/` files. All 35 sites are inside `#[cfg(test)] mod` (line >945), entirely test code: ShellState::new() setup, history.last() / get_array_all() / .as_ref() chains after preceding `assert!()` proofs of the Some/Ok case. Per-site policy: mass `replace_all` to `.unwrap()` is sound here because every site is test-internal scaffolding where `.unwrap()` is the conventional shape; preceding asserts (or impossibility-by-construction of the Err case in `ShellState::new("/tmp/...")`) carry the proof. Verified locally: cargo build -> EXIT 0 cargo test -> 703 passed / 0 failed / 14 ignored (unchanged across batches 1-4) Cumulative progress: 171 / ~530 sites cleared (~32%) across 14 files. Remaining big-3 in `impl/rust-cli/src/`: parser.rs (116), commands.rs (66), arith.rs (55) — each warrants its own dedicated session. Plus `impl/rust-ffi/` ↔ `ffi/rust/` duplicate tree (~50 more, separate finding requiring scope decision). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fc3313b commit 6d4c211

1 file changed

Lines changed: 35 additions & 35 deletions

File tree

impl/rust-cli/src/state.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ mod tests {
954954

955955
#[test]
956956
fn test_state_new() {
957-
let state = ShellState::new("/tmp/vsh_test").expect("TODO: handle error");
957+
let state = ShellState::new("/tmp/vsh_test").unwrap();
958958
assert!(state.root.exists());
959959
}
960960

@@ -964,7 +964,7 @@ mod tests {
964964

965965
#[test]
966966
fn test_set_array() {
967-
let mut state = ShellState::new("/tmp/vsh_array_test_1").expect("TODO: handle error");
967+
let mut state = ShellState::new("/tmp/vsh_array_test_1").unwrap();
968968
let elements = vec!["one".to_string(), "two".to_string(), "three".to_string()];
969969
state.set_array("arr", elements);
970970

@@ -974,7 +974,7 @@ mod tests {
974974

975975
#[test]
976976
fn test_get_array_element() {
977-
let mut state = ShellState::new("/tmp/vsh_array_test_2").expect("TODO: handle error");
977+
let mut state = ShellState::new("/tmp/vsh_array_test_2").unwrap();
978978
state.set_array("arr", vec!["first".to_string(), "second".to_string()]);
979979

980980
assert_eq!(state.get_array_element("arr", 0), Some("first"));
@@ -984,16 +984,16 @@ mod tests {
984984

985985
#[test]
986986
fn test_get_array_all() {
987-
let mut state = ShellState::new("/tmp/vsh_array_test_3").expect("TODO: handle error");
987+
let mut state = ShellState::new("/tmp/vsh_array_test_3").unwrap();
988988
state.set_array("arr", vec!["a".to_string(), "b".to_string(), "c".to_string()]);
989989

990-
let all = state.get_array_all("arr").expect("TODO: handle error");
990+
let all = state.get_array_all("arr").unwrap();
991991
assert_eq!(all, vec!["a", "b", "c"]);
992992
}
993993

994994
#[test]
995995
fn test_set_array_element_new() {
996-
let mut state = ShellState::new("/tmp/vsh_array_test_4").expect("TODO: handle error");
996+
let mut state = ShellState::new("/tmp/vsh_array_test_4").unwrap();
997997
state.set_array_element("arr", 0, "first".to_string());
998998
state.set_array_element("arr", 1, "second".to_string());
999999

@@ -1004,7 +1004,7 @@ mod tests {
10041004

10051005
#[test]
10061006
fn test_set_array_element_sparse() {
1007-
let mut state = ShellState::new("/tmp/vsh_array_test_5").expect("TODO: handle error");
1007+
let mut state = ShellState::new("/tmp/vsh_array_test_5").unwrap();
10081008
state.set_array_element("arr", 0, "zero".to_string());
10091009
state.set_array_element("arr", 100, "hundred".to_string());
10101010

@@ -1016,7 +1016,7 @@ mod tests {
10161016

10171017
#[test]
10181018
fn test_set_array_element_overwrite() {
1019-
let mut state = ShellState::new("/tmp/vsh_array_test_6").expect("TODO: handle error");
1019+
let mut state = ShellState::new("/tmp/vsh_array_test_6").unwrap();
10201020
state.set_array("arr", vec!["old".to_string()]);
10211021
state.set_array_element("arr", 0, "new".to_string());
10221022

@@ -1025,7 +1025,7 @@ mod tests {
10251025

10261026
#[test]
10271027
fn test_get_array_indices() {
1028-
let mut state = ShellState::new("/tmp/vsh_array_test_7").expect("TODO: handle error");
1028+
let mut state = ShellState::new("/tmp/vsh_array_test_7").unwrap();
10291029
state.set_array_element("arr", 0, "a".to_string());
10301030
state.set_array_element("arr", 2, "c".to_string());
10311031
state.set_array_element("arr", 5, "f".to_string());
@@ -1036,7 +1036,7 @@ mod tests {
10361036

10371037
#[test]
10381038
fn test_append_to_array() {
1039-
let mut state = ShellState::new("/tmp/vsh_array_test_8").expect("TODO: handle error");
1039+
let mut state = ShellState::new("/tmp/vsh_array_test_8").unwrap();
10401040
state.set_array("arr", vec!["one".to_string(), "two".to_string()]);
10411041
state.append_to_array("arr", vec!["three".to_string(), "four".to_string()]);
10421042

@@ -1047,7 +1047,7 @@ mod tests {
10471047

10481048
#[test]
10491049
fn test_append_to_empty_array() {
1050-
let mut state = ShellState::new("/tmp/vsh_array_test_9").expect("TODO: handle error");
1050+
let mut state = ShellState::new("/tmp/vsh_array_test_9").unwrap();
10511051
state.append_to_array("arr", vec!["first".to_string()]);
10521052

10531053
assert_eq!(state.get_array_element("arr", 0), Some("first"));
@@ -1056,7 +1056,7 @@ mod tests {
10561056

10571057
#[test]
10581058
fn test_append_to_scalar_converts() {
1059-
let mut state = ShellState::new("/tmp/vsh_array_test_10").expect("TODO: handle error");
1059+
let mut state = ShellState::new("/tmp/vsh_array_test_10").unwrap();
10601060
state.set_variable("var", "scalar");
10611061
state.append_to_array("var", vec!["new".to_string()]);
10621062

@@ -1067,7 +1067,7 @@ mod tests {
10671067

10681068
#[test]
10691069
fn test_scalar_and_array_separation() {
1070-
let mut state = ShellState::new("/tmp/vsh_array_test_11").expect("TODO: handle error");
1070+
let mut state = ShellState::new("/tmp/vsh_array_test_11").unwrap();
10711071
state.set_variable("scalar", "value");
10721072
state.set_array("arr", vec!["elem".to_string()]);
10731073

@@ -1081,7 +1081,7 @@ mod tests {
10811081

10821082
#[test]
10831083
fn test_unset_array() {
1084-
let mut state = ShellState::new("/tmp/vsh_array_test_12").expect("TODO: handle error");
1084+
let mut state = ShellState::new("/tmp/vsh_array_test_12").unwrap();
10851085
state.set_array("arr", vec!["elem".to_string()]);
10861086
assert!(state.is_array("arr"));
10871087

@@ -1092,19 +1092,19 @@ mod tests {
10921092

10931093
#[test]
10941094
fn test_export_array() {
1095-
let mut state = ShellState::new("/tmp/vsh_array_test_13").expect("TODO: handle error");
1095+
let mut state = ShellState::new("/tmp/vsh_array_test_13").unwrap();
10961096
state.set_array("arr", vec!["one".to_string(), "two".to_string(), "three".to_string()]);
10971097
state.export_variable("arr");
10981098

10991099
let exported = state.get_exported_env();
11001100
let arr_export = exported.iter().find(|(k, _)| k == "arr");
11011101
assert!(arr_export.is_some());
1102-
assert_eq!(arr_export.expect("TODO: handle error").1, "one two three");
1102+
assert_eq!(arr_export.unwrap().1, "one two three");
11031103
}
11041104

11051105
#[test]
11061106
fn test_is_array() {
1107-
let mut state = ShellState::new("/tmp/vsh_array_test_14").expect("TODO: handle error");
1107+
let mut state = ShellState::new("/tmp/vsh_array_test_14").unwrap();
11081108
state.set_variable("scalar", "value");
11091109
state.set_array("arr", vec!["elem".to_string()]);
11101110

@@ -1115,7 +1115,7 @@ mod tests {
11151115

11161116
#[test]
11171117
fn test_get_array_length_scalar() {
1118-
let mut state = ShellState::new("/tmp/vsh_array_test_15").expect("TODO: handle error");
1118+
let mut state = ShellState::new("/tmp/vsh_array_test_15").unwrap();
11191119
state.set_variable("scalar", "value");
11201120

11211121
assert_eq!(state.get_array_length("scalar"), 0);
@@ -1124,31 +1124,31 @@ mod tests {
11241124

11251125
#[test]
11261126
fn test_get_array_all_nonexistent() {
1127-
let state = ShellState::new("/tmp/vsh_array_test_16").expect("TODO: handle error");
1127+
let state = ShellState::new("/tmp/vsh_array_test_16").unwrap();
11281128
assert_eq!(state.get_array_all("nonexistent"), None);
11291129
}
11301130

11311131
#[test]
11321132
fn test_get_array_all_scalar() {
1133-
let mut state = ShellState::new("/tmp/vsh_array_test_17").expect("TODO: handle error");
1133+
let mut state = ShellState::new("/tmp/vsh_array_test_17").unwrap();
11341134
state.set_variable("scalar", "value");
11351135
assert_eq!(state.get_array_all("scalar"), None);
11361136
}
11371137

11381138
#[test]
11391139
fn test_empty_array() {
1140-
let mut state = ShellState::new("/tmp/vsh_array_test_18").expect("TODO: handle error");
1140+
let mut state = ShellState::new("/tmp/vsh_array_test_18").unwrap();
11411141
state.set_array("arr", vec![]);
11421142

11431143
assert!(state.is_array("arr"));
11441144
assert_eq!(state.get_array_length("arr"), 0);
1145-
assert_eq!(state.get_array_all("arr").expect("TODO: handle error"), Vec::<&str>::new());
1145+
assert_eq!(state.get_array_all("arr").unwrap(), Vec::<&str>::new());
11461146
assert_eq!(state.get_array_indices("arr"), Vec::<usize>::new());
11471147
}
11481148

11491149
#[test]
11501150
fn test_array_with_empty_strings() {
1151-
let mut state = ShellState::new("/tmp/vsh_array_test_19").expect("TODO: handle error");
1151+
let mut state = ShellState::new("/tmp/vsh_array_test_19").unwrap();
11521152
state.set_array("arr", vec!["".to_string(), "nonempty".to_string(), "".to_string()]);
11531153

11541154
assert_eq!(state.get_array_length("arr"), 3);
@@ -1182,7 +1182,7 @@ mod tests {
11821182
#[test]
11831183
fn test_backward_compatibility() {
11841184
// Test that old scalar variable usage still works
1185-
let mut state = ShellState::new("/tmp/vsh_array_test_20").expect("TODO: handle error");
1185+
let mut state = ShellState::new("/tmp/vsh_array_test_20").unwrap();
11861186

11871187
// set_variable should create scalar
11881188
state.set_variable("name", "value");
@@ -1199,59 +1199,59 @@ mod tests {
11991199

12001200
#[test]
12011201
fn test_set_variable_tracked_records_operation() {
1202-
let mut state = ShellState::new("/tmp/vsh_tracked_var_1").expect("TODO: handle error");
1202+
let mut state = ShellState::new("/tmp/vsh_tracked_var_1").unwrap();
12031203
state.set_variable_tracked("FOO", "bar");
12041204

12051205
assert_eq!(state.get_variable("FOO"), Some("bar"));
12061206
// Should have recorded a SetVariable operation
12071207
assert!(!state.history.is_empty());
1208-
let last_op = state.history.last().expect("TODO: handle error");
1208+
let last_op = state.history.last().unwrap();
12091209
assert_eq!(last_op.op_type, OperationType::SetVariable);
12101210
assert_eq!(last_op.path, "FOO");
12111211
}
12121212

12131213
#[test]
12141214
fn test_set_variable_tracked_captures_previous() {
1215-
let mut state = ShellState::new("/tmp/vsh_tracked_var_2").expect("TODO: handle error");
1215+
let mut state = ShellState::new("/tmp/vsh_tracked_var_2").unwrap();
12161216
// Set initial value
12171217
state.set_variable("FOO", "old_value");
12181218
// Now track-set a new value
12191219
state.set_variable_tracked("FOO", "new_value");
12201220

12211221
assert_eq!(state.get_variable("FOO"), Some("new_value"));
12221222
// undo_data should contain the previous value
1223-
let last_op = state.history.last().expect("TODO: handle error");
1223+
let last_op = state.history.last().unwrap();
12241224
let previous: Option<VariableValue> =
1225-
serde_json::from_slice(last_op.undo_data.as_ref().expect("TODO: handle error")).expect("TODO: handle error");
1225+
serde_json::from_slice(last_op.undo_data.as_ref().unwrap()).unwrap();
12261226
assert_eq!(previous, Some(VariableValue::Scalar("old_value".to_string())));
12271227
}
12281228

12291229
#[test]
12301230
fn test_set_variable_tracked_new_var_captures_none() {
1231-
let mut state = ShellState::new("/tmp/vsh_tracked_var_3").expect("TODO: handle error");
1231+
let mut state = ShellState::new("/tmp/vsh_tracked_var_3").unwrap();
12321232
state.set_variable_tracked("NEW_VAR", "value");
12331233

1234-
let last_op = state.history.last().expect("TODO: handle error");
1234+
let last_op = state.history.last().unwrap();
12351235
let previous: Option<VariableValue> =
1236-
serde_json::from_slice(last_op.undo_data.as_ref().expect("TODO: handle error")).expect("TODO: handle error");
1236+
serde_json::from_slice(last_op.undo_data.as_ref().unwrap()).unwrap();
12371237
assert_eq!(previous, None);
12381238
}
12391239

12401240
#[test]
12411241
fn test_unset_variable_tracked_records_operation() {
1242-
let mut state = ShellState::new("/tmp/vsh_tracked_var_4").expect("TODO: handle error");
1242+
let mut state = ShellState::new("/tmp/vsh_tracked_var_4").unwrap();
12431243
state.set_variable("FOO", "bar");
12441244
state.unset_variable_tracked("FOO");
12451245

12461246
assert_eq!(state.get_variable("FOO"), None);
1247-
let last_op = state.history.last().expect("TODO: handle error");
1247+
let last_op = state.history.last().unwrap();
12481248
assert_eq!(last_op.op_type, OperationType::UnsetVariable);
12491249
assert_eq!(last_op.path, "FOO");
12501250
}
12511251

12521252
#[test]
12531253
fn test_unset_variable_tracked_noop_for_nonexistent() {
1254-
let mut state = ShellState::new("/tmp/vsh_tracked_var_5").expect("TODO: handle error");
1254+
let mut state = ShellState::new("/tmp/vsh_tracked_var_5").unwrap();
12551255
let history_len = state.history.len();
12561256
state.unset_variable_tracked("NONEXISTENT");
12571257

0 commit comments

Comments
 (0)