Skip to content

fix(playground): resolve auto group model listing - #6163

Merged
Calcium-Ion merged 3 commits into
mainfrom
fix/playground-auto-group-models
Jul 20, 2026
Merged

Calcium-Ion merged 3 commits into
mainfrom
fix/playground-auto-group-models

Conversation

@QuentinHsu

@QuentinHsu QuentinHsu commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

问题描述

  • 游乐场请求 /api/user/models?group=auto 时,会直接查询名为 auto 的实体分组。
  • 接口未按照自动分配顺序展开用户可用分组,可能返回空列表或遗漏实际可用模型。

修复方式

  • 复用 service.GetUserAutoGroup 获取应用特殊可用分组规则后的自动分组列表。
  • 按 AutoGroups 配置顺序获取各分组模型并去重。
  • 保持普通分组的模型查询行为不变。
  • 增加回归测试,覆盖特殊分组增删、自动分组顺序、模型去重和不可用分组过滤。

测试说明

  • go test ./controller -count=1

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过相关测试。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

go test ./controller -count=1

结果:

ok github.com/QuantumNous/new-api/controller

Summary by CodeRabbit

  • New Features
    • Added automatic model group expansion when browsing models with the “auto” option.
    • Model results now expand in the configured order, follow special usable-group rules, and avoid duplicates.
  • Bug Fixes
    • Improved handling of the group parameter for “auto” and empty group selection to ensure models are gathered consistently from usable groups.
  • Tests
    • Added coverage to verify auto-group expansion order and the expected set of returned models.

- merge and deduplicate available models in configured auto group order.
- reuse special usable group rules and add model filtering regression coverage.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

GetUserModels now expands configured auto groups through shared ordered model aggregation. ListModels uses the same helper, and a regression test verifies special group mappings, deduplication, and returned model order.

Changes

Auto-group model expansion

Layer / File(s) Summary
Ordered model aggregation
service/group.go
Adds ordered, deduplicated enabled-model aggregation across groups.
Auto-group expansion
controller/user.go, controller/model.go
Uses the shared aggregation helper for auto groups, usable groups, explicit groups, and owner groups.
Ordered expansion regression test
controller/model_list_test.go
Configures group mappings, seeds abilities, and verifies three returned model IDs in the configured order.

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
Loading

Suggested reviewers: calcium-ion

Poem

A rabbit sorts groups in a row,
Vip first, then default below.
Duplicates hop out of sight,
Three models land just right.
“Clever!” says the moonlit hare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing Playground model listing for auto groups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/playground-auto-group-models

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
controller/model_list_test.go (1)

265-267: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use assert for non-fatal value checks per project test guidelines.

Lines 266-267 use require.ElementsMatch and require.Equal for non-fatal value checks. Per the project's test coding guideline, require is for setup and fatal assertions, while assert should be used for non-fatal value checks so the test reports all failures rather than stopping at the first. require.Len at 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 require for setup and fatal assertions and assert for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c28993 and d8935c1.

📒 Files selected for processing (2)
  • controller/model_list_test.go
  • controller/user.go

@Calcium-Ion
Calcium-Ion merged commit 4aa08f9 into main Jul 20, 2026
1 check was pending

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 792e9b7 and b520be1.

📒 Files selected for processing (4)
  • controller/model.go
  • controller/model_list_test.go
  • controller/user.go
  • service/group.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/model_list_test.go

Comment thread controller/user.go
Comment on lines +652 to 655
case group == "":
for g := range groups {
groupsToQuery = append(groupsToQuery, g)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

@Calcium-Ion
Calcium-Ion deleted the fix/playground-auto-group-models branch July 21, 2026 06:46
JacksonsY added a commit to JacksonsY/new-api that referenced this pull request Jul 22, 2026
同步上游 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>
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
* 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
@coderabbitai coderabbitai Bot mentioned this pull request Aug 1, 2026
9 of 11 tasks
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
* 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
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
* 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
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants