mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 12:16:46 +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 {
|
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;
|
let release: (() => void) | undefined;
|
||||||
|
|
||||||
if (!fs.existsSync(path.dirname(configPath))) {
|
if (!fs.existsSync(configDir)) {
|
||||||
fs.mkdirSync(path.dirname(configPath), { recursive: true, mode: 0o700 });
|
fs.mkdirSync(configDir, { recursive: true, mode: 0o700 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(lockTarget)) {
|
||||||
|
fs.writeFileSync(lockTarget, '', { encoding: 'utf8', mode: 0o600 });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ describe('ensureImageAnalysisMcp', () => {
|
|||||||
|
|
||||||
expect(ensureImageAnalysisMcp()).toBe(true);
|
expect(ensureImageAnalysisMcp()).toBe(true);
|
||||||
expect(lockSpy).toHaveBeenCalled();
|
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', () => {
|
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');
|
const claudeUserConfigPath = path.join(tempHome as string, '.claude.json');
|
||||||
fs.writeFileSync(claudeUserConfigPath, '{}\n', 'utf8');
|
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 {
|
try {
|
||||||
let result: boolean | undefined;
|
let result: boolean | undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user