fix(运行时): 将插件路径匹配移到宿主

新增宿主侧精确路径匹配和插件级 match.paths 配置。\n按请求路径固定插件会话链,移除 Lua 插件内的路径判断与 bypass 状态,并迁移现有插件配置和测试。
This commit is contained in:
starrrLight committed 2026-10-15 15:49:05 +08:00
1 parent f905aa22cc
commit d1f5f69454
12 files changed
+126 -200

No files matched your search

+20 -1
View File
@@ -3,7 +3,7 @@ from pathlib import Path
import pytest
from pydantic import ValidationError
from middleware.config import NetworkRule, Settings, load_settings
from middleware.config import NetworkRule, PluginConfig, PluginMatch, Settings, load_settings
def test_configuration_and_paths(tmp_path, monkeypatch):
@@ -73,6 +73,25 @@ def test_duplicate_ids_and_missing_file(tmp_path):
)
def test_plugin_match_paths_are_exact_and_legacy_paths_are_rejected(tmp_path):
plugin = tmp_path / "plugin.lua"
plugin.write_text("return {}", encoding="utf-8")
match = PluginMatch(paths=["/chat/stream"])
assert match.matches("/chat/stream")
assert not match.matches("/chat/stream/")
assert not match.matches("/chat/stream?token=x")
with pytest.raises(ValidationError):
PluginMatch(paths=[])
for invalid in ["chat/stream", "/chat/*", "/chat/stream?x=1", "/chat/stream#part"]:
with pytest.raises(ValidationError):
PluginMatch(paths=[invalid])
with pytest.raises(ValidationError, match="config.paths.*match.paths"):
PluginConfig(id="legacy", file=plugin, config={"paths": ["/chat/stream"]})
@pytest.mark.parametrize("domain", ["*", "bad/example.com", "foo..com", "127.0.0.1", "*.com*"])
def test_bad_domains(domain):
with pytest.raises(ValueError):