fix(cli): match dry-run sub-skill copies to installs (#571)

This commit is contained in:
조유경 (Cho Yugyeong) 2026-11-15 01:04:42 +09:00 committed by GitHub
parent 6ae86f61f5
commit d643997c82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 5 deletions

View File

@ -260,6 +260,14 @@ export async function listBundledSubSkills(): Promise<string[]> {
return entries.filter(e => e.isDirectory()).map(e => e.name).sort();
}
async function* subSkillsToCopy(skillsParentDir: string, force: boolean): AsyncGenerator<string> {
for (const name of await listBundledSubSkills()) {
if (force || !(await exists(join(skillsParentDir, name)))) {
yield name;
}
}
}
/**
* Paths of an earlier layout of aiType that exist under baseDir: the old skill
* file, the orchestrator folder and the bundled sub-skills left next to it.
@ -302,11 +310,8 @@ export async function removeLegacyInstall(baseDir: string, aiType: string): Prom
*/
async function copySubSkills(skillsParentDir: string, force: boolean): Promise<void> {
const skillsSource = join(ASSETS_DIR, 'skills');
if (!(await exists(skillsSource))) return;
for (const name of await listBundledSubSkills()) {
for await (const name of subSkillsToCopy(skillsParentDir, force)) {
const target = join(skillsParentDir, name);
if (await exists(target) && !force) continue;
await mkdir(target, { recursive: true });
await cp(join(skillsSource, name), target, { recursive: true });
}
@ -430,7 +435,10 @@ export async function planPlatformInstallActions(
actions.push(`Would write: ${skillFilePath}`);
actions.push(`Would copy data + scripts: ${dataDir}`);
const subSkills = await listBundledSubSkills();
const subSkills: string[] = [];
for await (const name of subSkillsToCopy(skillsParentDir, force)) {
subSkills.push(name);
}
if (subSkills.length > 0) {
actions.push(
`Would copy ${subSkills.length} sub-skills (${subSkills.join(', ')}): ${skillsParentDir}`

View File

@ -55,6 +55,59 @@ test('dry-run skips all install actions for an existing skill unless forced', as
expect(await readdir(skillDir)).toEqual(['SKILL.md']);
});
for (const force of [false, true]) {
test(`dry-run matches the sub-skills copied ${force ? 'with --force' : 'without --force'}`, async ({}, testInfo) => {
const scratch = testInfo.outputPath('project');
const skillsDir = join(scratch, '.opencode', 'skills');
const brandDir = join(skillsDir, 'brand');
const brandFile = join(brandDir, 'SKILL.md');
const existingBrand = 'existing brand skill';
await mkdir(brandDir, { recursive: true });
await writeFile(brandFile, existingBrand);
const bundledSkills = await listBundledSubSkills();
const copiedSkills = force ? bundledSkills : bundledSkills.filter(name => name !== 'brand');
const actions = await planPlatformInstallActions(scratch, 'opencode', false, force);
expect(actions).toContain(
`Would copy ${copiedSkills.length} sub-skills (${copiedSkills.join(', ')}): ${skillsDir}`
);
expect(await readdir(skillsDir)).toEqual(['brand']);
expect(await readFile(brandFile, 'utf-8')).toBe(existingBrand);
await generatePlatformFiles(scratch, 'opencode', false, force);
for (const name of copiedSkills) {
const bundledFile = new URL(`../../assets/skills/${name}/SKILL.md`, import.meta.url);
const installedFile = join(skillsDir, name, 'SKILL.md');
expect(await readFile(installedFile, 'utf-8')).toBe(await readFile(bundledFile, 'utf-8'));
}
if (!force) {
expect(await readFile(brandFile, 'utf-8')).toBe(existingBrand);
}
});
}
test('dry-run omits the sub-skill copy action when all target directories exist', async ({}, testInfo) => {
const scratch = testInfo.outputPath('project');
const skillsDir = join(scratch, '.opencode', 'skills');
const bundledSkills = await listBundledSubSkills();
for (const name of bundledSkills) {
await mkdir(join(skillsDir, name), { recursive: true });
}
const actions = await planPlatformInstallActions(scratch, 'opencode');
const orchestratorDir = join(skillsDir, 'ui-ux-pro-max');
expect(actions).toEqual([
`Would write: ${join(orchestratorDir, 'SKILL.md')}`,
`Would copy data + scripts: ${orchestratorDir}`,
]);
expect((await readdir(skillsDir)).sort()).toEqual(bundledSkills);
await generatePlatformFiles(scratch, 'opencode');
for (const name of bundledSkills) {
expect(await readdir(join(skillsDir, name))).toEqual([]);
}
});
test('dry-run plan supports the zcode platform layout', async () => {
const scratch = await mkdtemp(join(tmpdir(), 'uipro-dry-run-zcode-'));