mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-14 23:31:13 -07:00
fix(cli): disable folder trust in test environments
Disable folder trust when running in integration tests (GEMINI_CLI_INTEGRATION_TEST) or unit tests (VITEST) to prevent interactive prompts from blocking automated tests. Also updates config.test.ts to isolate folder trust tests from these environment variables so the underlying logic can still be verified.
This commit is contained in:
@@ -1792,14 +1792,29 @@ describe('loadCliConfig model selection', () => {
|
||||
});
|
||||
|
||||
describe('loadCliConfig folderTrust', () => {
|
||||
let originalVitest: string | undefined;
|
||||
let originalIntegrationTest: string | undefined;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
vi.mocked(os.homedir).mockReturnValue('/mock/home/user');
|
||||
vi.stubEnv('GEMINI_API_KEY', 'test-api-key');
|
||||
vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]);
|
||||
|
||||
originalVitest = process.env['VITEST'];
|
||||
originalIntegrationTest = process.env['GEMINI_CLI_INTEGRATION_TEST'];
|
||||
delete process.env['VITEST'];
|
||||
delete process.env['GEMINI_CLI_INTEGRATION_TEST'];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (originalVitest !== undefined) {
|
||||
process.env['VITEST'] = originalVitest;
|
||||
}
|
||||
if (originalIntegrationTest !== undefined) {
|
||||
process.env['GEMINI_CLI_INTEGRATION_TEST'] = originalIntegrationTest;
|
||||
}
|
||||
|
||||
vi.unstubAllEnvs();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
@@ -437,7 +437,11 @@ export async function loadCliConfig(
|
||||
|
||||
const ideMode = settings.ide?.enabled ?? false;
|
||||
|
||||
const folderTrust = settings.security?.folderTrust?.enabled ?? false;
|
||||
const folderTrust =
|
||||
process.env['GEMINI_CLI_INTEGRATION_TEST'] === 'true' ||
|
||||
process.env['VITEST'] === 'true'
|
||||
? false
|
||||
: (settings.security?.folderTrust?.enabled ?? false);
|
||||
const trustedFolder = isWorkspaceTrusted(settings, cwd)?.isTrusted ?? false;
|
||||
|
||||
// Set the context filename in the server's memoryTool module BEFORE loading memory
|
||||
|
||||
Reference in New Issue
Block a user