Skip to content

test(desktop): 补 agentTeamQueries 错误分支直测 - #1432

Merged
DeliciousBuding merged 1 commit into
masterfrom
test/desktop-agentteam-queries
Jul 27, 2026
Merged

test(desktop): 补 agentTeamQueries 错误分支直测#1432
DeliciousBuding merged 1 commit into
masterfrom
test/desktop-agentteam-queries

Conversation

@DeliciousBuding

@DeliciousBuding DeliciousBuding commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

覆盖

目标 状态
no token / preferHub=false empty overview,不 fetch
list 401/403/404/500 AppError 直抛
empty teams happy-path empty overview
mutation no token Hub session is required,不 fetch
create 401 / delete 403 AppError

验证

  • node ./node_modules/vitest/vitest.mjs run src/api/agentTeamQueries.test.tsx → 1 file / 10 tests PASS
  • git diff --check PASS
  • typecheck:仓库既有 shared/react JSX 噪声;本 PR 仅测试文件,tsc 无 agentTeamQueries 相关错误

风险

Closes #1395

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for agent team overview retrieval and mutations.
    • Verified secure behavior when Hub access is unavailable or no session token exists.
    • Added validation for successful empty results and consistent handling of common HTTP errors.

Copilot AI review requested due to automatic review settings July 27, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Agent team query tests

Layer / File(s) Summary
Overview query test coverage
app/desktop/src/api/agentTeamQueries.test.tsx
Adds React Query and fetch-response helpers, then tests fail-closed token behavior, Hub error mapping, and empty overview aggregation.
Mutation error coverage
app/desktop/src/api/agentTeamQueries.test.tsx
Tests missing-session rejection and propagation of create/delete mutation HTTP errors as AppError values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: copilot

🚥 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 clearly matches the change: desktop agentTeamQueries error-branch tests.
Linked Issues check ✅ Passed The PR adds direct coverage for agentTeamQueries fail-closed and HTTP error branches, aligning with the linked test-coverage gap.
Out of Scope Changes check ✅ Passed The diff is limited to a new test file and stays within the requested agentTeamQueries coverage work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 test/desktop-agentteam-queries

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 938c204 and 705148c.

📒 Files selected for processing (1)
  • app/desktop/src/api/agentTeamQueries.test.tsx

Comment on lines +110 to +120
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);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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 the message assertion.
  • app/desktop/src/api/agentTeamQueries.test.tsx#L126-L136: remove the message assertion.
  • app/desktop/src/api/agentTeamQueries.test.tsx#L142-L152: remove the message assertion.
  • app/desktop/src/api/agentTeamQueries.test.tsx#L158-L168: remove the message assertion.
  • app/desktop/src/api/agentTeamQueries.test.tsx#L209-L220: use toThrow() without a literal message.
  • app/desktop/src/api/agentTeamQueries.test.tsx#L238-L245: remove the message assertion.

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-L136
  • app/desktop/src/api/agentTeamQueries.test.tsx#L142-L152
  • app/desktop/src/api/agentTeamQueries.test.tsx#L158-L168
  • app/desktop/src/api/agentTeamQueries.test.tsx#L209-L220
  • app/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

Comment on lines +238 to +245
await expect(
act(async () => result.current.mutateAsync({ name: 'Team A' })),
).rejects.toMatchObject({
code: 'unauthorized',
message: 'bad token',
status: 401,
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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: add rejects.toBeInstanceOf(AppError).
  • app/desktop/src/api/agentTeamQueries.test.tsx#L260-L266: add rejects.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.

@DeliciousBuding
DeliciousBuding merged commit 7160400 into master Jul 27, 2026
20 checks passed
@DeliciousBuding
DeliciousBuding deleted the test/desktop-agentteam-queries branch July 27, 2026 15:26
DeliciousBuding added a commit that referenced this pull request Jul 27, 2026
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.

web: hook 层 8 文件零直测 + api 层 ~1150 行无测试且与 desktop 近重复

2 participants