-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathskill.test.ts
More file actions
172 lines (152 loc) · 4.96 KB
/
Copy pathskill.test.ts
File metadata and controls
172 lines (152 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { describe, it, expect } from 'vitest';
import {
SkillSchema,
SkillTriggerConditionSchema,
defineSkill,
type Skill,
} from './skill.zod';
describe('SkillTriggerConditionSchema', () => {
it('should accept all operators', () => {
const operators = ['eq', 'neq', 'in', 'not_in', 'contains'] as const;
operators.forEach(operator => {
expect(() => SkillTriggerConditionSchema.parse({
field: 'objectName',
operator,
value: 'support_case',
})).not.toThrow();
});
});
it('should accept array value for in/not_in', () => {
const result = SkillTriggerConditionSchema.parse({
field: 'userRole',
operator: 'in',
value: ['admin', 'support_agent'],
});
expect(result.value).toEqual(['admin', 'support_agent']);
});
it('should accept string value', () => {
const result = SkillTriggerConditionSchema.parse({
field: 'channel',
operator: 'eq',
value: 'web',
});
expect(result.value).toBe('web');
});
});
describe('SkillSchema', () => {
it('should accept minimal skill', () => {
const skill: Skill = {
name: 'case_management',
label: 'Case Management',
tools: ['create_case', 'update_case', 'resolve_case'],
};
const result = SkillSchema.parse(skill);
expect(result.name).toBe('case_management');
expect(result.active).toBe(true);
expect(result.tools).toHaveLength(3);
});
it('should accept full skill', () => {
const skill = {
name: 'order_management',
label: 'Order Management',
description: 'Handles order lifecycle operations',
instructions: 'Use these tools to manage customer orders. Always verify order ownership first.',
tools: ['create_order', 'update_order', 'cancel_order', 'query_orders'],
triggerPhrases: ['place an order', 'cancel my order', 'check order status'],
triggerConditions: [
{ field: 'objectName', operator: 'eq' as const, value: 'order' },
{ field: 'userRole', operator: 'in' as const, value: ['sales', 'support'] },
],
permissions: ['order.manage', 'order.view'],
active: true,
};
const result = SkillSchema.parse(skill);
expect(result.name).toBe('order_management');
expect(result.tools).toHaveLength(4);
expect(result.triggerPhrases).toHaveLength(3);
expect(result.triggerConditions).toHaveLength(2);
expect(result.permissions).toEqual(['order.manage', 'order.view']);
});
it('should enforce snake_case for skill name', () => {
const validNames = ['case_management', 'order_ops', '_internal', 'knowledge_search'];
validNames.forEach(name => {
expect(() => SkillSchema.parse({
name,
label: 'Test',
tools: [],
})).not.toThrow();
});
const invalidNames = ['caseManagement', 'Order-Ops', '123skill'];
invalidNames.forEach(name => {
expect(() => SkillSchema.parse({
name,
label: 'Test',
tools: [],
})).toThrow();
});
});
it('should accept empty tools array', () => {
const result = SkillSchema.parse({
name: 'empty_skill',
label: 'Empty Skill',
tools: [],
});
expect(result.tools).toHaveLength(0);
});
it('should accept skill with instructions', () => {
const result = SkillSchema.parse({
name: 'knowledge_search',
label: 'Knowledge Search',
instructions: 'Search the knowledge base before escalating to a human agent.',
tools: ['search_knowledge', 'get_article'],
});
expect(result.instructions).toContain('knowledge base');
});
it('should enforce snake_case for tool name references', () => {
expect(() => SkillSchema.parse({
name: 'valid_skill',
label: 'Test',
tools: ['valid_tool', 'another_tool'],
})).not.toThrow();
expect(() => SkillSchema.parse({
name: 'valid_skill',
label: 'Test',
tools: ['InvalidTool'],
})).toThrow();
expect(() => SkillSchema.parse({
name: 'valid_skill',
label: 'Test',
tools: ['valid_tool', 'Invalid-Tool'],
})).toThrow();
});
});
describe('defineSkill', () => {
it('should return a parsed skill', () => {
const skill = defineSkill({
name: 'case_management',
label: 'Case Management',
description: 'Handles support case lifecycle',
instructions: 'Use these tools to create, update, and resolve support cases.',
tools: ['create_case', 'update_case', 'resolve_case'],
triggerPhrases: ['create a case', 'open a ticket'],
});
expect(skill.name).toBe('case_management');
expect(skill.tools).toHaveLength(3);
expect(skill.active).toBe(true);
});
it('should apply defaults', () => {
const skill = defineSkill({
name: 'simple_skill',
label: 'Simple',
tools: ['tool_a'],
});
expect(skill.active).toBe(true);
});
it('should throw on invalid skill name', () => {
expect(() => defineSkill({
name: 'InvalidName',
label: 'Test',
tools: [],
})).toThrow();
});
});