From 2c80b720b5ca82adac06bb165c9a442e9f69a34e Mon Sep 17 00:00:00 2001 From: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> Date: Tue, 1 Sep 2026 21:50:35 +0800 Subject: [PATCH] test(cli): synchronize stale lock contenders Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> --- cli/test/helpers/target-lock-worker.ts | 14 ++++++++++++-- cli/test/unit/services/skill-target-lock.test.ts | 8 ++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cli/test/helpers/target-lock-worker.ts b/cli/test/helpers/target-lock-worker.ts index 52e134cb..d6d114a9 100644 --- a/cli/test/helpers/target-lock-worker.ts +++ b/cli/test/helpers/target-lock-worker.ts @@ -2,10 +2,20 @@ import { access, writeFile } from 'node:fs/promises' import { acquireSkillTargetLock } from '../../src/services/skill-target-lock' import { CliError } from '../../src/shared/errors' -const [rootDir, slug, acquiredPath, releasePath] = process.argv.slice(2) -if (!rootDir || !slug || !acquiredPath || !releasePath) process.exit(5) +const [rootDir, slug, readyPath, startPath, acquiredPath, releasePath] = process.argv.slice(2) +if (!rootDir || !slug || !readyPath || !startPath || !acquiredPath || !releasePath) process.exit(5) try { + await writeFile(readyPath, 'ready') + let startRequested = false + while (!startRequested) { + try { + await access(startPath) + startRequested = true + } catch { + await new Promise(resolve => setTimeout(resolve, 10)) + } + } const release = await acquireSkillTargetLock(rootDir, slug) await writeFile(acquiredPath, 'acquired') process.stdout.write('acquired\n') diff --git a/cli/test/unit/services/skill-target-lock.test.ts b/cli/test/unit/services/skill-target-lock.test.ts index 6fbabb8a..ddee6418 100644 --- a/cli/test/unit/services/skill-target-lock.test.ts +++ b/cli/test/unit/services/skill-target-lock.test.ts @@ -69,13 +69,17 @@ describe('skill target lifecycle lock', () => { const bunPath = (await Bun.which('bun')) ?? process.execPath const acquiredPath = join(rootDir, 'acquired') const releasePath = join(rootDir, 'release') + const startPath = join(rootDir, 'start') + const readyPaths = [join(rootDir, 'ready-0'), join(rootDir, 'ready-1')] - const processes = [0, 1].map(() => Bun.spawn({ - cmd: [bunPath, worker, rootDir, 'demo', acquiredPath, releasePath], + const processes = readyPaths.map(readyPath => Bun.spawn({ + cmd: [bunPath, worker, rootDir, 'demo', readyPath, startPath, acquiredPath, releasePath], stdout: 'pipe', stderr: 'pipe' })) try { + await Promise.all(readyPaths.map(waitForFile)) + await writeFile(startPath, 'start') await waitForFile(acquiredPath) const loserExitCode = await Promise.race([ ...processes.map(process => process.exited),