## 变更 - 将 `OneDrive.exe` 设为全局 `DIRECT`,优先于供应商 Microsoft 规则 - 为 Clash Verge 全局脚本补充国内可达的阿里 DNS / 腾讯 DNS DoH fallback - 同步更新路由器规则投影与跨平台生成说明 ## 验证 - `python -m unittest discover -s tests -v`:7 项通过 - mihomo DNS API 成功解析 OneDrive 目标 - 实际日志确认 `OneDrive.exe -> skydrive.wns.windows.com:443` 命中 `ProcessName(OneDrive.exe)` 并使用 `DIRECT` Reviewed-on: http://192.168.50.2:3000/ageorge156/vpn-rules/pulls/7
This commit was merged in pull request #7.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
@@ -10,10 +13,60 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
SPEC_PATH = ROOT / "MODULE_SPEC.yaml"
|
||||
sys.path.insert(0, str(ROOT / "scripts"))
|
||||
|
||||
from gen_clash_verge_script import load_payload, to_rule # noqa: E402
|
||||
from gen_clash_verge_script import ( # noqa: E402
|
||||
default_output_path,
|
||||
load_payload,
|
||||
render_script,
|
||||
to_rule,
|
||||
)
|
||||
|
||||
|
||||
class ModuleSpecTests(unittest.TestCase):
|
||||
def test_clash_verge_default_output_path_is_platform_aware(self) -> None:
|
||||
home = Path("C:/Users/example")
|
||||
appdata = Path("C:/Users/example/AppData/Roaming")
|
||||
|
||||
self.assertEqual(
|
||||
default_output_path("win32", home=home, appdata=appdata),
|
||||
appdata
|
||||
/ "io.github.clash-verge-rev.clash-verge-rev"
|
||||
/ "profiles"
|
||||
/ "Script.js",
|
||||
)
|
||||
self.assertEqual(
|
||||
default_output_path("darwin", home=home),
|
||||
home
|
||||
/ "Library/Application Support"
|
||||
/ "io.github.clash-verge-rev.clash-verge-rev"
|
||||
/ "profiles"
|
||||
/ "Script.js",
|
||||
)
|
||||
|
||||
def test_clash_verge_generator_supports_windows_gbk_console(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
output = Path(temp_dir) / "Script.js"
|
||||
env = os.environ.copy()
|
||||
env["PYTHONIOENCODING"] = "gbk"
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(ROOT / "scripts/gen_clash_verge_script.py"),
|
||||
"--out",
|
||||
str(output),
|
||||
],
|
||||
cwd=ROOT,
|
||||
env=env,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result.returncode,
|
||||
0,
|
||||
result.stderr.decode("gbk", errors="replace"),
|
||||
)
|
||||
self.assertTrue(output.is_file())
|
||||
|
||||
def test_module_spec_declares_rule_authority_and_safe_context(self) -> None:
|
||||
spec = json.loads(SPEC_PATH.read_text(encoding="utf-8"))
|
||||
|
||||
@@ -141,6 +194,23 @@ class ModuleSpecTests(unittest.TestCase):
|
||||
)
|
||||
self.assertTrue(all(",DIRECT" not in entry for entry in payload))
|
||||
|
||||
def test_onedrive_process_is_forced_to_use_direct_routing(self) -> None:
|
||||
payload = load_payload(ROOT / "direct.yaml")
|
||||
|
||||
self.assertIn("PROCESS-NAME,OneDrive.exe", payload)
|
||||
self.assertEqual(
|
||||
to_rule("PROCESS-NAME,OneDrive.exe"),
|
||||
"PROCESS-NAME,OneDrive.exe,DIRECT",
|
||||
)
|
||||
|
||||
def test_clash_verge_script_adds_reachable_direct_dns_fallbacks(self) -> None:
|
||||
script = render_script(["PROCESS-NAME,OneDrive.exe"])
|
||||
|
||||
self.assertIn("const directDnsFallbacks", script)
|
||||
self.assertIn("https://dns.alidns.com/dns-query", script)
|
||||
self.assertIn("https://doh.pub/dns-query", script)
|
||||
self.assertIn("config.dns = dns", script)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user