ci: enforce complexity reduction ratchet

This commit is contained in:
jxxghp
2026-08-21 22:23:37 +08:00
parent 59fa3c0e74
commit dd246fe045
5 changed files with 210 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
{
"api_endpoint": {
"app/api/endpoints/agent.py:web_agent_stream": 346,
"app/api/endpoints/download.py:add": 92,
"app/api/endpoints/mcp.py:mcp_jsonrpc": 83,
"app/api/endpoints/media.py:scrape": 105,
"app/api/endpoints/openai.py:chat_completions": 107,
"app/api/endpoints/openai.py:responses": 105,
"app/api/endpoints/system.py:get_logging": 111,
"app/api/endpoints/system.py:nettest": 87,
"app/api/endpoints/torrent.py:reidentify_cache": 147
},
"application_public": {
"app/application/messaging/site.py:SiteInteractionHandler.handle_text_interaction": 227,
"app/application/messaging/skill.py:SkillInteractionHandler.handle_callback_interaction": 158,
"app/application/messaging/skill.py:SkillInteractionHandler.handle_text_interaction": 296,
"app/application/messaging/subscribe.py:SubscribeInteractionHandler.handle_text_interaction": 205,
"app/application/rss.py:RssHelper.parse": 206,
"app/application/security/cookie.py:CookieHelper.get_site_cookie_ua": 221
},
"chain_public": {
"app/chain/download.py:DownloadChain.batch_download": 572,
"app/chain/download.py:DownloadChain.download_single": 276,
"app/chain/download.py:DownloadChain.get_no_exists_info": 152,
"app/chain/mediaserver.py:MediaServerChain.sync": 292,
"app/chain/site.py:SiteChain.sync_cookies": 180,
"app/chain/subscribe.py:SubscribeChain.add": 183,
"app/chain/subscribe.py:SubscribeChain.async_add": 186,
"app/chain/subscribe.py:SubscribeChain.match": 417,
"app/chain/subscribe.py:SubscribeChain.search": 249,
"app/chain/subscribe.py:SubscribeChain.subscribe_files_info": 199,
"app/chain/torrents.py:TorrentsChain.refresh": 235,
"app/chain/transfer.py:TransferChain.do_transfer": 885,
"app/chain/transfer.py:TransferChain.process": 154
}
}
+41
View File
@@ -0,0 +1,41 @@
"""复杂度只降不增 ratchet 测试。"""
from scripts.architecture.complexity import compare_complexity
def test_complexity_ratchet_allows_removal_and_reduction() -> None:
"""既有超限入口被删除或缩短必须允许合并。"""
baseline = {
"api_endpoint": {"app/api/endpoints/a.py:large": 100},
"application_public": {"app/application/a.py:Service.run": 180},
"chain_public": {},
}
current = {
"api_endpoint": {"app/api/endpoints/a.py:large": 90},
"application_public": {},
"chain_public": {},
}
assert compare_complexity(baseline, current) == []
def test_complexity_ratchet_rejects_growth_and_new_oversize() -> None:
"""既有入口增长和新增超预算入口必须同时给出精确诊断。"""
baseline = {
"api_endpoint": {"app/api/endpoints/a.py:large": 100},
"application_public": {},
"chain_public": {},
}
current = {
"api_endpoint": {
"app/api/endpoints/a.py:large": 101,
"app/api/endpoints/b.py:new_endpoint": 81,
},
"application_public": {},
"chain_public": {},
}
problems = compare_complexity(baseline, current)
assert any("既有超限增长" in problem for problem in problems)
assert any("新增超限" in problem for problem in problems)