Skip to content

fix: use actual user id for channel tests - #5109

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/channel-test-user-1
May 26, 2026
Merged

fix: use actual user id for channel tests#5109
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/channel-test-user-1

Conversation

@seefs001

@seefs001 seefs001 commented May 26, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

渠道测试硬编码userid=1修正为读取实际数据

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • Bug Fixes

    • Channel testing now correctly resolves and uses the appropriate user ID from request context or defaults to the root user, ensuring accurate channel consumption logging during testing operations.
  • Tests

    • Added unit test to verify proper user ID resolution in channel testing scenarios.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Channel test endpoints now resolve a test user ID from the request context or database, replacing hardcoded user references throughout test execution, logging, and context initialization.

Changes

User-aware channel testing

Layer / File(s) Summary
User ID resolution logic and test
controller/channel-test.go, controller/channel_test_internal_test.go
resolveChannelTestUserID extracts user ID from Gin context or queries the root user from database; unit test verifies context-based resolution.
Core test function user integration
controller/channel-test.go
testChannel now accepts a testUserID parameter and uses it for user cache loading, Gin context setup, group lookup, and consumption logging.
Public endpoint user ID propagation
controller/channel-test.go
TestChannel endpoint resolves testUserID and passes it to testChannel with error handling; testAllChannels resolves once upfront and passes the user ID to each channel test invocation.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 Where user IDs once were frozen in time,
Now context flows through tests so fine,
Each channel test knows who to be—
Root or request, resolved with glee! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: replacing hardcoded user ID 1 with actual user ID in channel tests.
Linked Issues check ✅ Passed The PR addresses Issue #5093 by using actual user IDs instead of hardcoded values, enabling proper testing with non-sequential IDs from MySQL multi-master setups.
Out of Scope Changes check ✅ Passed All changes focus on resolving user ID handling in channel tests; no unrelated modifications detected outside the stated objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@seefs001
seefs001 merged commit 30025ae into QuantumNous:main May 26, 2026
1 of 2 checks passed
52assert added a commit to 52assert/new-api that referenced this pull request May 28, 2026
…codes

* origin/main: (34 commits)
  fix: optimize batch update process
  fix: keep token log filters exact
  fix: keep usage log filters exact unless wildcard is explicit (QuantumNous#5097)
  fix(web): improve channel and usage log UI
  feat(theme): add simple-large preset, xl scale and clean up channel badge dots
  🐛 fix(system-settings): resolve save detection and number input NaN issues
  🎨 fix(logs): tune usage table typography
  fix: use actual user id for channel tests (QuantumNous#5109)
  fix: consolidate Waffo payment settings save flow (QuantumNous#5110)
  🎨 fix(charts): improve dark mode chart readability
  🎨 fix(logs): remove hardcoded font-mono to support global theme font inheritance
  🎨 fix(logs): restore timing background badges and optimize model/token spacing
  feat(subscription): support balance purchases
  🎨 fix(theme): default theme font preset falls back to Sans instead of Serif
  🎨 refactor(badge): restore status-badge sizes and classic color scheme
  fix: prevent duplicate channel action toasts (QuantumNous#5015)
  🎨 feat(web/default): add Anthropic theme preset and configurable serif typography
  ♻️ refactor(channels): rebuild channel editor UX with modular sections and Base UI multi-select
  ♻️ refactor(channels): rebuild channel create/edit drawer with modular sections and improved form UX
  fix: handle paginated API key search response (QuantumNous#5014)
  ...

# Conflicts:
#	controller/misc.go
#	web/default/src/features/auth/sign-in/components/user-auth-form.tsx
#	web/default/src/features/auth/sign-in/index.tsx
#	web/default/src/features/auth/sign-up/components/sign-up-form.tsx
#	web/default/src/hooks/use-sidebar-data.ts
#	web/default/src/routes/__root.tsx
xyfacai pushed a commit to xyfacai/new-api that referenced this pull request May 30, 2026
isboyjc pushed a commit to isboyjc/amux-api that referenced this pull request May 31, 2026
SamuelSxy pushed a commit to SamuelSxy/new-api-rh that referenced this pull request Jun 7, 2026
szxufan pushed a commit to szxufan/new-api that referenced this pull request Jun 9, 2026
fx247562340 pushed a commit to fx247562340/vancine-platform that referenced this pull request Jun 11, 2026
ysicing pushed a commit to ysicing/new-api that referenced this pull request Aug 7, 2026
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
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.

不支持mysql多主集群吗

2 participants