Skip to content
1 change: 1 addition & 0 deletions src-tauri/src/brew_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fn fixed_brew_path() -> Result<PathBuf, String> {

for path in [
Path::new("/opt/homebrew/bin/brew"),
Path::new("/usr/local/Homebrew/bin/brew"),
Path::new("/usr/local/bin/brew"),
] {
let metadata = std::fs::symlink_metadata(path).ok();
Expand Down
26 changes: 26 additions & 0 deletions src-tauri/tests/brew_cleanup_intel_install_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::path::PathBuf;

fn brew_cleanup_source() -> String {
std::fs::read_to_string(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/brew_cleanup.rs"))
.expect("brew cleanup production source must be readable")
}

#[test]
fn standard_intel_homebrew_repository_target_is_admitted_without_following_alias_symlinks() {
let source = brew_cleanup_source();
let (_, macos_implementation) = source
.split_once("#[cfg(target_os = \"macos\")]\nfn fixed_brew_path()")
.expect("macOS fixed Homebrew executable admission must remain present");
let (fixed_brew_path, _) = macos_implementation
.split_once("#[cfg(not(target_os = \"macos\"))]")
.expect("non-macOS fail-closed boundary must remain present");

assert!(
fixed_brew_path.contains("Path::new(\"/usr/local/Homebrew/bin/brew\")"),
"fixed candidates must include the standard Intel Homebrew repository target"
);
assert!(
fixed_brew_path.contains("!metadata.file_type().is_symlink()"),
"Intel compatibility must not weaken symbolic-link rejection"
);
}