feat(cli): support boolean and number casting for env vars in settings.json#26118
feat(cli): support boolean and number casting for env vars in settings.json#26118cocosheng-g merged 11 commits intomainfrom
Conversation
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 improves the CLI's configuration system by introducing robust type casting for environment variables used within Highlights
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. Footnotes
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request moves settings validation to occur after environment variable resolution and introduces preprocessing for numeric and boolean values to handle string-based environment variables. A high-severity security concern was identified in the validation logic, which currently falls back to the original settings on failure instead of failing closed, potentially allowing invalid or insecure configurations to be used.
There was a problem hiding this comment.
Code Review
This pull request introduces type casting for configuration settings during validation, enabling string representations of booleans and numbers—commonly sourced from environment variables—to be correctly parsed. The validation logic has been relocated to execute after environment variable expansion to ensure accurate type checking. Feedback was provided regarding the validateAndRecordErrors function, suggesting a more functional approach to avoid mutating the settingsErrors array from the outer scope.
|
Size Change: +1.04 kB (0%) Total Size: 33.9 MB
ℹ️ View Unchanged
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces type casting for numeric and boolean settings during validation, allowing environment variables to be correctly parsed into their respective types. It also shifts the validation process to occur after environment variable expansion to ensure final values are checked. A critical security concern was identified in the new validation logic: the implementation currently 'fails open' by returning an empty object when validation fails, which could allow security configurations in high-precedence files to be bypassed by falling back to less restrictive defaults.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces automatic type casting for configuration settings and ensures environment variables are resolved before validation. Specifically, the buildPrimitiveSchema function now uses Zod's preprocess to cast string representations of booleans and numbers to their respective types. The settings loading logic was updated to resolve environment variables prior to validation, allowing for more robust configuration handling. Comprehensive tests were added to verify these casting and resolution behaviors. I have no feedback to provide.
|
From SummaryThe PR correctly identifies and addresses the need for type casting when environment variables are used in Critical Issues1. Environment Variable Placeholder Loss on SaveIn const userOriginalSettings = structuredClone(userResult.settings);Since Recommendation: The 2. Inconsistent Casting in Shared Definitions (
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements automatic type casting for configuration settings, allowing environment variables to be correctly validated as numbers or booleans. It introduces Zod preprocessing to handle string-to-primitive conversions and updates the settings loading process to resolve environment variables before validation while preserving original placeholders for persistence. I have no feedback to provide.
Summary
Support boolean and number types when configuring
settings.jsonvia environment variables.Details
Currently, environment variables in
settings.jsonare expanded as strings. This causes validation errors for settings that expect boolean or number types (e.g.,ui.autoThemeSwitchingormodel.maxSessionTurns).This PR:
z.preprocessinsettings-validation.tsto automatically cast strings like"true","false", or numeric strings to their respective types during validation.settings.tsuntil after environment variable expansion has occurred.Related Issues
Fixes #25573
How to Validate
Manual Verification:
~/.gemini/settings.jsonto use placeholders:{ "ui": { "autoThemeSwitching": "${GEMINI_AUTO_THEME:-false}" }, "model": { "maxSessionTurns": "${GEMINI_MAX_TURNS:-7}" } }geminiand check/settings:falseand7.GEMINI_AUTO_THEME=true GEMINI_MAX_TURNS=42 gemini: Should showtrueand42.GEMINI_AUTO_THEME=TRUE geminishould result intrue.GEMINI_MAX_TURNS=not-a-number geminishould show a validation warning and fall back to default.Automated Tests:
Run the configuration tests:
npm test -w @google/gemini-cli -- src/config/settings.test.ts src/config/settings-validation.test.tsPre-Merge Checklist