From 80aad98358a0f867c221e69fce491c6b85f26064 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 6 Dec 2026 12:36:55 +0800 Subject: [PATCH] test(config-render): cover the edges mutation testing found untested The moved rules kept these changes undetected: a string provider DNS field being ignored or an empty one counted, a wider or empty gap after short-id disturbing the quoting, an unchanged scalar beside a numeric short-id rejecting the quoted result, and quoting leaking outside the fake-ip-filter block or at a deeper indentation. Each new test fails under its mutant and passes against the unchanged code. --- crates/clash-verge-config-render/src/dns.rs | 9 +++++ crates/clash-verge-config-render/src/yaml.rs | 41 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/crates/clash-verge-config-render/src/dns.rs b/crates/clash-verge-config-render/src/dns.rs index 60cbbaef6..a87dba9c3 100644 --- a/crates/clash-verge-config-render/src/dns.rs +++ b/crates/clash-verge-config-render/src/dns.rs @@ -120,4 +120,13 @@ mod tests { "tun: {enable: true}\ndns: {enable: false, enhanced-mode: fake-ip}" ))); } + + #[test] + fn override_source_accepts_a_string_field_only_when_it_has_content() -> Result<(), serde_json::Error> { + let config = mapping("dns: {proxy-server-nameserver: ' 1.1.1.1 '}"); + assert!(override_source("profile", &config)?.is_some()); + let config = mapping("dns: {nameserver-policy: ' '}"); + assert!(override_source("profile", &config)?.is_none()); + Ok(()) + } } diff --git a/crates/clash-verge-config-render/src/yaml.rs b/crates/clash-verge-config-render/src/yaml.rs index 4d01b37a7..7e79dc83a 100644 --- a/crates/clash-verge-config-render/src/yaml.rs +++ b/crates/clash-verge-config-render/src/yaml.rs @@ -218,4 +218,45 @@ note: | assert_eq!(roundtrip(&out), roundtrip(yaml)); assert!(out.contains("'+.market.xiaomi.com'")); } + + #[test] + fn unchanged_scalars_beside_a_numeric_short_id_keep_the_quoted_result() { + let value = parse_short_id_safe( + "proxies:\n - name: a\n reality-opts:\n short-id: 1234e123\n", + Path::new("profile.yaml"), + ) + .expect("profile should parse"); + let proxy = &value["proxies"].as_sequence().expect("sequence")[0]; + assert_eq!(proxy["name"], Value::String("a".into())); + assert_eq!(proxy["reality-opts"]["short-id"], Value::String("1234e123".into())); + } + + #[test] + fn wider_whitespace_and_empty_short_ids_do_not_disturb_the_quoting() { + let value = parse_short_id_safe( + "tunnels:\n - short-id: 1234e123\n - short-id:\t\n - short-id: 0e5\n", + Path::new("p.yaml"), + ) + .expect("yaml"); + let tunnels = value["tunnels"].as_sequence().expect("sequence"); + assert_eq!(tunnels[0]["short-id"], Value::String("1234e123".into())); + assert_eq!(tunnels[1]["short-id"], Value::Null); + assert_eq!(tunnels[2]["short-id"], Value::String("0e5".into())); + } + + #[test] + fn wildcards_outside_fake_ip_filter_are_left_alone() { + let yaml = "\ndns:\n fake-ip-filter:\n - .example.com\n fake-ip-filter-mode: blacklist\nsniffer:\n skip-domain:\n - +.push.apple.com\n"; + let out = serialize_for_export(&serde_yaml_ng::from_str::(yaml).expect("yaml")).expect("yaml"); + assert_eq!(roundtrip(&out), roundtrip(yaml)); + assert!(out.contains(" - '.example.com'\n"), "{out}"); + assert!(out.contains(" - +.push.apple.com\n"), "{out}"); + } + + #[test] + fn quoting_follows_the_block_indentation() { + let yaml = "\nwrap:\n dns:\n fake-ip-filter:\n - +.market.xiaomi.com\n"; + let out = serialize_for_export(&serde_yaml_ng::from_str::(yaml).expect("yaml")).expect("yaml"); + assert!(out.contains(" - '+.market.xiaomi.com'\n"), "{out}"); + } }