mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-04 21:30:06 +08:00
* chore(clippy): scope crate lint policy Keep panic-on-error lints at application target roots and scope signal dependencies to Linux. * docs(agents): define Rust backend architecture boundaries Document which layer owns Rust capabilities, fallible inputs, background work, and crate validation. * refactor(draft): type async publication conflicts Return typed conflicts for async Draft edits. Release the lock and edit permit before converting the error, and exercise overlapping updates. * refactor(logging): use typed logger errors Expose crate-owned logger errors and preserve the underlying error sources. * refactor(subscription): extract response decoding Keep HTTP and persistence in the app. Decode response metadata and framing in the crate, and fall back when the server filename is invalid. * refactor(profile): extract profile models and index rules Move profile models and index rules into the crate, preserving serialization and returning a typed missing-profile error. * refactor(profile): separate subscription refresh and scheduling policy Separate download and scheduling policy from the subscription use case while retaining the existing write path. * refactor(subscription): decode deep links in the subscription crate * refactor(profile): extract selected node recovery rules * docs(agents): define dependencies between capability crates * refactor(task): move retry primitives into the task crate * refactor(backup): extract backup ZIP writing * refactor(subscription): keep profile writes outside proxy fallback * refactor(runtime-bundle): extract runtime bundle planning Plan provider destinations and assets in the crate. Adapt the plan to the Service wire format at the call site. * perf(runtime-bundle): share destination strings with tristr Share destination storage within bundle planning and preserve the Service wire strings and provider readback. * refactor(profile): extract script validation and execution Share the Boa validation and execution API while preserving the save-side timeout and diagnostics. * refactor(config): extract configuration renderer Render from inputs supplied by the app, reuse the script crate, and preserve the default template fast path. * refactor(proxy): extract proxy view and its use case Project the Mihomo snapshot into the existing IPC DTO and move use-case orchestration out of the command. * refactor(config): inject the profile script executor * refactor(config): centralize Mihomo YAML output * perf(runtime-bundle): read remote providers from borrowed configuration * chore(clippy): scope crate lint policy Keep panic-on-error lints at application target roots and scope signal dependencies to Linux. * docs(agents): define Rust backend architecture boundaries Document which layer owns Rust capabilities, fallible inputs, background work, and crate validation. * refactor(draft): type async publication conflicts Return typed conflicts for async Draft edits. Release the lock and edit permit before converting the error, and exercise overlapping updates. * refactor(logging): use typed logger errors Expose crate-owned logger errors and preserve the underlying error sources. * refactor(subscription): extract response decoding Keep HTTP and persistence in the app. Decode response metadata and framing in the crate, and fall back when the server filename is invalid. * refactor(profile): extract profile models and index rules Move profile models and index rules into the crate, preserving serialization and returning a typed missing-profile error. * refactor(profile): separate subscription refresh and scheduling policy Separate download and scheduling policy from the subscription use case while retaining the existing write path. * refactor(subscription): decode deep links in the subscription crate * refactor(profile): extract selected node recovery rules * docs(agents): define dependencies between capability crates * refactor(task): move retry primitives into the task crate * refactor(backup): extract backup ZIP writing * refactor(subscription): keep profile writes outside proxy fallback * fix(profile): preserve delays for future update timestamps * fix(subscription): preserve filenames from response headers and URL paths * fix(subscription): separate deep link parameters from nested URLs * refactor(profile): look up the refresh target once * refactor(subscription): pass the proxy directly to each download * refactor(profile): build companion options in one place * refactor(profile): remove companions from the deleted profile * style(profile): keep profile fields together * refactor(profile): name index operations after what they change * refactor(profile): call the core reload directly * refactor(backup): move archive validation to the restore change * refactor(config): name the runtime rendering step * refactor(config): remove the unused runtime patch API * refactor(config): accumulate profile keys and logs during rendering * refactor(config): load cached chain items directly * refactor(script): keep console state local to evaluation * refactor(proxy): read group order and scope in one pass * refactor(config): reuse sequence storage when applying profile edits * refactor(proxy): collect provider snapshots in display order * refactor(proxy): build the view from its input * refactor(runtime-bundle): share provider section order * fix(config): fill blank IPv6 fake IP ranges in TUN mode * fix(config): keep runtime field sorting stable * perf(config): reuse profile sequence storage during rendering * fix(script): check the evaluated profile entry point * fix(script): support runtime console methods during validation * perf(script): count integer digits without formatting JSON * perf(proxy): resolve unique members without building scope caches * fix(runtime-bundle): reject mixed owners of a provider path * perf(runtime-bundle): reuse the normalized destination buffer * fix(script): reject oversized names before escaping
82 lines
2.7 KiB
Rust
82 lines
2.7 KiB
Rust
use super::{ResultLog, ScriptOutcome, field::use_lowercase};
|
|
use serde_yaml_ng::Mapping;
|
|
use tristr::alias::String;
|
|
|
|
type ScriptResult = (Mapping, Vec<String>, ResultLog);
|
|
|
|
/// Never fails: exceptions are logged and the input config is returned unchanged.
|
|
pub(super) async fn use_script<Fut: Future<Output = ScriptOutcome> + Send>(
|
|
script: String,
|
|
config: Mapping,
|
|
name: String,
|
|
execute: impl FnOnce(String, serde_json::Value, String) -> Fut + Send,
|
|
) -> ScriptResult {
|
|
// The template is identity-plus-lowercasing; skip the Boa round-trip.
|
|
if script == super::ITEM_SCRIPT {
|
|
return (use_lowercase(config), vec![], vec![]);
|
|
}
|
|
|
|
let json = match serde_json::to_value(&config) {
|
|
Ok(mut json) => {
|
|
if let Some(map) = json.as_object_mut() {
|
|
let mut lowered = serde_json::Map::with_capacity(map.len());
|
|
for (key, value) in std::mem::take(map) {
|
|
let mut key = key;
|
|
key.make_ascii_lowercase();
|
|
lowered.insert(key, value);
|
|
}
|
|
*map = lowered;
|
|
}
|
|
json
|
|
}
|
|
Err(err) => return (config, vec![], vec![("exception".into(), err.to_string().into())]),
|
|
};
|
|
|
|
let (outcome, mut logs) = execute(script, json, name).await;
|
|
match outcome {
|
|
Ok(result) => {
|
|
let result = use_lowercase(result);
|
|
// Compared against the config as handed in, not the lowercased copy the script saw.
|
|
let changed_keys = result
|
|
.iter()
|
|
.filter(|(key, value)| config.get(key) != Some(value))
|
|
.filter_map(|(key, _)| {
|
|
let mut key: String = key.as_str()?.into();
|
|
key.make_ascii_lowercase();
|
|
Some(key)
|
|
})
|
|
.collect();
|
|
(result, changed_keys, logs)
|
|
}
|
|
Err(reason) => {
|
|
logs.push(("exception".into(), reason.into()));
|
|
(config, vec![], logs)
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use std::future::ready;
|
|
|
|
use super::{Mapping, use_script};
|
|
|
|
#[tokio::test]
|
|
async fn default_template_skips_the_executor() {
|
|
let mut called = false;
|
|
let mut config = Mapping::new();
|
|
config.insert("MiXeD".into(), true.into());
|
|
let (config, changed_keys, logs) =
|
|
use_script(crate::ITEM_SCRIPT.into(), config, "profile".into(), |_, _, _| {
|
|
called = true;
|
|
ready((Ok(Mapping::new()), vec![]))
|
|
})
|
|
.await;
|
|
|
|
assert!(!called);
|
|
assert_eq!(config["mixed"], serde_yaml_ng::Value::Bool(true));
|
|
assert!(changed_keys.is_empty());
|
|
assert!(logs.is_empty());
|
|
}
|
|
}
|