| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653 |
- import {
- existsSync,
- lstatSync,
- mkdirSync,
- mkdtempSync,
- readFileSync,
- rmSync,
- writeFileSync,
- } from "node:fs";
- import { tmpdir } from "node:os";
- import { dirname, join } from "node:path";
- import { afterEach, describe, expect, it, vi } from "vitest";
- import type { ISettingService } from "../src/setting/setting.js";
- const originalHome = process.env.HOME;
- const tempHomes: string[] = [];
- function makeTempHome(): string {
- const home = mkdtempSync(join(tmpdir(), "zcode-settings-sync-home-"));
- tempHomes.push(home);
- return home;
- }
- function writeSkill(rootPath: string, folder: string, body: string): void {
- const skillDir = join(rootPath, folder);
- mkdirSync(skillDir, { recursive: true });
- writeFileSync(join(skillDir, "SKILL.md"), body, "utf-8");
- }
- function writeCommand(rootPath: string, fileName: string, body: string): void {
- const filePath = join(rootPath, fileName);
- mkdirSync(dirname(filePath), { recursive: true });
- writeFileSync(filePath, body, "utf-8");
- }
- function writePlugin(
- rootPath: string,
- folder: string,
- manifest: Record<string, unknown>,
- manifestDir = ".zcode-plugin",
- ): string {
- const pluginDir = join(rootPath, folder);
- mkdirSync(join(pluginDir, manifestDir), { recursive: true });
- writeFileSync(join(pluginDir, manifestDir, "plugin.json"), JSON.stringify(manifest), "utf-8");
- return pluginDir;
- }
- function writeJsonConfig(filePath: string, value: Record<string, unknown>): void {
- mkdirSync(dirname(filePath), { recursive: true });
- writeFileSync(filePath, JSON.stringify(value, null, 2), "utf-8");
- }
- function writeTextConfig(filePath: string, value: string): void {
- mkdirSync(dirname(filePath), { recursive: true });
- writeFileSync(filePath, value, "utf-8");
- }
- function createSettingService(): ISettingService {
- return {
- async get() {
- return {};
- },
- async update() {},
- async updateDataBaseDir() {},
- };
- }
- afterEach(() => {
- process.env.HOME = originalHome;
- vi.resetModules();
- while (tempHomes.length > 0) {
- const home = tempHomes.pop();
- if (home) {
- rmSync(home, { recursive: true, force: true });
- }
- }
- });
- describe("settingsSyncService Provider 导入边界", () => {
- it("尚未实现 Provider 数据迁移时明确返回 skipped", async () => {
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(
- service.importSelected({
- selections: [{ agent: "claudeCode", category: "providers" }],
- }),
- ).resolves.toEqual({
- successCount: 0,
- skippedCount: 1,
- failedCount: 0,
- taskResults: [
- {
- agent: "claudeCode",
- category: "providers",
- status: "skipped",
- importedCount: 0,
- skippedCount: 1,
- failedCount: 0,
- },
- ],
- });
- });
- });
- describe("settingsSyncService Claude AGENTS.md migration", () => {
- it("copies Claude user memory into a fresh default ZCode AGENTS.md", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeTextConfig(join(home, ".claude", "CLAUDE.md"), "claude memory");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(service.getClaudeAgentsFileMigrationStatus({ workspacePath })).resolves.toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- sourceExists: true,
- targetExists: false,
- supported: true,
- });
- await expect(
- service.copyClaudeAgentsFileToZcodeAgentsFile({
- workspacePath,
- overwrite: false,
- }),
- ).resolves.toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- status: "copied",
- overwritten: false,
- });
- expect(readFileSync(join(home, ".zcode", "AGENTS.md"), "utf-8")).toBe("claude memory");
- });
- it("detects and overwrites default ZCode AGENTS.md from Claude user memory", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeTextConfig(join(home, ".claude", "CLAUDE.md"), "claude memory");
- writeTextConfig(join(home, ".zcode", "AGENTS.md"), "existing agents");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const status = await service.getClaudeAgentsFileMigrationStatus({ workspacePath });
- expect(status).toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- sourceExists: true,
- targetExists: true,
- supported: true,
- });
- await expect(
- service.copyClaudeAgentsFileToZcodeAgentsFile({
- workspacePath,
- overwrite: false,
- }),
- ).resolves.toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- status: "skipped",
- overwritten: false,
- skippedReason: "targetExists",
- });
- expect(readFileSync(join(home, ".zcode", "AGENTS.md"), "utf-8")).toBe("existing agents");
- await expect(
- service.copyClaudeAgentsFileToZcodeAgentsFile({
- workspacePath,
- overwrite: true,
- }),
- ).resolves.toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- status: "copied",
- overwritten: true,
- });
- expect(readFileSync(join(home, ".zcode", "AGENTS.md"), "utf-8")).toBe("claude memory");
- });
- it("reports missing Claude user memory as unsupported", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(service.getClaudeAgentsFileMigrationStatus({ workspacePath })).resolves.toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- sourceExists: false,
- targetExists: false,
- supported: false,
- unavailableReason: "missingSource",
- });
- await expect(
- service.copyClaudeAgentsFileToZcodeAgentsFile({
- workspacePath,
- overwrite: true,
- }),
- ).resolves.toEqual({
- sourcePath: join(home, ".claude", "CLAUDE.md"),
- targetPath: join(home, ".zcode", "AGENTS.md"),
- status: "skipped",
- overwritten: false,
- skippedReason: "missingSource",
- });
- });
- });
- describe("settingsSyncService commands import", () => {
- it("does not scan external commands during first-run detection", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeCommand(
- join(home, ".claude", "commands"),
- "review.md",
- "---\ndescription: review\n---\nreview body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(service.detect({ workspacePath })).resolves.toEqual({ agents: [] });
- });
- it("scans and imports selected user commands into ZCode as symlinks by default", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeCommand(
- join(home, ".claude", "commands"),
- "review.md",
- "---\ndescription: review\nargument-hint: <file>\n---\nreview body",
- );
- writeCommand(
- join(home, ".claude", "commands"),
- "Git/commit.md",
- "---\ndescription: commit\n---\ncommit body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["commands"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "claudeCode",
- discovered: true,
- categories: [
- {
- category: "commands",
- discoveredCount: 2,
- importableCount: 2,
- skippedCount: 0,
- sourcePaths: [join(home, ".claude", "commands")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".claude", "commands"),
- discoveredCount: 2,
- importableCount: 2,
- skippedCount: 0,
- commands: [
- {
- name: "/Git/commit",
- path: join(home, ".claude", "commands", "Git", "commit.md"),
- importable: true,
- description: "commit",
- },
- {
- name: "/review",
- path: join(home, ".claude", "commands", "review.md"),
- importable: true,
- description: "review",
- argumentHint: "<file>",
- },
- ],
- },
- ],
- selectedByDefault: false,
- },
- ],
- },
- ]);
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "claudeCode", category: "commands" }],
- });
- const importedPath = join(home, ".zcode", "commands", "review.md");
- expect(result.successCount).toBe(2);
- expect(result.skippedCount).toBe(0);
- expect(result.failedCount).toBe(0);
- expect(result.taskResults[0]?.commandResults).toEqual([
- {
- name: "/Git/commit",
- path: join(home, ".claude", "commands", "Git", "commit.md"),
- sourceScope: "global",
- status: "imported",
- },
- {
- name: "/review",
- path: join(home, ".claude", "commands", "review.md"),
- sourceScope: "global",
- status: "imported",
- },
- ]);
- expect(existsSync(importedPath)).toBe(true);
- // Windows 使用硬链接(普通文件),非 Windows 使用 symlink
- if (process.platform === "win32") {
- expect(lstatSync(importedPath).isFile()).toBe(true);
- } else {
- expect(lstatSync(importedPath).isSymbolicLink()).toBe(true);
- }
- expect(readFileSync(importedPath, "utf-8")).toContain("review body");
- expect(existsSync(join(home, ".zcode", "commands", "Git", "commit.md"))).toBe(true);
- });
- it("scans global Claude commands without an active workspace", async () => {
- const home = makeTempHome();
- process.env.HOME = home;
- writeCommand(join(home, ".claude", "commands"), "dev.md", "dev body");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- categories: ["commands"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "claudeCode",
- discovered: true,
- categories: [
- {
- category: "commands",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(home, ".claude", "commands")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".claude", "commands"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- commands: [
- {
- name: "/dev",
- path: join(home, ".claude", "commands", "dev.md"),
- importable: true,
- },
- ],
- },
- ],
- selectedByDefault: false,
- },
- ],
- },
- ]);
- });
- it("imports only selected command paths from a source", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeCommand(join(home, ".codex", "commands"), "review.md", "review body");
- writeCommand(join(home, ".codex", "commands"), "write.md", "write body");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "codexCli",
- category: "commands",
- sourceScope: "global",
- commandPaths: [join(home, ".codex", "commands", "write.md")],
- },
- ],
- });
- expect(result.successCount).toBe(1);
- expect(existsSync(join(home, ".zcode", "commands", "write.md"))).toBe(true);
- expect(existsSync(join(home, ".zcode", "commands", "review.md"))).toBe(false);
- });
- it("imports selected commands into the requested project target as copies", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeCommand(join(home, ".qwen", "commands"), "review/code.md", "review body");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "qwenCode",
- category: "commands",
- sourceScope: "global",
- targetScope: "project",
- importMode: "copy",
- commandPaths: [join(home, ".qwen", "commands", "review", "code.md")],
- },
- ],
- });
- const importedPath = join(workspacePath, ".zcode", "commands", "review", "code.md");
- expect(result.successCount).toBe(1);
- expect(existsSync(importedPath)).toBe(true);
- expect(lstatSync(importedPath).isSymbolicLink()).toBe(false);
- expect(readFileSync(importedPath, "utf-8")).toContain("review body");
- expect(existsSync(join(home, ".zcode", "commands", "review", "code.md"))).toBe(false);
- });
- it("does not scan .agents commands for import", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeCommand(join(home, ".agents", "commands"), "already.md", "already");
- writeCommand(join(workspacePath, ".agents", "commands"), "project.md", "project");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(
- service.detect({
- workspacePath,
- categories: ["commands"],
- intent: "manualImport",
- }),
- ).resolves.toEqual({ agents: [] });
- });
- it("skips command imports when target file or same command name exists", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeCommand(join(home, ".claude", "commands"), "review.md", "source");
- writeCommand(join(home, ".codex", "commands"), "other-review.md", "source");
- writeCommand(join(home, ".zcode", "commands"), "review.md", "existing");
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["commands"],
- intent: "manualImport",
- });
- expect(discovery.agents[0]?.categories[0]?.sourceRoots?.[0]?.commands).toEqual([
- {
- name: "/review",
- path: join(home, ".claude", "commands", "review.md"),
- importable: false,
- skipReason: "targetExists",
- },
- ]);
- expect(discovery.agents[1]?.categories[0]?.sourceRoots?.[0]?.commands).toEqual([
- {
- name: "/other-review",
- path: join(home, ".codex", "commands", "other-review.md"),
- importable: true,
- },
- ]);
- writeCommand(join(home, ".zcode", "commands"), "other-review.md", "existing");
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "codexCli", category: "commands" }],
- });
- expect(result.successCount).toBe(0);
- expect(result.skippedCount).toBe(1);
- expect(result.taskResults[0]?.commandResults).toEqual([
- {
- name: "/other-review",
- path: join(home, ".codex", "commands", "other-review.md"),
- sourceScope: "global",
- status: "skipped",
- skipReason: "targetExists",
- },
- ]);
- });
- });
- describe("settingsSyncService plugins import", () => {
- it("does not scan external plugins during first-run detection", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writePlugin(join(home, ".claude", "plugins"), "review-plugin", {
- name: "review-plugin",
- });
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(service.detect({ workspacePath })).resolves.toEqual({ agents: [] });
- });
- it("scans and imports selected user plugins as symlinks by default", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- const pluginPath = writePlugin(join(home, ".claude", "plugins"), "review-plugin", {
- name: "review-plugin",
- version: "1.2.3",
- description: "review",
- });
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["plugins"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "claudeCode",
- discovered: true,
- categories: [
- {
- category: "plugins",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(home, ".claude", "plugins")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".claude", "plugins"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- plugins: [
- {
- name: "review-plugin",
- path: pluginPath,
- importable: true,
- version: "1.2.3",
- },
- ],
- },
- ],
- selectedByDefault: false,
- },
- ],
- },
- ]);
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "claudeCode", category: "plugins" }],
- });
- const importedPath = join(home, ".zcode", "plugins", "review-plugin");
- const config = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { plugins?: { dirs?: string[] } };
- expect(result.successCount).toBe(1);
- expect(result.skippedCount).toBe(0);
- expect(result.failedCount).toBe(0);
- expect(result.taskResults[0]?.pluginResults).toEqual([
- {
- name: "review-plugin",
- path: pluginPath,
- sourceScope: "global",
- status: "imported",
- version: "1.2.3",
- },
- ]);
- expect(existsSync(join(importedPath, ".zcode-plugin", "plugin.json"))).toBe(true);
- expect(lstatSync(importedPath).isSymbolicLink()).toBe(true);
- expect(config.plugins?.dirs).toEqual([importedPath]);
- });
- it("imports Claude-manifest plugins into the requested project target as copies", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- const pluginPath = writePlugin(
- join(home, ".codex", "plugins"),
- "writer-plugin",
- { name: "writer-plugin" },
- ".claude-plugin",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "codexCli",
- category: "plugins",
- sourceScope: "global",
- targetScope: "project",
- importMode: "copy",
- pluginPaths: [pluginPath],
- },
- ],
- });
- const importedPath = join(workspacePath, ".zcode", "plugins", "writer-plugin");
- const config = JSON.parse(
- readFileSync(join(workspacePath, ".zcode", "config.json"), "utf-8"),
- ) as { plugins?: { dirs?: string[] } };
- expect(result.successCount).toBe(1);
- expect(lstatSync(importedPath).isSymbolicLink()).toBe(false);
- expect(existsSync(join(importedPath, ".claude-plugin", "plugin.json"))).toBe(true);
- expect(config.plugins?.dirs).toEqual([importedPath]);
- expect(existsSync(join(home, ".zcode", "plugins", "writer-plugin"))).toBe(false);
- });
- it("skips plugin imports when target directory or same plugin id exists", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writePlugin(join(home, ".claude", "plugins"), "review-plugin", {
- name: "review-plugin",
- });
- writePlugin(join(home, ".codex", "plugins"), "other-review", {
- name: "other-review",
- });
- writePlugin(join(home, ".zcode", "plugins"), "review-plugin", {
- name: "review-plugin",
- });
- const configuredPluginPath = writePlugin(join(home, "configured"), "other-review", {
- name: "other-review",
- });
- mkdirSync(join(home, ".zcode", "cli"), { recursive: true });
- writeFileSync(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({ plugins: { dirs: [configuredPluginPath] } }),
- "utf-8",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["plugins"],
- intent: "manualImport",
- });
- expect(discovery.agents[0]?.categories[0]?.sourceRoots?.[0]?.plugins).toEqual([
- {
- name: "review-plugin",
- path: join(home, ".claude", "plugins", "review-plugin"),
- importable: false,
- skipReason: "targetExists",
- },
- ]);
- expect(discovery.agents[1]?.categories[0]?.sourceRoots?.[0]?.plugins).toEqual([
- {
- name: "other-review",
- path: join(home, ".codex", "plugins", "other-review"),
- importable: false,
- skipReason: "sameNameExists",
- },
- ]);
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "codexCli", category: "plugins" }],
- });
- expect(result.successCount).toBe(0);
- expect(result.skippedCount).toBe(1);
- expect(result.taskResults[0]?.pluginResults).toEqual([
- {
- name: "other-review",
- path: join(home, ".codex", "plugins", "other-review"),
- sourceScope: "global",
- status: "skipped",
- skipReason: "sameNameExists",
- },
- ]);
- });
- });
- describe("settingsSyncService MCP server import", () => {
- it("does not scan external MCP servers during first-run detection", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeJsonConfig(join(home, ".claude", "settings.json"), {
- mcpServers: {
- browser: { command: "npx", args: ["-y", "browser-mcp"], timeout: 30 },
- },
- });
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(service.detect({ workspacePath })).resolves.toEqual({ agents: [] });
- });
- it("scans and imports selected Claude MCP servers into global ZCode config", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeJsonConfig(join(home, ".claude", "settings.json"), {
- mcpServers: {
- browser: { command: "npx", args: ["-y", "browser-mcp"] },
- },
- });
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["mcpServers"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "claudeCode",
- discovered: true,
- categories: [
- {
- category: "mcpServers",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(home, ".claude", "settings.json")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".claude", "settings.json"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- mcpServers: [
- {
- name: "browser",
- path: `${join(home, ".claude", "settings.json")}#browser`,
- importable: true,
- },
- ],
- },
- ],
- selectedByDefault: false,
- },
- ],
- },
- ]);
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "claudeCode",
- category: "mcpServers",
- mcpServerPaths: [`${join(home, ".claude", "settings.json")}#browser`],
- },
- ],
- });
- const config = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { mcp?: { servers?: Record<string, unknown> } };
- expect(result.successCount).toBe(1);
- expect(result.skippedCount).toBe(0);
- expect(result.taskResults[0]?.mcpServerResults).toEqual([
- {
- name: "browser",
- path: `${join(home, ".claude", "settings.json")}#browser`,
- sourceScope: "global",
- status: "imported",
- },
- ]);
- expect(config.mcp?.servers?.browser).toEqual({
- command: "npx",
- args: ["-y", "browser-mcp"],
- });
- });
- it("does not migrate external MCP timeout fields", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeTextConfig(
- join(home, ".codex", "config.toml"),
- [
- "[mcp_servers.context7]",
- 'command = "npx"',
- 'args = ["-y", "@upstash/context7-mcp"]',
- "startup_timeout_sec = 120",
- "timeout = 30",
- ].join("\n"),
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "codexCli", category: "mcpServers" }],
- });
- const config = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { mcp?: { servers?: Record<string, unknown> } };
- expect(result.successCount).toBe(1);
- expect(config.mcp?.servers?.context7).toEqual({
- command: "npx",
- args: ["-y", "@upstash/context7-mcp"],
- });
- });
- it("imports Codex TOML MCP servers into the requested project target", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeTextConfig(
- join(home, ".codex", "config.toml"),
- ["[mcp_servers.context7]", 'command = "npx"', 'args = ["-y", "@upstash/context7-mcp"]'].join(
- "\n",
- ),
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "codexCli",
- category: "mcpServers",
- sourceScope: "global",
- targetScope: "project",
- },
- ],
- });
- const config = JSON.parse(
- readFileSync(join(workspacePath, ".zcode", "config.json"), "utf-8"),
- ) as { mcp?: { servers?: Record<string, unknown> } };
- expect(result.successCount).toBe(1);
- expect(config.mcp?.servers?.context7).toEqual({
- command: "npx",
- args: ["-y", "@upstash/context7-mcp"],
- });
- expect(existsSync(join(home, ".zcode", "cli", "config.json"))).toBe(false);
- });
- it("normalizes OpenCode command arrays when importing MCP servers", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeJsonConfig(join(home, ".config", "opencode", "opencode.json"), {
- mcp: {
- browser: {
- type: "local",
- command: ["npx", "-y", "browser-mcp"],
- env: { DEBUG: "1" },
- },
- },
- });
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "openCode", category: "mcpServers" }],
- });
- const config = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { mcp?: { servers?: Record<string, unknown> } };
- expect(result.successCount).toBe(1);
- expect(config.mcp?.servers?.browser).toEqual({
- type: "stdio",
- command: "npx",
- args: ["-y", "browser-mcp"],
- env: { DEBUG: "1" },
- });
- });
- it("skips imported MCP servers when the target already has the same name", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeJsonConfig(join(home, ".claude", "settings.json"), {
- mcpServers: {
- browser: { command: "external" },
- },
- });
- writeJsonConfig(join(home, ".zcode", "cli", "config.json"), {
- mcp: {
- servers: {
- browser: { command: "existing" },
- },
- },
- });
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["mcpServers"],
- intent: "manualImport",
- });
- expect(discovery.agents[0]?.categories[0]?.sourceRoots?.[0]?.mcpServers).toEqual([
- {
- name: "browser",
- path: `${join(home, ".claude", "settings.json")}#browser`,
- importable: false,
- skipReason: "sameNameExists",
- },
- ]);
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "claudeCode", category: "mcpServers" }],
- });
- const config = JSON.parse(
- readFileSync(join(home, ".zcode", "cli", "config.json"), "utf-8"),
- ) as { mcp?: { servers?: Record<string, unknown> } };
- expect(result.successCount).toBe(0);
- expect(result.skippedCount).toBe(1);
- expect(config.mcp?.servers?.browser).toEqual({ command: "existing" });
- });
- });
- describe("settingsSyncService skills import", () => {
- it("uses platform-specific directory symlink types", async () => {
- const { getSkillDirectorySymlinkType } =
- await import("../src/settings-sync/settingsSyncService.js");
- expect(getSkillDirectorySymlinkType("darwin")).toBe("dir");
- expect(getSkillDirectorySymlinkType("linux")).toBe("dir");
- expect(getSkillDirectorySymlinkType("win32")).toBe("junction");
- });
- it("does not scan external skills during first-run detection", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "review",
- "---\nname: review\nversion: 1.2.3\ndescription: review\n---\nbody",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(service.detect({ workspacePath })).resolves.toEqual({ agents: [] });
- });
- it("imports selected user skills into the ZCode user skills directory as symlinks by default", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "review",
- "---\nname: review\nversion: 1.2.3\ndescription: review\n---\nbody",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["skills"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "claudeCode",
- discovered: true,
- categories: [
- {
- category: "skills",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(home, ".claude", "skills")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".claude", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- skills: [
- {
- name: "review",
- path: join(home, ".claude", "skills", "review"),
- importable: true,
- version: "1.2.3",
- },
- ],
- },
- ],
- selectedByDefault: true,
- },
- ],
- },
- ]);
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "claudeCode", category: "skills" }],
- });
- expect(result.successCount).toBe(1);
- expect(result.skippedCount).toBe(0);
- expect(result.failedCount).toBe(0);
- expect(result.taskResults[0]?.skillResults).toEqual([
- {
- name: "review",
- path: join(home, ".claude", "skills", "review"),
- sourceScope: "global",
- status: "imported",
- version: "1.2.3",
- },
- ]);
- const importedDirectoryPath = join(home, ".zcode", "skills", "review");
- const importedPath = join(importedDirectoryPath, "SKILL.md");
- expect(existsSync(importedPath)).toBe(true);
- expect(lstatSync(importedDirectoryPath).isSymbolicLink()).toBe(true);
- expect(readFileSync(importedPath, "utf-8")).toContain("name: review");
- expect(readFileSync(importedPath, "utf-8")).toContain("version: 1.2.3");
- });
- it("imports only selected skill paths from a source", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "review",
- "---\nname: review\ndescription: review\n---\nreview-body",
- );
- writeSkill(
- join(home, ".claude", "skills"),
- "writer",
- "---\nname: writer\ndescription: writer\n---\nwriter-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "claudeCode",
- category: "skills",
- sourceScope: "global",
- skillPaths: [join(home, ".claude", "skills", "writer")],
- },
- ],
- });
- expect(result.successCount).toBe(1);
- expect(result.skippedCount).toBe(0);
- expect(result.failedCount).toBe(0);
- expect(existsSync(join(home, ".zcode", "skills", "writer", "SKILL.md"))).toBe(true);
- expect(existsSync(join(home, ".zcode", "skills", "review", "SKILL.md"))).toBe(false);
- });
- it("imports selected skills into the requested project target", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "review",
- "---\nname: review\ndescription: review\n---\nreview-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "claudeCode",
- category: "skills",
- sourceScope: "global",
- targetScope: "project",
- skillPaths: [join(home, ".claude", "skills", "review")],
- },
- ],
- });
- expect(result.successCount).toBe(1);
- expect(result.skippedCount).toBe(0);
- expect(result.failedCount).toBe(0);
- expect(existsSync(join(workspacePath, ".zcode", "skills", "review", "SKILL.md"))).toBe(true);
- expect(existsSync(join(home, ".zcode", "skills", "review", "SKILL.md"))).toBe(false);
- });
- it("can import selected skills as symlinks", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "linked-review",
- "---\nname: linked-review\ndescription: review\n---\nreview-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "claudeCode",
- category: "skills",
- sourceScope: "global",
- importMode: "symlink",
- skillPaths: [join(home, ".claude", "skills", "linked-review")],
- },
- ],
- });
- const targetPath = join(home, ".zcode", "skills", "linked-review");
- expect(result.successCount).toBe(1);
- expect(lstatSync(targetPath).isSymbolicLink()).toBe(true);
- expect(readFileSync(join(targetPath, "SKILL.md"), "utf-8")).toContain("linked-review");
- });
- it("can import selected skills as copies when requested", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "copied-review",
- "---\nname: copied-review\ndescription: review\n---\nreview-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [
- {
- agent: "claudeCode",
- category: "skills",
- sourceScope: "global",
- importMode: "copy",
- skillPaths: [join(home, ".claude", "skills", "copied-review")],
- },
- ],
- });
- const targetPath = join(home, ".zcode", "skills", "copied-review");
- expect(result.successCount).toBe(1);
- expect(lstatSync(targetPath).isSymbolicLink()).toBe(false);
- expect(readFileSync(join(targetPath, "SKILL.md"), "utf-8")).toContain("copied-review");
- });
- it("scans and imports global skills without an active workspace", async () => {
- const home = makeTempHome();
- process.env.HOME = home;
- writeSkill(
- join(home, ".codex", "skills"),
- "commit-helper",
- "---\nname: commit-helper\ndescription: commit\n---\nbody",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- categories: ["skills"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "codexCli",
- discovered: true,
- categories: [
- {
- category: "skills",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(home, ".codex", "skills")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".codex", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- skills: [
- {
- name: "commit-helper",
- path: join(home, ".codex", "skills", "commit-helper"),
- importable: true,
- },
- ],
- },
- ],
- selectedByDefault: true,
- },
- ],
- },
- ]);
- const result = await service.importSelected({
- selections: [{ agent: "codexCli", category: "skills" }],
- });
- expect(result.successCount).toBe(1);
- expect(existsSync(join(home, ".zcode", "skills", "commit-helper", "SKILL.md"))).toBe(true);
- });
- it("does not scan .agents skills for import", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".agents", "skills"),
- "already-readable",
- "---\nname: already-readable\ndescription: agents\n---\nbody",
- );
- writeSkill(
- join(workspacePath, ".agents", "skills"),
- "project-readable",
- "---\nname: project-readable\ndescription: project agents\n---\nbody",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- await expect(
- service.detect({
- workspacePath,
- categories: ["skills"],
- intent: "manualImport",
- }),
- ).resolves.toEqual({ agents: [] });
- });
- it("scans newly supported non-.agents skill roots", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".codeium", "windsurf", "skills"),
- "wave",
- "---\nname: wave\ndescription: windsurf\n---\nbody",
- );
- writeSkill(
- join(home, ".openclaw", "skills"),
- "claw",
- "---\nname: claw\ndescription: openclaw\n---\nbody",
- );
- writeSkill(
- join(home, ".qwen", "skills"),
- "qwen-skill",
- "---\nname: qwen-skill\ndescription: qwen code\n---\nbody",
- );
- writeSkill(
- join(home, ".qoder", "skills"),
- "qode-skill",
- "---\nname: qode-skill\ndescription: qode\n---\nbody",
- );
- writeSkill(
- join(home, ".qoder-cn", "skills"),
- "qode-cn-skill",
- "---\nname: qode-cn-skill\ndescription: qode cn\n---\nbody",
- );
- writeSkill(
- join(home, ".trae-cn", "skills"),
- "trae-cn-skill",
- "---\nname: trae-cn-skill\ndescription: trae cn\n---\nbody",
- );
- writeSkill(
- join(workspacePath, ".codebuddy", "skills"),
- "buddy",
- "---\nname: buddy\ndescription: codebuddy\n---\nbody",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["skills"],
- intent: "manualImport",
- });
- expect(discovery.agents.map((agent) => agent.agent)).toEqual([
- "openClaw",
- "qwenCode",
- "qode",
- "qodeCn",
- "windsurf",
- "traeCn",
- "codeBuddy",
- ]);
- expect(discovery.agents[0]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "global",
- path: join(home, ".openclaw", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- expect(discovery.agents[1]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "global",
- path: join(home, ".qwen", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- expect(discovery.agents[2]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "global",
- path: join(home, ".qoder", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- expect(discovery.agents[3]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "global",
- path: join(home, ".qoder-cn", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- expect(discovery.agents[4]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "global",
- path: join(home, ".codeium", "windsurf", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- expect(discovery.agents[5]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "global",
- path: join(home, ".trae-cn", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- expect(discovery.agents[6]?.categories[0]?.sourceRoots?.[0]).toMatchObject({
- scope: "project",
- path: join(workspacePath, ".codebuddy", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- });
- });
- it("imports workspace-level Codex skills but skips same-name target directories", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(workspacePath, ".codex", "skills"),
- "review",
- "---\nname: review\ndescription: source\n---\nsource-body",
- );
- writeSkill(
- join(workspacePath, ".zcode", "skills"),
- "review",
- "---\nname: review\ndescription: existing\n---\nexisting-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "codexCli", category: "skills", sourceScope: "project" }],
- });
- expect(result.successCount).toBe(0);
- expect(result.skippedCount).toBe(1);
- expect(result.failedCount).toBe(0);
- expect(result.taskResults[0]?.skillResults).toEqual([
- {
- name: "review",
- path: join(workspacePath, ".codex", "skills", "review"),
- sourceScope: "project",
- status: "skipped",
- skipReason: "targetExists",
- },
- ]);
- expect(
- readFileSync(join(workspacePath, ".zcode", "skills", "review", "SKILL.md"), "utf-8"),
- ).toContain("existing-body");
- });
- it("classifies workspace-level skill roots as project sources", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(workspacePath, ".claude", "skills"),
- "repo-review",
- "---\nname: repo-review\ndescription: project claude\n---\nbody",
- );
- writeSkill(
- join(workspacePath, ".codex", "skills"),
- "repo-helper",
- "---\nname: repo-helper\ndescription: project codex\n---\nbody",
- );
- writeSkill(
- join(workspacePath, ".opencode", "skills"),
- "repo-automation",
- "---\nname: repo-automation\ndescription: project opencode\n---\nbody",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["skills"],
- intent: "manualImport",
- });
- expect(discovery.agents).toEqual([
- {
- agent: "claudeCode",
- discovered: true,
- categories: [
- {
- category: "skills",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(workspacePath, ".claude", "skills")],
- sourceRoots: [
- {
- scope: "project",
- path: join(workspacePath, ".claude", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- skills: [
- {
- name: "repo-review",
- path: join(workspacePath, ".claude", "skills", "repo-review"),
- importable: true,
- },
- ],
- },
- ],
- selectedByDefault: true,
- },
- ],
- },
- {
- agent: "codexCli",
- discovered: true,
- categories: [
- {
- category: "skills",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(workspacePath, ".codex", "skills")],
- sourceRoots: [
- {
- scope: "project",
- path: join(workspacePath, ".codex", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- skills: [
- {
- name: "repo-helper",
- path: join(workspacePath, ".codex", "skills", "repo-helper"),
- importable: true,
- },
- ],
- },
- ],
- selectedByDefault: true,
- },
- ],
- },
- {
- agent: "openCode",
- discovered: true,
- categories: [
- {
- category: "skills",
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- sourcePaths: [join(workspacePath, ".opencode", "skills")],
- sourceRoots: [
- {
- scope: "project",
- path: join(workspacePath, ".opencode", "skills"),
- discoveredCount: 1,
- importableCount: 1,
- skippedCount: 0,
- skills: [
- {
- name: "repo-automation",
- path: join(workspacePath, ".opencode", "skills", "repo-automation"),
- importable: true,
- },
- ],
- },
- ],
- selectedByDefault: true,
- },
- ],
- },
- ]);
- });
- it("skips imported skills when an existing ZCode skill has the same name", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".codex", "skills"),
- "external-review",
- "---\nname: review\ndescription: source\n---\nsource-body",
- );
- writeSkill(
- join(home, ".zcode", "skills"),
- "current-review",
- "---\nname: review\ndescription: existing\n---\nexisting-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["skills"],
- intent: "manualImport",
- });
- expect(discovery.agents[0]?.categories[0]).toMatchObject({
- discoveredCount: 1,
- importableCount: 0,
- skippedCount: 1,
- sourcePaths: [join(home, ".codex", "skills")],
- sourceRoots: [
- {
- scope: "global",
- path: join(home, ".codex", "skills"),
- discoveredCount: 1,
- importableCount: 0,
- skippedCount: 1,
- skills: [
- {
- name: "review",
- path: join(home, ".codex", "skills", "external-review"),
- importable: false,
- skipReason: "sameNameExists",
- },
- ],
- },
- ],
- selectedByDefault: false,
- });
- const result = await service.importSelected({
- workspacePath,
- selections: [{ agent: "codexCli", category: "skills" }],
- });
- expect(result.successCount).toBe(0);
- expect(result.skippedCount).toBe(1);
- expect(result.failedCount).toBe(0);
- expect(result.taskResults[0]?.skillResults).toEqual([
- {
- name: "review",
- path: join(home, ".codex", "skills", "external-review"),
- sourceScope: "global",
- status: "skipped",
- skipReason: "sameNameExists",
- },
- ]);
- expect(existsSync(join(home, ".zcode", "skills", "external-review"))).toBe(false);
- expect(
- readFileSync(join(home, ".zcode", "skills", "current-review", "SKILL.md"), "utf-8"),
- ).toContain("existing-body");
- });
- it("reports target directory conflicts as skip reasons", async () => {
- const home = makeTempHome();
- const workspacePath = join(home, "workspace");
- process.env.HOME = home;
- writeSkill(
- join(home, ".claude", "skills"),
- "review",
- "---\nname: external-review\ndescription: source\n---\nsource-body",
- );
- writeSkill(
- join(home, ".zcode", "skills"),
- "review",
- "---\nname: existing-review\ndescription: existing\n---\nexisting-body",
- );
- const { createSettingsSyncService } =
- await import("../src/settings-sync/settingsSyncService.js");
- const service = createSettingsSyncService({ settingService: createSettingService() });
- const discovery = await service.detect({
- workspacePath,
- categories: ["skills"],
- intent: "manualImport",
- });
- expect(discovery.agents[0]?.categories[0]?.sourceRoots?.[0]?.skills).toEqual([
- {
- name: "external-review",
- path: join(home, ".claude", "skills", "review"),
- importable: false,
- skipReason: "targetExists",
- },
- ]);
- });
- });
|