fix(dsh): --openspec возвращает 1 при провале openspec init (#42)

Co-Authored-By: DeepSeek Harness <noreply@deepseek.com>
This commit is contained in:
Andrey Epifancev 2026-10-24 19:52:36 +04:00
parent 6876e4c6c8
commit 8c0fc89bac
2 changed files with 45 additions and 1 deletions

View File

@ -292,7 +292,10 @@ install_openspec() {
echo "FAIL: $dir has no openspec/ root; run: openspec init --tools agents" >&2 echo "FAIL: $dir has no openspec/ root; run: openspec init --tools agents" >&2
return 1 return 1
fi fi
( cd "$dir" && openspec init --tools agents ) if ! ( cd "$dir" && openspec init --tools agents ); then
echo "FAIL: openspec init --tools agents failed in $dir" >&2
return 1
fi
echo "ok: openspec agents adapter in $dir" echo "ok: openspec agents adapter in $dir"
} }

View File

@ -110,3 +110,44 @@ test('--openspec refuses a project without an openspec root', () => {
cleanup(home) cleanup(home)
} }
}) })
test('--openspec fails when openspec init fails', () => {
const home = tempDir()
try {
const project = join(home, 'project')
mkdirSync(join(project, 'openspec'), { recursive: true })
const bin = join(home, 'bin')
write(join(bin, 'openspec'), '#!/bin/sh\nexit 1\n')
chmodSync(join(bin, 'openspec'), 0o755)
const env = { ...process.env, HOME: home, DSH_HOME: join(home, '.dsh'), PATH: `${bin}:${process.env.PATH}` }
const run = spawnSync('bash', [script, '--openspec'], { cwd: project, env, encoding: 'utf8' })
assert.notEqual(run.status, 0)
assert.doesNotMatch(run.stdout, /ok: openspec agents adapter/)
assert.match(run.stderr, /FAIL/)
} finally {
cleanup(home)
}
})
test('--openspec fails without the openspec CLI', () => {
const home = tempDir()
try {
const project = join(home, 'project')
mkdirSync(join(project, 'openspec'), { recursive: true })
const bin = join(home, 'bin')
mkdirSync(bin, { recursive: true })
symlinkSync(process.execPath, join(bin, 'node'))
// openspec ставится в /opt/homebrew/bin; здесь только системные каталоги — CLI не найден
const env = {
...process.env,
HOME: home,
DSH_HOME: join(home, '.dsh'),
PATH: `${bin}:/usr/bin:/bin:/usr/sbin:/sbin`,
}
const run = spawnSync('bash', [script, '--openspec'], { cwd: project, env, encoding: 'utf8' })
assert.notEqual(run.status, 0)
assert.match(run.stdout + run.stderr, /FAIL: openspec CLI not found/)
} finally {
cleanup(home)
}
})