agent-ecosystem/test/main/services/extensions/SkillValidator.test.ts
iliya 4b4dccd13d feat: add skills management features and integrate skills API
- Introduced skills catalog management with functionalities to list, get details, preview, and apply skill changes.
- Implemented IPC handlers for skills-related actions, enhancing communication between renderer and main processes.
- Updated the UI to include a dedicated Skills panel within the extension store, improving user access to skills management.
- Added new constants and types for skills API integration, ensuring a structured approach to skills handling.
- Enhanced state management to support skills loading, error handling, and detail fetching.
2026-03-11 21:46:56 +02:00

60 lines
2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { SkillValidator } from '@main/services/extensions/skills/SkillValidator';
import type { SkillCatalogItem } from '@shared/types/extensions';
function makeSkill(overrides: Partial<SkillCatalogItem>): SkillCatalogItem {
return {
id: '/tmp/skill',
sourceType: 'filesystem',
name: 'demo',
description: 'demo',
folderName: 'demo',
scope: 'user',
rootKind: 'claude',
projectRoot: null,
discoveryRoot: '/tmp/.claude/skills',
skillDir: '/tmp/.claude/skills/demo',
skillFile: '/tmp/.claude/skills/demo/SKILL.md',
metadata: {},
invocationMode: 'auto',
flags: { hasScripts: false, hasReferences: false, hasAssets: false },
isValid: true,
issues: [],
modifiedAt: 1,
...overrides,
};
}
describe('SkillValidator', () => {
it('adds duplicate-name warnings across roots', () => {
const validator = new SkillValidator();
const result = validator.annotateCatalog([
makeSkill({ id: '/a', scope: 'project', rootKind: 'claude' }),
makeSkill({ id: '/b', scope: 'user', rootKind: 'cursor' }),
]);
expect(result[0].issues.map((issue) => issue.code)).toContain('duplicate-name');
expect(result[1].issues.map((issue) => issue.code)).toContain('duplicate-name');
});
it('sorts by validity, scope, root precedence, then name', () => {
const validator = new SkillValidator();
const result = validator.annotateCatalog([
makeSkill({ id: '/3', name: 'z-user', scope: 'user', rootKind: 'claude' }),
makeSkill({ id: '/2', name: 'b-project-cursor', scope: 'project', rootKind: 'cursor' }),
makeSkill({ id: '/1', name: 'a-project-claude', scope: 'project', rootKind: 'claude' }),
makeSkill({
id: '/4',
name: 'invalid',
isValid: false,
issues: [{ code: 'missing-name', message: 'missing', severity: 'error' }],
}),
]);
expect(result.map((item) => item.id)).toEqual(['/1', '/2', '/3', '/4']);
});
});