* fix: rename .claude.json to .openclaude.json with legacy fallback Rename the global config file from ~/.claude.json to ~/.openclaude.json, following the same migration pattern as the config directory (~/.claude → ~/.openclaude). - getGlobalClaudeFile() now prefers .openclaude.json; falls back to .claude.json only if the legacy file exists and the new one does not - Add .openclaude.json to filesystem permissions allowlist (keep .claude.json for legacy file protection) - Update all comment/string references from ~/.claude.json to ~/.openclaude.json across 12 files New installs get .openclaude.json from the start. Existing users continue using .claude.json until they rename it (or a future explicit migration). * test: add unit tests for getGlobalClaudeFile migration branches Covers the three cases: - new install (neither file exists) → .openclaude.json - existing user (only legacy .claude.json exists) → .claude.json - migrated user (both files exist) → .openclaude.json --------- Co-authored-by: Zartris <14197299+Zartris@users.noreply.github.com>
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { afterEach, beforeEach, expect, test } from 'bun:test'
|
|
import { mkdtempSync, rmSync, writeFileSync } from 'fs'
|
|
import { tmpdir } from 'os'
|
|
import { join } from 'path'
|
|
|
|
const originalEnv = {
|
|
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR,
|
|
CLAUDE_CODE_CUSTOM_OAUTH_URL: process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL,
|
|
USER_TYPE: process.env.USER_TYPE,
|
|
}
|
|
|
|
let tempDir: string
|
|
|
|
beforeEach(() => {
|
|
tempDir = mkdtempSync(join(tmpdir(), 'openclaude-env-test-'))
|
|
process.env.CLAUDE_CONFIG_DIR = tempDir
|
|
delete process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL
|
|
delete process.env.USER_TYPE
|
|
})
|
|
|
|
afterEach(() => {
|
|
rmSync(tempDir, { recursive: true, force: true })
|
|
if (originalEnv.CLAUDE_CONFIG_DIR === undefined) {
|
|
delete process.env.CLAUDE_CONFIG_DIR
|
|
} else {
|
|
process.env.CLAUDE_CONFIG_DIR = originalEnv.CLAUDE_CONFIG_DIR
|
|
}
|
|
if (originalEnv.CLAUDE_CODE_CUSTOM_OAUTH_URL === undefined) {
|
|
delete process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL
|
|
} else {
|
|
process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL = originalEnv.CLAUDE_CODE_CUSTOM_OAUTH_URL
|
|
}
|
|
if (originalEnv.USER_TYPE === undefined) {
|
|
delete process.env.USER_TYPE
|
|
} else {
|
|
process.env.USER_TYPE = originalEnv.USER_TYPE
|
|
}
|
|
})
|
|
|
|
async function importFreshEnvModule() {
|
|
return import(`./env.js?ts=${Date.now()}-${Math.random()}`)
|
|
}
|
|
|
|
// getGlobalClaudeFile — three migration branches
|
|
|
|
test('getGlobalClaudeFile: new install returns .openclaude.json when neither file exists', async () => {
|
|
const { getGlobalClaudeFile } = await importFreshEnvModule()
|
|
expect(getGlobalClaudeFile()).toBe(join(tempDir, '.openclaude.json'))
|
|
})
|
|
|
|
test('getGlobalClaudeFile: existing user keeps .claude.json when only legacy file exists', async () => {
|
|
writeFileSync(join(tempDir, '.claude.json'), '{}')
|
|
const { getGlobalClaudeFile } = await importFreshEnvModule()
|
|
expect(getGlobalClaudeFile()).toBe(join(tempDir, '.claude.json'))
|
|
})
|
|
|
|
test('getGlobalClaudeFile: migrated user uses .openclaude.json when both files exist', async () => {
|
|
writeFileSync(join(tempDir, '.claude.json'), '{}')
|
|
writeFileSync(join(tempDir, '.openclaude.json'), '{}')
|
|
const { getGlobalClaudeFile } = await importFreshEnvModule()
|
|
expect(getGlobalClaudeFile()).toBe(join(tempDir, '.openclaude.json'))
|
|
})
|