From 3a30b10bad667d00ea9cbbe34940c7f4c8b35185 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 22 Nov 2026 21:07:02 +0000 Subject: [PATCH] fix: honour dryRun on MCP exportSkills sync action Pass dryRun through HarnessSyncActionService exportSkills and preview would-be skill exports in SkillExportService without touching disk. Add regression tests for harness and MCP surfaces. Co-authored-by: Vinicius Lana --- CHANGELOG.md | 1 + .../__tests__/syncActionService.test.ts | 28 +++++++++++++++++++ .../__tests__/skillExportService.test.ts | 25 +++++++++++++++++ .../exchange/export/skillExportService.ts | 15 +++++++++- .../application/exchange/syncActionService.ts | 4 ++- src/mcp/gateway/__tests__/sync.test.ts | 27 ++++++++++++++++++ src/mcp/server/mcpServer.ts | 2 +- 7 files changed, 99 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0033e5e..f27bf695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Stabilized the `tests-passing` Jest result projector heap regression test by running Jest with `--expose-gc` and asserting median post-GC retained heap growth instead of a single pre-GC delta. - Routed PREVC phase auto-commit diagnostics to stderr and installed an MCP stdio console guard so non-protocol output cannot corrupt JSON-RPC on stdout (fixes MCP client disconnect on phase completion). +- Honoured `dryRun` on MCP `exportSkills` sync actions so previews no longer write skill export files to the repository. - Removed MCP response-body reparsing from action logging and replaced oversized response truncation risk with typed smaller-page or artifact-reference responses. - Applied the same bounded UTF-8 budget to every MCP resource, rejected oversized files before reading their bodies, enforced action-specific list maxima, and paginated `explore` file listings. - Bounded `explore` reads before file materialization and replaced whole-glob/whole-file code search with byte-capped streaming discovery, search, and cursor pages. diff --git a/src/harness/application/exchange/__tests__/syncActionService.test.ts b/src/harness/application/exchange/__tests__/syncActionService.test.ts index 54a4d9ff..805bf5c3 100644 --- a/src/harness/application/exchange/__tests__/syncActionService.test.ts +++ b/src/harness/application/exchange/__tests__/syncActionService.test.ts @@ -4,6 +4,13 @@ import * as path from 'path'; import { HarnessSyncActionService } from '../syncActionService'; +const EXPORT_MARKER_DIRS = ['.claude', '.codex', '.gemini', '.windsurf', '.github', '.agents'] as const; + +async function listExportMarkerDirs(repoPath: string): Promise { + const entries = await fs.readdir(repoPath); + return entries.filter((entry) => EXPORT_MARKER_DIRS.includes(entry as (typeof EXPORT_MARKER_DIRS)[number])); +} + describe('HarnessSyncActionService', () => { let tempDir: string; let service: HarnessSyncActionService; @@ -30,4 +37,25 @@ describe('HarnessSyncActionService', () => { expect(result.dryRun).toBe(true); expect(result.filesSkipped).toBeGreaterThan(0); }); + + it('exportSkills dry run previews without creating export directories', async () => { + await fs.outputFile( + path.join(tempDir, '.context', 'skills', 'sample', 'SKILL.md'), + '---\nname: sample\ndescription: Sample skill\n---\n# Sample\n' + ); + + const before = await listExportMarkerDirs(tempDir); + const result = await service.execute({ + action: 'exportSkills', + preset: 'claude', + dryRun: true, + }); + const after = await listExportMarkerDirs(tempDir); + + expect(before).toEqual(after); + expect(result.dryRun).toBe(true); + expect(result.success).toBe(true); + expect(result.filesCreated).toBeGreaterThan(0); + expect(result.skillsExported).toContain('sample'); + }); }); diff --git a/src/harness/application/exchange/export/__tests__/skillExportService.test.ts b/src/harness/application/exchange/export/__tests__/skillExportService.test.ts index ac78efac..4fca8b6d 100644 --- a/src/harness/application/exchange/export/__tests__/skillExportService.test.ts +++ b/src/harness/application/exchange/export/__tests__/skillExportService.test.ts @@ -62,4 +62,29 @@ describe('SkillExportService', () => { expect(content).toContain('## Resource Strategy'); expect(content).not.toContain('## When to Use'); }); + + it('dry run previews skill exports without writing files', async () => { + const scaffoldPath = path.join(repoPath, '.context', 'skills', 'sample', 'SKILL.md'); + await fs.outputFile( + scaffoldPath, + '---\nname: sample\ndescription: Sample skill\n---\n# Sample\n', + 'utf-8' + ); + + const service = new SkillExportService({ + ui: minimalUI as any, + t: mockTranslate, + version: 'test', + }); + + const result = await service.run(repoPath, { + targets: ['.claude/skills'], + skills: ['sample'], + dryRun: true, + }); + + expect(result.filesCreated).toBe(1); + expect(result.skillsExported).toEqual(['sample']); + expect(await fs.pathExists(path.join(repoPath, '.claude', 'skills', 'sample', 'SKILL.md'))).toBe(false); + }); }); diff --git a/src/harness/application/exchange/export/skillExportService.ts b/src/harness/application/exchange/export/skillExportService.ts index 49fc437c..fd1c5fee 100644 --- a/src/harness/application/exchange/export/skillExportService.ts +++ b/src/harness/application/exchange/export/skillExportService.ts @@ -184,8 +184,21 @@ export class SkillExportService { this.deps.ui.startSpinner(`Exporting skills to ${target.name}...`); if (options.dryRun) { + for (const skill of skills) { + const skillFile = path.join(targetPath, skill.slug, 'SKILL.md'); + + if (await pathExists(skillFile) && !options.force) { + result.filesSkipped++; + continue; + } + + result.filesCreated++; + if (!result.skillsExported.includes(skill.slug)) { + result.skillsExported.push(skill.slug); + } + } + this.deps.ui.updateSpinner(`[DRY-RUN] Would export to ${targetPath}`, 'success'); - result.filesSkipped++; this.deps.ui.stopSpinner(); return; } diff --git a/src/harness/application/exchange/syncActionService.ts b/src/harness/application/exchange/syncActionService.ts index 9c68e69e..e7825edd 100644 --- a/src/harness/application/exchange/syncActionService.ts +++ b/src/harness/application/exchange/syncActionService.ts @@ -153,14 +153,16 @@ export class HarnessSyncActionService { preset: params.preset, includeBuiltIn: params.includeBuiltIn, force: params.force, + dryRun: params.dryRun, }); return { - success: result.filesCreated > 0, + success: params.dryRun ? result.filesCreated > 0 || result.filesSkipped > 0 : result.filesCreated > 0, targets: result.targets, skillsExported: result.skillsExported, filesCreated: result.filesCreated, filesSkipped: result.filesSkipped, + dryRun: params.dryRun || false, }; } case 'reverseSync': { diff --git a/src/mcp/gateway/__tests__/sync.test.ts b/src/mcp/gateway/__tests__/sync.test.ts index a7cfe7a7..ae379fa5 100644 --- a/src/mcp/gateway/__tests__/sync.test.ts +++ b/src/mcp/gateway/__tests__/sync.test.ts @@ -31,4 +31,31 @@ describe('handleSync', () => { expect(payload.success).toBe(true); expect(payload.dryRun).toBe(true); }); + + it('exportSkills dry run reports a preview without writing files', async () => { + await fs.outputFile( + path.join(tempDir, '.context', 'skills', 'sample', 'SKILL.md'), + '---\nname: sample\ndescription: Sample skill\n---\n# Sample\n' + ); + + const markers = ['.claude', '.codex', '.gemini', '.windsurf', '.github', '.agents']; + const before = new Set((await fs.readdir(tempDir)).filter((entry) => markers.includes(entry))); + + const response = await handleSync( + { + action: 'exportSkills', + preset: 'claude', + dryRun: true, + }, + { repoPath: tempDir } + ); + const payload = JSON.parse(response.content[0].text); + const after = new Set((await fs.readdir(tempDir)).filter((entry) => markers.includes(entry))); + + expect(before).toEqual(after); + expect(payload.dryRun).toBe(true); + expect(payload.filesCreated).toBeGreaterThan(0); + expect(payload.skillsExported).toContain('sample'); + expect(await fs.pathExists(path.join(tempDir, '.claude', 'skills', 'sample', 'SKILL.md'))).toBe(false); + }); }); diff --git a/src/mcp/server/mcpServer.ts b/src/mcp/server/mcpServer.ts index 62cb1532..b6e28b53 100644 --- a/src/mcp/server/mcpServer.ts +++ b/src/mcp/server/mcpServer.ts @@ -488,7 +488,7 @@ Actions: - exportDocs: Export docs to AI tools (params: preset?, indexMode?, force?, dryRun?) - exportAgents: Export agents to AI tools (params: preset?, mode?, force?, dryRun?) - exportContext: Export all context (params: preset?, skipDocs?, skipAgents?, skipSkills?, docsIndexMode?, agentMode?, force?, dryRun?) -- exportSkills: Export skills to AI tools (params: preset?, includeBuiltIn?, force?) +- exportSkills: Export skills to AI tools (params: preset?, includeBuiltIn?, force?, dryRun?) - reverseSync: Import from AI tools to .context/ (params: skipRules?, skipAgents?, skipSkills?, mergeStrategy?, dryRun?, force?, addMetadata?) - importDocs: Import docs from AI tools (params: autoDetect?, force?, dryRun?) - importAgents: Import agents from AI tools (params: autoDetect?, force?, dryRun?)