fix(image-analysis): stabilize mcp config locking

This commit is contained in:
Tam Nhu Tran
2026-04-02 18:56:13 -04:00
parent afc8b0bb6e
commit 0347f5a973
2 changed files with 13 additions and 5 deletions
+8 -3
View File
@@ -121,11 +121,16 @@ function writeClaudeUserConfig(configPath: string, config: ClaudeUserConfig): bo
}
function withClaudeUserConfigLock<T>(configPath: string, callback: () => T): T {
const lockTarget = path.dirname(configPath);
const configDir = path.dirname(configPath);
const lockTarget = path.join(configDir, `${path.basename(configPath)}.ccs-lock`);
let release: (() => void) | undefined;
if (!fs.existsSync(path.dirname(configPath))) {
fs.mkdirSync(path.dirname(configPath), { recursive: true, mode: 0o700 });
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true, mode: 0o700 });
}
if (!fs.existsSync(lockTarget)) {
fs.writeFileSync(lockTarget, '', { encoding: 'utf8', mode: 0o600 });
}
try {
@@ -191,7 +191,7 @@ describe('ensureImageAnalysisMcp', () => {
expect(ensureImageAnalysisMcp()).toBe(true);
expect(lockSpy).toHaveBeenCalled();
expect(lockSpy.mock.calls[0]?.[0]).toBe(tempHome as string);
expect(lockSpy.mock.calls[0]?.[0]).toBe(path.join(tempHome as string, '.claude.json.ccs-lock'));
});
it('returns false instead of throwing when ~/.claude.json is already locked', () => {
@@ -200,8 +200,11 @@ describe('ensureImageAnalysisMcp', () => {
const claudeUserConfigPath = path.join(tempHome as string, '.claude.json');
fs.writeFileSync(claudeUserConfigPath, '{}\n', 'utf8');
fs.writeFileSync(path.join(tempHome as string, '.claude.json.ccs-lock'), '', 'utf8');
const release = lockfile.lockSync(tempHome as string, { stale: 10000 }) as () => void;
const release = lockfile.lockSync(path.join(tempHome as string, '.claude.json.ccs-lock'), {
stale: 10000,
}) as () => void;
try {
let result: boolean | undefined;