Refactor proxy routing and session management

This commit is contained in:
2026-07-08 00:09:38 +03:00
parent c5bdb10445
commit b45dd2ae05
26 changed files with 5193 additions and 307 deletions

View File

@@ -4,7 +4,8 @@ mod component_detection;
mod models;
use component_detection::{
detect_proxyfier_install_with_host, proxyfier_component_from_detection, ProxyfierDetectionHost,
detect_proxyfier_install_with_host, detect_singbox_install_with_host,
proxyfier_component_from_detection, singbox_component_from_detection, ProxyfierDetectionHost,
ProxyfierEngine, RegistryInstallEntry,
};
use models::ComponentState;
@@ -74,6 +75,66 @@ fn missing_proxyfier_returns_install_action_status() {
assert_eq!(component.actions, vec!["Установить ProxiFyre"]);
}
#[test]
fn detects_running_local_singbox_from_default_install_root_and_service() {
let host = MockHost::new()
.with_path(r"C:\Program Files\VpnProxy\sing-box\sing-box.exe")
.with_service("VpnProxySingBox");
let detected =
detect_singbox_install_with_host(&host).expect("existing sing-box should be detected");
assert_eq!(
detected.executable_path,
PathBuf::from(r"C:\Program Files\VpnProxy\sing-box\sing-box.exe")
);
assert_eq!(detected.service_name, "VpnProxySingBox");
assert!(detected.running);
let component = singbox_component_from_detection(Some(&detected));
assert_eq!(component.state, ComponentState::Running);
assert!(component.installed);
assert!(component.running);
assert_eq!(
component.path,
Some(r"C:\Program Files\VpnProxy\sing-box\sing-box.exe".to_string())
);
assert!(component.problems.is_empty());
}
#[test]
fn detects_stopped_local_singbox_from_env_override() {
let host = MockHost::new()
.with_env("VPN_PROXY_SINGBOX_ROOT", r"D:\Portable\sing-box")
.with_path(r"D:\Portable\sing-box\sing-box.exe");
let detected = detect_singbox_install_with_host(&host).expect("env override should be checked");
let component = singbox_component_from_detection(Some(&detected));
assert_eq!(
detected.executable_path,
PathBuf::from(r"D:\Portable\sing-box\sing-box.exe")
);
assert_eq!(component.state, ComponentState::Stopped);
assert!(component.installed);
assert!(!component.running);
assert!(component
.problems
.iter()
.any(|problem| problem.contains("остановлена")));
}
#[test]
fn missing_local_singbox_returns_optional_install_action_status() {
let component = singbox_component_from_detection(None);
assert_eq!(component.state, ComponentState::Missing);
assert!(!component.installed);
assert!(!component.running);
assert_eq!(component.actions, vec!["Установить Local sing-box"]);
assert!(component.problems.is_empty());
}
#[derive(Default)]
struct MockHost {
env: HashMap<String, String>,