| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533 |
- import {
- existsSync,
- mkdirSync,
- mkdtempSync,
- readFileSync,
- rmSync,
- symlinkSync,
- writeFileSync,
- } from "node:fs";
- import { tmpdir } from "node:os";
- import { join } from "node:path";
- import { afterEach, describe, expect, it, vi } from "vitest";
- import { MAX_SKILL_SCAN_DEPTH } from "@zcode/shared";
- import type { ISkillsService } from "../src/skills/skills.js";
- const originalHome = process.env.HOME;
- const originalProcessLabel = process.env.ZCODE_PROCESS_LABEL;
- const tempHomes: string[] = [];
- function makeTempHome(): string {
- const home = mkdtempSync(join(tmpdir(), "zcode-skills-home-"));
- tempHomes.push(home);
- return home;
- }
- async function createSkillsServiceInEnv(
- home: string,
- options?: { isDesktopRuntime?: boolean },
- ): Promise<ISkillsService> {
- process.env.HOME = home;
- vi.resetModules();
- const mod = await import("../src/skills/skillsService.js");
- return mod.createSkillsService(options);
- }
- function writeSkill(basePath: string, folder: string, content: string): void {
- const skillDir = join(basePath, folder);
- mkdirSync(skillDir, { recursive: true });
- writeFileSync(join(skillDir, "SKILL.md"), content, "utf-8");
- }
- function writeSkillMeta(basePath: string, folder: string, metadata: unknown): void {
- const skillDir = join(basePath, folder);
- mkdirSync(skillDir, { recursive: true });
- writeFileSync(join(skillDir, "_meta.json"), JSON.stringify(metadata, null, 2), "utf-8");
- }
- function workspaceSkillRoot(workspacePath: string): string {
- return join(workspacePath, ".zcode", "skills");
- }
- function userSkillRoot(home: string): string {
- return join(home, ".zcode", "skills");
- }
- function userAgentsSkillRoot(home: string): string {
- return join(home, ".agents", "skills");
- }
- function officialPluginRoot(home: string, pluginName: string, version = "0.1.0"): string {
- return join(
- home,
- ".zcode",
- "cli",
- "plugins",
- "cache",
- "zcode-plugins-official",
- pluginName,
- version,
- );
- }
- function marketplacePluginRoot(
- home: string,
- marketplace: string,
- pluginName: string,
- version = "0.0.0",
- ): string {
- return join(
- home,
- ".zcode",
- "cli",
- "plugins",
- "cache",
- marketplace,
- pluginName,
- version,
- );
- }
- function writePluginManifest(pluginRoot: string, manifest: Record<string, unknown>): void {
- mkdirSync(join(pluginRoot, ".zcode-plugin"), { recursive: true });
- writeFileSync(
- join(pluginRoot, ".zcode-plugin", "plugin.json"),
- JSON.stringify(manifest, null, 2),
- "utf-8",
- );
- }
- function writeClaudePluginManifest(pluginRoot: string, manifest: Record<string, unknown>): void {
- mkdirSync(join(pluginRoot, ".claude-plugin"), { recursive: true });
- writeFileSync(
- join(pluginRoot, ".claude-plugin", "plugin.json"),
- JSON.stringify(manifest, null, 2),
- "utf-8",
- );
- }
- function writeInstalledPluginRecord(
- home: string,
- record: {
- marketplace: string;
- name: string;
- installPath: string;
- version?: string;
- },
- ): void {
- const pluginsRoot = join(home, ".zcode", "cli", "plugins");
- mkdirSync(pluginsRoot, { recursive: true });
- writeFileSync(
- join(pluginsRoot, "installed_plugins.json"),
- JSON.stringify(
- {
- version: 1,
- plugins: [
- {
- id: `${record.name}@${record.marketplace}`,
- name: record.name,
- marketplace: record.marketplace,
- version: record.version ?? "0.0.0",
- installPath: record.installPath,
- installedAt: "2026-06-25T00:00:00.000Z",
- updatedAt: "2026-06-25T00:00:00.000Z",
- scope: "user",
- source: "./plugins/demo",
- },
- ],
- },
- null,
- 2,
- ),
- "utf-8",
- );
- }
- function writeCliConfig(home: string, config: Record<string, unknown>): void {
- const configPath = join(home, ".zcode", "cli", "config.json");
- mkdirSync(join(home, ".zcode", "cli"), { recursive: true });
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
- }
- afterEach(() => {
- process.env.HOME = originalHome;
- process.env.ZCODE_PROCESS_LABEL = originalProcessLabel;
- vi.doUnmock("node:fs/promises");
- vi.resetModules();
- while (tempHomes.length > 0) {
- const home = tempHomes.pop();
- if (home) {
- rmSync(home, { recursive: true, force: true });
- }
- }
- });
- describe("skillsService", () => {
- it("workspace 同层合并读取 .zcode 与 .agents,并忽略废弃和 Claude 技能目录", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "repo-review",
- `---
- name: repo-review
- description: from zcode
- ---
- zcode-body`,
- );
- writeSkill(
- join(workspacePath, ".zcode", "cli", "skills"),
- "old-glm",
- `---
- name: old-glm
- description: deprecated
- ---
- old-body`,
- );
- writeSkill(
- join(workspacePath, ".agents", "skills"),
- "agents-review",
- `---
- name: agents-review
- description: from agents
- ---
- agents-body`,
- );
- writeSkill(
- join(workspacePath, ".claude", "skills"),
- "claude-review",
- `---
- name: claude-review
- description: retired claude
- ---
- claude-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "claude" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["agents-review", "repo-review"]);
- expect(result.skills.find((skill) => skill.name === "agents-review")).toMatchObject({
- description: "from agents",
- scope: "workspace",
- enabled: true,
- });
- expect(result.skills.find((skill) => skill.name === "repo-review")).toMatchObject({
- description: "from zcode",
- scope: "workspace",
- enabled: true,
- });
- });
- it.skipIf(process.platform === "win32")(
- "workspace .zcode/skills 软链导入的技能可被 / 和 $ 面板发现",
- async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const sourceSkillParent = join(home, "external-agent", "skills");
- const sourceSkillDir = join(sourceSkillParent, "imported-skill");
- const linkedSkillDir = join(workspaceSkillRoot(workspacePath), "imported-skill");
- writeSkill(
- sourceSkillParent,
- "imported-skill",
- `---
- name: imported-skill
- description: imported via symlink
- ---
- imported-body`,
- );
- mkdirSync(workspaceSkillRoot(workspacePath), { recursive: true });
- symlinkSync(sourceSkillDir, linkedSkillDir, "dir");
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["imported-skill"]);
- expect(result.skills[0]).toMatchObject({
- description: "imported via symlink",
- scope: "workspace",
- });
- expect(result.skills[0]?.path).toContain("imported-skill/SKILL.md");
- },
- );
- it("workspace 只有 .agents/skills 时仍能发现技能", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- join(workspacePath, ".agents", "skills"),
- "agents-review",
- `---
- name: agents-review
- description: from agents
- ---
- agents-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "claude" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["agents-review"]);
- expect(result.skills[0]).toMatchObject({
- description: "from agents",
- scope: "workspace",
- });
- });
- it("递归发现分组目录,跳过隐藏目录但允许 .system 官方目录", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const root = workspaceSkillRoot(workspacePath);
- writeSkill(
- join(root, "group-a"),
- "public-skill",
- `---
- name: public-skill
- description: visible
- ---
- public-body`,
- );
- writeSkill(
- join(root, "bundle", ".agents", "skills"),
- "vendored-skill",
- `---
- name: vendored-skill
- description: hidden
- ---
- vendored-body`,
- );
- writeSkill(
- join(root, ".system"),
- "bundled-system-skill",
- `---
- name: bundled-system-skill
- description: official
- ---
- system-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name).sort()).toEqual([
- "bundled-system-skill",
- "public-skill",
- ]);
- });
- it.skipIf(process.platform === "win32")("递归扫描时跳过指向文件的软链", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const root = workspaceSkillRoot(workspacePath);
- writeSkill(
- root,
- "zai-grafana-cli",
- `---
- name: zai-grafana-cli
- description: grafana cli
- ---
- body`,
- );
- const skillDir = join(root, "zai-grafana-cli");
- const binDir = join(skillDir, "bin");
- const executablePath = join(home, "gfctl");
- mkdirSync(binDir, { recursive: true });
- writeFileSync(executablePath, "#!/bin/sh\n", "utf-8");
- symlinkSync(executablePath, join(binDir, "gfctl"));
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["zai-grafana-cli"]);
- expect(result.diagnostics.some((diagnostic) => diagnostic.code === "skill_scan_failed")).toBe(
- false,
- );
- });
- it("读取 SKILL.md 时兼容 CRLF、多行 description 和中文冒号", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "windows-skill",
- "---\r\nname: windows-skill\r\ndescription: |\r\n first line\r\n second line\r\n---\r\nbody line",
- );
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "cn-colon-skill",
- `---
- name: cn-colon-skill
- description: 学术数据查询。触发场景: 提到论文、学者、机构时使用。
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.find((skill) => skill.name === "windows-skill")).toMatchObject({
- description: "first line\nsecond line",
- body: "body line",
- });
- expect(result.skills.find((skill) => skill.name === "cn-colon-skill")).toMatchObject({
- description: "学术数据查询。触发场景: 提到论文、学者、机构时使用。",
- body: "body",
- });
- });
- it("读取技能时会合并同目录 _meta.json 的版本信息", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const publishedAt = Date.now();
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "feishu-drive",
- `---
- name: feishu-drive
- description: drive
- ---
- body`,
- );
- writeSkillMeta(workspaceSkillRoot(workspacePath), "feishu-drive", {
- ownerId: "owner-1",
- slug: "feishu-drive",
- version: "1.0.0",
- publishedAt,
- });
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills[0]?.metadata).toEqual({
- ownerId: "owner-1",
- slug: "feishu-drive",
- version: "1.0.0",
- publishedAt,
- });
- });
- it("桌面 runtime 同时读取用户级 ~/.zcode/skills 和 ~/.agents/skills", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- userSkillRoot(home),
- "zcode-global",
- `---
- name: zcode-global
- description: user zcode
- ---
- body`,
- );
- writeSkill(
- userAgentsSkillRoot(home),
- "agents-global",
- `---
- name: agents-global
- description: user agents
- ---
- body`,
- );
- writeSkill(
- userSkillRoot(home),
- "copied-global",
- `---
- name: copied-global
- description: copied into zcode
- ---
- zcode-body`,
- );
- writeSkill(
- userAgentsSkillRoot(home),
- "copied-global",
- `---
- name: copied-global
- description: original agents copy
- ---
- agents-body`,
- );
- writeSkill(
- userSkillRoot(home),
- "current-review",
- `---
- name: shared-review
- description: zcode version
- ---
- zcode-review-body`,
- );
- writeSkill(
- userAgentsSkillRoot(home),
- "external-review",
- `---
- name: shared-review
- description: agents version
- ---
- agents-review-body`,
- );
- writeSkill(
- join(home, ".zcode", "cli", "skills"),
- "old-global",
- `---
- name: old-global
- description: deprecated
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.capability).toEqual({ userScopeAvailable: true });
- expect(result.skills.map((skill) => skill.name)).toEqual([
- "agents-global",
- "copied-global",
- "shared-review",
- "zcode-global",
- ]);
- expect(result.skills.find((skill) => skill.name === "copied-global")?.path)
- .toContain(join(home, ".zcode", "skills", "copied-global"));
- expect(result.skills.find((skill) => skill.name === "shared-review")?.path)
- .toContain(join(home, ".zcode", "skills", "current-review"));
- expect(result.skills.every((skill) => skill.scope === "user")).toBe(true);
- });
- it("桌面 runtime 用户级 ~/.zcode/skills 没有技能时 fallback 到 ~/.agents/skills", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- userAgentsSkillRoot(home),
- "agents-global",
- `---
- name: agents-global
- description: user agents
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["agents-global"]);
- expect(result.skills[0]?.scope).toBe("user");
- });
- it("读取已启用官方 plugin 声明的技能目录", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const browserUsePluginRoot = officialPluginRoot(home, "browser-use");
- const documentPluginRoot = officialPluginRoot(home, "documents");
- const zcodeGuidePluginRoot = officialPluginRoot(home, "zcode-guide");
- const iosPluginRoot = officialPluginRoot(home, "ios-simulator");
- const androidPluginRoot = officialPluginRoot(home, "android-emulator");
- writePluginManifest(browserUsePluginRoot, {
- name: "browser-use",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(documentPluginRoot, {
- name: "documents",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(zcodeGuidePluginRoot, {
- name: "zcode-guide",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(iosPluginRoot, {
- name: "ios-simulator",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(androidPluginRoot, {
- name: "android-emulator",
- skills: "skills",
- version: "0.1.0",
- });
- writeSkill(
- join(browserUsePluginRoot, "skills"),
- "control-browser",
- `---
- name: control-browser
- description: browser skill
- ---
- browser-body`,
- );
- writeSkill(
- join(documentPluginRoot, "skills"),
- "docx",
- `---
- name: docx
- description: docx skill
- ---
- docx-body`,
- );
- writeSkill(
- join(documentPluginRoot, "skills"),
- "pdf",
- `---
- name: pdf
- description: pdf skill
- ---
- pdf-body`,
- );
- writeSkill(
- join(zcodeGuidePluginRoot, "skills"),
- "diagnosing-plugins",
- `---
- name: diagnosing-plugins
- description: Diagnose plugin discovery and enablement problems
- ---
- diagnosing-body`,
- );
- writeSkill(
- join(iosPluginRoot, "skills"),
- "ios-simulator",
- `---
- name: ios-simulator
- description: ios skill
- ---
- ios-body`,
- );
- writeSkill(
- join(androidPluginRoot, "skills"),
- "android-emulator",
- `---
- name: android-emulator
- description: android skill
- ---
- android-body`,
- );
- writeCliConfig(home, {
- plugins: {
- enabledPlugins: {
- "ios-simulator@zcode-plugins-official": true,
- },
- },
- });
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual([
- "control-browser",
- "diagnosing-plugins",
- "docx",
- "ios-simulator",
- "pdf",
- ]);
- expect(result.skills.map((skill) => skill.scope)).toEqual([
- "plugin",
- "plugin",
- "plugin",
- "plugin",
- "plugin",
- ]);
- expect(result.skills.map((skill) => skill.pluginName).sort()).toEqual([
- "browser-use",
- "documents",
- "documents",
- "ios-simulator",
- "zcode-guide",
- ]);
- expect(result.skills.find((skill) => skill.name === "android-emulator")).toBeUndefined();
- });
- it("suppressed 内置插件不贡献任何 skill", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const browserUsePluginRoot = officialPluginRoot(home, "browser-use");
- const documentPluginRoot = officialPluginRoot(home, "documents");
- const skillCreatorPluginRoot = officialPluginRoot(home, "skill-creator");
- const zcodeGuidePluginRoot = officialPluginRoot(home, "zcode-guide");
- writePluginManifest(browserUsePluginRoot, {
- name: "browser-use",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(documentPluginRoot, {
- name: "documents",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(skillCreatorPluginRoot, {
- name: "skill-creator",
- skills: "skills",
- version: "0.1.0",
- });
- writePluginManifest(zcodeGuidePluginRoot, {
- name: "zcode-guide",
- skills: "skills",
- version: "0.1.0",
- });
- writeSkill(
- join(browserUsePluginRoot, "skills"),
- "control-browser",
- `---
- name: control-browser
- description: browser skill
- ---
- browser-body`,
- );
- writeSkill(
- join(documentPluginRoot, "skills"),
- "docx",
- `---
- name: docx
- description: docx skill
- ---
- docx-body`,
- );
- writeSkill(
- join(skillCreatorPluginRoot, "skills"),
- "skill-creator",
- `---
- name: skill-creator
- description: skill creator skill
- ---
- creator-body`,
- );
- writeSkill(
- join(zcodeGuidePluginRoot, "skills"),
- "diagnosing-plugins",
- `---
- name: diagnosing-plugins
- description: Diagnose plugin discovery and enablement problems
- ---
- diagnosing-body`,
- );
- // browser、documents 和 zcode-guide 被卸载(suppressed),skill-creator 保持默认启用。
- writeCliConfig(home, {
- plugins: {
- suppressedBuiltins: [
- "browser-use@zcode-plugins-official",
- "documents@zcode-plugins-official",
- "zcode-guide@zcode-plugins-official",
- ],
- },
- });
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["skill-creator"]);
- expect(result.skills.find((skill) => skill.name === "control-browser")).toBeUndefined();
- expect(result.skills.find((skill) => skill.name === "docx")).toBeUndefined();
- expect(result.skills.find((skill) => skill.name === "diagnosing-plugins")).toBeUndefined();
- expect(result.skills.find((skill) => skill.pluginName === "browser")).toBeUndefined();
- expect(result.skills.find((skill) => skill.pluginName === "documents")).toBeUndefined();
- expect(result.skills.find((skill) => skill.pluginName === "zcode-guide")).toBeUndefined();
- });
- it("读取已安装 marketplace plugin 声明的技能目录", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const pluginRoot = marketplacePluginRoot(
- home,
- "claude-plugins-official",
- "amazon-location-service",
- );
- writeClaudePluginManifest(pluginRoot, {
- name: "amazon-location-service",
- skills: "skills",
- version: "1.0.0",
- });
- writeSkill(
- join(pluginRoot, "skills"),
- "amazon-location-service",
- `---
- name: amazon-location-service
- description: amazon location skill
- ---
- amazon-body`,
- );
- writeInstalledPluginRecord(home, {
- installPath: pluginRoot,
- marketplace: "claude-plugins-official",
- name: "amazon-location-service",
- });
- writeCliConfig(home, {
- plugins: {
- enabledPlugins: {
- "amazon-location-service@claude-plugins-official": true,
- },
- },
- });
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills).toEqual([
- expect.objectContaining({
- name: "amazon-location-service",
- pluginName: "amazon-location-service",
- pluginId: "amazon-location-service@claude-plugins-official",
- scope: "plugin",
- }),
- ]);
- });
- // Bugfix 回归(差一层目录):Claude 插件规范里 manifest skills 数组项指向「技能目录本身」
- // (项内直接是 SKILL.md),agent 端扫描已支持(adapters/src/skills/scan.ts);这里验证
- // 桌面 services 端技能列表对同一形态的消费,两端语义保持一致。
- it("读取 manifest skills 数组声明的插件技能(数组项即技能目录)", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const pluginRoot = marketplacePluginRoot(
- home,
- "claude-plugins-official",
- "mattpocock-skills",
- );
- writeClaudePluginManifest(pluginRoot, {
- name: "mattpocock-skills",
- skills: ["./skills/engineering/tdd", "./skills/productivity/tdd", "./skills/bundle-root"],
- version: "1.0.0",
- });
- // 数组项内直接是 SKILL.md;engineering/tdd 与 productivity/tdd 叶子同名但 frontmatter
- // name 不同,验证不被提前按目录名去重;bundle-root 验证「根自身即技能」规则。
- writeSkill(
- join(pluginRoot, "skills", "engineering", "tdd"),
- "tdd",
- `---
- name: tdd
- description: engineering tdd skill
- ---
- tdd-body`,
- );
- writeSkill(
- join(pluginRoot, "skills", "productivity", "tdd"),
- "productivity-tdd",
- `---
- name: productivity-tdd
- description: productivity tdd skill
- ---
- productivity-tdd-body`,
- );
- writeSkill(
- join(pluginRoot, "skills", "bundle-root"),
- "bundle-root",
- `---
- name: bundle-root
- description: skill whose SKILL.md sits directly in the declared root
- ---
- bundle-root-body`,
- );
- writeInstalledPluginRecord(home, {
- installPath: pluginRoot,
- marketplace: "claude-plugins-official",
- name: "mattpocock-skills",
- });
- writeCliConfig(home, {
- plugins: {
- enabledPlugins: {
- "mattpocock-skills@claude-plugins-official": true,
- },
- },
- });
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name).sort()).toEqual([
- "bundle-root",
- "productivity-tdd",
- "tdd",
- ]);
- for (const skill of result.skills) {
- expect(skill.pluginName).toBe("mattpocock-skills");
- expect(skill.scope).toBe("plugin");
- }
- });
- it("非桌面 runtime 不读取用户级技能", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- userSkillRoot(home),
- "zcode-global",
- `---
- name: zcode-global
- description: user zcode
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: false });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.capability).toEqual({
- userScopeAvailable: false,
- userScopeReason: "desktop_only",
- });
- expect(result.skills).toEqual([]);
- });
- // Windows 跳过:此测试失败原因是 CLI config 写入逻辑问题,非 Windows 特定
- const isWindows = process.platform === "win32";
- (isWindows ? it.skip : it)("setEnabled 会把技能开关按路径写入 CLI config 且不按 workspaceIdentity 隔离", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "repo-review",
- `---
- name: repo-review
- description: review
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({
- workspacePath,
- workspaceIdentity: "remote:ssh:a:/workspace",
- provider: "glm",
- });
- const skill = before.skills[0]!;
- await service.setEnabled({
- workspacePath,
- workspaceIdentity: "remote:ssh:a:/workspace",
- provider: "glm",
- scope: skill.scope,
- skillId: skill.id,
- enabled: false,
- });
- const disabled = await service.list({
- workspacePath,
- workspaceIdentity: "remote:ssh:a:/workspace",
- provider: "glm",
- });
- const enabled = await service.list({
- workspacePath,
- workspaceIdentity: "remote:ssh:b:/workspace",
- provider: "glm",
- });
- const config = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { skills?: Record<string, { enable?: boolean }> };
- expect(disabled.skills[0]?.enabled).toBe(false);
- expect(enabled.skills[0]?.enabled).toBe(false);
- expect(config.skills?.[skill.path]).toEqual({ enable: false });
- await service.setEnabled({
- workspacePath,
- workspaceIdentity: "remote:ssh:a:/workspace",
- provider: "glm",
- scope: skill.scope,
- skillId: skill.id,
- enabled: true,
- });
- const reenabled = await service.list({
- workspacePath,
- workspaceIdentity: "remote:ssh:a:/workspace",
- provider: "glm",
- });
- const reenabledConfig = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { skills?: Record<string, { enable?: boolean }> };
- expect(reenabled.skills[0]?.enabled).toBe(true);
- expect(reenabledConfig.skills?.[skill.path]).toBeUndefined();
- });
- it("读取旧版 skills-state.json 时不会迁移或写入旧状态文件", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const legacySkillId = "workspace:legacy-skill";
- const legacyStatePath = join(home, ".zcode", "v2", "skills-state.json");
- mkdirSync(join(home, ".zcode", "v2"), { recursive: true });
- writeFileSync(
- legacyStatePath,
- JSON.stringify({ disabledByWorkspace: { [workspacePath]: [legacySkillId] } }),
- "utf-8",
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- await service.list({ workspacePath, provider: "glm" });
- const state = JSON.parse(readFileSync(legacyStatePath, "utf-8")) as {
- disabledByWorkspace?: Record<string, string[]>;
- };
- expect(state.disabledByWorkspace).toEqual({ [workspacePath]: [legacySkillId] });
- expect(existsSync(join(home, ".zcode", "cli", "config.json"))).toBe(false);
- });
- it("buildPromptContext 只注入启用且被提及的技能正文", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "code-review",
- `---
- name: code-review
- description: Review code
- ---
- review-body`,
- );
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "plan-maker",
- `---
- name: plan-maker
- description: Make plans
- ---
- plan-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const context = await service.buildPromptContext({
- workspacePath,
- provider: "glm",
- prompt: "请先执行 $code-review",
- });
- expect(context.prompt).toContain("<available_skills>");
- expect(context.prompt).toContain("<activated_skill name=\"code-review\"");
- expect(context.prompt).toContain("review-body");
- expect(context.prompt).not.toContain("plan-body");
- expect(context.activatedSkillNames).toEqual(["code-review"]);
- expect(existsSync(join(home, ".zcode", "v2", "skills-audit.log"))).toBe(true);
- });
- it("被禁用的技能即便被提及也不会注入", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "code-review",
- `---
- name: code-review
- description: Review code
- ---
- review-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const list = await service.list({ workspacePath, provider: "glm" });
- await service.setEnabled({
- workspacePath,
- provider: "glm",
- scope: list.skills[0]!.scope,
- skillId: list.skills[0]!.id,
- enabled: false,
- });
- const context = await service.buildPromptContext({
- workspacePath,
- provider: "glm",
- prompt: "请先执行 $code-review",
- });
- expect(context.prompt).toBe("请先执行 $code-review");
- expect(context.activatedSkillNames).toEqual([]);
- });
- it("缺少 frontmatter 时用目录名加载且不产出诊断", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "no-frontmatter",
- "just markdown body without yaml header",
- );
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "good-skill",
- `---
- name: good-skill
- description: ok
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["good-skill", "no-frontmatter"]);
- expect(result.skills.find((skill) => skill.name === "no-frontmatter")?.description).toBe("");
- expect(result.skills.find((skill) => skill.name === "no-frontmatter")?.body).toBe(
- "just markdown body without yaml header",
- );
- expect(
- result.diagnostics.some(
- (diagnostic) =>
- diagnostic.code === "skill_missing_frontmatter" && diagnostic.severity === "error",
- ),
- ).toBe(false);
- });
- it("name 不符合 lowercase-hyphen 规范时仍按原 name 加载且不产出 warning", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "fallback-name",
- `---
- name: BadName_With_Caps
- description: bad name
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["BadName_With_Caps"]);
- expect(
- result.diagnostics.some(
- (diagnostic) =>
- diagnostic.code === "skill_invalid_name" && diagnostic.skillName === "BadName_With_Caps",
- ),
- ).toBe(false);
- });
- it("description 超过 1024 字符会产出 error 并跳过", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const longDescription = "a".repeat(1100);
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "too-long",
- `---
- name: too-long
- description: "${longDescription}"
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills).toEqual([]);
- expect(
- result.diagnostics.some((diagnostic) => diagnostic.code === "skill_description_too_long"),
- ).toBe(true);
- });
- it("未识别的 frontmatter key 不产出 warning 且 skill 仍可用", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "extra-key",
- `---
- name: extra-key
- description: ok
- unknown-field: hello
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["extra-key"]);
- expect(
- result.diagnostics.some(
- (diagnostic) =>
- diagnostic.code === "skill_unknown_frontmatter" &&
- diagnostic.message.includes("unknown-field"),
- ),
- ).toBe(false);
- });
- it("同名 skill 出现两次时按路径同时保留且不产出 duplicate warning", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "dup-first",
- `---
- name: shared-name
- description: first
- ---
- first-body`,
- );
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "dup-second",
- `---
- name: shared-name
- description: second
- ---
- second-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["shared-name", "shared-name"]);
- expect(result.skills.map((skill) => skill.path.replaceAll("\\", "/").split("/skills/").at(-1))).toEqual([
- "dup-first/SKILL.md",
- "dup-second/SKILL.md",
- ]);
- expect(
- result.diagnostics.some((diagnostic) => diagnostic.code === "skill_duplicate_name"),
- ).toBe(false);
- });
- it("worktree 内子目录扫描会向上汇集祖先 .zcode/skills", async () => {
- const home = makeTempHome();
- const repoRoot = join(home, "repo");
- mkdirSync(join(repoRoot, ".git"), { recursive: true });
- const childWorkspace = join(repoRoot, "packages", "child");
- writeSkill(
- workspaceSkillRoot(childWorkspace),
- "child-skill",
- `---
- name: child-skill
- description: scoped to child
- ---
- body`,
- );
- writeSkill(
- workspaceSkillRoot(repoRoot),
- "root-skill",
- `---
- name: root-skill
- description: scoped to repo root
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath: childWorkspace, provider: "glm" });
- expect(result.skills.map((skill) => skill.name).sort()).toEqual([
- "child-skill",
- "root-skill",
- ]);
- });
- it("deleteSkill 删除 .zcode/skills 工作区技能目录", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const skillDir = join(workspaceSkillRoot(workspacePath), "repo-review");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "repo-review",
- `---
- name: repo-review
- description: review
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- const skill = before.skills.find((s) => s.name === "repo-review")!;
- expect(existsSync(skillDir)).toBe(true);
- await service.deleteSkill({ workspacePath, skillId: skill.id });
- expect(existsSync(skillDir)).toBe(false);
- const after = await service.list({ workspacePath, provider: "glm" });
- expect(after.skills.find((s) => s.name === "repo-review")).toBeUndefined();
- });
- it.skipIf(process.platform === "win32")(
- "deleteSkill 删除用户级 ~/.zcode/skills 软链技能:只删链接、保留外部目标",
- async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const sourceParent = join(home, "external-agent", "skills");
- const sourceSkillDir = join(sourceParent, "cua-driver");
- const linkedSkillDir = join(userSkillRoot(home), "cua-driver");
- writeSkill(
- sourceParent,
- "cua-driver",
- `---
- name: cua-driver
- description: linked
- ---
- body`,
- );
- mkdirSync(userSkillRoot(home), { recursive: true });
- symlinkSync(sourceSkillDir, linkedSkillDir, "dir");
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- const skill = before.skills.find((s) => s.name === "cua-driver")!;
- expect(skill.scope).toBe("user");
- await service.deleteSkill({ workspacePath, skillId: skill.id });
- // 软链本体被删除
- expect(existsSync(linkedSkillDir)).toBe(false);
- // 外部目标目录及其 SKILL.md 完好无损
- expect(existsSync(sourceSkillDir)).toBe(true);
- expect(existsSync(join(sourceSkillDir, "SKILL.md"))).toBe(true);
- const after = await service.list({ workspacePath, provider: "glm" });
- expect(after.skills.find((s) => s.name === "cua-driver")).toBeUndefined();
- },
- );
- it.skipIf(process.platform === "win32")(
- "deleteSkill 删除工作区 .zcode/skills 软链技能:只删链接、保留外部目标",
- async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const sourceParent = join(home, "external-agent", "skills");
- const sourceSkillDir = join(sourceParent, "imported-skill");
- const linkedSkillDir = join(workspaceSkillRoot(workspacePath), "imported-skill");
- writeSkill(
- sourceParent,
- "imported-skill",
- `---
- name: imported-skill
- description: linked
- ---
- body`,
- );
- mkdirSync(workspaceSkillRoot(workspacePath), { recursive: true });
- symlinkSync(sourceSkillDir, linkedSkillDir, "dir");
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- const skill = before.skills.find((s) => s.name === "imported-skill")!;
- await service.deleteSkill({ workspacePath, skillId: skill.id });
- expect(existsSync(linkedSkillDir)).toBe(false);
- expect(existsSync(join(sourceSkillDir, "SKILL.md"))).toBe(true);
- const after = await service.list({ workspacePath, provider: "glm" });
- expect(after.skills.find((s) => s.name === "imported-skill")).toBeUndefined();
- },
- );
- it.skipIf(process.platform === "win32")(
- "deleteSkill 拒绝经由“软链祖先目录”删除,保护外部目标数据",
- async () => {
- // 用户把一整个外部目录软链进 ~/.zcode/skills(分组软链),
- // 其下的技能扫描时会被发现。删除时若顺着分组软链 rm,会删掉外部真实目录里的子技能——数据丢失。
- // 本用例断言这种情况被安全拦截:抛错、且外部目标完好。
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const externalGroup = join(home, "external-agent", "group");
- writeSkill(
- externalGroup,
- "nested-skill",
- `---
- name: nested-skill
- description: nested under a symlinked group dir
- ---
- body`,
- );
- mkdirSync(userSkillRoot(home), { recursive: true });
- // ~/.zcode/skills/mygroup -> /external-agent/group
- symlinkSync(externalGroup, join(userSkillRoot(home), "mygroup"), "dir");
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- const skill = before.skills.find((s) => s.name === "nested-skill")!;
- await expect(
- service.deleteSkill({ workspacePath, skillId: skill.id }),
- ).rejects.toThrow();
- // 外部目标目录及其 SKILL.md 必须完好无损
- expect(existsSync(join(externalGroup, "nested-skill", "SKILL.md"))).toBe(true);
- },
- );
- it("deleteSkill 删除用户级 ~/.agents/skills 技能(removeFromCommon 会拒绝的场景)", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const skillDir = join(userAgentsSkillRoot(home), "feishu-drive");
- writeSkill(
- userAgentsSkillRoot(home),
- "feishu-drive",
- `---
- name: feishu-drive
- description: drive
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- const skill = before.skills.find((s) => s.name === "feishu-drive")!;
- expect(skill.scope).toBe("user");
- expect(existsSync(skillDir)).toBe(true);
- await service.deleteSkill({ workspacePath, skillId: skill.id });
- expect(existsSync(skillDir)).toBe(false);
- const after = await service.list({ workspacePath, provider: "glm" });
- expect(after.skills.find((s) => s.name === "feishu-drive")).toBeUndefined();
- });
- it("deleteSkill 拒绝删除 plugin 作用域技能", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const pluginRoot = marketplacePluginRoot(
- home,
- "claude-plugins-official",
- "amazon-location-service",
- );
- writeClaudePluginManifest(pluginRoot, {
- name: "amazon-location-service",
- skills: "skills",
- version: "1.0.0",
- });
- const pluginSkillDir = join(pluginRoot, "skills", "amazon-location-service");
- writeSkill(
- join(pluginRoot, "skills"),
- "amazon-location-service",
- `---
- name: amazon-location-service
- description: amazon location skill
- ---
- amazon-body`,
- );
- writeInstalledPluginRecord(home, {
- installPath: pluginRoot,
- marketplace: "claude-plugins-official",
- name: "amazon-location-service",
- });
- writeCliConfig(home, {
- plugins: {
- enabledPlugins: {
- "amazon-location-service@claude-plugins-official": true,
- },
- },
- });
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- const skill = before.skills.find((s) => s.name === "amazon-location-service")!;
- expect(skill.scope).toBe("plugin");
- await expect(service.deleteSkill({ workspacePath, skillId: skill.id })).rejects.toThrow();
- // 插件技能目录不应被删除。
- expect(existsSync(pluginSkillDir)).toBe(true);
- });
- it("deleteSkill 对未知 skillId 抛错", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- writeSkill(
- workspaceSkillRoot(workspacePath),
- "repo-review",
- `---
- name: repo-review
- description: review
- ---
- body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- await expect(
- service.deleteSkill({ workspacePath, skillId: "does-not-exist" }),
- ).rejects.toThrow();
- });
- it("扫描技能根时跳过 node_modules 等内容目录", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const root = workspaceSkillRoot(workspacePath);
- // 真实技能。
- writeSkill(
- root,
- "real-skill",
- `---
- name: real-skill
- description: real
- ---
- real-body`,
- );
- // Bugfix(ZCT-2070384010482601984):node_modules 里携带的 SKILL.md 不应被发现,
- // 旧实现会整棵递归 node_modules,在 Windows 上把扫描放大到数十秒。
- writeSkill(
- join(root, "real-skill", "node_modules", "some-dep"),
- "skill",
- `---
- name: dep-skill
- description: should be ignored
- ---
- dep-body`,
- );
- // dist 同理排除。
- writeSkill(
- join(root, "dist"),
- "built",
- `---
- name: dist-skill
- description: should be ignored
- ---
- dist-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["real-skill"]);
- });
- it("分组目录(depth 2)内的技能仍可被发现", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const root = workspaceSkillRoot(workspacePath);
- writeSkill(
- join(root, "group-a"),
- "grouped-skill",
- `---
- name: grouped-skill
- description: grouped
- ---
- grouped-body`,
- );
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).toEqual(["grouped-skill"]);
- });
- it("超过最大扫描深度的技能不会被发现", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const root = workspaceSkillRoot(workspacePath);
- // 构造一条超过 MAX_SKILL_SCAN_DEPTH 的目录链,末端放一个 SKILL.md。
- const segments = Array.from({ length: MAX_SKILL_SCAN_DEPTH + 2 }, (_, index) => `lvl-${index}`);
- writeSkill(join(root, ...segments), "too-deep", `---
- name: too-deep
- description: beyond depth cap
- ---
- deep-body`);
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.skills.map((skill) => skill.name)).not.toContain("too-deep");
- });
- it.skipIf(process.platform === "win32")(
- "目录软链构成环时扫描可终止且不重复",
- async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- const root = workspaceSkillRoot(workspacePath);
- writeSkill(
- root,
- "cyclic-skill",
- `---
- name: cyclic-skill
- description: cyclic
- ---
- cyclic-body`,
- );
- // 在技能根内放一个指回根的软链,制造潜在环路。
- mkdirSync(root, { recursive: true });
- symlinkSync(root, join(root, "loop-back"), "dir");
- const service = await createSkillsServiceInEnv(home, { isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- // 不应卡死、不应重复列出同一技能。
- expect(result.skills.map((skill) => skill.name)).toEqual(["cyclic-skill"]);
- },
- );
- });
|