openpencil/tools/release/package-artifacts/tests/process.test.ts
Danila Poyarkov 1aa10a4fed
build(tools): group tools by role and gate them like the rest of the repo (#791)
Tools live under tools/<role>/<domain> (checks, generate, release, ci, dev), every tool is a workspace named @open-pencil/<domain>-tools, a shared tools/tsconfig.json backs the new check:tools gate that fixed 55 latent type errors, test:tools runs through bun --filter, the placement check is its own checks/test-homes package, and every tool resolves the repository through resolveWorkspaceRoot. Bun, Node, and mdast types live in a tools-root workspace so they never reach the app program.
2026-09-30 05:00:31 +04:00

62 lines
2 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { CommandError, runCommand } from '#package-artifacts/process'
describe('runCommand', () => {
test('captures output', async () => {
const result = await runCommand({
command: process.execPath,
args: ['--eval', "process.stdout.write('ready')"],
cwd: process.cwd()
})
expect(result.stdout).toBe('ready')
})
test('captures output larger than a pipe buffer before resolving', async () => {
const result = await runCommand({
command: process.execPath,
args: ['--eval', "process.stdout.write('x'.repeat(262144)); process.stderr.write('done')"],
cwd: process.cwd(),
timeoutMs: 10_000
})
expect(result.stdout).toHaveLength(262144)
expect(result.stderr).toBe('done')
})
test('reports missing executables', async () => {
await expect(
runCommand({
command: '/nonexistent/open-pencil-command',
cwd: process.cwd(),
timeoutMs: 1000
})
).rejects.toThrow()
})
test('returns structured command failures', async () => {
const failure = runCommand({
command: process.execPath,
args: ['--eval', "process.stderr.write('broken'); process.exit(7)"],
cwd: process.cwd()
})
const error = await failure.catch((caught: unknown) => caught)
expect(error).toBeInstanceOf(CommandError)
if (!(error instanceof CommandError)) throw new Error('Expected CommandError')
expect(error.exitCode).toBe(7)
expect(error.stderr).toBe('broken')
})
test('terminates commands after their deadline', async () => {
const error = await runCommand({
command: process.execPath,
args: ['--eval', 'setTimeout(() => {}, 10_000)'],
cwd: process.cwd(),
timeoutMs: 20
}).catch((caught: unknown) => caught)
expect(error).toBeInstanceOf(CommandError)
if (!(error instanceof CommandError)) throw new Error('Expected CommandError')
expect(error.timedOut).toBe(true)
expect(error.message).toContain('timed out after 20ms')
})
})