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
+52 -2
View File
@@ -13,6 +13,7 @@ use proxywarden_lib::models::{
self, ComponentId, ComponentState, ComponentStatus, Profile, ProfileItem, ProfileItemType,
Protocol, ProxyProtocol, Target, TargetKind,
};
use proxywarden_lib::proxifyre_ownership::ManagedProxiFyreOwnership;
use proxywarden_lib::storage::JsonStorage;
use std::collections::HashSet;
use std::fs;
@@ -358,7 +359,7 @@ fn proxifyre_uninstall_script_parses_as_powershell() {
};
let script = commands::wrap_elevated_package_script(
&commands::uninstall_proxifyre_script(Some(&detected)),
&commands::uninstall_proxifyre_script(Some(&detected), &managed_ownership(true)),
&root.join("uninstall.log"),
);
let script_path = root.join("uninstall.ps1");
@@ -397,8 +398,13 @@ fn proxifyre_uninstall_script_removes_packet_filter_after_proxifyre() {
service_name: Some("ProxiFyreService".to_string()),
service_status: Some("running".to_string()),
};
let script = commands::uninstall_proxifyre_script(Some(&detected));
let script = commands::uninstall_proxifyre_script(Some(&detected), &managed_ownership(true));
assert!(script.contains("function Find-ManagedProxiFyreService"));
assert!(script.contains("Get-CimInstance Win32_Service"));
assert!(script.contains("[StringComparison]::OrdinalIgnoreCase"));
assert!(!script.contains("function Find-ProxiFyreService"));
assert!(!script.contains("Where-Object { $_.Name -match 'ProxiFyre|Proxifyre'"));
assert!(script.contains("function Resolve-MsiProductCode($program, [string]$label)"));
assert!(script.contains("Отказываюсь запускать произвольный UninstallString"));
assert!(script.contains("Start-Process -FilePath 'msiexec.exe'"));
@@ -413,6 +419,29 @@ fn proxifyre_uninstall_script_removes_packet_filter_after_proxifyre() {
assert!(proxifyre_step < packet_filter_step);
}
#[test]
fn proxifyre_uninstall_script_leaves_shared_packet_filter_installed() {
let detected = DetectedProxyfier {
engine: ProxyfierEngine::ProxiFyre,
name: "ProxiFyre".to_string(),
install_dir: PathBuf::from(r"C:\Program Files\ProxyWarden\components\ProxiFyre"),
executable_path: PathBuf::from(
r"C:\Program Files\ProxyWarden\components\ProxiFyre\ProxiFyre.exe",
),
config_path: None,
running: false,
service_name: Some("ProxiFyreService".to_string()),
service_status: Some("stopped".to_string()),
};
let script = commands::uninstall_proxifyre_script(Some(&detected), &managed_ownership(false));
assert!(script.contains("$removePacketFilter = $false"));
assert!(script.contains("if ($removePacketFilter)"));
assert!(script.contains("Windows Packet Filter оставлен"));
assert!(!script.contains("Get-Process -Name 'ProxiFyre'"));
}
#[test]
fn singbox_runner_preserves_installer_args_with_spaces() {
let script = commands::singbox_installer_runner_script(
@@ -540,6 +569,20 @@ fn component_status_merges_detected_existing_proxifyre() {
assert!(proxyfier.problems.is_empty());
}
#[test]
fn component_status_does_not_keep_stale_installed_state_when_detection_is_missing() {
let components = resolve_component_statuses(vec![proxyfier_running()], None, None);
let proxyfier = components
.iter()
.find(|component| component.id == ComponentId::Proxyfier)
.expect("proxyfier component");
assert_eq!(proxyfier.state, ComponentState::Missing);
assert!(!proxyfier.installed);
assert!(!proxyfier.running);
assert_eq!(proxyfier.path, None);
}
#[test]
fn detected_proxy_apply_helper_writes_proxifyre_app_config() {
let root = test_root("detected-proxifyre");
@@ -782,3 +825,10 @@ fn singbox_missing() -> ComponentStatus {
actions: vec!["Установить локальный sing-box".to_string()],
}
}
fn managed_ownership(remove_packet_filter: bool) -> ManagedProxiFyreOwnership {
ManagedProxiFyreOwnership {
service_name: "ProxiFyreService".to_string(),
remove_packet_filter,
}
}