import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { after, test } from "node:test"; const CLI = fileURLToPath(new URL("../dist/index.js", import.meta.url)); const built = await fs .access(CLI) .then(() => true) .catch(() => false); const home = await fs.mkdtemp(path.join(os.tmpdir(), "designpaca-cli-")); after(async () => { await fs.rm(home, { recursive: true, force: true }); }); /** 빌드 산출물을 사용자가 실행하는 방식 그대로 돌린다 */ function run(args: string[]): string { return execFileSync(process.execPath, [CLI, ...args, "--no-update-check"], { encoding: "utf8", env: { ...process.env, HOME: home, USERPROFILE: home, FORCE_COLOR: "0" }, }); } test("빌드 산출물이 있어야 한다", { skip: built ? false : "pnpm build 먼저 실행해라" }, () => { assert.ok(built); }); test("--version 은 스킬 버전과 같다", { skip: !built }, async () => { const stamp = ( await fs.readFile(fileURLToPath(new URL("../dist/skill/.designpaca_version", import.meta.url)), "utf8") ).trim(); assert.equal(run(["--version"]).trim(), stamp); }); test("도움말에 모든 명령이 나온다", { skip: !built }, () => { const out = run(["--help"]); for (const cmd of ["install", "update", "uninstall", "doctor", "list"]) { assert.ok(out.includes(cmd), `도움말에 ${cmd} 가 없다`); } }); test("dry-run 은 아무 파일도 쓰지 않는다", { skip: !built }, async () => { const before = await fs.readdir(home); const out = run(["install", "-t", "claude-code", "-s", "user", "-y", "--dry-run"]); assert.ok(out.includes("설치 계획")); assert.deepEqual(await fs.readdir(home), before); }); test("알 수 없는 대상은 종료 코드 2 로 거부한다", { skip: !built }, () => { assert.throws( () => run(["install", "-t", "emacs", "-y"]), (err: { status?: number }) => err.status === 2, ); }); test("설치 → doctor → 제거 왕복", { skip: !built }, async () => { run(["install", "-t", "claude-code", "-s", "user", "-y"]); const skillMd = path.join(home, ".claude", "skills", "designpaca", "SKILL.md"); assert.ok((await fs.readFile(skillMd, "utf8")).includes("name: designpaca")); assert.ok(run(["doctor"]).includes("claude-code")); run(["uninstall", "-y"]); await assert.rejects(() => fs.access(skillMd)); });