kilo-loop/test/verify.test.mjs

41 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-09-13 16:29:03 +00:00
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { runVerify, verifyCommandFor, summariseVerify } from '../src/verify.mjs'
test('verifyCommandFor prefers the stage command over the global default', () => {
assert.equal(verifyCommandFor({ verify: 'pnpm test' }, { verify: 'global' }), 'pnpm test')
assert.equal(verifyCommandFor({}, { verify: 'global' }), 'global')
assert.equal(verifyCommandFor({}, {}), null)
})
2026-09-13 22:20:42 +00:00
test('verifyCommandFor unwraps inline-code backticks from a verify value', () => {
// `:: verify: \`pnpm test\`` must run `pnpm test`, not a command substitution
// whose stdout ("Test run for …") is then executed as a command (exit 127).
assert.equal(verifyCommandFor({ verify: '`pnpm test`' }, {}), 'pnpm test')
assert.equal(verifyCommandFor({}, { verify: '`node --test`' }), 'node --test')
// An inner pair of backticks is legitimate shell syntax: leave it alone.
assert.equal(verifyCommandFor({ verify: 'echo "`date`"' }, {}), 'echo "`date`"')
})
2026-09-13 16:29:03 +00:00
test('runVerify reports success and captures output', async () => {
const res = await runVerify({ command: 'echo hello-verify', cwd: process.cwd() })
assert.equal(res.ok, true)
assert.equal(res.exitCode, 0)
assert.match(res.output, /hello-verify/)
})
test('runVerify reports a non-zero exit as failure', async () => {
const res = await runVerify({ command: 'exit 7', cwd: process.cwd() })
assert.equal(res.ok, false)
assert.equal(res.exitCode, 7)
assert.match(summariseVerify(res), /FAILED \(exit 7\)/)
})
test('runVerify times out and kills a hanging command', async () => {
const res = await runVerify({ command: 'sleep 5', cwd: process.cwd(), timeoutMs: 300 })
assert.equal(res.ok, false)
assert.equal(res.timedOut, true)
assert.match(summariseVerify(res), /TIMED OUT/)
})