feat(extensions): add MacOSPathHeuristic for detecting hardcoded macOS paths

This commit introduces a new heuristic, MacOSPathHeuristic, which checks for potential hardcoded macOS paths in file content. The heuristic is added to the existing list of checks in the run_heuristic_checks function, enhancing the compatibility checks for extensions.
This commit is contained in:
ByteAtATime 2025-07-05 21:13:13 -07:00
parent 3ee3787a05
commit c8b4cb58e0
No known key found for this signature in database

View file

@ -38,6 +38,22 @@ impl IncompatibilityHeuristic for AppleScriptHeuristic {
}
}
struct MacOSPathHeuristic;
impl IncompatibilityHeuristic for MacOSPathHeuristic {
fn check(&self, command_title: &str, file_content: &str) -> Option<HeuristicViolation> {
let macos_paths = ["/Applications/", "/Library/", "/Users/"];
for path in macos_paths {
if file_content.contains(path) {
return Some(HeuristicViolation {
command_name: command_title.to_string(),
reason: format!("Potential hardcoded macOS path: '{}'", path),
});
}
}
None
}
}
fn get_extension_dir(app: &tauri::AppHandle, slug: &str) -> Result<PathBuf, String> {
let data_dir = app
.path()
@ -139,7 +155,7 @@ fn get_commands_from_package_json(
fn run_heuristic_checks(archive_data: &bytes::Bytes) -> Result<Vec<HeuristicViolation>, String> {
let heuristics: Vec<Box<dyn IncompatibilityHeuristic + Send + Sync>> =
vec![Box::new(AppleScriptHeuristic)];
vec![Box::new(AppleScriptHeuristic), Box::new(MacOSPathHeuristic)];
if heuristics.is_empty() {
return Ok(vec![]);
}