feat(credentials): 增加 API Key 手动测试 - #495
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
📝 WalkthroughWalkthrough新增组凭据连接测试功能。控制服务会解密凭据、执行探测并返回稳定的结果分类。测试通过且凭据被拉黑时,服务会生成恢复证明。恢复请求会校验证明、目标签名、凭据版本和冷却时间。新增 HTTP 路由、审计处理器、运行时状态恢复接口及完整测试。管理界面新增测试菜单、结果对话框、恢复操作、请求状态管理和中英文日文文案。 Merge Risk: 🟡 Moderate · up to The PR adds manual upstream testing and proof-bound restoration for blacklisted credentials. Restoration can activate a credential before the response is fully produced, so a late failure may report an error even though the credential is already active, leaving retry and operator recovery ambiguous; this should be fixed or explicitly accepted before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation 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 32 functions across 14 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches✨ Simplify code
Warning Some tools did not complete. Review the errors below. 🔧 golangci-lint (2.12.2)Error: can't load config: the Go language version (go1.26) used to build golangci-lint is lower than the targeted Go version (1.27.0) 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/state/weights_test.go (1)
298-300: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win建议补充
RecoverIfMatch在非零 cooldown 下的用例。新测试覆盖了指针非空分支。指针为空分支的关键差异是:条目带非零
CooldownUntil时,RecoverIfMatch仍须成功,且必须保留CooldownUntil。现有RecoverIfMatch用例的条目 cooldown 均为零值,无法区分这一行为。自动校验路径internal/control/validation.go依赖该语义。♻️ 建议新增的测试
func TestKeyRegistryRecoverIfMatchKeepsCooldown(t *testing.T) { registry := NewCredentialRegistry() cooldownUntil := time.Now().UTC().Add(time.Hour) mustReplaceKeyEntries(t, registry, []CredentialEntry{{ ID: 1, GroupID: 10, Status: CredentialStatusActive, Blacklisted: true, FailureCount: 3, CooldownUntil: cooldownUntil, WeightAuto: 17, Version: 1, IdentityGeneration: 1, Fingerprint: "test-fingerprint", EncryptedValue: "cipher-one", }}) ref := CredentialRef{ ID: 1, GroupID: 10, Version: 1, IdentityGeneration: 1, Fingerprint: "test-fingerprint", EncryptedValue: "cipher-one", } if !registry.RecoverIfMatch(ref, DefaultWeight) { t.Fatal("RecoverIfMatch() = false, want true") } got := registryEntry(t, registry, 1) if got.Blacklisted || !got.CooldownUntil.Equal(cooldownUntil) { t.Fatalf("entry after RecoverIfMatch() = %#v, want cooldown preserved", got) } }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 8cb1bba8-0859-4617-bd88-6f3892ae2219
📒 Files selected for processing (17)
internal/control/credential_api_foundation_test.gointernal/control/credential_mutations.gointernal/control/credential_probe.gointernal/control/credential_probe_test.gointernal/control/http_routes.gointernal/control/server.gointernal/control/validation.gointernal/state/registry.gointernal/state/weights_test.goweb/src/api/control/types.tsweb/src/app/resources/credentials.tsweb/src/features/groups/credentials/CredentialTestDialog.vueweb/src/features/groups/credentials/GroupCredentialRecord.vueweb/src/features/groups/credentials/GroupCredentialsTab.vueweb/src/i18n/locales/en-US/group.tsweb/src/i18n/locales/ja-JP/group.tsweb/src/i18n/locales/zh-CN/group.ts
Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.
关联 Issue / Related Issue
无 / None
变更内容 / Change Content
Bug 修复 / Bug fix
新功能 / New feature
其他改动 / Other changes
在 API Key 行操作菜单首项增加“测试连接”,打开弹窗后立即发送一次最小真实上游请求。
抽取并复用自动验活的
OperationProbe执行链路,沿用模型、协议、代理、Header 和超时配置,不重复构造探测请求。手动测试只返回通过、失败或无法判断及模型、协议、耗时、原因、时间,不写入调度、健康统计、黑名单、请求日志或用量。
已拉黑密钥测试通过后提供确认恢复;恢复凭证绑定当次 credential、probe target 与 cooldown 快照,状态变化时返回冲突并要求重新测试。
订阅账号不提供入口,服务端也明确拒绝测试。
自查清单 / Checklist
make check,或在说明中写明无法运行的原因和未验证范围。 / I ranmake check, or documented why it could not run and what remains unverified.验证:
make check兼容性:新增两个管理 API;无数据库迁移,不改变原有自动验活与手动恢复接口。
Summary by CodeRabbit