mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 02:11:28 +00:00
fix(image-analysis): stabilize mcp config locking
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user