| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607 |
- 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() {},
- async ensureDefaultProject(path: string) {
- return { path, created: false };
- },
- };
- }
- 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("uses file symlink type for command imports", async () => {
- const { getCommandFileSymlinkType } = await import(
- "../src/settings-sync/settingsSyncService.js"
- );
- expect(getCommandFileSymlinkType()).toBe("file");
- });
- 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",
- }]);
- });
- });
|