Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions robot-repo-automaton/src/exclusion_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,20 @@ impl ExclusionRegistry {

/// Decision for a given action context.
pub fn check(&self, ctx: &ActionContext<'_>) -> Decision {
self.check_with_kill_switch(ctx, env::var("HYPATIA_AUTOMATION").ok().as_deref())
}

/// `check` with the `HYPATIA_AUTOMATION` value passed in, so the kill
/// switch can be exercised without mutating the process environment (a
/// global that parallel tests in other modules would otherwise observe).
fn check_with_kill_switch(&self, ctx: &ActionContext<'_>, kill: Option<&str>) -> Decision {
// Scans are always allowed.
if !ctx.action.is_write() {
return Decision::Allow;
}

// Kill-switch check first — cheapest, catches everything.
if let Ok(kill) = env::var("HYPATIA_AUTOMATION") {
if let Some(kill) = kill {
let k = kill.to_ascii_lowercase();
if matches!(k.as_str(), "off" | "disabled" | "0" | "false" | "halt") {
return Decision::Deny {
Expand Down Expand Up @@ -584,17 +591,19 @@ reason = "upstream homebrew"

#[test]
fn kill_switch_blocks_everything() {
let _g = ENV_LOCK.lock().unwrap();
clear_env();
std::env::set_var("HYPATIA_AUTOMATION", "off");
// Pass the kill-switch value in directly instead of setting
// `HYPATIA_AUTOMATION`: a process-wide env mutation made unrelated
// tests (e.g. the fixer's) see denied writes while it was set.
let r = registry();
let d = r.check(&ActionContext {
repo_full_name: "The-Metadatastician/007-lang",
file_path: None,
remote_origin: None,
action: Action::CreatePr,
});
std::env::remove_var("HYPATIA_AUTOMATION");
let d = r.check_with_kill_switch(
&ActionContext {
repo_full_name: "The-Metadatastician/007-lang",
file_path: None,
remote_origin: None,
action: Action::CreatePr,
},
Some("off"),
);
match d {
Decision::Deny { axis, .. } => assert_eq!(axis, DenyAxis::KillSwitch),
_ => panic!("expected kill-switch deny"),
Expand Down
Loading