fix(providers): 修复供应商统一测试前端无法展示后端返回结果#1158
Conversation
testProviderUnified was the only test-* api-client helper missing the toActionResult wrapper after the v1 REST refactor (7e2a722). The backend handler unwraps {ok,data} via actionJson, so apiPost returns the raw test-result body. The frontend api-test-button.tsx still expected the ActionResult shape, so response.ok was always undefined, the failure branch fired, and TestResultCard was never rendered regardless of the backend outcome. Wrap with toActionResult to match every other test* function in the same file and restore the expected success/failure UI plus details panel (requestUrl, rawResponse, validationDetails). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough在 Changes返回值标准化
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Code Review
This pull request updates the testProviderUnified function in the API client to wrap the apiPost call with toActionResult, ensuring the function returns a standardized action result. I have no feedback to provide as there were no review comments.
🧪 测试结果
总体结果: ✅ 所有测试通过 |
There was a problem hiding this comment.
Code Review Summary
This PR correctly fixes a silent failure bug in the provider unified test API client. The change aligns testProviderUnified with the established pattern used by all other testProvider* functions in the file.
PR Size: XS
- Lines changed: 1 addition, 1 deletion (net: 0)
- Files changed: 1
Issue Analysis (Pre-PR)
[ERROR-SILENT] Critical Bug Fixed
The testProviderUnified function was missing the toActionResult() wrapper, making it inconsistent with 5 sibling functions:
testProviderProxy(line 146)testProviderAnthropicMessages(line 155)testProviderOpenAIChatCompletions(line 160)testProviderOpenAIResponses(line 165)testProviderGemini(line 169)
Impact: The frontend expected an ActionResult shape {ok, data} but received the raw API response. Since response.ok was always undefined, the UI always displayed "测试失败" (test failed) regardless of the actual backend result. This is a silent failure pattern where the error is not logged or surfaced to the user correctly.
Fix Verification
toActionResultis properly imported from./_compat- The fix follows the exact pattern used by 17+ other API functions in the same file
- Unit tests for the affected path pass (9/9)
- No callers or UI components require changes - purely API-client layer fix
Review Coverage
- Logic and correctness - Bug correctly identified and fixed
- Security (OWASP Top 10) - No security impact (same-origin API call)
- Error handling - Silent failure pattern eliminated
- Type safety -
toActionResultproperly typed withunknowninput - Documentation accuracy - PR description accurately describes the issue
- Test coverage - Existing tests pass, no new tests required (pattern fix)
- Code clarity - Single-line fix consistent with codebase conventions
Recommendation: Approve. This is a safe, minimal fix that resolves a real user-facing bug.
Automated review by Claude AI
There was a problem hiding this comment.
Code Review Summary
No significant issues identified in this PR.
PR Size: XS
- Lines changed: 2
- Files changed: 1
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean
- Type safety - Clean
- Documentation accuracy - Clean
- Test coverage - Adequate
- Code clarity - Good
Automated review by Codex AI
There was a problem hiding this comment.
- Identified open PR
#1158and fetched metadata + full diff (/tmp/pr-review/pr.diff). - Classified PR size as XS (2 lines changed, 1 file) and applied label
size/XS. - Reviewed only the diff hunk in
src/lib/api-client/v1/actions/providers.ts:188across all required perspectives; no issues met the reporting threshold (>= 80), so no inline review comments were posted. - Submitted the required summary review via
gh pr review --comment(comment-only) using the “No Issues” template.
Summary
src/lib/api-client/v1/actions/providers.ts的testProviderUnified是同文件里唯一漏写toActionResult(...)包装的test*函数(应该是 refactor: add v1 REST management OpenAPI #1140 v1 REST 重构时遗漏)。actionJson()把{ok,data}剥离为裸 body,前端api-test-button.tsx仍按 ActionResult 解构 →response.ok永远是undefined→ 直接走失败分支提前return,导致无论后端返回什么,Toast 都显示"测试失败"且TestResultCard永不渲染。testProviderXxx(Anthropic / OpenAI Chat / OpenAI Responses / Gemini / Proxy)一致,加上toActionResult包装。修改一行,前端调用方与结果卡片组件无须改动。
Test plan
bun run typecheck通过bun run lint无新增告警(预存在的 8 个 warnings 在tests/unit/proxy/response-handler-bill-non-success.test.ts,与本次无关)bunx vitest run tests/unit/settings/providers/api-test-button.test.tsx9/9 通过bun run dev后:TestResultCard展示三层校验、requestUrl、详情对话框可看rawResponsemessage,TestResultCard仍渲染并展示httpStatusCode: 403/subStatus: auth_error/requestUrl/ 原始 403 响应文本TestResultCard显示network_error详情testProviderGemini分支)继续工作正常🤖 Generated with Claude Code
Greptile Summary
This PR fixes a one-line omission in
src/lib/api-client/v1/actions/providers.tswheretestProviderUnifiedwas the onlytestProvider*function not wrapped withtoActionResult. Without the wrapper the frontend received a raw fetch body instead of anActionResultshape, causingresponse.okto always beundefinedand every unified-test invocation to silently show "test failed" regardless of the actual backend result.testProviderUnifiednow wrapsapiPost(...)withtoActionResult(...), matching the pattern used bytestProviderProxy,testProviderAnthropicMessages,testProviderOpenAIChatCompletions,testProviderOpenAIResponses, andtestProviderGemini.Confidence Score: 5/5
Safe to merge — the change is a single-line addition of an already-imported wrapper that every other test function in the file already uses.
The fix is minimal, targeted, and directly verifiable by inspection: adding
toActionResult(...)around theapiPostcall intestProviderUnifiedmatches the exact pattern used by the five sibling functions above it. No callers change, no new logic is introduced, and the existing unit tests (9/9 passing) cover the affected path.No files require special attention.
Important Files Changed
toActionResultwrapper totestProviderUnified, making it consistent with all othertestProvider*functions in the file and fixing the silent failure on the unified test path.Sequence Diagram
sequenceDiagram participant UI as api-test-button.tsx participant Client as providers.ts (testProviderUnified) participant Compat as toActionResult (_compat.ts) participant API as /api/v1/providers/test:unified participant Handler as actionJson() backend handler UI->>Client: testProviderUnified(data) Client->>API: apiPost(...) API->>Handler: HTTP POST Handler-->>API: raw body (ok+data stripped) API-->>Compat: Promise raw body Compat-->>Client: ActionResult { ok, data } Client-->>UI: ActionResult UI->>UI: response.ok branch to success/failure toast + TestResultCardReviews (1): Last reviewed commit: "fix(providers): wrap unified test api-cl..." | Re-trigger Greptile