Skip to content

test(a2a-server): use vi.stubEnv() for env vars per GEMINI.md#27584

Open
Pluviobyte wants to merge 1 commit into
google-gemini:mainfrom
Pluviobyte:19826-a2a-server-stub-env
Open

test(a2a-server): use vi.stubEnv() for env vars per GEMINI.md#27584
Pluviobyte wants to merge 1 commit into
google-gemini:mainfrom
Pluviobyte:19826-a2a-server-stub-env

Conversation

@Pluviobyte
Copy link
Copy Markdown

@Pluviobyte Pluviobyte commented May 30, 2026

Summary

Migrate the remaining direct process.env usage in the a2a-server tests to vi.stubEnv() / vi.unstubAllEnvs(), following the testing convention documented in GEMINI.md. Direct process.env mutation can leak state between tests. config.test.ts already follows the convention, so this completes the migration for the package.

Details

From 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 and is less reliable. To "unset" a variable, use an empty string vi.stubEnv('NAME', '').

Changes:

  • src/commands/init.test.ts: stub CODER_AGENT_WORKSPACE_PATH in beforeEach, and add an afterEach that calls vi.unstubAllEnvs().
  • src/http/app.test.ts: replace the inline set/delete of CODER_AGENT_WORKSPACE_PATH with vi.stubEnv(); use an empty string when testing an unset value, matching GEMINI.md; and add vi.unstubAllEnvs() to the suite afterEach.

No production code changes.

Related Issues

Fixes #19826

How to Validate

From packages/a2a-server:

  • npx vitest run src/commands/init.test.ts src/http/app.test.ts -> 25 tests pass (5 + 20).
  • npx prettier --check src/commands/init.test.ts src/http/app.test.ts -> passes.
  • npx eslint src/commands/init.test.ts src/http/app.test.ts -> no warnings/errors.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed) — N/A
  • Added/updated tests (if needed) — test-only change
  • Noted breaking changes (if any) — none
  • Validated on required platforms/methods:
    • MacOS
      • npm run (vitest, prettier, eslint)

@Pluviobyte Pluviobyte requested a review from a team as a code owner May 30, 2026 17:01
@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 refactors test suites in the a2a-server package to align with established testing conventions. By replacing direct modifications of process.env with Vitest's stubbing utilities, the changes improve test isolation and reliability, ensuring that environment variable changes do not persist across test boundaries.

Highlights

  • Environment Variable Stubbing: Replaced direct process.env mutations with vi.stubEnv() to prevent test state leakage.
  • Test Cleanup: Added vi.unstubAllEnvs() to afterEach hooks to ensure a clean environment after every test execution.
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.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 30, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

This pull request refactors the test files init.test.ts and app.test.ts to use Vitest's environment variable 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, environment variables should be unset using an empty string (e.g., vi.stubEnv('CODER_AGENT_WORKSPACE_PATH', '')) rather than passing 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 during testing, 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. 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 during testing, 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. 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 May 30, 2026
Pluviobyte added a commit to Pluviobyte/gemini-cli that referenced this pull request May 30, 2026
Use an empty string with vi.stubEnv() when testing an unset
CODER_AGENT_WORKSPACE_PATH, matching the repository convention in
GEMINI.md and addressing the review feedback on google-gemini#27584.

Co-authored-by: Cursor <cursoragent@cursor.com>
GEMINI.md asks tests that depend on environment variables to use
vi.stubEnv()/vi.unstubAllEnvs() instead of mutating process.env
directly, which can leak state across tests. config.test.ts already
follows this; this change migrates the remaining direct process.env
usage in the a2a-server tests.

- init.test.ts: stub CODER_AGENT_WORKSPACE_PATH in beforeEach and add an
afterEach that calls vi.unstubAllEnvs().
- app.test.ts: replace the inline set/delete of CODER_AGENT_WORKSPACE_PATH
with vi.stubEnv(); use an empty string when testing an unset value,
matching the convention documented in GEMINI.md.

No production code changes.

Fixes google-gemini#19826
@Pluviobyte Pluviobyte force-pushed the 19826-a2a-server-stub-env branch from 2a77e9d to eb63c8e Compare May 30, 2026 17:19
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.

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