mirror of
https://github.com/iflytek/skillhub.git
synced 2026-10-14 04:08:16 +00:00
Implement complete CLI tool for SkillHub with 12 commands, 7 backend API endpoints, and comprehensive documentation. CLI Commands: - help, version: Basic information - login, logout, whoami: Authentication management - search: Discover published skills - install: Install skills to agent directories (14 Tier 1 agents supported) - list, remove, doctor: Local skill management - publish: Publish skill packages - update: Self-update mechanism Backend API: - Add /api/cli/v1 endpoints for auth, search, resolve, download, delete, publish - Implement CliAuthController and CliSkillController - Add security policies for CLI routes - Full test coverage (19 backend tests) CLI Implementation: - TypeScript with strict mode, Bun runtime - Pure JS zip handling (fflate) for cross-platform compatibility - 15 agent profiles (14 Tier 1 + generic fallback) - Secure token storage (0600 permissions) - Path safety validation for remove operations - Comprehensive error handling (404/403/network distinction) - 41 unit and integration tests Documentation: - CLI user guide (Chinese and English) - README updates with quick start - GitHub Actions workflow for cross-platform CI Quality: - lint: 0 errors - typecheck: pass - test: 41/41 pass - build: 0.30 MB (target=node for npm/npx compatibility)
52 lines
1.6 KiB
TypeScript
52 lines
1.6 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 { runCli } from '../helpers/run-cli'
|
|
|
|
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('0.1.0')
|
|
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: '0.1.0'
|
|
})
|
|
})
|
|
|
|
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' }))
|
|
const build = Bun.spawn({
|
|
cmd: ['bun', 'build', 'src/index.ts', '--target=node', `--outfile=${outfile}`],
|
|
cwd: new URL('../../', import.meta.url).pathname,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe'
|
|
})
|
|
expect(await build.exited).toBe(0)
|
|
|
|
const node = Bun.spawn({
|
|
cmd: ['node', outfile, 'version'],
|
|
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(stderr).toBe('')
|
|
})
|
|
})
|