|
| 1 | +import { existsSync, mkdtempSync } from "node:fs"; |
| 2 | +import { tmpdir } from "node:os"; |
| 3 | +import { join } from "node:path"; |
| 4 | +import { describe, expect, test } from "vite-plus/test"; |
| 5 | +import { isBailianE2EEnabled, parseStdoutJson, runCommandE2e } from "./helpers.ts"; |
| 6 | +import { SKILL_ROUTES } from "./topic-routes.ts"; |
| 7 | + |
| 8 | +/** Canonical always-published skill; also the backbone of advisor wiki sync */ |
| 9 | +const WIKI_SKILL = "bailian-docs-llm-wiki"; |
| 10 | + |
| 11 | +/** Redirect ~/.bailian into a throwaway dir so lock/skill writes never touch the real user config */ |
| 12 | +function makeTempConfigDir(): string { |
| 13 | + return mkdtempSync(join(tmpdir(), "bl-skill-e2e-")); |
| 14 | +} |
| 15 | + |
| 16 | +describe("e2e: skill", () => { |
| 17 | + test("skill add --help exits successfully", async () => { |
| 18 | + const { stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, ["skill", "add", "--help"]); |
| 19 | + expect(exitCode, stderr).toBe(0); |
| 20 | + expect(stderr).toMatch(/--name/); |
| 21 | + }); |
| 22 | + |
| 23 | + test("skill update --help exits successfully", async () => { |
| 24 | + const { stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, ["skill", "update", "--help"]); |
| 25 | + expect(exitCode, stderr).toBe(0); |
| 26 | + expect(stderr).toMatch(/--name/); |
| 27 | + }); |
| 28 | + |
| 29 | + test("skill remove --help exits successfully", async () => { |
| 30 | + const { stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, ["skill", "remove", "--help"]); |
| 31 | + expect(exitCode, stderr).toBe(0); |
| 32 | + expect(stderr).toMatch(/--name/); |
| 33 | + }); |
| 34 | + |
| 35 | + test("skill list --help exits successfully", async () => { |
| 36 | + const { stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, ["skill", "list", "--help"]); |
| 37 | + expect(exitCode, stderr).toBe(0); |
| 38 | + expect(stderr).toMatch(/list|registry/i); |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
| 42 | +// Local-only cases: auth "none" + validation happens before any network access, no gating needed |
| 43 | +describe("e2e: skill (local, no credentials)", () => { |
| 44 | + test("skill add without --name errors as usage error (2)", async () => { |
| 45 | + const { stdout, stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, [ |
| 46 | + "skill", |
| 47 | + "add", |
| 48 | + "--quiet", |
| 49 | + ]); |
| 50 | + expect(exitCode).toBe(2); |
| 51 | + expect(`${stdout}\n${stderr}`).toMatch(/--name|Usage:/i); |
| 52 | + }); |
| 53 | + |
| 54 | + test("skill remove without --name errors as usage error (2)", async () => { |
| 55 | + const { stdout, stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, [ |
| 56 | + "skill", |
| 57 | + "remove", |
| 58 | + "--quiet", |
| 59 | + ]); |
| 60 | + expect(exitCode).toBe(2); |
| 61 | + expect(`${stdout}\n${stderr}`).toMatch(/--name|Usage:/i); |
| 62 | + }); |
| 63 | + |
| 64 | + test("skill add rejects mixing all with specific names (2)", async () => { |
| 65 | + // parseSkillNames throws UsageError before fetchSkillsIndex — offline-safe |
| 66 | + const { stdout, stderr, exitCode } = await runCommandE2e(SKILL_ROUTES, [ |
| 67 | + "skill", |
| 68 | + "add", |
| 69 | + "--name", |
| 70 | + "all,spark-video", |
| 71 | + "--quiet", |
| 72 | + ]); |
| 73 | + expect(exitCode).toBe(2); |
| 74 | + expect(`${stdout}\n${stderr}`).toMatch(/all/i); |
| 75 | + }); |
| 76 | + |
| 77 | + test("skill remove of a not-installed skill fails with reason (1)", async () => { |
| 78 | + const configDir = makeTempConfigDir(); |
| 79 | + const { stdout, exitCode } = await runCommandE2e( |
| 80 | + SKILL_ROUTES, |
| 81 | + ["skill", "remove", "--name", "definitely-not-installed", "--output", "json"], |
| 82 | + { BAILIAN_CONFIG_DIR: configDir }, |
| 83 | + ); |
| 84 | + expect(exitCode).toBe(1); |
| 85 | + const data = parseStdoutJson<{ |
| 86 | + skills?: Array<{ name?: string; status?: string; reason?: string }>; |
| 87 | + }>(stdout); |
| 88 | + expect(data.skills?.[0]?.status).toBe("failed"); |
| 89 | + expect(data.skills?.[0]?.reason).toMatch(/not installed/i); |
| 90 | + }); |
| 91 | +}); |
| 92 | + |
| 93 | +describe.skipIf(!isBailianE2EEnabled())("e2e: skill (real registry)", () => { |
| 94 | + test("skill list --output json returns registry and status rows", async () => { |
| 95 | + const configDir = makeTempConfigDir(); |
| 96 | + const { stdout, stderr, exitCode } = await runCommandE2e( |
| 97 | + SKILL_ROUTES, |
| 98 | + ["skill", "list", "--output", "json"], |
| 99 | + { BAILIAN_CONFIG_DIR: configDir }, |
| 100 | + ); |
| 101 | + expect(exitCode, stderr).toBe(0); |
| 102 | + const data = parseStdoutJson<{ |
| 103 | + registry?: string; |
| 104 | + skills?: Array<{ name?: string; status?: string }>; |
| 105 | + }>(stdout); |
| 106 | + expect(data.registry).toMatch(/^https?:\/\//); |
| 107 | + expect(Array.isArray(data.skills)).toBe(true); |
| 108 | + }, 60_000); |
| 109 | + |
| 110 | + test("skill add + remove full lifecycle in isolated dirs", async () => { |
| 111 | + const configDir = makeTempConfigDir(); |
| 112 | + // Empty fake home → no agents detected → fan-out never leaves the sandbox |
| 113 | + const fakeHome = makeTempConfigDir(); |
| 114 | + const env = { BAILIAN_CONFIG_DIR: configDir, HOME: fakeHome, USERPROFILE: fakeHome }; |
| 115 | + |
| 116 | + const added = await runCommandE2e( |
| 117 | + SKILL_ROUTES, |
| 118 | + ["skill", "add", "--name", WIKI_SKILL, "--output", "json"], |
| 119 | + env, |
| 120 | + ); |
| 121 | + expect(added.exitCode, added.stderr).toBe(0); |
| 122 | + const addData = parseStdoutJson<{ skills?: Array<{ name?: string; status?: string }> }>( |
| 123 | + added.stdout, |
| 124 | + ); |
| 125 | + expect(addData.skills?.[0]?.status).toBe("installed"); |
| 126 | + expect(existsSync(join(configDir, "skills", WIKI_SKILL, "SKILL.md"))).toBe(true); |
| 127 | + |
| 128 | + const removed = await runCommandE2e( |
| 129 | + SKILL_ROUTES, |
| 130 | + ["skill", "remove", "--name", WIKI_SKILL, "--output", "json"], |
| 131 | + env, |
| 132 | + ); |
| 133 | + expect(removed.exitCode, removed.stderr).toBe(0); |
| 134 | + const removeData = parseStdoutJson<{ skills?: Array<{ name?: string; status?: string }> }>( |
| 135 | + removed.stdout, |
| 136 | + ); |
| 137 | + expect(removeData.skills?.[0]?.status).toBe("removed"); |
| 138 | + expect(existsSync(join(configDir, "skills", WIKI_SKILL))).toBe(false); |
| 139 | + }, 300_000); |
| 140 | +}); |
0 commit comments