test(api): agents(wikiCompose / research ノード・core tools)の未テストノードにテストを追加する (#1033) - #1042
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (8)
📝 WalkthroughWalkthroughAdds Vitest suites across agents (usageCallback, resolveWebSearchModel, briefDialogue, draftSections, humanReviewBrief, fetchArticles, webSearch) with mocked LLM/external boundaries, and changes draftSections to log errors and persist a generic retry message instead of provider error text. ChangesTest Coverage for Untested Agents Nodes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 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)
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive unit tests for several agent nodes, tools, and utility functions, including usageCallback, resolveWebSearchModel, briefDialogue, draftSections, humanReviewBrief, fetchArticles, and webSearchTool. Additionally, it updates the error handling in draftSections.ts to log errors and return a generic failure message to avoid leaking raw provider error details. The review feedback suggests improving this error handling by appending the generic failure message to any partially streamed content when a draft fails mid-stream, rather than silently preserving the partial content, and updating the corresponding unit test accordingly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| console.error("[draftSections] per-section draft error:", err); | ||
| body = body || "*(Section draft failed. Please retry drafting this section.)*"; |
There was a problem hiding this comment.
If a section draft fails mid-stream, body will contain the partially streamed content. Using body = body || ... means the partial content is preserved as-is, but the user is never notified that the draft failed mid-way and is incomplete.\n\nConsider appending the generic failure message to the partial content so the user is aware of the interruption.\n\nNote: If you apply this change, you will also need to update the corresponding unit test preserves partial streamed content when the stream throws mid-section in draftSections.test.ts to expect the appended fallback message.
console.error("[draftSections] per-section draft error:", err);\n const fallback = "*(Section draft failed. Please retry drafting this section.)*";\n body = body ? `${body}\\n\\n${fallback}` : fallback;| config as never, | ||
| ); | ||
|
|
||
| expect(update.draftedSections?.[0]?.body).toBe("Partial"); |
There was a problem hiding this comment.
If you update the implementation in draftSections.ts to append the generic failure message to partially drafted content, update this assertion to expect the appended fallback message.
| expect(update.draftedSections?.[0]?.body).toBe("Partial"); | |
| expect(update.draftedSections?.[0]?.body).toBe("Partial\\n\\n*(Section draft failed. Please retry drafting this section.)*"); |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@server/api/src/__tests__/agents/core/tools/resolveWebSearchModel.test.ts`:
- Around line 1-4: The file-level header comments in
resolveWebSearchModel.test.ts are English-only; update the file header to
include a Japanese translation alongside the existing English text to satisfy
the repo policy for bilingual comments (for .ts files). Edit the top-of-file
comment block used for the `resolveWebSearchModelId` unit tests and prepend or
append the equivalent Japanese description (matching the English meaning, e.g.,
mention fixed Wiki Compose model → env override → cheapest OpenAI/Google) so
both Japanese and English appear in the header.
In
`@server/api/src/__tests__/agents/graphs/wikiCompose/nodes/briefDialogue.test.ts`:
- Around line 1-5: The file header comment above the briefDialogue unit tests is
English-only; update the top comment in the briefDialogue test (the header block
in
server/api/src/__tests__/agents/graphs/wikiCompose/nodes/briefDialogue.test.ts)
to include a concise Japanese translation alongside the existing English lines
so the header contains bilingual documentation per policy—preserve the existing
English lines and add equivalent Japanese sentences describing the test purpose
and behavior (e.g., mention loading page snapshot, projecting briefQuestions,
and LLM failure degrading to empty questions with briefDegraded=true).
In
`@server/api/src/__tests__/agents/graphs/wikiCompose/nodes/draftSections.test.ts`:
- Around line 1-6: The file-level doc comment at the top of
draftSections.test.ts is English-only and must include Japanese per the
bilingual rule; update that top comment block (the triple-slash block containing
the three bullets about per-section LLM streaming, section failure behavior, and
user-visible body leakage) to add concise Japanese translations of the same
sentences so the file-level documentation contains both English and Japanese.
In
`@server/api/src/__tests__/agents/graphs/wikiCompose/nodes/humanReviewBrief.test.ts`:
- Around line 1-5: Update the file header comment in humanReviewBrief.test.ts to
include Japanese alongside the existing English lines: locate the top block
comment that currently documents the test purpose and add concise Japanese
translations for each English sentence (e.g., describe the unit tests, interrupt
payload shape and resume projection into state.brief, and allowed/disallowed
resume payloads/schema validation) so the header is bilingual and follows the
repository rule.
🪄 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
Run ID: 9b521ada-4f63-444a-8d3f-6aef0a5e9eff
📒 Files selected for processing (8)
server/api/src/__tests__/agents/core/llm/usageCallback.test.tsserver/api/src/__tests__/agents/core/tools/resolveWebSearchModel.test.tsserver/api/src/__tests__/agents/graphs/wikiCompose/nodes/briefDialogue.test.tsserver/api/src/__tests__/agents/graphs/wikiCompose/nodes/draftSections.test.tsserver/api/src/__tests__/agents/graphs/wikiCompose/nodes/humanReviewBrief.test.tsserver/api/src/__tests__/agents/subgraphs/research/nodes/fetchArticles.test.tsserver/api/src/__tests__/agents/subgraphs/research/tools/webSearch.test.tsserver/api/src/agents/graphs/wikiCompose/nodes/draftSections.ts
| /** | ||
| * `resolveWebSearchModelId` unit tests (#1033). | ||
| * Priority: fixed Wiki Compose model → env override → cheapest OpenAI/Google. | ||
| */ |
There was a problem hiding this comment.
Consolidated: all three new test files have English-only header docs.
Root cause is a single policy mismatch: file-level comments were added in English only, while repo rules require bilingual Japanese+English comments/documentation for .ts files.
As per coding guidelines, "**/*.{ts,tsx,js,jsx,md}: Comments and documentation must include both Japanese and English text".
🤖 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 `@server/api/src/__tests__/agents/core/tools/resolveWebSearchModel.test.ts`
around lines 1 - 4, The file-level header comments in
resolveWebSearchModel.test.ts are English-only; update the file header to
include a Japanese translation alongside the existing English text to satisfy
the repo policy for bilingual comments (for .ts files). Edit the top-of-file
comment block used for the `resolveWebSearchModelId` unit tests and prepend or
append the equivalent Japanese description (matching the English meaning, e.g.,
mention fixed Wiki Compose model → env override → cheapest OpenAI/Google) so
both Japanese and English appear in the header.
Source: Coding guidelines
| /** | ||
| * `briefDialogue` unit tests (#1033). | ||
| * - Loads page snapshot once and projects briefQuestions into state. | ||
| * - LLM failure degrades to empty questions with `briefDegraded=true`. | ||
| */ |
There was a problem hiding this comment.
Add Japanese text to the test header comment to satisfy repo documentation policy.
Lines 1-5 are English-only; this violates the bilingual comment/documentation requirement for .ts files.
Suggested patch
/**
- * `briefDialogue` unit tests (`#1033`).
- * - Loads page snapshot once and projects briefQuestions into state.
- * - LLM failure degrades to empty questions with `briefDegraded=true`.
+ * `briefDialogue` unit tests (`#1033`).
+ * `briefDialogue` のユニットテスト (`#1033`)。
+ * - Loads page snapshot once and projects briefQuestions into state.
+ * - pageSnapshot を 1 回だけ読み込み、briefQuestions を state に反映する。
+ * - LLM failure degrades to empty questions with `briefDegraded=true`.
+ * - LLM 失敗時は空の質問へフォールバックし、`briefDegraded=true` を設定する。
*/As per coding guidelines: **/*.{ts,tsx,js,jsx,md} comments and documentation must include both Japanese and English text.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * `briefDialogue` unit tests (#1033). | |
| * - Loads page snapshot once and projects briefQuestions into state. | |
| * - LLM failure degrades to empty questions with `briefDegraded=true`. | |
| */ | |
| /** | |
| * `briefDialogue` unit tests (`#1033`). | |
| * `briefDialogue` のユニットテスト (`#1033`)。 | |
| * - Loads page snapshot once and projects briefQuestions into state. | |
| * - pageSnapshot を 1 回だけ読み込み、briefQuestions を state に反映する。 | |
| * - LLM failure degrades to empty questions with `briefDegraded=true`. | |
| * - LLM 失敗時は空の質問へフォールバックし、`briefDegraded=true` を設定する。 | |
| */ |
🤖 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
`@server/api/src/__tests__/agents/graphs/wikiCompose/nodes/briefDialogue.test.ts`
around lines 1 - 5, The file header comment above the briefDialogue unit tests
is English-only; update the top comment in the briefDialogue test (the header
block in
server/api/src/__tests__/agents/graphs/wikiCompose/nodes/briefDialogue.test.ts)
to include a concise Japanese translation alongside the existing English lines
so the header contains bilingual documentation per policy—preserve the existing
English lines and add equivalent Japanese sentences describing the test purpose
and behavior (e.g., mention loading page snapshot, projecting briefQuestions,
and LLM failure degrading to empty questions with briefDegraded=true).
Source: Coding guidelines
| /** | ||
| * `draftSections` unit tests (#1033, #976). | ||
| * - Per-section LLM streaming with state projection. | ||
| * - One section failure must not abort the whole Draft. | ||
| * - User-visible body must not leak raw provider error messages. | ||
| */ |
There was a problem hiding this comment.
Add Japanese text to the file-level test doc comment.
Lines 1-6 are English-only comments, which violates the bilingual comment/documentation rule for .ts files.
As per coding guidelines, "**/*.{ts,tsx,js,jsx,md}: Comments and documentation must include both Japanese and English text".
🤖 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
`@server/api/src/__tests__/agents/graphs/wikiCompose/nodes/draftSections.test.ts`
around lines 1 - 6, The file-level doc comment at the top of
draftSections.test.ts is English-only and must include Japanese per the
bilingual rule; update that top comment block (the triple-slash block containing
the three bullets about per-section LLM streaming, section failure behavior, and
user-visible body leakage) to add concise Japanese translations of the same
sentences so the file-level documentation contains both English and Japanese.
Source: Coding guidelines
| /** | ||
| * `humanReviewBrief` unit tests (#1033). | ||
| * - Interrupt payload shape and resume projection into `state.brief`. | ||
| * - Allowed and disallowed resume payloads (schema validation). | ||
| */ |
There was a problem hiding this comment.
Make the file header bilingual (Japanese + English) to match repository rules.
Lines 1-5 currently include only English documentation text.
Suggested patch
/**
- * `humanReviewBrief` unit tests (`#1033`).
- * - Interrupt payload shape and resume projection into `state.brief`.
- * - Allowed and disallowed resume payloads (schema validation).
+ * `humanReviewBrief` unit tests (`#1033`).
+ * `humanReviewBrief` のユニットテスト (`#1033`)。
+ * - Interrupt payload shape and resume projection into `state.brief`.
+ * - interrupt ペイロード形状と `state.brief` への resume 反映を検証する。
+ * - Allowed and disallowed resume payloads (schema validation).
+ * - 許可/不許可の resume ペイロードをスキーマ検証する。
*/As per coding guidelines: **/*.{ts,tsx,js,jsx,md} comments and documentation must include both Japanese and English text.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * `humanReviewBrief` unit tests (#1033). | |
| * - Interrupt payload shape and resume projection into `state.brief`. | |
| * - Allowed and disallowed resume payloads (schema validation). | |
| */ | |
| /** | |
| * `humanReviewBrief` unit tests (`#1033`). | |
| * `humanReviewBrief` のユニットテスト (`#1033`)。 | |
| * - Interrupt payload shape and resume projection into `state.brief`. | |
| * - interrupt ペイロード形状と `state.brief` への resume 反映を検証する。 | |
| * - Allowed and disallowed resume payloads (schema validation). | |
| * - 許可/不許可の resume ペイロードをスキーマ検証する。 | |
| */ |
🤖 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
`@server/api/src/__tests__/agents/graphs/wikiCompose/nodes/humanReviewBrief.test.ts`
around lines 1 - 5, Update the file header comment in humanReviewBrief.test.ts
to include Japanese alongside the existing English lines: locate the top block
comment that currently documents the test purpose and add concise Japanese
translations for each English sentence (e.g., describe the unit tests, interrupt
payload shape and resume projection into state.brief, and allowed/disallowed
resume payloads/schema validation) so the header is bilingual and follows the
repository rule.
Source: Coding guidelines
Add unit tests for draftSections, briefDialogue, humanReviewBrief, fetchArticles, resolveWebSearchModel, webSearch, and usageCallback. Each target file reaches 80%+ line coverage. Align draftSections error fallback with #976: generic user-safe message, append note on partial stream failure. Co-authored-by: Akimasa Sugai <otomatty@users.noreply.github.com>
2bf70a5 to
b23be77
Compare
概要
Issue #1033 の受け入れ条件に沿い、
server/apiagents 層の未テストノード 7 ファイルに単体テストを追加しました。LLM / 外部 HTTP はモック境界とし、ノードの state 変換契約を検証しています。あわせて #976 と整合するようdraftSectionsのセクション失敗時メッセージをユーザー向けの汎用文言に変更しました。変更点
server/api/src/__tests__/agents/graphs/wikiCompose/nodes/draftSections.test.ts— セクション単位ストリーミング、部分失敗時の継続、エラー詳細非漏洩graphs/wikiCompose/nodes/briefDialogue.test.ts— 質問生成、pageSnapshot 読み込み、LLM 失敗時briefDegradedgraphs/wikiCompose/nodes/humanReviewBrief.test.ts— interrupt/resume の状態遷移、スキーマ拒否subgraphs/research/nodes/fetchArticles.test.ts— 部分 fetch 成功、in-place 昇格、5 件上限core/tools/resolveWebSearchModel.test.ts— モデル解決優先順位(固定 ID → env override → 最安 OpenAI)subgraphs/research/tools/webSearch.test.ts— LLM 成功/失敗パスを追加(内部ヘルパはモックしない)core/llm/usageCallback.test.ts—toZediMessages、0 トークン usage の具体値検証を追加server/api/src/agents/graphs/wikiCompose/nodes/draftSections.ts— セクション失敗時に rawerr.messageを本文へ埋め込まない(security: Avoid leaking raw err.message in drafted section content (draftSections node) #976)変更の種類
テスト方法
cd server/api && bunx vitest run src/__tests__/agents/graphs/wikiCompose/nodes/ src/__tests__/agents/subgraphs/research/nodes/fetchArticles.test.ts src/__tests__/agents/core/tools/resolveWebSearchModel.test.ts src/__tests__/agents/subgraphs/research/tools/webSearch.test.ts src/__tests__/agents/core/llm/usageCallback.test.ts--coverageと--coverage.includeで対象 7 ファイルを指定(いずれも Lines 80% 以上)cd server/api && bunx vitest run(1604 tests green)チェックリスト
スクリーンショット(UI 変更がある場合)
該当なし(バックエンドテストのみ)
関連 Issue
Closes #1033
Related to #976
Summary by CodeRabbit
Bug Fixes
Tests