mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
fix(config): 修复测试污染用户配置的问题,支持 CCW_DATA_DIR 环境变量
修改内容: - getGlobalConfigPath() 和 getGlobalSettingsPath() 现在尊重 CCW_DATA_DIR 环境变量 - ensureClaudeCliTools()、saveClaudeCliTools()、saveClaudeCliSettings() 同步更新 - 测试现在使用独立的临时目录,不会修改用户的生产配置文件 ~/.claude/cli-tools.json 修复问题: - 集成测试会修改用户的 gemini primaryModel 为 test-model - 导致后续 Codex CLI 执行时读取到错误的配置 验证: - 所有集成测试通过 (4/4) - 用户配置保持不变 - 生产环境默认行为不受影响
This commit is contained in:
@@ -212,11 +212,19 @@ function getProjectSettingsPath(projectDir: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getGlobalConfigPath(): string {
|
function getGlobalConfigPath(): string {
|
||||||
return path.join(os.homedir(), '.claude', 'cli-tools.json');
|
// Support CCW_DATA_DIR for test isolation
|
||||||
|
const claudeHome = process.env.CCW_DATA_DIR
|
||||||
|
? path.join(process.env.CCW_DATA_DIR, '.claude')
|
||||||
|
: path.join(os.homedir(), '.claude');
|
||||||
|
return path.join(claudeHome, 'cli-tools.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGlobalSettingsPath(): string {
|
function getGlobalSettingsPath(): string {
|
||||||
return path.join(os.homedir(), '.claude', 'cli-settings.json');
|
// Support CCW_DATA_DIR for test isolation
|
||||||
|
const claudeHome = process.env.CCW_DATA_DIR
|
||||||
|
? path.join(process.env.CCW_DATA_DIR, '.claude')
|
||||||
|
: path.join(os.homedir(), '.claude');
|
||||||
|
return path.join(claudeHome, 'cli-settings.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,10 +399,12 @@ export function ensureClaudeCliTools(projectDir: string, createInProject: boolea
|
|||||||
|
|
||||||
const defaultConfig: ClaudeCliToolsConfig = { ...DEFAULT_TOOLS_CONFIG };
|
const defaultConfig: ClaudeCliToolsConfig = { ...DEFAULT_TOOLS_CONFIG };
|
||||||
|
|
||||||
// Always create in global directory (user-level config)
|
// Always create in global directory (user-level config), respecting CCW_DATA_DIR
|
||||||
const globalDir = path.join(os.homedir(), '.claude');
|
const claudeHome = process.env.CCW_DATA_DIR
|
||||||
if (!fs.existsSync(globalDir)) {
|
? path.join(process.env.CCW_DATA_DIR, '.claude')
|
||||||
fs.mkdirSync(globalDir, { recursive: true });
|
: path.join(os.homedir(), '.claude');
|
||||||
|
if (!fs.existsSync(claudeHome)) {
|
||||||
|
fs.mkdirSync(claudeHome, { recursive: true });
|
||||||
}
|
}
|
||||||
const globalPath = getGlobalConfigPath();
|
const globalPath = getGlobalConfigPath();
|
||||||
try {
|
try {
|
||||||
@@ -471,10 +481,12 @@ export function loadClaudeCliTools(projectDir: string): ClaudeCliToolsConfig & {
|
|||||||
export function saveClaudeCliTools(projectDir: string, config: ClaudeCliToolsConfig & { _source?: string }): void {
|
export function saveClaudeCliTools(projectDir: string, config: ClaudeCliToolsConfig & { _source?: string }): void {
|
||||||
const { _source, ...configToSave } = config;
|
const { _source, ...configToSave } = config;
|
||||||
|
|
||||||
// Always save to global directory
|
// Always save to global directory, respecting CCW_DATA_DIR
|
||||||
const globalDir = path.join(os.homedir(), '.claude');
|
const claudeHome = process.env.CCW_DATA_DIR
|
||||||
if (!fs.existsSync(globalDir)) {
|
? path.join(process.env.CCW_DATA_DIR, '.claude')
|
||||||
fs.mkdirSync(globalDir, { recursive: true });
|
: path.join(os.homedir(), '.claude');
|
||||||
|
if (!fs.existsSync(claudeHome)) {
|
||||||
|
fs.mkdirSync(claudeHome, { recursive: true });
|
||||||
}
|
}
|
||||||
const configPath = getGlobalConfigPath();
|
const configPath = getGlobalConfigPath();
|
||||||
|
|
||||||
@@ -531,10 +543,12 @@ export function loadClaudeCliSettings(projectDir: string): ClaudeCliSettingsConf
|
|||||||
export function saveClaudeCliSettings(projectDir: string, config: ClaudeCliSettingsConfig & { _source?: string }): void {
|
export function saveClaudeCliSettings(projectDir: string, config: ClaudeCliSettingsConfig & { _source?: string }): void {
|
||||||
const { _source, ...configToSave } = config;
|
const { _source, ...configToSave } = config;
|
||||||
|
|
||||||
// Always save to global directory
|
// Always save to global directory, respecting CCW_DATA_DIR
|
||||||
const globalDir = path.join(os.homedir(), '.claude');
|
const claudeHome = process.env.CCW_DATA_DIR
|
||||||
if (!fs.existsSync(globalDir)) {
|
? path.join(process.env.CCW_DATA_DIR, '.claude')
|
||||||
fs.mkdirSync(globalDir, { recursive: true });
|
: path.join(os.homedir(), '.claude');
|
||||||
|
if (!fs.existsSync(claudeHome)) {
|
||||||
|
fs.mkdirSync(claudeHome, { recursive: true });
|
||||||
}
|
}
|
||||||
const settingsPath = getGlobalSettingsPath();
|
const settingsPath = getGlobalSettingsPath();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user