Skip to content

fix(providers): 修复供应商统一测试前端无法展示后端返回结果#1158

Merged
ding113 merged 1 commit into
devfrom
fix/provider-unified-test-result
May 5, 2026
Merged

fix(providers): 修复供应商统一测试前端无法展示后端返回结果#1158
ding113 merged 1 commit into
devfrom
fix/provider-unified-test-result

Conversation

@ding113

@ding113 ding113 commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • src/lib/api-client/v1/actions/providers.tstestProviderUnified 是同文件里唯一漏写 toActionResult(...) 包装的 test* 函数(应该是 refactor: add v1 REST management OpenAPI #1140 v1 REST 重构时遗漏)。
  • 后端 handler 经 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.tsx 9/9 通过
  • 手动验证 bun run dev 后:
    • 成功路径(可用供应商):Toast 绿色"测试成功" + 模型/延迟,TestResultCard 展示三层校验、requestUrl、详情对话框可看 rawResponse
    • 401/403 路径:Toast 红色"测试失败" + message,TestResultCard 仍渲染并展示 httpStatusCode: 403 / subStatus: auth_error / requestUrl / 原始 403 响应文本
    • 网络超时:TestResultCard 显示 network_error 详情
    • Gemini 路径(走 testProviderGemini 分支)继续工作正常

🤖 Generated with Claude Code

Greptile Summary

This PR fixes a one-line omission in src/lib/api-client/v1/actions/providers.ts where testProviderUnified was the only testProvider* function not wrapped with toActionResult. Without the wrapper the frontend received a raw fetch body instead of an ActionResult shape, causing response.ok to always be undefined and every unified-test invocation to silently show "test failed" regardless of the actual backend result.

  • testProviderUnified now wraps apiPost(...) with toActionResult(...), matching the pattern used by testProviderProxy, testProviderAnthropicMessages, testProviderOpenAIChatCompletions, testProviderOpenAIResponses, and testProviderGemini.
  • No callers or UI components required changes; the fix is purely on the API-client layer.

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 the apiPost call in testProviderUnified matches 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

Filename Overview
src/lib/api-client/v1/actions/providers.ts Added missing toActionResult wrapper to testProviderUnified, making it consistent with all other testProvider* 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 + TestResultCard
Loading

Reviews (1): Last reviewed commit: "fix(providers): wrap unified test api-cl..." | Re-trigger Greptile

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>
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

src/lib/api-client/v1/actions/providers.ts 中,testProviderUnified 函数现在通过 toActionResult 包装 apiPost 调用的返回值,以标准化其输出形状与其他提供商操作助手的一致性。

Changes

返回值标准化

Layer / File(s) Summary
返回值包装
src/lib/api-client/v1/actions/providers.ts
testProviderUnifiedapiPost 调用被 toActionResult 包装,将原始 API 调用结果转换为操作结果对象。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 标题准确总结了主要改动:修复供应商统一测试功能前端无法正确展示后端返回结果的问题,与代码变更(添加 toActionResult 包装)相符。
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 PR描述详细阐述了问题根因、解决方案及测试计划,与代码变更(testProviderUnified添加toActionResult包装)直接相关。

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/provider-unified-test-result

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.

@github-actions github-actions Bot added bug Something isn't working area:provider area:core javascript Pull requests that update javascript code labels May 5, 2026
@github-actions github-actions Bot added the size/XS Extra Small PR (< 50 lines) label May 5, 2026

@gemini-code-assist gemini-code-assist 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.

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.

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@github-actions github-actions 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.

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

  • toActionResult is 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 - toActionResult properly typed with unknown input
  • 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

@ding113
ding113 merged commit a9c1e83 into dev May 5, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap May 5, 2026
@ding113
ding113 deleted the fix/provider-unified-test-result branch May 5, 2026 15:55

@github-actions github-actions 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.

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

@github-actions github-actions 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.

  • Identified open PR #1158 and 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:188 across 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core area:provider bug Something isn't working javascript Pull requests that update javascript code size/XS Extra Small PR (< 50 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant