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
48 changes: 48 additions & 0 deletions src/tui/__tests__/App.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import * as childProcess from 'node:child_process';
import * as fs from 'node:fs';
import {
afterEach,
Expand Down Expand Up @@ -441,6 +442,53 @@ describe('App after a global update run from the TUI', () => {
});
});

describe('App launched through npx', () => {
let sandbox: AppSandbox;

beforeEach(() => {
sandbox = setUpAppSandbox();
});

afterEach(() => {
sandbox.restore();
});

it.skipIf(process.platform === 'win32')('still guards a pinned npm install older than the running TUI', async () => {
fs.writeFileSync(sandbox.settingsPath, JSON.stringify({
...DEFAULT_SETTINGS,
installation: { method: 'pinned', installedVersion: '2.0.0' }
}));
vi.spyOn(claudeStatus, 'loadClaudeStatusLineState').mockResolvedValue({ existingStatusLine: null, refreshInterval: null });
vi.spyOn(claudeSettings, 'isInstalled').mockResolvedValue(true);
// While npx runs the TUI, its cache's bin dir comes first on PATH
const responses: Record<string, string> = {
'which -a ccstatusline': '/home/alice/.npm/_npx/9f3c1e2a7b6d4c80/node_modules/.bin/ccstatusline\n/home/alice/.npm-global/bin/ccstatusline\n',
'npm prefix -g': '/home/alice/.npm-global\n'
};
vi.spyOn(childProcess, 'execFileSync').mockImplementation((command, args) => {
const key = `${command} ${(args as string[]).join(' ')}`;
const response = responses[key];

if (response === undefined) {
throw new Error(`Unexpected command: ${key}`);
}

return response;
});
const rendered = renderApp();

try {
await waitFor(() => {
expect(rendered.getFrame()).toContain('Pinned Install Version Mismatch');
});
expect(rendered.getFrame()).toContain(`Claude Code is pinned to ccstatusline v2.0.0, but this TUI is v${getPackageVersion()}.`);
expect(rendered.getFrame()).toContain(`Update npm global install to v${getPackageVersion()}`);
} finally {
rendered.cleanup();
}
});
});

describe('App live label preview', () => {
let sandbox: AppSandbox;

Expand Down
43 changes: 43 additions & 0 deletions src/utils/__tests__/global-command-resolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,49 @@ describe('global command resolution', () => {
expect(resolution.warning).toBeNull();
});

it('ignores transient npx status line shims when resolving global commands', () => {
mockExecFileSync({
'which -a ccstatusline': '/Users/alice/.npm/_npx/9f3c1e2a7b6d4c80/node_modules/.bin/ccstatusline\n/Users/alice/.nvm/versions/node/v24.9.0/bin/ccstatusline\n',
'npm prefix -g': '/Users/alice/.nvm/versions/node/v24.9.0\n'
});

const resolution = inspectGlobalCommandResolution('npm', { platform: 'darwin' });

expect(resolution.firstResolvedPath).toBe('/Users/alice/.nvm/versions/node/v24.9.0/bin/ccstatusline');
expect(resolution.resolvedPaths).toEqual(['/Users/alice/.nvm/versions/node/v24.9.0/bin/ccstatusline']);
expect(resolution.warning).toBeNull();
});

it('ignores npx shims from a custom npm cache directory', () => {
mockExecFileSync({
'which -a ccstatusline': '/srv/cache/npm/_npx/0a1b2c3d4e5f6789/node_modules/.bin/ccstatusline\n/usr/local/bin/ccstatusline\n',
'npm prefix -g': '/usr/local\n'
});

const resolution = inspectGlobalCommandResolution('npm', { platform: 'linux' });

expect(resolution.resolvedPaths).toEqual(['/usr/local/bin/ccstatusline']);
expect(resolution.warning).toBeNull();
});

it('ignores transient npx shims in the Windows npm cache', () => {
mockExecFileSync({
'where ccstatusline': [
'C:\\Users\\Alice\\AppData\\Local\\npm-cache\\_npx\\9f3c1e2a7b6d4c80\\node_modules\\.bin\\ccstatusline',
'C:\\Users\\Alice\\AppData\\Local\\npm-cache\\_npx\\9f3c1e2a7b6d4c80\\node_modules\\.bin\\ccstatusline.cmd',
'C:\\Users\\Alice\\AppData\\Local\\npm-cache\\_npx\\9f3c1e2a7b6d4c80\\node_modules\\.bin\\ccstatusline.ps1',
'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.cmd',
''
].join('\r\n'),
'npm.cmd prefix -g': 'C:\\Users\\Alice\\AppData\\Roaming\\npm\r\n'
});

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

expect(resolution.resolvedPaths).toEqual(['C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.cmd']);
expect(resolution.warning).toBeNull();
});

it('compares Windows npm prefixes with WSL /mnt paths', () => {
mockExecFileSync({
'which -a ccstatusline': '/mnt/c/Users/Alice/AppData/Roaming/npm/ccstatusline\n',
Expand Down
79 changes: 79 additions & 0 deletions src/utils/__tests__/global-package-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,85 @@ describe('global package manager inspection', () => {
});
});

it('ignores transient npx status line shims when identifying the active global command', () => {
mockExecFileSync({
'which -a ccstatusline': '/Users/alice/.npm/_npx/9f3c1e2a7b6d4c80/node_modules/.bin/ccstatusline\n/Users/alice/.nvm/versions/node/v24.9.0/bin/ccstatusline\n',
'npm prefix -g': '/Users/alice/.nvm/versions/node/v24.9.0\n',
'npm root -g': '/Users/alice/.nvm/versions/node/v24.9.0/lib/node_modules\n'
});
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => (
filePath === '/Users/alice/.nvm/versions/node/v24.9.0/lib/node_modules/ccstatusline/package.json'
));
vi.spyOn(fs, 'readFileSync').mockImplementation((filePath) => {
if (filePath === '/Users/alice/.nvm/versions/node/v24.9.0/lib/node_modules/ccstatusline/package.json') {
return '{"version":"2.2.14"}';
}

throw new Error(`Unexpected read: ${String(filePath)}`);
});

const activeCommand = inspectActiveGlobalCommand({
commandAvailability: {
npm: true,
bun: false
},
platform: 'darwin'
});

expect(activeCommand).toEqual({
packageManager: 'npm',
resolvedPath: '/Users/alice/.nvm/versions/node/v24.9.0/bin/ccstatusline',
resolvedPaths: ['/Users/alice/.nvm/versions/node/v24.9.0/bin/ccstatusline'],
binDir: '/Users/alice/.nvm/versions/node/v24.9.0/bin',
version: '2.2.14',
warning: null
});
});

it('ignores transient npx shims in the Windows npm cache when identifying the active global command', () => {
mockExecFileSync({
'where ccstatusline': [
'C:\\Users\\Alice\\AppData\\Local\\npm-cache\\_npx\\9f3c1e2a7b6d4c80\\node_modules\\.bin\\ccstatusline.cmd',
'C:\\Users\\Alice\\AppData\\Local\\npm-cache\\_npx\\9f3c1e2a7b6d4c80\\node_modules\\.bin\\ccstatusline.ps1',
'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.cmd',
'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.ps1',
''
].join('\r\n'),
'npm.cmd prefix -g': 'C:\\Users\\Alice\\AppData\\Roaming\\npm\r\n',
'npm.cmd root -g': 'C:\\Users\\Alice\\AppData\\Roaming\\npm\\node_modules\r\n'
});
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => (
filePath === 'C:\\Users\\Alice\\AppData\\Roaming\\npm\\node_modules\\ccstatusline\\package.json'
));
vi.spyOn(fs, 'readFileSync').mockImplementation((filePath) => {
if (filePath === 'C:\\Users\\Alice\\AppData\\Roaming\\npm\\node_modules\\ccstatusline\\package.json') {
return '{"version":"2.2.14"}';
}

throw new Error(`Unexpected read: ${String(filePath)}`);
});

const activeCommand = inspectActiveGlobalCommand({
commandAvailability: {
npm: true,
bun: false
},
platform: 'win32'
});

expect(activeCommand).toEqual({
packageManager: 'npm',
resolvedPath: 'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.cmd',
resolvedPaths: [
'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.cmd',
'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.ps1'
],
binDir: 'C:\\Users\\Alice\\AppData\\Roaming\\npm',
version: '2.2.14',
warning: null
});
});

it('uses npm.cmd for Windows npm version lookup', () => {
const execFileSyncSpy = mockExecFileSync({
'where ccstatusline': 'C:\\Users\\Alice\\AppData\\Roaming\\npm\\ccstatusline.cmd\r\n',
Expand Down
15 changes: 12 additions & 3 deletions src/utils/global-command-resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@ function splitCommandOutput(output: string): string[] {
return paths;
}

function isTransientBunxStatusLinePath(filePath: string): boolean {
// While bunx or npx runs the TUI, the bin dir of its temporary copy comes first
// on PATH, ahead of any persistent install:
// - bunx: <temp dir>/bunx-<uid>-ccstatusline@<tag>/node_modules/.bin
// - npx: <npm cache>/_npx/<hash>/node_modules/.bin, wherever the npm cache lives
const TRANSIENT_STATUS_LINE_PATH_PATTERNS = [
/(?:^|\/)bunx-[^/]*ccstatusline@[^/]+\/node_modules\/\.bin\/ccstatusline(?:\.(?:cmd|ps1))?$/i,
/(?:^|\/)_npx\/[^/]+\/node_modules\/\.bin\/ccstatusline(?:\.(?:cmd|ps1))?$/i
];

function isTransientStatusLinePath(filePath: string): boolean {
const normalized = filePath.replace(/\\/g, '/');

return /(?:^|\/)bunx-[^/]*ccstatusline@[^/]+\/node_modules\/\.bin\/ccstatusline(?:\.(?:cmd|ps1))?$/i.test(normalized);
return TRANSIENT_STATUS_LINE_PATH_PATTERNS.some(pattern => pattern.test(normalized));
}

export function getPersistentCommandResolutionPaths(paths: string[]): string[] {
return paths.filter(path => !isTransientBunxStatusLinePath(path));
return paths.filter(path => !isTransientStatusLinePath(path));
}

export function getCommandResolutionPaths(
Expand Down
Loading