mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-20 11:00:40 -07:00
feat(ui): improve startup warnings UX with dismissal and show-count limits (#19584)
This commit is contained in:
@@ -13,7 +13,10 @@ import {
|
||||
isFolderTrustEnabled,
|
||||
isWorkspaceTrusted,
|
||||
} from '../config/trustedFolders.js';
|
||||
import { getCompatibilityWarnings } from '@google/gemini-cli-core';
|
||||
import {
|
||||
getCompatibilityWarnings,
|
||||
WarningPriority,
|
||||
} from '@google/gemini-cli-core';
|
||||
|
||||
// Mock os.homedir to control the home directory in tests
|
||||
vi.mock('os', async (importOriginal) => {
|
||||
@@ -31,6 +34,10 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
...actual,
|
||||
homedir: () => os.homedir(),
|
||||
getCompatibilityWarnings: vi.fn().mockReturnValue([]),
|
||||
WarningPriority: {
|
||||
Low: 'low',
|
||||
High: 'high',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -65,12 +72,13 @@ describe('getUserStartupWarnings', () => {
|
||||
it('should return a warning when running in home directory', async () => {
|
||||
const warnings = await getUserStartupWarnings({}, homeDir);
|
||||
expect(warnings).toContainEqual(
|
||||
expect.stringContaining(
|
||||
'Warning you are running Gemini CLI in your home directory',
|
||||
),
|
||||
);
|
||||
expect(warnings).toContainEqual(
|
||||
expect.stringContaining('warning can be disabled in /settings'),
|
||||
expect.objectContaining({
|
||||
id: 'home-directory',
|
||||
message: expect.stringContaining(
|
||||
'Warning you are running Gemini CLI in your home directory',
|
||||
),
|
||||
priority: WarningPriority.Low,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -78,9 +86,7 @@ describe('getUserStartupWarnings', () => {
|
||||
const projectDir = path.join(testRootDir, 'project');
|
||||
await fs.mkdir(projectDir);
|
||||
const warnings = await getUserStartupWarnings({}, projectDir);
|
||||
expect(warnings).not.toContainEqual(
|
||||
expect.stringContaining('home directory'),
|
||||
);
|
||||
expect(warnings.find((w) => w.id === 'home-directory')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not return a warning when showHomeDirectoryWarning is false', async () => {
|
||||
@@ -88,9 +94,7 @@ describe('getUserStartupWarnings', () => {
|
||||
{ ui: { showHomeDirectoryWarning: false } },
|
||||
homeDir,
|
||||
);
|
||||
expect(warnings).not.toContainEqual(
|
||||
expect.stringContaining('home directory'),
|
||||
);
|
||||
expect(warnings.find((w) => w.id === 'home-directory')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not return a warning when folder trust is enabled and workspace is trusted', async () => {
|
||||
@@ -101,9 +105,7 @@ describe('getUserStartupWarnings', () => {
|
||||
});
|
||||
|
||||
const warnings = await getUserStartupWarnings({}, homeDir);
|
||||
expect(warnings).not.toContainEqual(
|
||||
expect.stringContaining('home directory'),
|
||||
);
|
||||
expect(warnings.find((w) => w.id === 'home-directory')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -112,10 +114,11 @@ describe('getUserStartupWarnings', () => {
|
||||
const rootDir = path.parse(testRootDir).root;
|
||||
const warnings = await getUserStartupWarnings({}, rootDir);
|
||||
expect(warnings).toContainEqual(
|
||||
expect.stringContaining('root directory'),
|
||||
);
|
||||
expect(warnings).toContainEqual(
|
||||
expect.stringContaining('folder structure will be used'),
|
||||
expect.objectContaining({
|
||||
id: 'root-directory',
|
||||
message: expect.stringContaining('root directory'),
|
||||
priority: WarningPriority.High,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -123,9 +126,7 @@ describe('getUserStartupWarnings', () => {
|
||||
const projectDir = path.join(testRootDir, 'project');
|
||||
await fs.mkdir(projectDir);
|
||||
const warnings = await getUserStartupWarnings({}, projectDir);
|
||||
expect(warnings).not.toContainEqual(
|
||||
expect.stringContaining('root directory'),
|
||||
);
|
||||
expect(warnings.find((w) => w.id === 'root-directory')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,24 +134,37 @@ describe('getUserStartupWarnings', () => {
|
||||
it('should handle errors when checking directory', async () => {
|
||||
const nonExistentPath = path.join(testRootDir, 'non-existent');
|
||||
const warnings = await getUserStartupWarnings({}, nonExistentPath);
|
||||
const expectedWarning =
|
||||
const expectedMessage =
|
||||
'Could not verify the current directory due to a file system error.';
|
||||
expect(warnings).toEqual([expectedWarning, expectedWarning]);
|
||||
expect(warnings).toEqual([
|
||||
expect.objectContaining({ message: expectedMessage }),
|
||||
expect.objectContaining({ message: expectedMessage }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('compatibility warnings', () => {
|
||||
it('should include compatibility warnings by default', async () => {
|
||||
vi.mocked(getCompatibilityWarnings).mockReturnValue(['Comp warning 1']);
|
||||
const compWarning = {
|
||||
id: 'comp-1',
|
||||
message: 'Comp warning 1',
|
||||
priority: WarningPriority.High,
|
||||
};
|
||||
vi.mocked(getCompatibilityWarnings).mockReturnValue([compWarning]);
|
||||
const projectDir = path.join(testRootDir, 'project');
|
||||
await fs.mkdir(projectDir);
|
||||
|
||||
const warnings = await getUserStartupWarnings({}, projectDir);
|
||||
expect(warnings).toContain('Comp warning 1');
|
||||
expect(warnings).toContainEqual(compWarning);
|
||||
});
|
||||
|
||||
it('should not include compatibility warnings when showCompatibilityWarnings is false', async () => {
|
||||
vi.mocked(getCompatibilityWarnings).mockReturnValue(['Comp warning 1']);
|
||||
const compWarning = {
|
||||
id: 'comp-1',
|
||||
message: 'Comp warning 1',
|
||||
priority: WarningPriority.High,
|
||||
};
|
||||
vi.mocked(getCompatibilityWarnings).mockReturnValue([compWarning]);
|
||||
const projectDir = path.join(testRootDir, 'project');
|
||||
await fs.mkdir(projectDir);
|
||||
|
||||
@@ -158,7 +172,7 @@ describe('getUserStartupWarnings', () => {
|
||||
{ ui: { showCompatibilityWarnings: false } },
|
||||
projectDir,
|
||||
);
|
||||
expect(warnings).not.toContain('Comp warning 1');
|
||||
expect(warnings).not.toContainEqual(compWarning);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user