|
| 1 | +import * as path from 'path'; |
| 2 | + |
| 3 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 4 | +import { setupTestTree } from '../common/setup.spec'; |
| 5 | +import { IG_LICENSED_PACKAGE_NAME, IG_PACKAGE_NAME } from '../common/tsUtils'; |
| 6 | + |
| 7 | +describe(`Add Agent skills`, () => { |
| 8 | + let appTree: UnitTestTree; |
| 9 | + const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json')); |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + appTree = setupTestTree(); |
| 13 | + }); |
| 14 | + |
| 15 | + const migrationName = 'migration-54'; |
| 16 | + |
| 17 | + const packagePath = `/node_modules/${IG_PACKAGE_NAME}`; |
| 18 | + const licensedPackagePath = `/node_modules/${IG_LICENSED_PACKAGE_NAME}`; |
| 19 | + |
| 20 | + const addPackageSkills = (tree: UnitTestTree, basePath: string, packageName = IG_PACKAGE_NAME) => { |
| 21 | + tree.create(`${basePath}/package.json`, JSON.stringify({ name: packageName, version: '21.1.0' })); |
| 22 | + tree.create(`${basePath}/skills/igniteui-angular-components/SKILL.md`, '# Components Skill'); |
| 23 | + tree.create(`${basePath}/skills/igniteui-angular-grids/SKILL.md`, '# Grids Skill'); |
| 24 | + }; |
| 25 | + |
| 26 | + it('should copy skill files to .claude/skills by default when no existing agent directories have content', async () => { |
| 27 | + addPackageSkills(appTree, packagePath); |
| 28 | + |
| 29 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 30 | + |
| 31 | + expect(tree.exists('/.claude/skills/igniteui-angular-components/SKILL.md')).toBeTrue(); |
| 32 | + expect(tree.exists('/.claude/skills/igniteui-angular-grids/SKILL.md')).toBeTrue(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should copy skill files to .agents/skills when that directory already has content', async () => { |
| 36 | + addPackageSkills(appTree, packagePath); |
| 37 | + appTree.create('/.agents/skills/existing-skill/SKILL.md', '# Existing Skill'); |
| 38 | + |
| 39 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 40 | + |
| 41 | + expect(tree.exists('/.agents/skills/igniteui-angular-components/SKILL.md')).toBeTrue(); |
| 42 | + expect(tree.exists('/.agents/skills/igniteui-angular-grids/SKILL.md')).toBeTrue(); |
| 43 | + expect(tree.exists('/.claude/skills/igniteui-angular-components/SKILL.md')).toBeFalse(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should copy skill files to .cursor/skills when that directory already has content', async () => { |
| 47 | + addPackageSkills(appTree, packagePath); |
| 48 | + appTree.create('/.cursor/skills/existing-skill/SKILL.md', '# Existing Skill'); |
| 49 | + |
| 50 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 51 | + |
| 52 | + expect(tree.exists('/.cursor/skills/igniteui-angular-components/SKILL.md')).toBeTrue(); |
| 53 | + expect(tree.exists('/.cursor/skills/igniteui-angular-grids/SKILL.md')).toBeTrue(); |
| 54 | + expect(tree.exists('/.claude/skills/igniteui-angular-components/SKILL.md')).toBeFalse(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should copy skill files to .github/skills when that directory already has content', async () => { |
| 58 | + addPackageSkills(appTree, packagePath); |
| 59 | + appTree.create('/.github/skills/existing-skill/SKILL.md', '# Existing Skill'); |
| 60 | + |
| 61 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 62 | + |
| 63 | + expect(tree.exists('/.github/skills/igniteui-angular-components/SKILL.md')).toBeTrue(); |
| 64 | + expect(tree.exists('/.github/skills/igniteui-angular-grids/SKILL.md')).toBeTrue(); |
| 65 | + expect(tree.exists('/.claude/skills/igniteui-angular-components/SKILL.md')).toBeFalse(); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should use the licensed package skills when only the licensed package is installed', async () => { |
| 69 | + addPackageSkills(appTree, licensedPackagePath, IG_LICENSED_PACKAGE_NAME); |
| 70 | + |
| 71 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 72 | + |
| 73 | + expect(tree.exists('/.claude/skills/igniteui-angular-components/SKILL.md')).toBeTrue(); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should not create any skill files when neither package is installed', async () => { |
| 77 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 78 | + |
| 79 | + expect(tree.exists('/.claude/skills/igniteui-angular-components/SKILL.md')).toBeFalse(); |
| 80 | + expect(tree.exists('/.agents/skills/igniteui-angular-components/SKILL.md')).toBeFalse(); |
| 81 | + expect(tree.exists('/.cursor/skills/igniteui-angular-components/SKILL.md')).toBeFalse(); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should overwrite existing skill files when re-running the migration', async () => { |
| 85 | + addPackageSkills(appTree, packagePath); |
| 86 | + appTree.create('/.claude/skills/igniteui-angular-components/SKILL.md', '# Old Content'); |
| 87 | + |
| 88 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 89 | + |
| 90 | + expect(tree.readContent('/.claude/skills/igniteui-angular-components/SKILL.md')).toBe('# Components Skill'); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should preserve content of all skill files during copy', async () => { |
| 94 | + const componentsContent = '# Components Skill\nSome detailed content here.'; |
| 95 | + const gridsContent = '# Grids Skill\nGrid-specific instructions.'; |
| 96 | + appTree.create(`${packagePath}/package.json`, JSON.stringify({ name: IG_PACKAGE_NAME, version: '21.1.0' })); |
| 97 | + appTree.create(`${packagePath}/skills/igniteui-angular-components/SKILL.md`, componentsContent); |
| 98 | + appTree.create(`${packagePath}/skills/igniteui-angular-grids/SKILL.md`, gridsContent); |
| 99 | + |
| 100 | + const tree = await schematicRunner.runSchematic(migrationName, {}, appTree); |
| 101 | + |
| 102 | + expect(tree.readContent('/.claude/skills/igniteui-angular-components/SKILL.md')).toBe(componentsContent); |
| 103 | + expect(tree.readContent('/.claude/skills/igniteui-angular-grids/SKILL.md')).toBe(gridsContent); |
| 104 | + }); |
| 105 | +}); |
0 commit comments