mirror of
https://github.com/nextlevelbuilder/ui-ux-pro-max-skill.git
synced 2026-11-20 01:20:33 +00:00
fix(cli): match dry-run sub-skill copies to installs (#571)
This commit is contained in:
parent
6ae86f61f5
commit
d643997c82
@ -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}`
|
||||
|
||||
@ -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-'));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user