Repository navigation
fix(sharing): reject an onboarding whose plan is not routable - #202
Merged
Merged
Conversation
POST /api/sharings 存的 provider / plan / model 一律原样落库。C2065 已补上 「能计价」((provider, model) 必须在 models 表中),本提交补上另一半:**能路由**。 路由按 plan id 在 config `[[plans]]` 中解析端点 (`gateway::resolve_outbound` / `resolve_endpoint`: `cfg.plans.iter().find(|p| p.id == plan_id)`)。plan 不在其中时该 key **永远不可路由**(调用 503「该模型暂无可用 key」),但它仍以 `status='on'` 落库,并被 `dao::list_models_with_availability`(`k.status = 'on'`,不认识 plan) 计入 `available_keys` ⇒ 市场与共享页展示一个平台**交不出**的可用性。 `plan` 是 `#[serde(default)]`,省略字段即空串,同样不是任何 plan 的 id, 因此一并拒绝。前端上架表单本就必选 plan(提交 `plan: plan.id`),合法客户端不受影响。 守卫放在 INSERT 之前,被拒绝的上架不落库。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/sharings把provider/plan/model一律原样落库。上一个 PR(#201)补上了「能计价」((provider, model)必须在models表中,否则调用会静默 0 计费);本 PR 补上另一半:能路由。路由按 plan id 在 config
[[plans]]中解析端点(gateway::resolve_outbound/resolve_endpoint:cfg.plans.iter().find(|p| p.id == plan_id))。plan不在 config 中时,该 key 永远不可路由——调用返回 503「该模型暂无可用 key」——但它仍以status='on'落库,并被dao::list_models_with_availability(只按k.status = 'on'计数,不认识 plan)计入available_keys。结果:市场页与共享页展示一个平台交不出的可用性。运行期复现(注入测试模块,跑完即还原):只留一条 plan 为
no-such-plan的 key 时,市场仍报available_keys=1,而同一模型的POST /v1/chat/completions返回 503;阳性对照(真实 plan)同样 +1,说明计数器没坏,只是不区分。Related Issue
无(本仓库当前 0 个 open issue;由代码巡查发现,与 #201 同源)
Changes
src/routes/sharing.rs::create在INSERT之前新增守卫:req.plan必须在st.cfg.plans中,否则 400plan 不在平台的套餐目录中,无法路由plan是#[serde(default)],省略字段即空串(同样不是任何 plan 的 id)⇒ 一并拒绝;前端上架表单本就必选 plan(提交plan: plan.id),合法客户端不受影响"plan":"deepseek-paygo"(它们此前省略了plan,即在上架不可路由的 key——正是本 PR 修掉的情形)ui/、未改 config / schemaTests
cargo test全部通过 —— 190 passed(189 → 190)cargo fmt --check通过cargo clippy --all-targets -- -D warnings通过create_rejects_unroutable_plan:① 未知 plan → 400;② 省略 plan → 400;③ 两次拒绝均不落库;④ 阳性对照:config 中的 plan → 200 且落库;⑤ 失配配对断言:直接写入一条历史遗留的「未知 plan 却status='on'」行,断言它仍被计入available_keys而该 plan 不在 config 中(⇒ 路由解析不到)——即本守卫要挡住的情形A/B 牙齿证明:只删掉守卫块,
cargo test sharing::⇒ 恰好 1 红 / 6 绿,且失败输出正是缺陷现象(响应体打印"plan"未知却"status":"on")。Checklist
fix/)fix(sharing): …)