Refactor application structure and simplify implementation

This commit is contained in:
2026-07-22 00:08:09 +03:00
parent dbba3806cc
commit 90b2eb507c
74 changed files with 11362 additions and 6814 deletions
+65 -3
View File
@@ -15,7 +15,10 @@ fn detects_existing_proxifyre_from_registry_install_location() {
.with_registry("ProxiFyre", r"C:\Tools\ProxiFyre")
.with_path(r"C:\Tools\ProxiFyre")
.with_path(r"C:\Tools\ProxiFyre\ProxiFyre.exe")
.with_service("ProxiFyreService");
.with_service_path(
"ProxiFyreService",
r#""C:\Tools\ProxiFyre\ProxiFyre.exe" --service"#,
);
let detected = detect_proxyfier_install_with_host(&host)
.expect("existing ProxiFyre install should be detected");
@@ -82,7 +85,10 @@ fn reports_stopped_proxifyre_service_when_executable_exists() {
let host = MockHost::new()
.with_env("PROXYWARDEN_PROXIFYRE_ROOT", r"C:\Tools\ProxiFyre")
.with_path(r"C:\Tools\ProxiFyre\ProxiFyre.exe")
.with_stopped_service("ProxiFyreService");
.with_stopped_service_path(
"ProxiFyreService",
r#""C:\Tools\ProxiFyre\ProxiFyre.exe" --service"#,
);
let detected =
detect_proxyfier_install_with_host(&host).expect("proxifyre executable should be detected");
@@ -105,6 +111,37 @@ fn missing_proxyfier_returns_install_action_status() {
assert_eq!(component.actions, vec!["Установить ProxiFyre"]);
}
#[test]
fn ignores_known_service_name_when_path_points_to_foreign_binary() {
let host = MockHost::new()
.with_env("PROXYWARDEN_PROXIFYRE_ROOT", r"C:\Tools\ProxiFyre")
.with_path(r"C:\Tools\ProxiFyre\ProxiFyre.exe")
.with_service_path(
"ProxiFyreService",
r#""C:\Foreign\ProxiFyre.exe" --service"#,
);
let detected =
detect_proxyfier_install_with_host(&host).expect("executable should still be detected");
assert!(!detected.running);
assert_eq!(detected.service_status, None);
}
#[test]
fn ignores_known_service_name_without_path_metadata() {
let host = MockHost::new()
.with_env("PROXYWARDEN_PROXIFYRE_ROOT", r"C:\Tools\ProxiFyre")
.with_path(r"C:\Tools\ProxiFyre\ProxiFyre.exe")
.with_service("ProxiFyreService");
let detected =
detect_proxyfier_install_with_host(&host).expect("executable should still be detected");
assert!(!detected.running);
assert_eq!(detected.service_status, None);
}
#[test]
fn detects_running_local_singbox_from_default_install_root_and_service() {
let host = MockHost::new()
@@ -176,6 +213,7 @@ struct MockHost {
paths: HashSet<String>,
processes: HashSet<String>,
services: HashMap<String, String>,
service_paths: HashMap<String, String>,
registry: Vec<RegistryInstallEntry>,
}
@@ -205,9 +243,19 @@ impl MockHost {
self
}
fn with_stopped_service(mut self, service: &str) -> Self {
fn with_service_path(mut self, service: &str, path_name: &str) -> Self {
self.services
.insert(service.to_ascii_lowercase(), "running".to_string());
self.service_paths
.insert(service.to_ascii_lowercase(), path_name.to_string());
self
}
fn with_stopped_service_path(mut self, service: &str, path_name: &str) -> Self {
self.services
.insert(service.to_ascii_lowercase(), "stopped".to_string());
self.service_paths
.insert(service.to_ascii_lowercase(), path_name.to_string());
self
}
@@ -241,6 +289,20 @@ impl ProxyfierDetectionHost for MockHost {
.cloned()
}
fn service_info(
&self,
service_name: &str,
) -> Option<proxywarden_lib::component_detection::DetectedService> {
let key = service_name.to_ascii_lowercase();
self.services.get(&key).map(|status| {
proxywarden_lib::component_detection::DetectedService {
name: service_name.to_string(),
status: status.clone(),
path_name: self.service_paths.get(&key).cloned(),
}
})
}
fn registry_install_entries(&self) -> Vec<RegistryInstallEntry> {
self.registry.clone()
}