-
-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathboot_sim.test.ts
More file actions
153 lines (130 loc) · 4.52 KB
/
boot_sim.test.ts
File metadata and controls
153 lines (130 loc) · 4.52 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
/**
* Tests for boot_sim plugin (session-aware version)
* Follows CLAUDE.md guidance: dependency injection, no vi-mocks, literal validation.
*/
import { describe, it, expect, beforeEach } from 'vitest';
import { z } from 'zod';
import { createMockExecutor } from '../../../../test-utils/mock-executors.ts';
import { sessionStore } from '../../../../utils/session-store.ts';
import bootSim, { boot_simLogic } from '../boot_sim.ts';
describe('boot_sim tool', () => {
beforeEach(() => {
sessionStore.clear();
});
describe('Export Field Validation (Literal)', () => {
it('should have correct name', () => {
expect(bootSim.name).toBe('boot_sim');
});
it('should have concise description', () => {
expect(bootSim.description).toBe('Boots an iOS simulator.');
});
it('should expose empty public schema', () => {
const schema = z.object(bootSim.schema);
expect(schema.safeParse({}).success).toBe(true);
expect(Object.keys(bootSim.schema)).toHaveLength(0);
});
});
describe('Handler Requirements', () => {
it('should require simulatorId when not provided', async () => {
const result = await bootSim.handler({});
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('Missing required session defaults');
expect(result.content[0].text).toContain('simulatorId is required');
expect(result.content[0].text).toContain('session-set-defaults');
});
});
describe('Logic Behavior (Literal Results)', () => {
it('should handle successful boot', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: 'Simulator booted successfully',
});
const result = await boot_simLogic({ simulatorId: 'test-uuid-123' }, mockExecutor);
expect(result).toEqual({
content: [
{
type: 'text',
text: `✅ Simulator booted successfully. To make it visible, use: open_sim()
Next steps:
1. Open the Simulator app (makes it visible): open_sim()
2. Install an app: install_app_sim({ simulatorId: "test-uuid-123", appPath: "PATH_TO_YOUR_APP" })
3. Launch an app: launch_app_sim({ simulatorId: "test-uuid-123", bundleId: "YOUR_APP_BUNDLE_ID" })`,
},
],
});
});
it('should handle command failure', async () => {
const mockExecutor = createMockExecutor({
success: false,
error: 'Simulator not found',
});
const result = await boot_simLogic({ simulatorId: 'invalid-uuid' }, mockExecutor);
expect(result).toEqual({
content: [
{
type: 'text',
text: 'Boot simulator operation failed: Simulator not found',
},
],
});
});
it('should handle exception with Error object', async () => {
const mockExecutor = async () => {
throw new Error('Connection failed');
};
const result = await boot_simLogic({ simulatorId: 'test-uuid-123' }, mockExecutor);
expect(result).toEqual({
content: [
{
type: 'text',
text: 'Boot simulator operation failed: Connection failed',
},
],
});
});
it('should handle exception with string error', async () => {
const mockExecutor = async () => {
throw 'String error';
};
const result = await boot_simLogic({ simulatorId: 'test-uuid-123' }, mockExecutor);
expect(result).toEqual({
content: [
{
type: 'text',
text: 'Boot simulator operation failed: String error',
},
],
});
});
it('should verify command generation with mock executor', async () => {
const calls: Array<{
command: string[];
description: string;
allowStderr: boolean;
timeout?: number;
}> = [];
const mockExecutor = async (
command: string[],
description: string,
allowStderr: boolean,
timeout?: number,
) => {
calls.push({ command, description, allowStderr, timeout });
return {
success: true,
output: 'Simulator booted successfully',
error: undefined,
process: { pid: 12345 },
};
};
await boot_simLogic({ simulatorId: 'test-uuid-123' }, mockExecutor);
expect(calls).toHaveLength(1);
expect(calls[0]).toEqual({
command: ['xcrun', 'simctl', 'boot', 'test-uuid-123'],
description: 'Boot Simulator',
allowStderr: true,
timeout: undefined,
});
});
});
});