Skip to content

Add test for streaming text concatenation in gemini_agent - #1279

Merged
isamu merged 1 commit into
mainfrom
gemini-260130
Jan 30, 2026
Merged

isamu merged 1 commit into
mainfrom
gemini-260130

Conversation

@ystknsh

@ystknsh ystknsh commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

概要

PR #1276 で修正されたストリーミング時のテキスト連結機能に対するテストを追加しました。

変更内容

tests/run_gemini.ts にストリーミングの連結テスト test gemini stream concatenation を追加
ストリーミング中に収集したチャンクと、最終結果の res.text が一致することを検証

テスト内容

ストリーミングモードで Gemini API を呼び出し
streamTokenCallback で各チャンクのテキストを収集
収集したチャンクを連結した結果と res.text が一致することを確認

関連

Resolves: なし(テスト追加のみ)
Related: #1276

Collected chunks: [
  'The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. It typically starts with 0 and 1, though sometimes 1 and 1.',
  ' This generates a sequence like 0, 1, 1, 2, 3, 5, 8, 13, and so forth, appearing frequently in nature and mathematics.'
]
Concatenated from chunks: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. It typically starts with 0 and 1, though sometimes 1 and 1. This generates a sequence like 0, 1, 1, 2, 3, 5, 8, 13, and so forth, appearing frequently in nature and mathematics.
Result text: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. It typically starts with 0 and 1, though sometimes 1 and 1. This generates a sequence like 0, 1, 1, 2, 3, 5, 8, 13, and so forth, appearing frequently in nature and mathematics.

Summary by CodeRabbit

Tests

  • Added test coverage for stream data concatenation to verify that streamed chunks are correctly assembled and produce expected output with proper validation of text content integrity.

✏️ Tip: You can customize this high-level summary in your review settings.

@ystknsh
ystknsh requested a review from isamu January 30, 2026 05:30
@coderabbitai

coderabbitai Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new test case named "test gemini stream concatenation" was added to verify that streamed chunks from dataStream are correctly concatenated. The test collects chunk texts via streamTokenCallback, concatenates them, and validates that the concatenated result matches the final response text.

Changes

Cohort / File(s) Summary
Gemini Stream Test
llm_agents/gemini_agent/tests/run_gemini.ts
Added a new test case to verify stream chunk concatenation behavior, collecting chunks via streamTokenCallback and asserting final text matches concatenated chunks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through streaming data,
Chunks concatenated with glee,
Each piece aligned, no more debate-a,
Tests verify what they should be! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding a test for streaming text concatenation in the gemini_agent component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gemini-260130

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.

@isamu
isamu merged commit 7966c58 into main Jan 30, 2026

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@llm_agents/gemini_agent/tests/run_gemini.ts`:
- Around line 173-191: The test dereferences res.text without checking that
geminiAgent returned a value; update the assertion to guard against undefined by
checking the result (res) and res.text before using them (e.g., if (!res ||
typeof res.text !== "string") handle/log/throw a clear error), and then compare
concatenatedFromChunks to res.text; reference the geminiAgent call, the res
variable, res.text, concatenatedFromChunks and collectedChunks when making this
defensive check so failures report a clear message instead of throwing on
undefined.

Comment on lines +173 to +191
const res = (await geminiAgent({
...defaultTestContext,
namedInputs,
params,
filterParams: {
streamTokenCallback: (data: any) => {
const text = data?.response?.output?.[0]?.text;
if (text) {
collectedChunks.push(text);
}
},
},
})) as any;

const concatenatedFromChunks = collectedChunks.join("");

console.log("Collected chunks:", collectedChunks);
console.log("Concatenated from chunks:", concatenatedFromChunks);
console.log("Result text:", res.text);

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.

⚠️ Potential issue | 🟡 Minor

Guard against undefined response before dereferencing res.text.

res.text is accessed unconditionally; if geminiAgent returns undefined on error, this will throw before the assertion explains why. Add a quick guard so failures are clearer.

Suggested fix
-  const res = (await geminiAgent({
+  const res = (await geminiAgent({
     ...defaultTestContext,
     namedInputs,
     params,
     filterParams: {
       streamTokenCallback: (data: any) => {
         const text = data?.response?.output?.[0]?.text;
         if (text) {
           collectedChunks.push(text);
         }
       },
     },
   })) as any;
 
+  assert.ok(res, "Expected a response from geminiAgent");
   const concatenatedFromChunks = collectedChunks.join("");
📝 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.

Suggested change
const res = (await geminiAgent({
...defaultTestContext,
namedInputs,
params,
filterParams: {
streamTokenCallback: (data: any) => {
const text = data?.response?.output?.[0]?.text;
if (text) {
collectedChunks.push(text);
}
},
},
})) as any;
const concatenatedFromChunks = collectedChunks.join("");
console.log("Collected chunks:", collectedChunks);
console.log("Concatenated from chunks:", concatenatedFromChunks);
console.log("Result text:", res.text);
const res = (await geminiAgent({
...defaultTestContext,
namedInputs,
params,
filterParams: {
streamTokenCallback: (data: any) => {
const text = data?.response?.output?.[0]?.text;
if (text) {
collectedChunks.push(text);
}
},
},
})) as any;
assert.ok(res, "Expected a response from geminiAgent");
const concatenatedFromChunks = collectedChunks.join("");
console.log("Collected chunks:", collectedChunks);
console.log("Concatenated from chunks:", concatenatedFromChunks);
console.log("Result text:", res.text);
🤖 Prompt for AI Agents
In `@llm_agents/gemini_agent/tests/run_gemini.ts` around lines 173 - 191, The test
dereferences res.text without checking that geminiAgent returned a value; update
the assertion to guard against undefined by checking the result (res) and
res.text before using them (e.g., if (!res || typeof res.text !== "string")
handle/log/throw a clear error), and then compare concatenatedFromChunks to
res.text; reference the geminiAgent call, the res variable, res.text,
concatenatedFromChunks and collectedChunks when making this defensive check so
failures report a clear message instead of throwing on undefined.

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.

2 participants