mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-07 05:05:44 +00:00
fix(cli): resolve executable path for Claude CLI on Windows
This commit is contained in:
47
server/shared/claude-cli-path.test.ts
Normal file
47
server/shared/claude-cli-path.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import {
|
||||
resolveClaudeCodeExecutablePath,
|
||||
type ResolveClaudeCodeExecutablePathDependencies,
|
||||
} from '@/shared/claude-cli-path.js';
|
||||
|
||||
test('resolveClaudeCodeExecutablePath resolves the npm Claude wrapper to its native exe on Windows', () => {
|
||||
const wrapperDir = 'C:\\nvm4w\\nodejs';
|
||||
const nativePath = `${wrapperDir}\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe`;
|
||||
const execFileSync =
|
||||
(() => `${wrapperDir}\\claude\r\n${wrapperDir}\\claude.cmd\r\n`) as unknown as ResolveClaudeCodeExecutablePathDependencies['execFileSync'];
|
||||
const readFileSync = (() => '') as unknown as ResolveClaudeCodeExecutablePathDependencies['readFileSync'];
|
||||
|
||||
const resolved = resolveClaudeCodeExecutablePath('claude', {
|
||||
platform: 'win32',
|
||||
execFileSync,
|
||||
existsSync: (candidate) => candidate === nativePath,
|
||||
readFileSync,
|
||||
});
|
||||
|
||||
assert.equal(resolved, nativePath);
|
||||
});
|
||||
|
||||
test('resolveClaudeCodeExecutablePath keeps an explicit JavaScript launcher path unchanged', () => {
|
||||
const scriptPath = 'C:\\tools\\claude.js';
|
||||
|
||||
const resolved = resolveClaudeCodeExecutablePath(scriptPath, {
|
||||
platform: 'win32',
|
||||
});
|
||||
|
||||
assert.equal(resolved, scriptPath);
|
||||
});
|
||||
|
||||
test('resolveClaudeCodeExecutablePath falls back to the configured command when PATH lookup fails', () => {
|
||||
const execFileSync = (() => {
|
||||
throw new Error('not found');
|
||||
}) as unknown as ResolveClaudeCodeExecutablePathDependencies['execFileSync'];
|
||||
|
||||
const resolved = resolveClaudeCodeExecutablePath('claude', {
|
||||
platform: 'win32',
|
||||
execFileSync,
|
||||
});
|
||||
|
||||
assert.equal(resolved, 'claude');
|
||||
});
|
||||
Reference in New Issue
Block a user