Skip to content

test(a2a-server): migrate process.env to vi.stubEnv() per GEMINI.md conventions#28487

Open
kunalrawat425 wants to merge 1 commit into
google-gemini:mainfrom
kunalrawat425:fix/19826-vi-stubenv-a2a-server
Open

test(a2a-server): migrate process.env to vi.stubEnv() per GEMINI.md conventions#28487
kunalrawat425 wants to merge 1 commit into
google-gemini:mainfrom
kunalrawat425:fix/19826-vi-stubenv-a2a-server

Conversation

@kunalrawat425

Copy link
Copy Markdown

Summary

Replaces all direct process.env mutations in packages/a2a-server/ tests with vi.stubEnv() / vi.unstubAllEnvs() as documented in GEMINI.md:

When testing code that depends on environment variables, use vi.stubEnv('NAME', 'value') in beforeEach and vi.unstubAllEnvs() in afterEach. Avoid modifying process.env directly as it can lead to test leakage.

Changes

File What changed
src/commands/init.test.ts process.env['CODER_AGENT_WORKSPACE_PATH'] = …vi.stubEnv(…); add afterEach(() => vi.unstubAllEnvs())
src/http/app.test.ts Three inline delete process.env[…] / process.env[…] = …vi.stubEnv(…, undefined) / vi.stubEnv(…, value); add vi.unstubAllEnvs() to describe-block afterEach

Test plan

  • npx vitest run packages/a2a-server/src/commands/init.test.ts packages/a2a-server/src/http/app.test.ts — all 25 tests pass
  • No functional changes to test logic — only how env vars are set/restored

Fixes #19826

… conventions

Direct process.env mutations can cause test leakage when tests run in
the same process and a test fails before teardown runs. Migrate all
direct assignments and deletes to vi.stubEnv() / vi.unstubAllEnvs()
as documented in GEMINI.md testing conventions.

Files changed:
- src/commands/init.test.ts: beforeEach assignment → vi.stubEnv();
  add afterEach vi.unstubAllEnvs()
- src/http/app.test.ts: three inline delete/assignment mutations in
  /executeCommand tests → vi.stubEnv(); add vi.unstubAllEnvs() to
  the describe-block afterEach

Fixes google-gemini#19826

Signed-off-by: Kunal Rawat <kunalrawat425@gmail.com>
@kunalrawat425
kunalrawat425 requested a review from a team as a code owner July 22, 2026 15:45
@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 standardizes environment variable handling in the a2a-server package tests. By migrating from direct process.env modifications to Vitest's built-in stubbing utilities, the changes improve test reliability and maintainability in accordance with the project's established testing conventions.

Highlights

  • Environment Variable Management: Replaced direct mutations of process.env with Vitest's vi.stubEnv() to ensure environment variable isolation during tests.
  • Test Cleanup: Added vi.unstubAllEnvs() to afterEach hooks to prevent test leakage and ensure a clean state between test cases.
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 the 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 counterproductive. 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.

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.

@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 15
  • Additions: +10
  • Deletions: -5
  • Files changed: 2

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the test files init.test.ts and app.test.ts to use Vitest's environment stubbing utilities (vi.stubEnv and vi.unstubAllEnvs) instead of directly modifying process.env. The review feedback correctly points out that, according to the repository style guide, unsetting an environment variable should be done by passing an empty string '' to vi.stubEnv rather than undefined.

vi.spyOn(commandRegistry, 'get').mockReturnValue(mockCommand);

delete process.env['CODER_AGENT_WORKSPACE_PATH'];
vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', undefined);

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.

high

According to the repository style guide, to "unset" an environment variable, you should use an empty string vi.stubEnv('NAME', '') instead of passing undefined.

Suggested change
vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', undefined);
vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', '');
References
  1. The Repository Style Guide states: 'To "unset" a variable, use an empty string vi.stubEnv('NAME', '').' (link)

vi.spyOn(commandRegistry, 'get').mockReturnValue(mockWorkspaceCommand);

delete process.env['CODER_AGENT_WORKSPACE_PATH'];
vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', undefined);

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.

high

According to the repository style guide, to "unset" an environment variable, you should use an empty string vi.stubEnv('NAME', '') instead of passing undefined.

Suggested change
vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', undefined);
vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', '');
References
  1. The Repository Style Guide states: 'To "unset" a variable, use an empty string vi.stubEnv('NAME', '').' (link)

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(a2a-server): migrate process.env to vi.stubEnv() per GEMINI.md conventions

1 participant