Repository navigation
fix(playground): resolve auto group model listing - #6163
Conversation
- merge and deduplicate available models in configured auto group order. - reuse special usable group rules and add model filtering regression coverage.
Walkthrough
ChangesAuto-group model expansion
Estimated code review effort: 3 (Moderate) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant GetUserModels
participant GetGroupsEnabledModels
participant GetGroupEnabledModels
GetUserModels->>GetGroupsEnabledModels: pass expanded auto groups
GetGroupsEnabledModels->>GetGroupEnabledModels: fetch enabled models per group
GetGroupEnabledModels-->>GetGroupsEnabledModels: return model names
GetGroupsEnabledModels-->>GetUserModels: return ordered deduplicated models
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
controller/model_list_test.go (1)
265-267: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
assertfor non-fatal value checks per project test guidelines.Lines 266-267 use
require.ElementsMatchandrequire.Equalfor non-fatal value checks. Per the project's test coding guideline,requireis for setup and fatal assertions, whileassertshould be used for non-fatal value checks so the test reports all failures rather than stopping at the first.require.Lenat line 265 is correctly fatal (subsequent slicing depends on the length), but the two value assertions that follow are non-fatal.As per coding guidelines: "New or substantially rewritten Go backend tests must use
requirefor setup and fatal assertions andassertfor non-fatal value checks."♻️ Proposed fix
models := decodeUserModelsResponse(t, recorder) require.Len(t, models, 3) - require.ElementsMatch(t, []string{"zz-vip-model", "zz-shared-model"}, models[:2]) - require.Equal(t, "zz-default-model", models[2]) + assert.ElementsMatch(t, []string{"zz-vip-model", "zz-shared-model"}, models[:2]) + assert.Equal(t, "zz-default-model", models[2])🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@controller/model_list_test.go` around lines 265 - 267, In the model list test, keep require.Len as the fatal precondition for slicing, but change the subsequent non-fatal value checks from require.ElementsMatch and require.Equal to assert.ElementsMatch and assert.Equal so all mismatches are reported.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@controller/model_list_test.go`:
- Around line 265-267: In the model list test, keep require.Len as the fatal
precondition for slicing, but change the subsequent non-fatal value checks from
require.ElementsMatch and require.Equal to assert.ElementsMatch and assert.Equal
so all mismatches are reported.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4c85e84f-3dce-4a01-a2f9-9bebadde006f
📒 Files selected for processing (2)
controller/model_list_test.gocontroller/user.go
# Conflicts: # controller/model_list_test.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@controller/user.go`:
- Around line 652-655: Update the group == "" branch in the relevant controller
logic to sort groupsToQuery after populating it from the groups map, importing
the sort package as needed. Preserve the existing map iteration and query
behavior while ensuring the API response order is deterministic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d179b1d-586c-4242-8ac5-011f1287eafc
📒 Files selected for processing (4)
controller/model.gocontroller/model_list_test.gocontroller/user.goservice/group.go
🚧 Files skipped from review as they are similar to previous changes (1)
- controller/model_list_test.go
| case group == "": | ||
| for g := range groups { | ||
| groupsToQuery = append(groupsToQuery, g) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Ensure deterministic API response order.
Iterating over the groups map results in a random order, which will cause the API to return models in a non-deterministic order when group == "" is requested. Sort the populated slice to ensure a stable response.
🐛 Proposed fix
case group == "":
for g := range groups {
groupsToQuery = append(groupsToQuery, g)
}
+ sort.Strings(groupsToQuery)
case group == "auto":(Note: Ensure "sort" is imported in this file)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| case group == "": | |
| for g := range groups { | |
| groupsToQuery = append(groupsToQuery, g) | |
| } | |
| case group == "": | |
| for g := range groups { | |
| groupsToQuery = append(groupsToQuery, g) | |
| } | |
| sort.Strings(groupsToQuery) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@controller/user.go` around lines 652 - 655, Update the group == "" branch in
the relevant controller logic to sort groupsToQuery after populating it from the
groups map, importing the sort package as needed. Preserve the existing map
iteration and query behavior while ensuring the API response order is
deterministic.
同步上游 10 个提交(至 1721144),重点整合: - QuantumNous#6329 鉴权重构:dashboard 会话全面改为无状态 token(access/refresh + 版本栅栏 + 会话管理),gin session 全部移除。fork 侧适配: - turnstile 一次性消费改为按 token 键控内存缓存(兼容发码+注册两步流) - TRUSTED_PROXY_CIDRS 作为 TRUSTED_PROXIES 的兼容别名保留 - UserBase/ToBaseUser 保留 ParentId(子号计费),补 AuthVersion/CacheSchema - OAuth 绑定改 flow_token 流,保留 GitHub 账号年龄门禁(消费 flow 后校验) - RecordUserIP 反欺诈埋点移入 setupLoginAtAuthVersion - 子号/代理鉴权门(SubPermission/RejectSubAccount/AgentAuth)原样保留 - profile 嫁接上游 LoginSessionsCard(会话管理 UI),绑定卡接入 popup+postMessage 新绑定机制 - 2FA/OAuth/微信登录后 redirect 目标经 handleLoginSuccess 传递恢复 - web/default → web/ 扁平化 + 删除 classic 主题:fork 全部前端定制 (agent/supplier/detector/sub-account 等 180+ 文件)迁移至新路径, 保留 fork 的 i18n 按需加载、每表分页记忆、主题调校与设计系统 - QuantumNous#6157 渠道代理客户端重构(别名缓存+失效清理),保留 fork 全局代理 与 RELAY_DISABLE_HTTP2;QuantumNous#6074 suno CAS 防重复退款;QuantumNous#6163 playground 自动分组;QuantumNous#6224 无限额度密钥显示已用量;QuantumNous#6032 realtime GA 去 beta 头 - 语言文件三方合并:fork ~6280 键 + 上游新增 55 键鉴权文案 - fork 刻意删除的组件与 workflows 维持删除(上次合并曾误恢复) 验证:go build/test 全绿,前端 tsgo 类型检查与 rsbuild 构建通过。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(playground): resolve auto group model listing - merge and deduplicate available models in configured auto group order. - reuse special usable group rules and add model filtering regression coverage. * refactor: extract GetGroupsEnabledModels to dedupe group model expansion
* fix(playground): resolve auto group model listing - merge and deduplicate available models in configured auto group order. - reuse special usable group rules and add model filtering regression coverage. * refactor: extract GetGroupsEnabledModels to dedupe group model expansion
* fix(playground): resolve auto group model listing - merge and deduplicate available models in configured auto group order. - reuse special usable group rules and add model filtering regression coverage. * refactor: extract GetGroupsEnabledModels to dedupe group model expansion
* fix(playground): resolve auto group model listing - merge and deduplicate available models in configured auto group order. - reuse special usable group rules and add model filtering regression coverage. * refactor: extract GetGroupsEnabledModels to dedupe group model expansion
Important
📝 变更描述 / Description
问题描述
/api/user/models?group=auto时,会直接查询名为auto的实体分组。修复方式
service.GetUserAutoGroup获取应用特殊可用分组规则后的自动分组列表。AutoGroups配置顺序获取各分组模型并去重。测试说明
go test ./controller -count=1🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue。📸 运行证明 / Proof of Work
go test ./controller -count=1结果:
ok github.com/QuantumNous/new-api/controllerSummary by CodeRabbit
groupparameter for “auto” and empty group selection to ensure models are gathered consistently from usable groups.