skillhub/cli/test/integration/version-command.test.ts
D41910 db6308adde fix(web): align namespace slug validation with SlugValidator
The create-namespace dialog validates slugs client-side before sending
the request, and its pattern was still ASCII-only. SlugValidator has
accepted Unicode letters, numbers and symbols since #196, so the form
rejected slugs the server accepts.

Signed-off-by: D41910 <158550716+D41910@users.noreply.github.com>
2026-10-15 01:22:38 +08:00

69 lines
2.3 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { mkdtemp, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { runCli } from '../helpers/run-cli'
import { CLI_VERSION } from '../../src/shared/constants'
describe('version command', () => {
test('prints human readable version', async () => {
const result = await runCli(['version'])
expect(result.exitCode).toBe(0)
expect(result.stdout).toContain('SkillHub CLI')
expect(result.stdout).toContain(CLI_VERSION)
expect(result.stderr).toBe('')
})
test('prints json version', async () => {
const result = await runCli(['version', '--json'])
expect(result.exitCode).toBe(0)
expect(JSON.parse(result.stdout)).toEqual({
ok: true,
version: CLI_VERSION
})
})
test.each(['--version', '-v'])('%s prints the same human-readable version', async flag => {
const shortcut = await runCli([flag])
const command = await runCli(['version'])
expect(shortcut.exitCode).toBe(0)
expect(shortcut.stdout).toBe(command.stdout)
expect(shortcut.stderr).toBe('')
})
test('built npm artifact runs on node without Bun runtime', async () => {
const dir = await mkdtemp(join(tmpdir(), 'skillhub-node-build-'))
const outfile = join(dir, 'index.js')
await writeFile(join(dir, 'package.json'), JSON.stringify({ type: 'module' }))
// Use process.execPath to ensure we use the current Bun executable
const bunPath = process.execPath
const build = Bun.spawn({
cmd: [bunPath, 'build', 'src/index.ts', '--target=node', `--outfile=${outfile}`],
cwd: fileURLToPath(new URL('../../', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe'
})
expect(await build.exited).toBe(0)
for (const args of [['version'], ['--version'], ['-v']]) {
const node = Bun.spawn({
cmd: ['node', outfile, ...args],
stdout: 'pipe',
stderr: 'pipe'
})
const [stdout, stderr, exitCode] = await Promise.all([
new Response(node.stdout).text(),
new Response(node.stderr).text(),
node.exited
])
expect(exitCode).toBe(0)
expect(stdout).toContain('SkillHub CLI')
expect(stdout).toContain(CLI_VERSION)
expect(stderr).toBe('')
}
})
})