test(core): add missing tests for prompts/utils.ts#20604
test(core): add missing tests for prompts/utils.ts#20604yashodipmore wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
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
Summary of ChangesHello, 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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
Summary
Adds comprehensive test coverage for all three exported functions in
packages/core/src/prompts/utils.ts—resolvePathFromEnv(),applySubstitutions(), andisSectionEnabled(). This addresses the missing test gap identified in #19940.Details
Created
packages/core/src/prompts/utils.test.tswith 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 withGEMINI_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
Expected: 43/43 new tests pass, 57/57 total prompts tests pass.
Pre-Merge Checklist