Skip to content

test(core): add missing tests for prompts/utils.ts#20604

Open
yashodipmore wants to merge 2 commits intogoogle-gemini:mainfrom
yashodipmore:test/add-prompts-utils-tests
Open

test(core): add missing tests for prompts/utils.ts#20604
yashodipmore wants to merge 2 commits intogoogle-gemini:mainfrom
yashodipmore:test/add-prompts-utils-tests

Conversation

@yashodipmore
Copy link

Summary

Adds comprehensive test coverage for all three exported functions in packages/core/src/prompts/utils.tsresolvePathFromEnv(), applySubstitutions(), and isSectionEnabled(). This addresses the missing test gap identified in #19940.

Details

Created packages/core/src/prompts/utils.test.ts with 43 tests covering:

  • resolvePathFromEnv() (19 tests): undefined/empty input, boolean switches (case-insensitive true/false/0/1), absolute paths, relative paths, tilde expansion, whitespace trimming, and home directory resolution failure fallback.
  • applySubstitutions() (12 tests): {{AgentSkills}} replacement, {{SubAgents}} rendering (Gemini3 vs legacy snippets), {{AvailableTools}} list with fallback, tool name variables, empty/plain prompts with no variables, and combined substitutions.
  • isSectionEnabled() (12 tests): unset/empty env vars default to enabled, disabled values (0, false), enabled values (1, true, other strings), case insensitivity, uppercase key conversion with GEMINI_ prefix, and whitespace handling.

All tests follow existing project patterns (Vitest, vi.mock, vi.spyOn, co-located test files).

Related Issues

Fixes #19940

How to Validate

# Run only the new tests
npx vitest run packages/core/src/prompts/utils.test.ts

# Run all prompts directory tests to confirm no regressions
npx vitest run packages/core/src/prompts/

Expected: 43/43 new tests pass, 57/57 total prompts tests pass.

Pre-Merge Checklist

  • Added/updated tests (if needed)
  • Validated on required platforms/methods:
    • Linux
      • npm run

Add comprehensive test coverage for all three exported functions in
packages/core/src/prompts/utils.ts:

- resolvePathFromEnv(): 19 tests covering undefined/empty input,
  boolean switches (case-insensitive), path resolution (absolute,
  relative, tilde expansion), whitespace handling, and home directory
  resolution failure.
- applySubstitutions(): 12 tests covering AgentSkills, SubAgents,
  AvailableTools, tool name variables, empty/no-variable prompts,
  Gemini3 vs legacy snippets, and combined substitutions.
- isSectionEnabled(): 12 tests covering unset/empty env vars,
  disabled values (0, false), enabled values (1, true, other),
  case insensitivity, uppercase key conversion, and whitespace.

Fixes google-gemini#19940
@yashodipmore yashodipmore requested a review from a team as a code owner February 27, 2026 20:23
@gemini-code-assist
Copy link
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 significantly enhances the robustness and reliability of core prompt utility functions by introducing comprehensive unit tests. It addresses a previously identified testing gap, ensuring that critical logic for path resolution, prompt substitutions, and feature enablement behaves as expected across various inputs and environmental configurations.

Highlights

  • Comprehensive Test Coverage: Added extensive unit tests for the resolvePathFromEnv(), applySubstitutions(), and isSectionEnabled() utility functions within packages/core/src/prompts/utils.ts.
  • New Test File: Introduced a new test file, packages/core/src/prompts/utils.test.ts, which includes a total of 43 new tests to cover various scenarios for the utility functions.
  • Detailed Test Scenarios: The new tests cover a wide range of cases, including handling undefined/empty inputs, boolean-like string values, absolute and relative path resolution, tilde expansion, environment variable substitutions for agents and tools, and section enablement logic with case-insensitivity and whitespace handling.
Changelog
  • packages/core/src/prompts/utils.test.ts
    • Added a new test file to provide comprehensive unit test coverage for resolvePathFromEnv, applySubstitutions, and isSectionEnabled functions.
Activity
  • Added/updated tests as required.
  • Validated changes on Linux using npm run.
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
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 adds comprehensive test coverage for prompts/utils.ts, which is a great addition. My review focuses on ensuring the new tests adhere to the project's established testing conventions. I've identified one area for improvement in the isSectionEnabled test suite where direct manipulation of process.env is used instead of the recommended vi.stubEnv API. I've provided a code suggestion to refactor this to align with the repository's style guide, which will improve test reliability.

…tion

Address code review feedback: replace direct process.env manipulation
with vi.stubEnv()/vi.unstubAllEnvs() in isSectionEnabled tests to
follow repository testing conventions and prevent test leakage.
@gemini-cli gemini-cli bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 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(core): add missing tests for prompts/utils.ts

2 participants