fix: guard against empty YAML and missing proxy name in expander

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 00:05:03 +03:00
parent c597a1add7
commit 5000079cbe
2 changed files with 26 additions and 2 deletions
+24
View File
@@ -149,3 +149,27 @@ def test_build_mihomo_config_no_providers():
result = build_mihomo_config(["proxies: []"], "s")
cfg = yaml.safe_load(result)
assert "proxy-providers" not in cfg
def test_expand_config_skips_proxies_without_name():
result = expand_config(BASE_YAML, {"provider1": [
{"type": "ss", "server": "1.2.3.4", "port": 443}, # no "name"
{"name": "valid-node", "type": "ss", "server": "5.6.7.8", "port": 443},
]})
cfg = yaml.safe_load(result)
names = [p["name"] for p in cfg["proxies"]]
assert "valid-node" in names
assert len(names) == 1
def test_build_mihomo_config_skips_malformed_yaml():
valid_yaml = """
proxy-providers:
p1:
type: http
url: https://example.com/sub
interval: 3600
"""
result = build_mihomo_config([valid_yaml, ":: invalid yaml ::: {{{"], "s")
cfg = yaml.safe_load(result)
assert "p1" in cfg["proxy-providers"]