Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions packages/cli/src/utils/userStartupWarnings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { getUserStartupWarnings } from './userStartupWarnings.js';
import * as os from 'node:os';
import fs from 'node:fs/promises';
import path from 'node:path';

// Mock os.homedir to control the home directory in tests
vi.mock('os', async (importOriginal) => {
const actualOs = await importOriginal<typeof os>();
return {
...actualOs,
homedir: vi.fn(),
};
});

describe('getUserStartupWarnings', () => {
let testRootDir: string;
let homeDir: string;
let startupOptions: {
workspaceRoot: string;
useRipgrep: boolean;
Expand All @@ -30,9 +20,6 @@ describe('getUserStartupWarnings', () => {

beforeEach(async () => {
testRootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'warnings-test-'));
homeDir = path.join(testRootDir, 'home');
await fs.mkdir(homeDir, { recursive: true });
vi.mocked(os.homedir).mockReturnValue(homeDir);
startupOptions = {
workspaceRoot: testRootDir,
useRipgrep: true,
Expand All @@ -42,31 +29,6 @@ describe('getUserStartupWarnings', () => {

afterEach(async () => {
await fs.rm(testRootDir, { recursive: true, force: true });
vi.clearAllMocks();
});

describe('home directory check', () => {
it('should return a warning when running in home directory', async () => {
const warnings = await getUserStartupWarnings({
...startupOptions,
workspaceRoot: homeDir,
});
expect(warnings).toContainEqual(
expect.stringContaining('home directory'),
);
});

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({
...startupOptions,
workspaceRoot: projectDir,
});
expect(warnings).not.toContainEqual(
expect.stringContaining('home directory'),
);
});
});

describe('root directory check', () => {
Expand Down Expand Up @@ -106,7 +68,7 @@ describe('getUserStartupWarnings', () => {
});
const expectedWarning =
'Could not verify the current directory due to a file system error.';
expect(warnings).toEqual([expectedWarning, expectedWarning]);
expect(warnings).toEqual([expectedWarning]);
});
});
});
21 changes: 0 additions & 21 deletions packages/cli/src/utils/userStartupWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import fs from 'node:fs/promises';
import * as os from 'node:os';
import path from 'node:path';
import { canUseRipgrep } from '@qwen-code/qwen-code-core';

Expand All @@ -21,25 +20,6 @@ type WarningCheck = {
};

// Individual warning checks
const homeDirectoryCheck: WarningCheck = {
id: 'home-directory',
check: async (options: WarningCheckOptions) => {
try {
const [workspaceRealPath, homeRealPath] = await Promise.all([
fs.realpath(options.workspaceRoot),
fs.realpath(os.homedir()),
]);

if (workspaceRealPath === homeRealPath) {
return 'You are running Qwen Code in your home directory. It is recommended to run in a project-specific directory.';
}
return null;
} catch (_err: unknown) {
return 'Could not verify the current directory due to a file system error.';
}
},
};

const rootDirectoryCheck: WarningCheck = {
id: 'root-directory',
check: async (options: WarningCheckOptions) => {
Expand Down Expand Up @@ -81,7 +61,6 @@ const ripgrepAvailabilityCheck: WarningCheck = {

// All warning checks
const WARNING_CHECKS: readonly WarningCheck[] = [
homeDirectoryCheck,
rootDirectoryCheck,
ripgrepAvailabilityCheck,
];
Expand Down
Loading