Add unit tests for skill capabilities, skill planner, and UV setup
- Implement tests for random ID generation, ensuring preference for crypto.randomUUID. - Create tests for runtime context capabilities, validating the injection of enabled skill capabilities. - Add tests for skill capability parsing, including classification and command example extraction. - Introduce tests for the skill planner, verifying tool call planning based on user requests and attachment requirements. - Establish tests for UV setup, ensuring proper handling of Python installation scenarios and environment checks.
This commit is contained in:
77
tests/skill-planner.test.ts
Normal file
77
tests/skill-planner.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { planToolCall } from '../electron/gateway/skill-planner';
|
||||
|
||||
const spreadsheetCapability = {
|
||||
capabilityKey: 'minimax-xlsx',
|
||||
toolName: 'minimax-xlsx',
|
||||
skillKey: 'minimax-xlsx',
|
||||
slug: 'minimax-xlsx',
|
||||
name: 'MiniMax XLSX',
|
||||
displayName: 'MiniMax XLSX',
|
||||
description: 'Analyze spreadsheet files such as .xlsx, .csv, and .tsv.',
|
||||
kind: 'skill' as const,
|
||||
aliases: ['minimax-xlsx', 'xlsx', 'spreadsheet', 'excel'],
|
||||
inputKinds: ['text', 'file', 'attachment'],
|
||||
outputKinds: ['text', 'json', 'artifacts'],
|
||||
triggerHints: ['spreadsheet', 'excel', 'xlsx', 'csv'],
|
||||
supportedFileTypes: ['.xlsx', '.csv', '.tsv'],
|
||||
requiresFiles: true,
|
||||
enabled: true,
|
||||
metadata: {
|
||||
renderHints: {
|
||||
card: 'document-analysis',
|
||||
preferredView: 'table',
|
||||
skillType: 'spreadsheet',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('skill planner', () => {
|
||||
it('plans a spreadsheet tool call when the user explicitly requests minimax-xlsx with an attachment', () => {
|
||||
const decision = planToolCall({
|
||||
userText: '使用minimax-xlsx这个skill,帮我分析下。',
|
||||
message: {
|
||||
role: 'user',
|
||||
content: '使用minimax-xlsx这个skill,帮我分析下。',
|
||||
},
|
||||
attachments: [
|
||||
{
|
||||
fileName: 'report.xlsx',
|
||||
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
fileSize: 1024,
|
||||
preview: null,
|
||||
filePath: 'C:\\tmp\\report.xlsx',
|
||||
source: 'user-upload',
|
||||
},
|
||||
],
|
||||
capabilities: [spreadsheetCapability],
|
||||
});
|
||||
|
||||
expect(decision.kind).toBe('tool');
|
||||
expect(decision.reason).toBe('explicit_skill_request');
|
||||
expect(decision.toolCall?.name).toBe('minimax-xlsx');
|
||||
expect(decision.toolCall?.input).toEqual(expect.objectContaining({
|
||||
filePaths: ['C:\\tmp\\report.xlsx'],
|
||||
skillKey: 'minimax-xlsx',
|
||||
}));
|
||||
});
|
||||
|
||||
it('returns a blocking no-tool decision when spreadsheet analysis is requested without an attachment', () => {
|
||||
const decision = planToolCall({
|
||||
userText: '使用minimax-xlsx这个skill,帮我分析下。',
|
||||
message: {
|
||||
role: 'user',
|
||||
content: '使用minimax-xlsx这个skill,帮我分析下。',
|
||||
},
|
||||
capabilities: [spreadsheetCapability],
|
||||
});
|
||||
|
||||
expect(decision.kind).toBe('no-tool');
|
||||
expect(decision.reason).toBe('missing_required_attachment');
|
||||
expect(decision.blockingIssue).toEqual(expect.objectContaining({
|
||||
code: 'missing_required_attachment',
|
||||
}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user