test(integration): add failing test for stdin context with prompt#6158
test(integration): add failing test for stdin context with prompt#6158allenhutchison merged 10 commits intomainfrom
Conversation
This test demonstrates a bug where content piped to stdin is ignored when the --prompt flag is also used. The CLI should combine the stdin content with the prompt, but it currently only uses the prompt, causing this test to fail.
There was a problem hiding this comment.
Summary of Changes
Hello @allenhutchison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new integration test to highlight and reproduce a bug in the CLI. The bug occurs when content piped via stdin is not correctly processed or is ignored when the --prompt flag is simultaneously used. The added test is expected to fail, thereby demonstrating the current incorrect behavior where the CLI only utilizes the prompt and disregards the stdin input. This test serves as a clear indicator for the required fix to ensure stdin content is properly combined with the prompt.
Highlights
- New Integration Test File: A new integration test file,
integration-tests/stdin-context.test.ts, has been added to the codebase. - Bug Demonstration: The newly added test is specifically designed to expose a bug where content piped to
stdinis ignored when the--promptflag is also used in the CLI. - Test Logic and Verification: The test uses a
TestRigto simulate a CLI execution, providing bothstdincontent and aprompt, and then asserts that the model's output correctly incorporates thestdincontent.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request adds a failing integration test to demonstrate a bug with stdin handling when a prompt is also provided. The test implementation is sound, but I've found a high-severity issue with the assertion logic. The current check is not robust and could lead to the test passing incorrectly, thereby masking the bug it's intended to expose. I've provided a suggestion to make the assertion more reliable using a regular expression.
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
…tory - Update stdin-context test to check that stdin content appears in telemetry - Verify that stdin content appears before prompt in conversation history - Fix test-helper to consistently use test directory for telemetry logs - Add TODO note about stdin not being forwarded correctly in sandbox mode
When stdin is provided without a --prompt argument, the sandbox mode now correctly passes the stdin content as a prompt to the CLI inside the container. Previously, stdin data would be consumed by the parent process but not forwarded to the containerized CLI, causing "No input provided via stdin" errors. The fix adds the stdin data as a --prompt argument when no prompt is provided, ensuring the CLI receives the input through command-line args rather than attempting to read from an already-consumed stdin stream.
The previous implementation was brittle, with the low-level `sandbox.ts` utility directly parsing `process.argv` and handling specific CLI flags like `--prompt`. This created a tight coupling between the sandbox implementation and the command-line interface. This change refactors the logic to address this: - The responsibility for handling stdin and modifying CLI arguments is now centralized in the higher-level `gemini.tsx` entrypoint. - The `start_sandbox` and `entrypoint` functions in `sandbox.ts` have been updated to accept a pre-processed `cliArgs` array, making them more generic and removing their direct dependency on `process.argv`. - The `injectStdinIntoArgs` helper function was moved from `sandbox.ts` to `gemini.tsx` to facilitate this change. This resolves reviewer feedback and makes the sandbox utility more robust and maintainable.
… context with prompt (google-gemini#6158)
This test demonstrates a bug where content piped to stdin is ignored when the --prompt flag is also used.
The CLI should combine the stdin content with the prompt, but it currently only uses the prompt, causing this test to fail.
The fix for this test is in #4406