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
26 changes: 26 additions & 0 deletions src/utils/__tests__/global-command-resolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ describe('global command resolution', () => {
]);
});

it('silences child stderr on best-effort probes so failures cannot leak to the terminal', () => {
const execFileSyncSpy = mockExecFileSync({
'which -a ccstatusline': '/home/alice/.bun/bin/ccstatusline\n',
'bun pm bin -g': '/home/alice/.bun/bin\n'
});

inspectGlobalCommandResolution('bun', { platform: 'linux' });

expect(execFileSyncSpy).toHaveBeenCalled();
for (const call of execFileSyncSpy.mock.calls) {
const options = call[2] as { stdio?: string[] };
expect(options.stdio).toEqual(['ignore', 'pipe', 'ignore']);
}
});

it('treats a probe that throws with stderr output as not found without surfacing an error', () => {
vi.spyOn(childProcess, 'execFileSync').mockImplementation(() => {
throw new Error('error: No package.json was found for directory "C:\\Users\\alice\\.bun\\install\\global"');
});

const resolution = inspectGlobalCommandResolution('bun', { platform: 'win32' });

expect(resolution.resolvedPaths).toEqual([]);
expect(resolution.expectedBinDir).toBeNull();
});

it('warns when multiple PATH directories contain ccstatusline', () => {
mockExecFileSync({
'which -a ccstatusline': '/home/alice/.bun/bin/ccstatusline\n/usr/local/bin/ccstatusline\n',
Expand Down
13 changes: 10 additions & 3 deletions src/utils/global-command-resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ export function getCommandResolutionPaths(
? execFileSync('where', [command], {
encoding: 'utf-8',
timeout: COMMAND_LOOKUP_TIMEOUT_MS,
windowsHide: true
windowsHide: true,
stdio: ['ignore', 'pipe', 'ignore']
})
: execFileSync('which', ['-a', command], {
encoding: 'utf-8',
timeout: COMMAND_LOOKUP_TIMEOUT_MS,
windowsHide: true
windowsHide: true,
stdio: ['ignore', 'pipe', 'ignore']
});

return splitCommandOutput(output);
Expand All @@ -76,6 +78,7 @@ function getNpmGlobalBinDir(platform: NodeJS.Platform): string | null {
encoding: 'utf-8',
timeout: COMMAND_LOOKUP_TIMEOUT_MS,
windowsHide: true,
stdio: ['ignore', 'pipe', 'ignore'],
...getPackageManagerShellOptions(executable, platform)
}).trim();

Expand All @@ -93,10 +96,14 @@ function getNpmGlobalBinDir(platform: NodeJS.Platform): string | null {

function getBunGlobalBinDir(): string | null {
try {
// bun writes an error to stderr when its global dir was never
// initialized (no `bun add -g` ever run); silence it so best-effort
// probing cannot leak into the TUI terminal.
const binDir = execFileSync('bun', ['pm', 'bin', '-g'], {
encoding: 'utf-8',
timeout: COMMAND_LOOKUP_TIMEOUT_MS,
windowsHide: true
windowsHide: true,
stdio: ['ignore', 'pipe', 'ignore']
}).trim();

return binDir || null;
Expand Down
1 change: 1 addition & 0 deletions src/utils/global-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function getNpmGlobalPackageVersion(platform: NodeJS.Platform): string | null {
encoding: 'utf-8',
timeout: VERSION_LOOKUP_TIMEOUT_MS,
windowsHide: true,
stdio: ['ignore', 'pipe', 'ignore'],
...getPackageManagerShellOptions(executable, platform)
}).trim();

Expand Down