refactor: unify site chain data port access

This commit is contained in:
jxxghp
2026-08-24 04:25:29 +08:00
parent 286b5836a1
commit 836cbfbbb2
6 changed files with 51 additions and 18 deletions
+19
View File
@@ -467,6 +467,25 @@ def test_music_chain_uses_explicit_subscribe_data_port_getter():
assert violations == []
def test_site_chains_use_explicit_site_data_port_getter():
"""站点与种子链不得把 SitePortProxy 伪装成 SiteOper。"""
paths = [APP_ROOT / "chain" / "site.py", APP_ROOT / "chain" / "torrents.py"]
violations: list[str] = []
for path in paths:
tree = ast.parse(path.read_text(encoding="utf-8-sig"), filename=str(path))
for node in ast.walk(tree):
if not isinstance(node, ast.ImportFrom):
continue
if node.module != "app.application.chain.data":
continue
if any(alias.name == "SitePortProxy" for alias in node.names):
violations.append(
f"{path.relative_to(PROJECT_ROOT).as_posix()}:{node.lineno}"
)
assert violations == []
def test_plugin_components_do_not_reexport_legacy_abi_names():
"""新插件组件只提供 canonical 能力,不得复制旧 Helper、Manager 或 Oper 导出。"""
violations: list[str] = []
+4 -1
View File
@@ -209,7 +209,10 @@ class TestSlashCommandInteractions(unittest.TestCase):
)
]
with patch("app.chain.site.SiteOper.list", return_value=fake_sites), patch.object(
with patch(
"app.chain.site.get_chain_site_port",
return_value=SimpleNamespace(list=lambda: fake_sites),
), patch.object(
chain, "post_message"
) as post_message:
chain.remote_list(channel=NotificationChannel.Web, userid="u1", source="web")