Skip to content

feat(channel): 多密钥渠道: 密钥管理追加单个密码测试按钮.定期渠道测试时候,测试所有key,如果成功将自动禁用的key恢复 - #6015

Open
fengye110 wants to merge 3 commits into
QuantumNous:mainfrom
fengye110:feat/multiple_key_check
Open

Conversation

@fengye110

@fengye110 fengye110 commented Jul 8, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

多密钥渠道时候追加两个功能:

  1. 密钥管理追加单个密码测试按钮
  2. 定期渠道测试时候:测试所有key,如果成功,且打开了"成功后重新启用",那将已自动禁用的key恢复

🚀 变更类型 / 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

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


image

Summary by CodeRabbit

  • New Features
    • Added a “test all keys” action for multi-key channels, including per-key results, aggregate summaries, and automatic channel/key status updates.
    • Channel testing now supports scoping to a single key via key_index.
    • Updated multi-key management UI to test individual keys with busy/loading states.
  • Bug Fixes
    • Improved recovery and state transitions when keys are auto-disabled or manually disabled during testing.
  • Documentation
    • Added new audit template and expanded multilingual i18n strings for test results and status/action labels.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a165c61-4871-42c9-99c2-a7e149fe78e1

📥 Commits

Reviewing files that changed from the base of the PR and between 0a35c7c and c3c2ffa.

📒 Files selected for processing (1)
  • controller/channel-test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/channel-test.go

Walkthrough

This PR adds multi-key channel testing across backend execution, routing, audit logging, frontend per-key testing, and localized UI strings. It also threads an optional key index through the existing channel test path and updates automatic multi-key test handling.

Changes

Backend test-all-keys implementation

Layer / File(s) Summary
Multi-key test execution
controller/channel-test.go
Adds multi-key test types, option resolution, key masking/cloning helpers, per-key outcome updates, and concurrent all-keys execution.
Channel test handler and route wiring
controller/channel-test.go, controller/audit.go, router/channel-router.go, router/channel_router_test.go
Adds key-indexed single-key testing, the TestAllKeys handler, multi-key automatic testing, audit logging, and route registration/testing.
Backend unit tests
controller/channel_test_internal_test.go
Covers multi-key recovery, auto-disable, manual-disable preservation, cloning, masking, option resolution, and outcome persistence.

Estimated code review effort: 4 (Complex) | ~60 minutes

Frontend test-all-keys UI and API

Layer / File(s) Summary
API and i18n contracts
web/default/src/features/channels/api.ts, web/default/src/features/channels/types.ts, web/default/src/i18n/static-keys.ts, web/default/src/i18n/locales/{en,fr,ja,ru,vi,zh-TW,zh}.json
Adds optional key_index support and new static/localized strings for test results, statuses, and the test-all-keys flow.
Multi-key dialog and row actions
web/default/src/features/channels/components/dialogs/multi-key-manage-dialog.tsx, web/default/src/features/channels/components/dialogs/multi-key-table-row-actions.tsx
Adds per-row testing state, handleTestKey, busy/testing button handling, and dialog table rendering updates.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: Calcium-Ion, seefs001

Poem

A rabbit tapped each key in line,
and watched the statuses align.
Some skipped, some failed, some hopped back bright,
now all the keys can test just right. 🐇

🚥 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 accurately describes the two main changes: per-key testing in multi-key management and testing all keys during scheduled channel tests with auto-disabled recovery.
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 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.

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/default/src/features/channels/components/dialogs/multi-key-manage-dialog.tsx (1)

169-224: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

performAction has no handler for test-all-keys.

The MultiKeyConfirmAction type includes 'test-all-keys' and getMultiKeyConfirmMessage returns a confirm prompt for it, but performAction has no test-all-keys branch. If this action is ever triggered, response stays undefined and the user sees "Operation failed". If a "Test All Keys" button belongs in this PR, add a case that calls testAllMultiKeys and processes the TestAllKeysResponse:

Proposed handler addition
       } else if (type === 'delete-disabled') {
         response = await deleteDisabledMultiKeys(currentRow.id)
+      } else if (type === 'test-all-keys') {
+        const res = await testAllMultiKeys(currentRow.id)
+        response = { success: res.success, message: res.message }
       }

If the button is planned for a follow-up, disregard.

🤖 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
`@web/default/src/features/channels/components/dialogs/multi-key-manage-dialog.tsx`
around lines 169 - 224, `performAction` is missing a branch for the
`test-all-keys` action, so that confirm flow falls through to a failed response.
Update `performAction` in `multi-key-manage-dialog` to handle
`confirmAction.type === 'test-all-keys'` by calling the matching
`testAllMultiKeys` helper, then treat its `TestAllKeysResponse` the same way as
the other actions for success/error toast handling and refresh behavior. Keep
the change aligned with the existing `enable-all`, `disable-all`, and
`delete-disabled` branches, and make sure the new action is wired through the
same `MultiKeyConfirmAction` flow used by `getMultiKeyConfirmMessage`.
🧹 Nitpick comments (2)
controller/channel-test.go (2)

386-442: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use stable action constants instead of display labels for control flow.

Comparing result.Action against "Auto Enabled", "Auto Disabled", and "Kept Manual Disabled" ties control flow to display labels returned by channelMultiKeyActionLabel. If those labels change, the comparisons break silently with no compiler error. Introduce stable action constants (e.g., actionAutoEnabled, actionAutoDisabled, actionKeptManualDisabled) for comparisons, and map them to labels only for the API response.

♻️ Proposed refactor
+const (
+	actionKept              = "kept"
+	actionAutoEnabled      = "auto_enabled"
+	actionAutoDisabled     = "auto_disabled"
+	actionKeptManualDisabled = "kept_manual_disabled"
+	actionSkipped          = "skipped"
+)
+
 // ... in workers, set result.Action = actionAutoEnabled etc.
 // ... in response, convert to labels via channelMultiKeyActionLabel

 // Then in the aggregation loop:
-	if result.Action == "Auto Enabled" {
+	if result.Action == actionAutoEnabled {
 // ...
-	} else if result.Action == "Auto Disabled" {
+	} else if result.Action == actionAutoDisabled {
 // ...
-	} else if result.Action == "Kept Manual Disabled" {
+	} else if result.Action == actionKeptManualDisabled {
🤖 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/channel-test.go` around lines 386 - 442, The control flow in
channel test result handling is comparing result.Action against display strings,
which should be replaced with stable action constants. Update the logic in the
result-processing loop to use dedicated constants for the Auto Enabled, Auto
Disabled, and Kept Manual Disabled cases, and keep channelMultiKeyActionLabel
only for formatting API-facing labels. This refactor should be applied where
result.Action is checked and where summary/status updates occur, so behavior is
not tied to user-visible wording.

386-468: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Eliminate duplicated status-mutation logic between performTestAllKeys and applySingleKeyTestOutcome.

Lines 386-464 re-implement the same per-key status map updates and channel-level enable/disable logic already in applySingleKeyTestOutcome (lines 197-283). These two implementations can diverge over time. Consider extracting the shared logic into a helper, or having performTestAllKeys call applySingleKeyTestOutcome for each key after the concurrent test phase.

🤖 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/channel-test.go` around lines 386 - 468, The per-key status update
and channel status transition logic in performTestAllKeys is duplicated from
applySingleKeyTestOutcome and should be unified. Extract the shared mutation
flow into a helper or reuse applySingleKeyTestOutcome from performTestAllKeys
after the test results are collected, so status map updates, disabled
reasons/timestamps, and channel-level enable/disable changes stay consistent.
Make sure the shared logic still handles MultiKeyStatusList,
MultiKeyDisabledReason, MultiKeyDisabledTime, and the status_reason/status_time
updates in one place.
🤖 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/channel-test.go`:
- Around line 162-167: The maskChannelKey helper still exposes the full value
for short keys because the prefix and suffix slices overlap for lengths between
9 and 11. Update maskChannelKey to use a safer masking rule with a higher
minimum length threshold or a shorter suffix so no input length can reconstruct
the original key; keep the fallback "***" behavior for short values and adjust
the slicing logic accordingly.
- Around line 1402-1408: The JSON responses in the channel validation branch
still return hardcoded Chinese messages, which breaks API language consistency.
Update the nil-channel and non-multi-key error paths in the channel test handler
to use English response text, matching the audit template and the rest of the
API; use the existing handler logic around the channel check and IsMultiKey
guard to locate the affected responses.
- Around line 1489-1551: The multi-key path in the channel test flow ignores the
same auto-disable gates used by the single-key path. Update the
`performTestAllKeys` call inside the multi-key branch so `autoDisableFailed` is
only enabled when both `allowDisable` and `channel.GetAutoBan()` permit it,
matching the logic used elsewhere in this function; if the per-key behavior is
intentional, document that clearly near `performTestAllKeys` to explain why
those checks are bypassed.

---

Outside diff comments:
In
`@web/default/src/features/channels/components/dialogs/multi-key-manage-dialog.tsx`:
- Around line 169-224: `performAction` is missing a branch for the
`test-all-keys` action, so that confirm flow falls through to a failed response.
Update `performAction` in `multi-key-manage-dialog` to handle
`confirmAction.type === 'test-all-keys'` by calling the matching
`testAllMultiKeys` helper, then treat its `TestAllKeysResponse` the same way as
the other actions for success/error toast handling and refresh behavior. Keep
the change aligned with the existing `enable-all`, `disable-all`, and
`delete-disabled` branches, and make sure the new action is wired through the
same `MultiKeyConfirmAction` flow used by `getMultiKeyConfirmMessage`.

---

Nitpick comments:
In `@controller/channel-test.go`:
- Around line 386-442: The control flow in channel test result handling is
comparing result.Action against display strings, which should be replaced with
stable action constants. Update the logic in the result-processing loop to use
dedicated constants for the Auto Enabled, Auto Disabled, and Kept Manual
Disabled cases, and keep channelMultiKeyActionLabel only for formatting
API-facing labels. This refactor should be applied where result.Action is
checked and where summary/status updates occur, so behavior is not tied to
user-visible wording.
- Around line 386-468: The per-key status update and channel status transition
logic in performTestAllKeys is duplicated from applySingleKeyTestOutcome and
should be unified. Extract the shared mutation flow into a helper or reuse
applySingleKeyTestOutcome from performTestAllKeys after the test results are
collected, so status map updates, disabled reasons/timestamps, and channel-level
enable/disable changes stay consistent. Make sure the shared logic still handles
MultiKeyStatusList, MultiKeyDisabledReason, MultiKeyDisabledTime, and the
status_reason/status_time updates in one place.
🪄 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: 6bbb9667-6e50-443f-8830-e3a2cabebcec

📥 Commits

Reviewing files that changed from the base of the PR and between 8739c05 and 4ecaaa2.

📒 Files selected for processing (19)
  • controller/audit.go
  • controller/channel-test.go
  • controller/channel_test_internal_test.go
  • router/channel-router.go
  • router/channel_router_test.go
  • web/default/src/features/channels/api.ts
  • web/default/src/features/channels/components/dialogs/multi-key-manage-dialog.tsx
  • web/default/src/features/channels/components/dialogs/multi-key-table-row-actions.tsx
  • web/default/src/features/channels/constants.ts
  • web/default/src/features/channels/lib/multi-key-utils.ts
  • web/default/src/features/channels/types.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh-TW.json
  • web/default/src/i18n/locales/zh.json
  • web/default/src/i18n/static-keys.ts

Comment thread controller/channel-test.go
Comment thread controller/channel-test.go
Comment thread controller/channel-test.go
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.

1 participant