Skip to content

test(billing): fix websocket rejection refund test after pre-consume dropped output estimation - #7491

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:fix/ws-billing-test-preconsume
Sep 21, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:fix/ws-billing-test-preconsume

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

🔗 关联任务 / Related Issue

测试回归

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

📝 变更描述 / Description

main 上 TestResponsesWebSocketInitialUpstreamRejectionRefundsReservation 现在必挂(expected 2990 / actual 3000)。

9978ee1e2 之后预扣只按输入算,relay/helper/price.go 的 tiered 分支固定传 C: 0,不再用 max_tokens 估输出。这个测试用的表达式是 tier("output", c * 2),预留因此恒为 0,断言"上游拒绝前已预留额度"就落空了。

只改测试:表达式换成 tier("request", fixed(0.002)),断言 2990 → 2000。请求计价在预扣时是确定值,测试原本要保护的契约(上游拒绝前已预留、拒绝后退款回滚)没变。

📸 运行证明 / Proof of Work

在 upstream/main (9a0be8750) 干净 worktree 上验证。

改之前,复现失败:

$ go test ./controller/ -run TestResponsesWebSocketInitialUpstreamRejectionRefundsReservation -count=1
--- FAIL: TestResponsesWebSocketInitialUpstreamRejectionRefundsReservation (0.04s)
    --- FAIL: .../structured_error (0.02s)
        expected: 2990
        actual  : 3000
    --- FAIL: .../bare_error (0.02s)
        expected: 2990
        actual  : 3000
FAIL	github.com/QuantumNous/new-api/controller	0.912s

改之后,单测通过:

$ go test ./controller/ -run TestResponsesWebSocketInitialUpstreamRejectionRefundsReservation -count=1
ok  	github.com/QuantumNous/new-api/controller	0.991s

整包通过:

$ go test ./controller/ -count=1
ok  	github.com/QuantumNous/new-api/controller	25.391s

✅ 提交前检查项 / Checklist

  • 人工确认
  • 非重复提交
  • 新功能关联 Issue: 不适用
  • 事前沟通: 改动仅两行测试
  • 功能范围
  • 非透传
  • 范围聚焦
  • 本地验证
  • 安全合规

Summary by CodeRabbit

  • Bug Fixes
    • Updated billing behavior for rejected WebSocket requests to use request-based pricing.
    • Corrected quota reservation handling when an upstream connection is rejected.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 6a26766d-d936-46c4-aa5f-fe2c88769537

📥 Commits

Reviewing files that changed from the base of the PR and between 9a0be87 and 73b3caa.

📒 Files selected for processing (1)
  • controller/responses_websocket_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The rejected-token refund test now uses request-priced billing. Its pre-upstream quota assertion changes from 2990 to 2000 to match the 1000-quota reservation.

Changes

WebSocket billing test

Layer / File(s) Summary
Request-priced reservation assertion
controller/responses_websocket_test.go
The test uses a fixed request charge because pre-consume no longer estimates completion tokens. The expected reserved quota changes from 2990 to 2000.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: calcium-ion

🚥 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the billing test fix and explains that it updates the websocket rejection refund test after output estimation was removed from pre-consume.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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

A rabbit checks the quota with care
The request price is now laid bare
A thousand hops are held in store
The rejected stream refunds once more
The test now matches the billing door

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

@Calcium-Ion
Calcium-Ion merged commit 9c293e8 into QuantumNous:main Sep 21, 2026
3 checks passed
Javabcd pushed a commit to Javabcd/new-api that referenced this pull request Sep 22, 2026
Steve3184 pushed a commit to Steve3184/new-api that referenced this pull request Sep 25, 2026
TomJKS pushed a commit to TomJKS/new-api that referenced this pull request Sep 28, 2026
meatRoll pushed a commit to meatRoll/new-api that referenced this pull request Oct 12, 2026
xiaolanawaqaq pushed a commit to xiaolanawaqaq/new-apiaaa that referenced this pull request Nov 26, 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.

2 participants