Refactor proxy routing and installer flows

This commit is contained in:
2026-07-08 11:05:52 +03:00
parent e745633d91
commit 88d5b94133
14 changed files with 1899 additions and 487 deletions

View File

@@ -303,9 +303,10 @@ fn apply_generates_derived_config_and_records_activity_with_mock_helper() {
storage
.write_targets(&[external_socks5_target()])
.expect("write targets");
storage
.write_components(&[proxyfier_running(), singbox_missing()])
.expect("write components");
write_json(
&storage.paths().components_file,
&[proxyfier_running(), singbox_missing()],
);
let response = apply_profiles_with_services(
&storage,
@@ -345,9 +346,7 @@ fn apply_blocks_local_singbox_target_when_component_is_missing() {
storage
.write_targets(&[local_singbox_target()])
.expect("write targets");
storage
.write_components(&[singbox_missing()])
.expect("write components");
write_json(&storage.paths().components_file, &[singbox_missing()]);
let error = apply_profiles_with_services(
&storage,
@@ -405,7 +404,7 @@ fn detected_proxy_apply_helper_writes_proxifyre_app_config() {
.with_registry("ProxiFyre", &install_dir)
.with_path(&install_dir)
.with_path(&install_dir.join("ProxiFyre.exe"));
let helper = DetectedProxyApplyHelper::new(host);
let helper = DetectedProxyApplyHelper::from(host);
let result = helper
.apply_proxy_config(HelperApplyRequest {
@@ -438,7 +437,7 @@ fn detected_proxy_apply_helper_ignores_plain_proxifier_install() {
.with_registry("Proxifier", &install_dir)
.with_path(&install_dir)
.with_path(&install_dir.join("Proxifier.exe"));
let helper = DetectedProxyApplyHelper::new(host);
let helper = DetectedProxyApplyHelper::from(host);
let result = helper
.apply_proxy_config(HelperApplyRequest {
@@ -554,6 +553,14 @@ fn cleanup(root: &Path) {
let _ = fs::remove_dir_all(root);
}
fn write_json<T: serde::Serialize + ?Sized>(path: &Path, value: &T) {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).expect("create json parent dir");
}
let contents = serde_json::to_vec_pretty(value).expect("serialize json");
fs::write(path, contents).expect("write json");
}
fn discord_profile(target_id: &str) -> Profile {
Profile {
id: "discord".to_string(),

View File

@@ -39,10 +39,8 @@ fn roundtrips_profiles_targets_components_and_activity() {
storage.write_profiles(&profiles).expect("write profiles");
storage.write_targets(&targets).expect("write targets");
storage
.write_components(&components)
.expect("write components");
storage.write_activity(&activity).expect("write activity");
write_json(&storage.paths().components_file, &components);
write_json(&storage.paths().activity_file, &activity);
assert_eq!(storage.read_profiles().expect("read profiles"), profiles);
assert_eq!(storage.read_targets().expect("read targets"), targets);
@@ -118,7 +116,7 @@ fn missing_local_singbox_config_defaults_to_optional_empty_state() {
fn invalid_subscription_cache_falls_back_to_none() {
let root = test_root("invalid-subscription-cache");
let storage = JsonStorage::new(root.clone());
storage.ensure_dirs().expect("create storage dirs");
fs::create_dir_all(&storage.paths().state_dir).expect("create state dir");
fs::write(
&storage.paths().singbox_subscription_cache_file,
"{not valid json",
@@ -139,7 +137,7 @@ fn invalid_subscription_cache_falls_back_to_none() {
fn invalid_json_falls_back_to_empty_collection() {
let root = test_root("invalid-json");
let storage = JsonStorage::new(root.clone());
storage.ensure_dirs().expect("create storage dirs");
fs::create_dir_all(&storage.paths().config_dir).expect("create config dir");
fs::write(&storage.paths().profiles_file, "{not valid json").expect("write invalid json");
assert_eq!(
@@ -227,6 +225,14 @@ fn cleanup(root: &Path) {
let _ = fs::remove_dir_all(root);
}
fn write_json<T: serde::Serialize + ?Sized>(path: &Path, value: &T) {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).expect("create json parent dir");
}
let contents = serde_json::to_vec_pretty(value).expect("serialize json");
fs::write(path, contents).expect("write json");
}
fn sample_profile(id: &str) -> Profile {
Profile {
id: id.to_string(),