diff --git a/cli/src/utils/template.ts b/cli/src/utils/template.ts index 429be1f..170effa 100755 --- a/cli/src/utils/template.ts +++ b/cli/src/utils/template.ts @@ -424,11 +424,10 @@ export async function planPlatformInstallActions( const actions: string[] = []; const skillFileExists = await exists(skillFilePath); - actions.push( - skillFileExists && !force - ? `Would skip (exists, use --force): ${skillFilePath}` - : `Would write: ${skillFilePath}` - ); + if (skillFileExists && !force) { + return [`Would skip (exists, use --force): ${skillFilePath}`]; + } + actions.push(`Would write: ${skillFilePath}`); actions.push(`Would copy data + scripts: ${dataDir}`); const subSkills = await listBundledSubSkills(); @@ -438,10 +437,8 @@ export async function planPlatformInstallActions( ); } - if (!skillFileExists || force) { - for (const path of await findLegacyInstallPaths(baseDir, aiType)) { - actions.push(`Would remove legacy install: ${join(baseDir, path)}`); - } + for (const path of await findLegacyInstallPaths(baseDir, aiType)) { + actions.push(`Would remove legacy install: ${join(baseDir, path)}`); } return actions; diff --git a/cli/tests/e2e/dry-run.spec.ts b/cli/tests/e2e/dry-run.spec.ts index 2dd9e90..3128e1a 100644 --- a/cli/tests/e2e/dry-run.spec.ts +++ b/cli/tests/e2e/dry-run.spec.ts @@ -1,10 +1,12 @@ import { expect, test } from '@playwright/test'; -import { mkdtemp, readdir } from 'node:fs/promises'; +import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { planAllPlatformInstallActions, planPlatformInstallActions, + generatePlatformFiles, + listBundledSubSkills, } from '../../src/utils/template.js'; test('dry-run plan lists the install actions for one platform', async () => { @@ -30,6 +32,29 @@ test('dry-run plan writes nothing to the target directory', async () => { expect(await readdir(scratch)).toEqual(before); }); +test('dry-run skips all install actions for an existing skill unless forced', async () => { + const scratch = await mkdtemp(join(tmpdir(), 'uipro-dry-run-existing-')); + const skillDir = join(scratch, '.opencode', 'skills', 'ui-ux-pro-max'); + const skillFile = join(skillDir, 'SKILL.md'); + await mkdir(skillDir, { recursive: true }); + await writeFile(skillFile, 'existing skill'); + + const skipped = await planPlatformInstallActions(scratch, 'opencode'); + expect(skipped).toEqual([`Would skip (exists, use --force): ${skillFile}`]); + const all = await planAllPlatformInstallActions(scratch); + expect(all.get('opencode')).toEqual(skipped); + expect(await generatePlatformFiles(scratch, 'opencode')).toEqual([]); + expect(await readdir(skillDir)).toEqual(['SKILL.md']); + expect(await readFile(skillFile, 'utf-8')).toBe('existing skill'); + + const forced = await planPlatformInstallActions(scratch, 'opencode', false, true); + expect(forced[0]).toBe(`Would write: ${skillFile}`); + expect(forced).toContain(`Would copy data + scripts: ${skillDir}`); + const subSkills = await listBundledSubSkills(); + expect(forced.some(action => action.startsWith(`Would copy ${subSkills.length} sub-skills`))).toBe(true); + expect(await readdir(skillDir)).toEqual(['SKILL.md']); +}); + test('dry-run plan supports the zcode platform layout', async () => { const scratch = await mkdtemp(join(tmpdir(), 'uipro-dry-run-zcode-'));