mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
用户指出「为什么生产插件会有实例平台?」—— 确实是设计错误。 ## ① 夹具内联进生产源码(根因) `PLATFORMS` 里内联了 4 个测试夹具: example / googleish / loopbackish / cookieish 后果:生产 `/api/plugins/http/channels/platforms` 返回 **16 个平台,其中 4 个是 夹具**,运维在 UI 上真的能选到。夹具属于测试,不属于发行物。 修法: - 生产 `PLATFORMS` 只留 12 个真实厂商。 - 新增 `plugin.state.injected_platforms` + `allPlatforms()`;`platformById` 先查内建再查注入表。 - 新增端点 `channels/inject_platforms`(roles=admin):运行时整表替换注入, 边界校验 —— 不得覆盖内建平台(注入不能劫持真实厂商)、拒绝重复 id、 拒绝无 id、限 32 条;空数组 = 清空。 - 8 处运行时遍历点(list_platforms/provider_status/backup/auto_checkin/ gateway 开关等)改用 `allPlatforms()`;4 处**加载期**遍历(HMAC 钩子绑定、 declaredHosts)保持 `PLATFORMS` —— 它们在 plugin.state 建立之前、注入尚未 发生,改了无意义。 - 测试改为经 `injectTestPlatforms` 注入夹具(channels_plugin_test / channels_stress_test);e2e 本就用真实平台(minimax/cline/opencode/qoder), 无需改动。 ## ② callback 路径的 account_id 漏网 UI 流程 = account/add 建占位账号 → login 带 account_id → 完成时回填。 `oauth_callback`(trae/gemini/lobsterai 的 callback 流)调 complete_login 时 **没传 account_id** —— 与 buddy poll_login 同一缺陷,此前只修了 device-poll / state-poll 两条分支,这条是漏网:凭据落到与占位账号无关的 `channels:<plat>`, 池账号永远 has_credential=false。 ## 判据 - TestInjectPlatformsRejectsBadInput:注入生效 + 三条拒绝规则 + 空数组清空 - TestTraeCallbackPoolPath:callback 池路径凭据落 `channels:trae:<aid>` 且 account_list 报 has_credential=true - 变异:callback 去掉 account_id → TestTraeCallbackPoolPath 立即 FAIL(已实测) go test ./internal/core/ 全绿(119s)。