Skip to content

test: add Object.create context regression test and tool confirmation integration test#22356

Merged
gsquared94 merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/browser-agent-context
Mar 13, 2026
Merged

test: add Object.create context regression test and tool confirmation integration test#22356
gsquared94 merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/browser-agent-context

Conversation

@gsquared94
Copy link
Copy Markdown
Contributor

Summary

Adds test coverage for the Object.create() context pattern used by the agent scheduler, and a tool confirmation integration test for the browser agent test suite.

Details

The agent scheduler creates AgentLoopContext via Object.create(config), which means properties like config and messageBus live on the prototype chain — not as own properties. This is a known footgun: spreading such objects ({ ...context }) silently drops all inherited properties.

This PR adds:

  1. Unit test (policy.test.ts): Verifies updatePolicy works correctly when the context is created via Object.create(), ensuring prototype-inherited properties are accessible.

  2. Integration test (browser-agent.test.ts): Exercises the tool confirmation flow end-to-end using runInteractive with approvalMode: 'default'. The test triggers a write_file call, waits for the confirmation prompt, approves it, and verifies the response. Note: browser_agent itself cannot be tested for confirmation in integration tests because it is experimental and not registered in the test tool registry.

  3. BrowserAgentInvocation fix (subagent-tool-wrapper.ts): Passes the full AgentLoopContext instead of just Config to BrowserAgentInvocation, aligning with the constructor's expected parameter type.

Related Issues

Related to #21766

How to Validate

  1. Run the unit test:

    npm test -w @google/gemini-cli-core -- src/scheduler/policy.test.ts
    

    Verify the new should work when context is created via Object.create (prototype chain) test passes.

  2. Run the integration tests:

    cd integration-tests && GEMINI_API_KEY=dummy-key-for-test npx vitest run browser-agent.test.ts
    

    Verify all 6 tests pass, including should handle tool confirmation for write_file without crashing.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@gsquared94 gsquared94 requested a review from a team as a code owner March 13, 2026 17:30
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 improves the robustness and test coverage of the agent system by addressing how AgentLoopContext is handled when created with Object.create() and by adding a comprehensive integration test for tool confirmation. It ensures that prototype-inherited properties are correctly accessed and that the interactive tool approval process functions as expected, preventing potential issues with context propagation and improving the reliability of agent interactions.

Highlights

  • Object.create() Context Handling: Added a unit test to policy.test.ts to ensure that updatePolicy correctly processes AgentLoopContext objects created using Object.create(), which places properties on the prototype chain.
  • Tool Confirmation Integration Test: Implemented a new integration test in browser-agent.test.ts to validate the end-to-end tool confirmation flow, specifically for write_file actions, including the interactive approval process.
  • BrowserAgentInvocation Context Fix: Corrected subagent-tool-wrapper.ts to pass the complete AgentLoopContext object to BrowserAgentInvocation instead of only the Config object, ensuring proper context propagation.
Changelog
  • integration-tests/browser-agent.confirmation.responses
    • Added a JSON file containing a mock response for a generateContentStream call, including a write_file function call and a confirmation message.
  • integration-tests/browser-agent.test.ts
    • Added a new integration test case titled 'should handle tool confirmation for write_file without crashing'.
    • Configured the test rig to use a fake response path and specific browser agent settings for the confirmation test.
    • Simulated user input to trigger a write_file command, await a confirmation prompt, and approve it.
    • Verified that the system responds with a success message after confirmation.
  • packages/core/src/agents/subagent-tool-wrapper.ts
    • Removed the import for the Config type.
    • Removed the private config getter property.
    • Modified the BrowserAgentInvocation constructor call to pass this.context (which is AgentLoopContext) instead of this.config.
  • packages/core/src/scheduler/policy.test.ts
    • Added a new unit test titled 'should work when context is created via Object.create (prototype chain)'.
    • Created a mock AgentLoopContext using Object.create() to simulate prototype inheritance.
    • Asserted that properties are correctly accessed from the prototype chain.
    • Called updatePolicy with the prototype-based context and verified that messageBus.publish was invoked with the expected arguments.
Activity
  • The pull request was created by gsquared94.
  • No human review comments or approvals have been recorded yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces valuable test coverage for the Object.create() context pattern in policy.test.ts and a tool confirmation integration test in browser-agent.test.ts. The refactor in subagent-tool-wrapper.ts to pass the full AgentLoopContext to BrowserAgentInvocation is a positive change, improving consistency and access to context properties. All changes appear to be well-implemented and align with existing code patterns and testing methodologies. No critical or high-severity issues were identified.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 13, 2026
mattKorwel

This comment was marked as outdated.

@gsquared94 gsquared94 added this pull request to the merge queue Mar 13, 2026
@mattKorwel
Copy link
Copy Markdown
Collaborator

Corrected Static Analysis Summary

Apologies for the mangled text in the previous review. Here is the full summary:

The implementation aligns perfectly with the stated goals, addressing the prototype-inherited property 'footgun' and improving integration test coverage.

Key Findings:

  • Correctness: The update to BrowserAgentInvocation correctly aligns the passed context with the constructor's expected type.
  • Robustness: The new unit test in policy.test.ts provides critical verification for the Object.create() pattern used in the scheduler.
  • Validation: The tool confirmation integration test effectively exercises the runInteractive flow with approvalMode: 'default'.

Observation:
While updatePolicy is now verified for prototype safety, it's worth a future check to ensure other functions consuming AgentLoopContext avoid the spread operator ({ ...context }) to prevent similar inherited property loss.

Merged via the queue into google-gemini:main with commit d368997 Mar 13, 2026
30 checks passed
@gsquared94 gsquared94 deleted the fix/browser-agent-context branch March 13, 2026 18:02
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 21, 2026
SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants