feat(ui): reduce home directory warning noise and add opt-out setting (#16229)

This commit is contained in:
N. Taylor Mullen
2026-01-09 11:56:22 -08:00
committed by GitHub
parent ca48661423
commit 14f0cb4538
6 changed files with 95 additions and 12 deletions

View File

@@ -9,6 +9,10 @@ import { getUserStartupWarnings } from './userStartupWarnings.js';
import * as os from 'node:os';
import fs from 'node:fs/promises';
import path from 'node:path';
import {
isFolderTrustEnabled,
isWorkspaceTrusted,
} from '../config/trustedFolders.js';
// Mock os.homedir to control the home directory in tests
vi.mock('os', async (importOriginal) => {
@@ -28,6 +32,11 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
};
});
vi.mock('../config/trustedFolders.js', () => ({
isFolderTrustEnabled: vi.fn(),
isWorkspaceTrusted: vi.fn(),
}));
describe('getUserStartupWarnings', () => {
let testRootDir: string;
let homeDir: string;
@@ -37,6 +46,11 @@ describe('getUserStartupWarnings', () => {
homeDir = path.join(testRootDir, 'home');
await fs.mkdir(homeDir, { recursive: true });
vi.mocked(os.homedir).mockReturnValue(homeDir);
vi.mocked(isFolderTrustEnabled).mockReturnValue(false);
vi.mocked(isWorkspaceTrusted).mockReturnValue({
isTrusted: false,
source: undefined,
});
});
afterEach(async () => {
@@ -46,16 +60,44 @@ describe('getUserStartupWarnings', () => {
describe('home directory check', () => {
it('should return a warning when running in home directory', async () => {
const warnings = await getUserStartupWarnings(homeDir);
const warnings = await getUserStartupWarnings({}, homeDir);
expect(warnings).toContainEqual(
expect.stringContaining('home directory'),
expect.stringContaining(
'Warning you are running Gemini CLI in your home directory',
),
);
expect(warnings).toContainEqual(
expect.stringContaining('warning can be disabled in /settings'),
);
});
it('should not return a warning when running in a project directory', async () => {
const projectDir = path.join(testRootDir, 'project');
await fs.mkdir(projectDir);
const warnings = await getUserStartupWarnings(projectDir);
const warnings = await getUserStartupWarnings({}, projectDir);
expect(warnings).not.toContainEqual(
expect.stringContaining('home directory'),
);
});
it('should not return a warning when showHomeDirectoryWarning is false', async () => {
const warnings = await getUserStartupWarnings(
{ ui: { showHomeDirectoryWarning: false } },
homeDir,
);
expect(warnings).not.toContainEqual(
expect.stringContaining('home directory'),
);
});
it('should not return a warning when folder trust is enabled and workspace is trusted', async () => {
vi.mocked(isFolderTrustEnabled).mockReturnValue(true);
vi.mocked(isWorkspaceTrusted).mockReturnValue({
isTrusted: true,
source: 'file',
});
const warnings = await getUserStartupWarnings({}, homeDir);
expect(warnings).not.toContainEqual(
expect.stringContaining('home directory'),
);
@@ -65,7 +107,7 @@ describe('getUserStartupWarnings', () => {
describe('root directory check', () => {
it('should return a warning when running in a root directory', async () => {
const rootDir = path.parse(testRootDir).root;
const warnings = await getUserStartupWarnings(rootDir);
const warnings = await getUserStartupWarnings({}, rootDir);
expect(warnings).toContainEqual(
expect.stringContaining('root directory'),
);
@@ -77,7 +119,7 @@ describe('getUserStartupWarnings', () => {
it('should not return a warning when running in a non-root directory', async () => {
const projectDir = path.join(testRootDir, 'project');
await fs.mkdir(projectDir);
const warnings = await getUserStartupWarnings(projectDir);
const warnings = await getUserStartupWarnings({}, projectDir);
expect(warnings).not.toContainEqual(
expect.stringContaining('root directory'),
);
@@ -87,7 +129,7 @@ describe('getUserStartupWarnings', () => {
describe('error handling', () => {
it('should handle errors when checking directory', async () => {
const nonExistentPath = path.join(testRootDir, 'non-existent');
const warnings = await getUserStartupWarnings(nonExistentPath);
const warnings = await getUserStartupWarnings({}, nonExistentPath);
const expectedWarning =
'Could not verify the current directory due to a file system error.';
expect(warnings).toEqual([expectedWarning, expectedWarning]);