test(desktop): 补 agentTeamQueries 错误分支直测 - #1432
Conversation
📝 WalkthroughWalkthroughChangesAgent team query tests
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 2
🤖 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 `@app/desktop/src/api/agentTeamQueries.test.tsx`:
- Around line 238-245: Add rejects.toBeInstanceOf(AppError) to the mutation
rejection assertions at app/desktop/src/api/agentTeamQueries.test.tsx lines
238-245 and 260-266, while preserving the existing toMatchObject field checks so
both mutations verify the documented AppError type and properties.
- Around line 110-120: In app/desktop/src/api/agentTeamQueries.test.tsx, remove
literal message assertions from the error expectations at lines 110-120,
126-136, 142-152, 158-168, and 238-245 while retaining structured fields such as
code and status; at lines 209-220, use toThrow() without a literal message. Keep
the tests focused on the structured failure contract.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6b51347b-bc82-4e33-82d9-83d50f608e41
📒 Files selected for processing (1)
app/desktop/src/api/agentTeamQueries.test.tsx
| await expect( | ||
| fetchAgentTeamOverview(true, () => 'stale-token', 'http://test.local'), | ||
| ).rejects.toMatchObject({ | ||
| code: 'unauthorized', | ||
| message: 'bad token', | ||
| status: 401, | ||
| }); | ||
| await expect( | ||
| fetchAgentTeamOverview(true, () => 'stale-token', 'http://test.local'), | ||
| ).rejects.toBeInstanceOf(AppError); | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Avoid hard assertions on error prose. Error messages are presentation text; assert the structured failure contract instead.
app/desktop/src/api/agentTeamQueries.test.tsx#L110-L120: remove themessageassertion.app/desktop/src/api/agentTeamQueries.test.tsx#L126-L136: remove themessageassertion.app/desktop/src/api/agentTeamQueries.test.tsx#L142-L152: remove themessageassertion.app/desktop/src/api/agentTeamQueries.test.tsx#L158-L168: remove themessageassertion.app/desktop/src/api/agentTeamQueries.test.tsx#L209-L220: usetoThrow()without a literal message.app/desktop/src/api/agentTeamQueries.test.tsx#L238-L245: remove themessageassertion.
As per coding guidelines, “禁止无保护力测试:不要复制实现 switch、测试常量字符串、硬断错误文案,或 mock 被测函数本身;mock 应模拟外部系统。”
📍 Affects 1 file
app/desktop/src/api/agentTeamQueries.test.tsx#L110-L120(this comment)app/desktop/src/api/agentTeamQueries.test.tsx#L126-L136app/desktop/src/api/agentTeamQueries.test.tsx#L142-L152app/desktop/src/api/agentTeamQueries.test.tsx#L158-L168app/desktop/src/api/agentTeamQueries.test.tsx#L209-L220app/desktop/src/api/agentTeamQueries.test.tsx#L238-L245
🤖 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 `@app/desktop/src/api/agentTeamQueries.test.tsx` around lines 110 - 120, In
app/desktop/src/api/agentTeamQueries.test.tsx, remove literal message assertions
from the error expectations at lines 110-120, 126-136, 142-152, 158-168, and
238-245 while retaining structured fields such as code and status; at lines
209-220, use toThrow() without a literal message. Keep the tests focused on the
structured failure contract.
Source: Coding guidelines
| await expect( | ||
| act(async () => result.current.mutateAsync({ name: 'Team A' })), | ||
| ).rejects.toMatchObject({ | ||
| code: 'unauthorized', | ||
| message: 'bad token', | ||
| status: 401, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the promised AppError type for mutations. toMatchObject also accepts a plain object with matching fields, so these tests do not prove the documented error contract.
app/desktop/src/api/agentTeamQueries.test.tsx#L238-L245: addrejects.toBeInstanceOf(AppError).app/desktop/src/api/agentTeamQueries.test.tsx#L260-L266: addrejects.toBeInstanceOf(AppError).
📍 Affects 1 file
app/desktop/src/api/agentTeamQueries.test.tsx#L238-L245(this comment)app/desktop/src/api/agentTeamQueries.test.tsx#L260-L266
🤖 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 `@app/desktop/src/api/agentTeamQueries.test.tsx` around lines 238 - 245, Add
rejects.toBeInstanceOf(AppError) to the mutation rejection assertions at
app/desktop/src/api/agentTeamQueries.test.tsx lines 238-245 and 260-266, while
preserving the existing toMatchObject field checks so both mutations verify the
documented AppError type and properties.
Summary
app/desktop/src/api/agentTeamQueries.ts补 vitest 直测,收口 web: hook 层 8 文件零直测 + api 层 ~1150 行无测试且与 desktop 近重复 #1395 在 test(web): 补 hooks 与 query 错误分支直测 #1425 之后的残余。fetchAgentTeamOverview的 401/403/404/500 与无 token / preferHub=false fail-closed(不打 Hub)。覆盖
Hub session is required,不 fetch验证
node ./node_modules/vitest/vitest.mjs run src/api/agentTeamQueries.test.tsx→ 1 file / 10 tests PASSgit diff --checkPASStsc无 agentTeamQueries 相关错误风险
Closes #1395
Summary by CodeRabbit