summaryrefslogtreecommitdiff
path: root/packages/cli/src/utils/userStartupWarnings.test.ts
diff options
context:
space:
mode:
authorYuki Okita <[email protected]>2025-07-21 06:57:09 +0900
committerGitHub <[email protected]>2025-07-20 21:57:09 +0000
commit0996d91f0b4a0befe3553016518fd40898699f0a (patch)
tree5168adba7102a916d703145fcac222732151ccc0 /packages/cli/src/utils/userStartupWarnings.test.ts
parent2a95c8287ed3b6fc38e7dcec5f0a19b9e2d843e7 (diff)
feat(cli): add warnings when gemini-cli is called in the root directory (#4542)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/cli/src/utils/userStartupWarnings.test.ts')
-rw-r--r--packages/cli/src/utils/userStartupWarnings.test.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/packages/cli/src/utils/userStartupWarnings.test.ts b/packages/cli/src/utils/userStartupWarnings.test.ts
index 61053029..7c0e1264 100644
--- a/packages/cli/src/utils/userStartupWarnings.test.ts
+++ b/packages/cli/src/utils/userStartupWarnings.test.ts
@@ -8,6 +8,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { getUserStartupWarnings } from './userStartupWarnings.js';
import * as os from 'os';
import fs from 'fs/promises';
+import path from 'path';
vi.mock('os', () => ({
default: { homedir: vi.fn() },
@@ -71,4 +72,60 @@ describe('getUserStartupWarnings', () => {
// // Tests for node version check would go here
// // This shows how easy it is to add new test sections
// });
+
+ describe('root directory check', () => {
+ it('should return a warning when running in root directory on Unix', async () => {
+ vi.mocked(fs.realpath)
+ .mockResolvedValueOnce('/')
+ .mockResolvedValueOnce(homeDir);
+
+ const warnings = await getUserStartupWarnings('/');
+
+ expect(warnings).toContainEqual(
+ expect.stringContaining('root directory'),
+ );
+ expect(warnings).toContainEqual(
+ expect.stringContaining('folder structure will be used'),
+ );
+ });
+
+ it('should return a warning when running in root directory on Windows', async () => {
+ vi.mocked(fs.realpath)
+ .mockResolvedValueOnce('C:\\')
+ .mockResolvedValueOnce(homeDir);
+
+ vi.spyOn(path, 'dirname').mockImplementation(path.win32.dirname);
+
+ const warnings = await getUserStartupWarnings('C:\\');
+
+ expect(warnings).toContainEqual(
+ expect.stringContaining('root directory'),
+ );
+ expect(warnings).toContainEqual(
+ expect.stringContaining('folder structure will be used'),
+ );
+ });
+
+ it('should not return a warning when running in a non-root directory', async () => {
+ vi.mocked(fs.realpath)
+ .mockResolvedValueOnce('/some/project/path')
+ .mockResolvedValueOnce(homeDir);
+
+ const warnings = await getUserStartupWarnings('/some/project/path');
+ expect(warnings).not.toContainEqual(
+ expect.stringContaining('root directory'),
+ );
+ });
+
+ it('should handle errors when checking root directory', async () => {
+ vi.mocked(fs.realpath)
+ .mockRejectedValueOnce(new Error('FS error'))
+ .mockResolvedValueOnce(homeDir);
+
+ const warnings = await getUserStartupWarnings('/');
+ expect(warnings).toContainEqual(
+ expect.stringContaining('Could not verify'),
+ );
+ });
+ });
});