agent-skills-standard 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/commands/init.js +7 -11
- package/dist/constants/enums.d.ts +21 -0
- package/dist/constants/enums.js +26 -0
- package/dist/constants/index.d.ts +3 -21
- package/dist/constants/index.js +24 -43
- package/dist/constants/skills.js +3 -3
- package/dist/index.js +1 -1
- package/dist/scripts/calculate-tokens.d.ts +7 -0
- package/dist/scripts/calculate-tokens.js +176 -0
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +9 -1
- package/dist/services/SkillValidator.js +37 -22
- package/dist/services/__tests__/ConfigService.spec.d.ts +1 -0
- package/dist/services/__tests__/ConfigService.spec.js +213 -0
- package/dist/services/__tests__/DetectionService.spec.d.ts +1 -0
- package/dist/services/__tests__/DetectionService.spec.js +122 -0
- package/dist/services/__tests__/GithubService.spec.d.ts +1 -0
- package/dist/services/__tests__/GithubService.spec.js +197 -0
- package/dist/services/__tests__/RegistryService.spec.d.ts +1 -0
- package/dist/services/__tests__/RegistryService.spec.js +77 -0
- package/dist/services/__tests__/SkillValidator.spec.d.ts +1 -0
- package/dist/services/__tests__/SkillValidator.spec.js +367 -0
- package/package.json +10 -4
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SkillValidator = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
|
-
const console_1 = __importDefault(require("console"));
|
|
9
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const picocolors_1 = __importDefault(require("picocolors"));
|
|
@@ -20,7 +19,7 @@ class SkillValidator {
|
|
|
20
19
|
return summary.failed > 0 ? 1 : 0;
|
|
21
20
|
}
|
|
22
21
|
catch (error) {
|
|
23
|
-
|
|
22
|
+
console.error(picocolors_1.default.red(`❌ Validation error: ${error instanceof Error ? error.stack : error}`));
|
|
24
23
|
return 1;
|
|
25
24
|
}
|
|
26
25
|
}
|
|
@@ -33,24 +32,24 @@ class SkillValidator {
|
|
|
33
32
|
let skillFiles;
|
|
34
33
|
if (validateAll) {
|
|
35
34
|
skillFiles = await this.findSkillFiles(skillsDir);
|
|
36
|
-
|
|
35
|
+
console.log(picocolors_1.default.blue(`🔍 Found ${skillFiles.length} skills to validate\n`));
|
|
37
36
|
}
|
|
38
37
|
else {
|
|
39
38
|
skillFiles = await this.findChangedSkillFiles();
|
|
40
|
-
|
|
39
|
+
console.log(picocolors_1.default.blue(`🔍 Found ${skillFiles.length} changed skills to validate\n`));
|
|
41
40
|
}
|
|
42
41
|
for (const skillFile of skillFiles) {
|
|
43
42
|
const result = await this.validateSkill(skillFile);
|
|
44
43
|
this.results.push(result);
|
|
45
44
|
if (result.passed) {
|
|
46
|
-
|
|
45
|
+
console.log(picocolors_1.default.green(`✅ ${result.file}`));
|
|
47
46
|
if (result.warnings.length > 0) {
|
|
48
|
-
result.warnings.forEach((warning) =>
|
|
47
|
+
result.warnings.forEach((warning) => console.log(picocolors_1.default.yellow(` ⚠️ ${warning}`)));
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
else {
|
|
52
|
-
|
|
53
|
-
result.errors.forEach((error) =>
|
|
51
|
+
console.log(picocolors_1.default.red(`❌ ${result.file}`));
|
|
52
|
+
result.errors.forEach((error) => console.log(picocolors_1.default.red(` ❌ ${error}`)));
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
// Validate metadata.json
|
|
@@ -114,7 +113,7 @@ class SkillValidator {
|
|
|
114
113
|
return [...changedSkillFiles, ...untrackedSkillFiles];
|
|
115
114
|
}
|
|
116
115
|
catch (error) {
|
|
117
|
-
|
|
116
|
+
console.warn(picocolors_1.default.yellow(`⚠️ Could not determine changed files, ${error}`));
|
|
118
117
|
return [];
|
|
119
118
|
}
|
|
120
119
|
}
|
|
@@ -159,10 +158,26 @@ class SkillValidator {
|
|
|
159
158
|
result.passed = false;
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
|
-
// Check for conversational style (
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
// Check for conversational style in instructions (ignoring code blocks)
|
|
162
|
+
const bodyLines = body.split('\n');
|
|
163
|
+
let isInCodeBlock = false;
|
|
164
|
+
let hasConversationalStyle = false;
|
|
165
|
+
for (const line of bodyLines) {
|
|
166
|
+
if (line.trim().startsWith('```')) {
|
|
167
|
+
isInCodeBlock = !isInCodeBlock;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (isInCodeBlock)
|
|
171
|
+
continue;
|
|
172
|
+
// Target bullet points and numbered lists that start with conversational phrases
|
|
173
|
+
const conversationalPatterns = /^(?:\s*[-*+]\s*|\s*\d+\.\s*)(?:you should|please|let's|we can|I recommend)/i;
|
|
174
|
+
if (conversationalPatterns.test(line)) {
|
|
175
|
+
hasConversationalStyle = true;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (hasConversationalStyle) {
|
|
180
|
+
result.warnings.push('Consider using imperative mood instead of conversational style in instructions');
|
|
166
181
|
}
|
|
167
182
|
// Check for proper priority format
|
|
168
183
|
if (!body.includes('## **Priority:')) {
|
|
@@ -219,7 +234,7 @@ class SkillValidator {
|
|
|
219
234
|
if (!catConfig.tag_prefix) {
|
|
220
235
|
throw new Error(`Category "${category}" missing tag_prefix in metadata.json`);
|
|
221
236
|
}
|
|
222
|
-
|
|
237
|
+
console.log(picocolors_1.default.green(`✅ Category metadata valid: ${category} (v${catConfig.version}, ${catConfig.tag_prefix})`));
|
|
223
238
|
}
|
|
224
239
|
}
|
|
225
240
|
catch (error) {
|
|
@@ -245,18 +260,18 @@ class SkillValidator {
|
|
|
245
260
|
return summary;
|
|
246
261
|
}
|
|
247
262
|
printSummary(summary) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
263
|
+
console.log('\n' + '='.repeat(50));
|
|
264
|
+
console.log(picocolors_1.default.blue('📊 VALIDATION SUMMARY'));
|
|
265
|
+
console.log('='.repeat(50));
|
|
266
|
+
console.log(picocolors_1.default.green(`Passed: ${summary.passed}`));
|
|
267
|
+
console.log(picocolors_1.default.red(`Failed: ${summary.failed}`));
|
|
253
268
|
if (summary.failed > 0) {
|
|
254
|
-
|
|
269
|
+
console.log('\n' + picocolors_1.default.red('❌ Validation failed! Please fix the errors above.'));
|
|
255
270
|
}
|
|
256
271
|
else {
|
|
257
|
-
|
|
272
|
+
console.log('\n' + picocolors_1.default.green('✅ All skills passed validation!'));
|
|
258
273
|
if (summary.warnings > 0) {
|
|
259
|
-
|
|
274
|
+
console.log(picocolors_1.default.yellow(`⚠️ ${summary.warnings} warnings found. Consider addressing them for better token efficiency.`));
|
|
260
275
|
}
|
|
261
276
|
}
|
|
262
277
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const vitest_1 = require("vitest");
|
|
10
|
+
const constants_1 = require("../../constants");
|
|
11
|
+
const ConfigService_1 = require("../ConfigService");
|
|
12
|
+
vitest_1.vi.mock('fs-extra');
|
|
13
|
+
vitest_1.vi.mock('js-yaml');
|
|
14
|
+
(0, vitest_1.describe)('ConfigService', () => {
|
|
15
|
+
let configService;
|
|
16
|
+
const mockCwd = '/mock/cwd';
|
|
17
|
+
(0, vitest_1.beforeEach)(() => {
|
|
18
|
+
vitest_1.vi.clearAllMocks();
|
|
19
|
+
configService = new ConfigService_1.ConfigService();
|
|
20
|
+
});
|
|
21
|
+
(0, vitest_1.describe)('loadConfig', () => {
|
|
22
|
+
(0, vitest_1.it)('should return null if .skillsrc does not exist', async () => {
|
|
23
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation(() => Promise.resolve(false));
|
|
24
|
+
const config = await configService.loadConfig(mockCwd);
|
|
25
|
+
(0, vitest_1.expect)(config).toBeNull();
|
|
26
|
+
(0, vitest_1.expect)(fs_extra_1.default.pathExists).toHaveBeenCalledWith(path_1.default.join(mockCwd, '.skillsrc'));
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('should return parsed config if .skillsrc exists and is valid', async () => {
|
|
29
|
+
const mockYamlText = 'registry: https://example.com\nskills: {}';
|
|
30
|
+
const mockConfig = {
|
|
31
|
+
registry: 'https://example.com',
|
|
32
|
+
skills: {},
|
|
33
|
+
agents: ['cursor'],
|
|
34
|
+
custom_overrides: [],
|
|
35
|
+
};
|
|
36
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation(() => Promise.resolve(true));
|
|
37
|
+
vitest_1.vi.mocked(fs_extra_1.default.readFile).mockImplementation(() => Promise.resolve(mockYamlText));
|
|
38
|
+
vitest_1.vi.mocked(js_yaml_1.default.load).mockReturnValue(mockConfig);
|
|
39
|
+
const config = await configService.loadConfig(mockCwd);
|
|
40
|
+
(0, vitest_1.expect)(config).toEqual(mockConfig);
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('should throw error if .skillsrc format is invalid', async () => {
|
|
43
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation(() => Promise.resolve(true));
|
|
44
|
+
vitest_1.vi.mocked(fs_extra_1.default.readFile).mockImplementation(() => Promise.resolve('invalid yaml'));
|
|
45
|
+
vitest_1.vi.mocked(js_yaml_1.default.load).mockReturnValue({ some: 'garbage' });
|
|
46
|
+
await (0, vitest_1.expect)(configService.loadConfig(mockCwd)).rejects.toThrow('Invalid .skillsrc format');
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.it)('should throw error if file reading fails', async () => {
|
|
49
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation(() => Promise.resolve(true));
|
|
50
|
+
vitest_1.vi.mocked(fs_extra_1.default.readFile).mockRejectedValue(new Error('Read failed'));
|
|
51
|
+
await (0, vitest_1.expect)(configService.loadConfig(mockCwd)).rejects.toThrow('Failed to load config');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
(0, vitest_1.describe)('saveConfig', () => {
|
|
55
|
+
(0, vitest_1.it)('should save config as YAML', async () => {
|
|
56
|
+
const mockConfig = {
|
|
57
|
+
registry: 'https://example.com',
|
|
58
|
+
skills: {},
|
|
59
|
+
agents: ['cursor'],
|
|
60
|
+
custom_overrides: [],
|
|
61
|
+
};
|
|
62
|
+
vitest_1.vi.mocked(js_yaml_1.default.dump).mockReturnValue('mock yaml');
|
|
63
|
+
await configService.saveConfig(mockConfig, mockCwd);
|
|
64
|
+
(0, vitest_1.expect)(js_yaml_1.default.dump).toHaveBeenCalledWith(mockConfig);
|
|
65
|
+
(0, vitest_1.expect)(fs_extra_1.default.writeFile).toHaveBeenCalledWith(path_1.default.join(mockCwd, '.skillsrc'), 'mock yaml');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.describe)('buildInitialConfig', () => {
|
|
69
|
+
(0, vitest_1.it)('should build initial config correctly', () => {
|
|
70
|
+
const metadata = {
|
|
71
|
+
global: { author: 'test', repository: 'test' },
|
|
72
|
+
categories: {
|
|
73
|
+
flutter: { version: '1.0.0', tag_prefix: 'v' },
|
|
74
|
+
common: { version: '1.2.0', tag_prefix: '' },
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const config = configService.buildInitialConfig('flutter', ['cursor'], 'https://registry.com', metadata);
|
|
78
|
+
(0, vitest_1.expect)(config.registry).toBe('https://registry.com');
|
|
79
|
+
(0, vitest_1.expect)(config.agents).toEqual(['cursor']);
|
|
80
|
+
(0, vitest_1.expect)(config.skills.flutter?.ref).toBe('v1.0.0');
|
|
81
|
+
(0, vitest_1.expect)(config.skills.common?.ref).toBe('1.2.0');
|
|
82
|
+
});
|
|
83
|
+
(0, vitest_1.it)('should handle missing metadata/tags in buildInitialConfig', () => {
|
|
84
|
+
const metadata = {
|
|
85
|
+
global: { author: 'test', repository: 'test' },
|
|
86
|
+
categories: {
|
|
87
|
+
flutter: { version: '1.0.0' }, // missing tag_prefix
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const config = configService.buildInitialConfig('flutter', ['cursor'], 'https://registry.com', metadata);
|
|
91
|
+
(0, vitest_1.expect)(config.skills.flutter?.ref).toBe('1.0.0');
|
|
92
|
+
(0, vitest_1.expect)(config.skills.common).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
(0, vitest_1.it)('should handle missing tag_prefix for languages in buildInitialConfig', () => {
|
|
95
|
+
const metadata = {
|
|
96
|
+
global: { author: 'test', repository: 'test' },
|
|
97
|
+
categories: {
|
|
98
|
+
typescript: { version: '1.1.0' }, // missing tag_prefix
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const config = configService.buildInitialConfig('flutter', ['cursor'], 'https://registry.com', metadata, ['typescript']);
|
|
102
|
+
// Branch check for line 76: fallback to '' (empty string) prefix
|
|
103
|
+
(0, vitest_1.expect)(config.skills.typescript?.ref).toBe('1.1.0');
|
|
104
|
+
});
|
|
105
|
+
(0, vitest_1.it)('should add associated languages to initial config', () => {
|
|
106
|
+
const metadata = {
|
|
107
|
+
global: { author: 'test', repository: 'test' },
|
|
108
|
+
categories: {
|
|
109
|
+
flutter: { version: '1.0.0', tag_prefix: 'v' },
|
|
110
|
+
typescript: { version: '1.1.0', tag_prefix: 'v' },
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const config = configService.buildInitialConfig('flutter', ['cursor'], 'https://registry.com', metadata, ['typescript', 'nonexistent']);
|
|
114
|
+
(0, vitest_1.expect)(config.skills.typescript?.ref).toBe('v1.1.0');
|
|
115
|
+
// Should NOT add nonexistent
|
|
116
|
+
(0, vitest_1.expect)(config.skills.nonexistent).toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
(0, vitest_1.it)('should handle missing categories or framework in registry metadata', () => {
|
|
119
|
+
// Missing categories entirely
|
|
120
|
+
const config1 = configService.buildInitialConfig('f', [], 'url', {}, []);
|
|
121
|
+
(0, vitest_1.expect)(Object.keys(config1.skills)).toHaveLength(1);
|
|
122
|
+
(0, vitest_1.expect)(config1.skills.f.ref).toBe('main');
|
|
123
|
+
// Category missing for primary framework
|
|
124
|
+
const config2 = configService.buildInitialConfig('f', [], 'url', { categories: {} }, []);
|
|
125
|
+
(0, vitest_1.expect)(Object.keys(config2.skills)).toHaveLength(1);
|
|
126
|
+
(0, vitest_1.expect)(config2.skills.f.ref).toBe('main');
|
|
127
|
+
});
|
|
128
|
+
(0, vitest_1.it)('should fallback to empty registry in buildInitialConfig if not provided (branch coverage)', () => {
|
|
129
|
+
// Branch check for line 108 if framework detections are missing
|
|
130
|
+
const config = configService.buildInitialConfig('unknown', [], 'url', {}, []);
|
|
131
|
+
(0, vitest_1.expect)(config.skills.unknown.ref).toBe('main');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
(0, vitest_1.describe)('applyDependencyExclusions', () => {
|
|
135
|
+
(0, vitest_1.it)('should add exclusions for missing dependencies', () => {
|
|
136
|
+
const config = {
|
|
137
|
+
registry: 'https://example.com',
|
|
138
|
+
agents: ['cursor'],
|
|
139
|
+
skills: {
|
|
140
|
+
flutter: { ref: 'v1.0.0' },
|
|
141
|
+
},
|
|
142
|
+
custom_overrides: [],
|
|
143
|
+
};
|
|
144
|
+
const projectDeps = new Set(['flutter_bloc']);
|
|
145
|
+
configService.applyDependencyExclusions(config, 'flutter', projectDeps);
|
|
146
|
+
const category = config.skills.flutter;
|
|
147
|
+
(0, vitest_1.expect)(category.exclude).toBeDefined();
|
|
148
|
+
(0, vitest_1.expect)(category.exclude).toContain('riverpod-state-management');
|
|
149
|
+
(0, vitest_1.expect)(category.exclude).not.toContain('bloc-state-management');
|
|
150
|
+
});
|
|
151
|
+
(0, vitest_1.it)('should do nothing if category does not exist', () => {
|
|
152
|
+
const config = {
|
|
153
|
+
registry: 'https://example.com',
|
|
154
|
+
agents: ['cursor'],
|
|
155
|
+
skills: {},
|
|
156
|
+
custom_overrides: [],
|
|
157
|
+
};
|
|
158
|
+
configService.applyDependencyExclusions(config, 'flutter', new Set());
|
|
159
|
+
(0, vitest_1.expect)(config.skills).toEqual({});
|
|
160
|
+
});
|
|
161
|
+
(0, vitest_1.it)('should handle category with existing empty exclusions (branch coverage)', () => {
|
|
162
|
+
const config = {
|
|
163
|
+
registry: 'https://example.com',
|
|
164
|
+
agents: ['cursor'],
|
|
165
|
+
skills: {
|
|
166
|
+
flutter: { ref: 'v1.0.0', exclude: [] },
|
|
167
|
+
},
|
|
168
|
+
custom_overrides: [],
|
|
169
|
+
};
|
|
170
|
+
// Should add exclusions to the empty list
|
|
171
|
+
configService.applyDependencyExclusions(config, 'flutter', new Set());
|
|
172
|
+
const category = config.skills.flutter;
|
|
173
|
+
(0, vitest_1.expect)(category.exclude?.length).toBeGreaterThan(0);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
(0, vitest_1.describe)('SKILL_DETECTION_REGISTRY Guard Tests', () => {
|
|
177
|
+
Object.entries(constants_1.SKILL_DETECTION_REGISTRY).forEach(([framework, detections]) => {
|
|
178
|
+
(0, vitest_1.describe)(`Framework: ${framework}`, () => {
|
|
179
|
+
detections.forEach((detection) => {
|
|
180
|
+
(0, vitest_1.it)(`should exclude ${detection.id} when dependencies ${JSON.stringify(detection.packages)} are missing`, () => {
|
|
181
|
+
const config = {
|
|
182
|
+
registry: 'https://example.com',
|
|
183
|
+
agents: ['cursor'],
|
|
184
|
+
skills: {
|
|
185
|
+
[framework]: { ref: 'v1.0.0' },
|
|
186
|
+
},
|
|
187
|
+
custom_overrides: [],
|
|
188
|
+
};
|
|
189
|
+
const projectDeps = new Set(['some-other-dep']);
|
|
190
|
+
configService.applyDependencyExclusions(config, framework, projectDeps);
|
|
191
|
+
const category = config.skills[framework];
|
|
192
|
+
(0, vitest_1.expect)(category.exclude).toContain(detection.id);
|
|
193
|
+
});
|
|
194
|
+
(0, vitest_1.it)(`should NOT exclude ${detection.id} when dependency ${detection.packages[0]} is present`, () => {
|
|
195
|
+
const config = {
|
|
196
|
+
registry: 'https://example.com',
|
|
197
|
+
agents: ['cursor'],
|
|
198
|
+
skills: {
|
|
199
|
+
[framework]: { ref: 'v1.0.0' },
|
|
200
|
+
},
|
|
201
|
+
custom_overrides: [],
|
|
202
|
+
};
|
|
203
|
+
// Simulate presence of the first package in the detection list
|
|
204
|
+
const projectDeps = new Set([detection.packages[0], 'other-dep']);
|
|
205
|
+
configService.applyDependencyExclusions(config, framework, projectDeps);
|
|
206
|
+
const category = config.skills[framework];
|
|
207
|
+
(0, vitest_1.expect)(category.exclude || []).not.toContain(detection.id);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const DetectionService_1 = require("../DetectionService");
|
|
9
|
+
vitest_1.vi.mock('fs-extra');
|
|
10
|
+
(0, vitest_1.describe)('DetectionService', () => {
|
|
11
|
+
let detectionService;
|
|
12
|
+
(0, vitest_1.beforeEach)(() => {
|
|
13
|
+
vitest_1.vi.clearAllMocks();
|
|
14
|
+
detectionService = new DetectionService_1.DetectionService();
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.describe)('detectFrameworks', () => {
|
|
17
|
+
(0, vitest_1.it)('should detect Flutter if pubspec.yaml exists', async () => {
|
|
18
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
19
|
+
return Promise.resolve(p.endsWith('pubspec.yaml'));
|
|
20
|
+
});
|
|
21
|
+
vitest_1.vi.mocked(fs_extra_1.default.readJson).mockResolvedValue({});
|
|
22
|
+
const results = await detectionService.detectFrameworks();
|
|
23
|
+
(0, vitest_1.expect)(results.flutter).toBe(true);
|
|
24
|
+
(0, vitest_1.expect)(results.nestjs).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.it)('should detect NestJS if @nestjs/core dependency exists', async () => {
|
|
27
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
28
|
+
return Promise.resolve(p.endsWith('package.json'));
|
|
29
|
+
});
|
|
30
|
+
vitest_1.vi.mocked(fs_extra_1.default.readJson).mockResolvedValue({
|
|
31
|
+
dependencies: { '@nestjs/core': '^10.0.0' },
|
|
32
|
+
});
|
|
33
|
+
const results = await detectionService.detectFrameworks();
|
|
34
|
+
(0, vitest_1.expect)(results.nestjs).toBe(true);
|
|
35
|
+
(0, vitest_1.expect)(results.flutter).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)('should return empty deps if package.json read fails', async () => {
|
|
38
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
39
|
+
return Promise.resolve(p.endsWith('package.json'));
|
|
40
|
+
});
|
|
41
|
+
vitest_1.vi.mocked(fs_extra_1.default.readJson).mockRejectedValue(new Error('Read failed'));
|
|
42
|
+
const results = await detectionService.detectFrameworks();
|
|
43
|
+
// Should still work but with no deps detected
|
|
44
|
+
(0, vitest_1.expect)(results.nestjs).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.describe)('detectAgents', () => {
|
|
48
|
+
(0, vitest_1.it)('should detect Cursor if .cursor exists', async () => {
|
|
49
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
50
|
+
return Promise.resolve(p.endsWith('.cursor'));
|
|
51
|
+
});
|
|
52
|
+
const results = await detectionService.detectAgents();
|
|
53
|
+
(0, vitest_1.expect)(results.cursor).toBe(true);
|
|
54
|
+
(0, vitest_1.expect)(results.copilot).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.it)('should handle missing agents detection files', async () => {
|
|
57
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation(async () => false);
|
|
58
|
+
const results = await detectionService.detectAgents();
|
|
59
|
+
(0, vitest_1.expect)(results.cursor).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.describe)('getProjectDeps', () => {
|
|
63
|
+
(0, vitest_1.it)('should handle missing dependencies keys in package.json', async () => {
|
|
64
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => Promise.resolve(p.endsWith('package.json')));
|
|
65
|
+
vitest_1.vi.mocked(fs_extra_1.default.readJson).mockResolvedValue({});
|
|
66
|
+
const deps = await detectionService.getProjectDeps();
|
|
67
|
+
(0, vitest_1.expect)(deps.size).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)('should collect dependencies from package.json', async () => {
|
|
70
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
71
|
+
return Promise.resolve(p.endsWith('package.json'));
|
|
72
|
+
});
|
|
73
|
+
vitest_1.vi.mocked(fs_extra_1.default.readJson).mockResolvedValue({
|
|
74
|
+
dependencies: { react: '^18.0.0' },
|
|
75
|
+
devDependencies: { typescript: '^5.0.0' },
|
|
76
|
+
});
|
|
77
|
+
const deps = await detectionService.getProjectDeps();
|
|
78
|
+
(0, vitest_1.expect)(deps.has('react')).toBe(true);
|
|
79
|
+
(0, vitest_1.expect)(deps.has('typescript')).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.it)('should handle package.json read failure gracefully', async () => {
|
|
82
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
83
|
+
return Promise.resolve(p.endsWith('package.json'));
|
|
84
|
+
});
|
|
85
|
+
vitest_1.vi.mocked(fs_extra_1.default.readJson).mockRejectedValue(new Error('Parse error'));
|
|
86
|
+
const deps = await detectionService.getProjectDeps();
|
|
87
|
+
(0, vitest_1.expect)(deps.size).toBe(0);
|
|
88
|
+
});
|
|
89
|
+
(0, vitest_1.it)('should collect dependencies from pubspec.yaml', async () => {
|
|
90
|
+
const mockPubspec = `
|
|
91
|
+
dependencies:
|
|
92
|
+
flutter:
|
|
93
|
+
sdk: flutter
|
|
94
|
+
flutter_bloc: ^8.1.0
|
|
95
|
+
http: ^1.1.0
|
|
96
|
+
|
|
97
|
+
dev_dependencies:
|
|
98
|
+
flutter_test:
|
|
99
|
+
sdk: flutter
|
|
100
|
+
mocktail: ^1.0.0
|
|
101
|
+
`;
|
|
102
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
103
|
+
return Promise.resolve(p.endsWith('pubspec.yaml'));
|
|
104
|
+
});
|
|
105
|
+
vitest_1.vi.mocked(fs_extra_1.default.readFile).mockImplementation(() => Promise.resolve(mockPubspec));
|
|
106
|
+
const deps = await detectionService.getProjectDeps();
|
|
107
|
+
(0, vitest_1.expect)(deps.has('flutter_bloc')).toBe(true);
|
|
108
|
+
(0, vitest_1.expect)(deps.has('http')).toBe(true);
|
|
109
|
+
(0, vitest_1.expect)(deps.has('flutter_test')).toBe(true);
|
|
110
|
+
(0, vitest_1.expect)(deps.has('mocktail')).toBe(true);
|
|
111
|
+
(0, vitest_1.expect)(deps.has('flutter')).toBe(false); // Should be excluded based on logic
|
|
112
|
+
});
|
|
113
|
+
(0, vitest_1.it)('should handle pubspec.yaml read failure gracefully', async () => {
|
|
114
|
+
vitest_1.vi.mocked(fs_extra_1.default.pathExists).mockImplementation((p) => {
|
|
115
|
+
return Promise.resolve(p.endsWith('pubspec.yaml'));
|
|
116
|
+
});
|
|
117
|
+
vitest_1.vi.mocked(fs_extra_1.default.readFile).mockRejectedValue(new Error('IO error'));
|
|
118
|
+
const deps = await detectionService.getProjectDeps();
|
|
119
|
+
(0, vitest_1.expect)(deps.size).toBe(0);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|