Skip to content

fix: support numeric status code mapping in ResetStatusCode - #2926

Merged
Calcium-Ion merged 4 commits into
QuantumNous:mainfrom
seefs001:fix/status_code_mapping
Feb 12, 2026
Merged

fix: support numeric status code mapping in ResetStatusCode#2926
Calcium-Ion merged 4 commits into
QuantumNous:mainfrom
seefs001:fix/status_code_mapping

Conversation

@seefs001

@seefs001 seefs001 commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Robust status-code mapping accepts string and numeric values with safety checks.
    • Header override logic refined so channel tests skip passthrough rules and ignore client-header placeholders.
  • Tests

    • New unit tests for status-code mapping and header override behavior.
    • Channel tests updated to skip manually disabled channels.
  • UI

    • "Test all channels" updated to target only channels not manually disabled (label and confirmation).
  • Localization

    • Added translations for the updated label and confirmation across locales.
  • Improvements

    • Pagination inputs normalized to ensure valid page/size values.

@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds robust JSON parsing for status-code mappings with tests; adjusts header passthrough/override behavior during channel tests and corresponding tests; excludes manually disabled channels from "test all channels" flows and updates UI text/translations; minor tokens pagination/input normalization and form submit fixes.

Changes

Cohort / File(s) Summary
Status Code Mapping (server)
service/error.go
Add parseStatusCodeMappingValue to convert mapping values (string/number/json.Number) to int; ResetStatusCode now accepts map[string]any and includes nil/validation checks; imports updated.
Status Code Mapping Tests
service/error_test.go
Add parallel subtests for ResetStatusCode: string mapping, numeric mapping, invalid string (no change), and skip-for-200 case.
Header passthrough / overrides (relay)
relay/channel/api_request.go, relay/channel/api_request_test.go
Skip parsing passthrough rules when info.IsChannelTest is true; validate empty regex patterns; avoid applying client_header placeholder in channel-test overrides; add unit tests covering test vs non-test behaviors.
Controller: channel testing
controller/channel-test.go
Skip channels whose status is ChannelStatusManuallyDisabled in testAllChannels loop (early continue).
UI: action text & i18n
web/src/components/table/channels/ChannelsActions.jsx, web/src/i18n/locales/...
Update confirmation message and button label to "test all channels except manually disabled ones" and add translations across en/fr/ja/ru/vi/zh-CN/zh-TW.
Tokens form submit change
web/src/components/table/tokens/TokensFilters.jsx
Change onSubmit to call searchTokens(1) instead of passing the function reference.
Tokens pagination normalization
web/src/hooks/tokens/useTokensData.jsx
Normalize page and size to positive integers; use normalized values in API queries; explicit early return when no keywords.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client as Client
participant Relay as Relay.processHeaderOverride
participant Rules as HeadersOverrideRules
participant Upstream as UpstreamRequest

Client->>Relay: HTTP request with headers + info (IsChannelTest?)
alt Channel test (IsChannelTest = true)
Relay->>Rules: Skip passthrough parsing; filter overrides
Relay-->>Upstream: Apply overrides excluding client_header placeholders
else Normal request (IsChannelTest = false)
Relay->>Rules: Parse passthrough rules, validate regexes
Rules-->>Relay: Compiled passthroughRegexes
Relay->>Upstream: Apply overrides (resolve client_header placeholders)
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024

Poem

🐇
I nibble at mappings, strings and sums,
I skip the muted channels' drums,
Headers tidy for test-time play,
Tokens paginated, bright as day,
Hooray — the rabbit hops away! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly addresses the main code change in service/error.go: adding support for numeric status code mapping alongside string values in ResetStatusCode.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
relay/channel/api_request_test.go (1)

13-81: Good test coverage for the new channel-test bypass logic.

The three scenarios cleanly verify the core behaviors: passthrough rules skipped, client_header placeholders skipped, and non-test resolution preserved.

Consider adding a test where IsChannelTest == true with a static override (e.g., "X-Custom": "fixed-value") to confirm non-placeholder overrides are still applied during channel tests. This would guard against future regressions in the early-continue logic.


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.

This was linked to issues Feb 12, 2026

@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

🤖 Fix all issues with AI agents
In `@web/src/components/table/channels/ChannelsActions.jsx`:
- Around line 102-109: The success toast in useChannelsData.jsx (around the
success handler that runs after testAllChannels) uses wording
"已成功开始测试所有已启用通道..." which conflicts with the button/confirm text "未手动禁用渠道";
update the toast message to the matching semantics by replacing the translation
key/value with wording like "已成功开始测试所有未手动禁用渠道,请刷新页面查看结果。" (or add a new i18n key
and use that) in the success handler that is triggered by testAllChannels() so
the toast matches the confirmation/button text.

Comment on lines +102 to +109
content: t('确定要测试所有未手动禁用渠道吗?'),
onOk: () => testAllChannels(),
size: 'small',
centered: true,
});
}}
>
{t('测试所有通道')}
{t('测试所有未手动禁用渠道')}

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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Locate useChannelsData.jsx and check the success message
find . -name "useChannelsData.jsx" -type f

Repository: QuantumNous/new-api

Length of output: 107


🏁 Script executed:

# Search for the success message mentioned in the review
rg -n '已成功开始测试所有已启用通道' --type=js --type=jsx -C 3

Repository: QuantumNous/new-api

Length of output: 90


🏁 Script executed:

# Also search for the button/confirmation text changes
rg -n '确定要测试所有未手动禁用渠道' --type=js --type=jsx -C 2
rg -n '测试所有未手动禁用渠道' --type=js --type=jsx -C 2

Repository: QuantumNous/new-api

Length of output: 118


🏁 Script executed:

# Check for any related success message keys in locale files
rg -n '已成功开始测试所有' --type=json -C 1

Repository: QuantumNous/new-api

Length of output: 3537


🏁 Script executed:

#!/bin/bash
# Search useChannelsData.jsx for the success message usage
rg -n '已成功开始测试所有已启用通道' ./web/src/hooks/channels/useChannelsData.jsx -C 3

Repository: QuantumNous/new-api

Length of output: 297


🏁 Script executed:

# Search for any new success message key with "未手动禁用"
rg -n '未手动禁用' ./web/src/i18n/locales/ --type=json

Repository: QuantumNous/new-api

Length of output: 1601


🏁 Script executed:

# Check the actual ChannelsActions.jsx file to confirm button changes
cat -n ./web/src/components/table/channels/ChannelsActions.jsx | sed -n '95,115p'

Repository: QuantumNous/new-api

Length of output: 948


Update success message to match button semantics in useChannelsData.jsx:720.

The button and confirmation now say "未手动禁用渠道" (channels except manually disabled), but the success toast still uses t('已成功开始测试所有已启用通道,请刷新页面查看结果。') which says "enabled channels". These have different semantics—"not manually disabled" includes system-disabled channels while "enabled" does not. Update the success message to use consistent terminology with the button/confirmation dialogs.

🤖 Prompt for AI Agents
In `@web/src/components/table/channels/ChannelsActions.jsx` around lines 102 -
109, The success toast in useChannelsData.jsx (around the success handler that
runs after testAllChannels) uses wording "已成功开始测试所有已启用通道..." which conflicts
with the button/confirm text "未手动禁用渠道"; update the toast message to the matching
semantics by replacing the translation key/value with wording like
"已成功开始测试所有未手动禁用渠道,请刷新页面查看结果。" (or add a new i18n key and use that) in the
success handler that is triggered by testAllChannels() so the toast matches the
confirmation/button text.

@seefs001 seefs001 linked an issue Feb 12, 2026 that may be closed by this pull request
@seefs001 seefs001 mentioned this pull request Feb 12, 2026
5 tasks
@Calcium-Ion
Calcium-Ion merged commit f77381c into QuantumNous:main Feb 12, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…ping

fix: support numeric status code mapping in ResetStatusCode
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.

BUG:令牌查询参数错误问题 状态码复写没有效果 状态码覆写未生效

2 participants