Skip to content

Commit bf5a430

Browse files
committed
test(cli): mock PATH in scanPathExecutables test to prevent timeouts
Isolate the test from the real system PATH by using a small controlled directory. This prevents timeouts on Windows in CI where scanning large PATHs can take too long. TAG=agy CONV=4043d296-611e-448a-a9d9-cd78f122b436
1 parent 6b42c28 commit bf5a430

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

packages/cli/src/ui/hooks/useShellCompletion.test.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { describe, it, expect, afterEach, vi } from 'vitest';
8+
import * as path from 'node:path';
89
import {
910
getTokenAtCursor,
1011
escapeShellPath,
@@ -382,15 +383,28 @@ describe('useShellCompletion utilities', () => {
382383

383384
describe('scanPathExecutables', () => {
384385
it('should return an array of executables', async () => {
385-
const results = await scanPathExecutables();
386-
expect(Array.isArray(results)).toBe(true);
387-
// Very basic sanity check: common commands should be found
388-
if (process.platform !== 'win32') {
389-
expect(results).toContain('ls');
390-
} else {
391-
expect(results).toContain('dir');
392-
expect(results).toContain('cls');
393-
expect(results).toContain('copy');
386+
const isWin = process.platform === 'win32';
387+
const exeName = isWin ? 'my-test-exe.exe' : 'my-test-exe';
388+
const structure: FileSystemStructure = {
389+
[exeName]: '',
390+
};
391+
const testTmpDir = await createTmpDir(structure);
392+
393+
// Make it executable on non-Windows
394+
if (!isWin) {
395+
const fsPromises = await import('node:fs/promises');
396+
await fsPromises.chmod(path.join(testTmpDir, exeName), 0o755);
397+
}
398+
399+
vi.stubEnv('PATH', testTmpDir);
400+
401+
try {
402+
const results = await scanPathExecutables();
403+
expect(Array.isArray(results)).toBe(true);
404+
expect(results).toContain(isWin ? 'my-test-exe.exe' : 'my-test-exe');
405+
} finally {
406+
await cleanupTmpDir(testTmpDir);
407+
vi.unstubAllEnvs();
394408
}
395409
});
396410

0 commit comments

Comments
 (0)