Skip to content

Commit d8ddefe

Browse files
committed
fix: isolate cursor hook tests from local settings (determinist)
1 parent a1d46f3 commit d8ddefe

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎src/hooks/hook_cmd.rs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,18 @@ pub fn run_cursor() -> Result<()> {
459459
Ok(())
460460
}
461461

462-
/// Process a Cursor hook payload from a string (for testing).
463462
#[cfg(test)]
464463
fn run_cursor_inner(input: &str) -> String {
464+
run_cursor_inner_with_rules(input, &[], &[], &[])
465+
}
466+
467+
#[cfg(test)]
468+
fn run_cursor_inner_with_rules(
469+
input: &str,
470+
deny_rules: &[String],
471+
ask_rules: &[String],
472+
allow_rules: &[String],
473+
) -> String {
465474
let v: Value = match serde_json::from_str(input) {
466475
Ok(v) => v,
467476
Err(_) => return "{}".to_string(),
@@ -476,7 +485,7 @@ fn run_cursor_inner(input: &str) -> String {
476485
None => return "{}".to_string(),
477486
};
478487

479-
let verdict = permissions::check_command(&cmd);
488+
let verdict = permissions::check_command_with_rules(&cmd, deny_rules, ask_rules, allow_rules);
480489
if verdict == PermissionVerdict::Deny {
481490
return "{}".to_string();
482491
}
@@ -796,12 +805,7 @@ mod tests {
796805
let result = run_cursor_inner(&cursor_input("cargo test"));
797806
let v: Value = serde_json::from_str(&result).unwrap();
798807
assert!(v.get("hookSpecificOutput").is_none());
799-
// Permission is "allow" or "ask" depending on settings.json rules
800-
let perm = v["permission"].as_str().unwrap();
801-
assert!(
802-
perm == "allow" || perm == "ask",
803-
"expected allow or ask, got {perm}"
804-
);
808+
assert_eq!(v["permission"], "ask");
805809
}
806810

807811
// --- Audit logging ---

0 commit comments

Comments
 (0)