-
-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathsession_set_defaults.test.ts
More file actions
112 lines (96 loc) · 4.38 KB
/
session_set_defaults.test.ts
File metadata and controls
112 lines (96 loc) · 4.38 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
import { describe, it, expect, beforeEach } from 'vitest';
import { sessionStore } from '../../../../utils/session-store.ts';
import plugin, { sessionSetDefaultsLogic } from '../session_set_defaults.ts';
describe('session-set-defaults tool', () => {
beforeEach(() => {
sessionStore.clear();
});
describe('Export Field Validation (Literal)', () => {
it('should have correct name', () => {
expect(plugin.name).toBe('session-set-defaults');
});
it('should have correct description', () => {
expect(plugin.description).toBe(
'Set the session defaults needed by many tools. Most tools require one or more session defaults to be set before they can be used. Agents should set the relevant defaults at the beginning of a session.',
);
});
it('should have handler function', () => {
expect(typeof plugin.handler).toBe('function');
});
it('should have schema object', () => {
expect(plugin.schema).toBeDefined();
expect(typeof plugin.schema).toBe('object');
});
});
describe('Handler Behavior', () => {
it('should set provided defaults and return updated state', async () => {
const result = await sessionSetDefaultsLogic({
scheme: 'MyScheme',
simulatorName: 'iPhone 16',
useLatestOS: true,
arch: 'arm64',
});
expect(result.isError).toBe(false);
expect(result.content[0].text).toContain('Defaults updated:');
const current = sessionStore.getAll();
expect(current.scheme).toBe('MyScheme');
expect(current.simulatorName).toBe('iPhone 16');
expect(current.useLatestOS).toBe(true);
expect(current.arch).toBe('arm64');
});
it('should validate parameter types via Zod', async () => {
const result = await plugin.handler({
useLatestOS: 'yes' as unknown as boolean,
});
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('Parameter validation failed');
expect(result.content[0].text).toContain('useLatestOS');
});
it('should clear workspacePath when projectPath is set', async () => {
sessionStore.setDefaults({ workspacePath: '/old/App.xcworkspace' });
await sessionSetDefaultsLogic({ projectPath: '/new/App.xcodeproj' });
const current = sessionStore.getAll();
expect(current.projectPath).toBe('/new/App.xcodeproj');
expect(current.workspacePath).toBeUndefined();
});
it('should clear projectPath when workspacePath is set', async () => {
sessionStore.setDefaults({ projectPath: '/old/App.xcodeproj' });
await sessionSetDefaultsLogic({ workspacePath: '/new/App.xcworkspace' });
const current = sessionStore.getAll();
expect(current.workspacePath).toBe('/new/App.xcworkspace');
expect(current.projectPath).toBeUndefined();
});
it('should clear simulatorName when simulatorId is set', async () => {
sessionStore.setDefaults({ simulatorName: 'iPhone 16' });
await sessionSetDefaultsLogic({ simulatorId: 'SIM-UUID' });
const current = sessionStore.getAll();
expect(current.simulatorId).toBe('SIM-UUID');
expect(current.simulatorName).toBeUndefined();
});
it('should clear simulatorId when simulatorName is set', async () => {
sessionStore.setDefaults({ simulatorId: 'SIM-UUID' });
await sessionSetDefaultsLogic({ simulatorName: 'iPhone 16' });
const current = sessionStore.getAll();
expect(current.simulatorName).toBe('iPhone 16');
expect(current.simulatorId).toBeUndefined();
});
it('should reject when both projectPath and workspacePath are provided', async () => {
const res = await plugin.handler({
projectPath: '/app/App.xcodeproj',
workspacePath: '/app/App.xcworkspace',
});
expect(res.isError).toBe(true);
expect(res.content[0].text).toContain('Parameter validation failed');
expect(res.content[0].text).toContain('projectPath and workspacePath are mutually exclusive');
});
it('should reject when both simulatorId and simulatorName are provided', async () => {
const res = await plugin.handler({
simulatorId: 'SIM-1',
simulatorName: 'iPhone 16',
});
expect(res.isError).toBe(true);
expect(res.content[0].text).toContain('Parameter validation failed');
expect(res.content[0].text).toContain('simulatorId and simulatorName are mutually exclusive');
});
});
});