-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathinstall_app_device.test.ts
More file actions
315 lines (273 loc) · 8.48 KB
/
install_app_device.test.ts
File metadata and controls
315 lines (273 loc) · 8.48 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/**
* Tests for install_app_device plugin (device-shared)
* Following CLAUDE.md testing standards with literal validation
* Using dependency injection for deterministic testing
*/
import { describe, it, expect, beforeEach } from 'vitest';
import { z } from 'zod';
import { createMockExecutor } from '../../../../test-utils/mock-executors.ts';
import installAppDevice, { install_app_deviceLogic } from '../install_app_device.ts';
import { sessionStore } from '../../../../utils/session-store.ts';
describe('install_app_device plugin', () => {
beforeEach(() => {
sessionStore.clear();
});
describe('Handler Requirements', () => {
it('should require deviceId when session defaults are missing', async () => {
const result = await installAppDevice.handler({
appPath: '/path/to/test.app',
});
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('deviceId is required');
});
});
describe('Export Field Validation (Literal)', () => {
it('should have correct name', () => {
expect(installAppDevice.name).toBe('install_app_device');
});
it('should have correct description', () => {
expect(installAppDevice.description).toBe('Installs an app on a connected device.');
});
it('should have handler function', () => {
expect(typeof installAppDevice.handler).toBe('function');
});
it('should require appPath in public schema', () => {
const schema = z.object(installAppDevice.schema).strict();
expect(schema.safeParse({ appPath: '/path/to/test.app' }).success).toBe(true);
expect(schema.safeParse({}).success).toBe(false);
expect(schema.safeParse({ deviceId: 'test-device-123' }).success).toBe(false);
expect(Object.keys(installAppDevice.schema)).toEqual(['appPath']);
});
});
describe('Command Generation', () => {
it('should generate correct devicectl command with basic parameters', async () => {
let capturedCommand: unknown[] = [];
let capturedDescription: string = '';
let capturedUseShell: boolean = false;
let capturedEnv: unknown = undefined;
const mockExecutor = createMockExecutor({
success: true,
output: 'App installation successful',
process: { pid: 12345 },
});
const trackingExecutor = async (
command: unknown[],
description: string,
useShell: boolean,
env: unknown,
) => {
capturedCommand = command;
capturedDescription = description;
capturedUseShell = useShell;
capturedEnv = env;
return mockExecutor(command, description, useShell, env);
};
await install_app_deviceLogic(
{
deviceId: 'test-device-123',
appPath: '/path/to/test.app',
},
trackingExecutor,
);
expect(capturedCommand).toEqual([
'xcrun',
'devicectl',
'device',
'install',
'app',
'--device',
'test-device-123',
'/path/to/test.app',
]);
expect(capturedDescription).toBe('Install app on device');
expect(capturedUseShell).toBe(true);
expect(capturedEnv).toBe(undefined);
});
it('should generate correct command with different device ID', async () => {
let capturedCommand: unknown[] = [];
const mockExecutor = createMockExecutor({
success: true,
output: 'App installation successful',
process: { pid: 12345 },
});
const trackingExecutor = async (command: unknown[]) => {
capturedCommand = command;
return mockExecutor(command);
};
await install_app_deviceLogic(
{
deviceId: 'different-device-uuid',
appPath: '/apps/MyApp.app',
},
trackingExecutor,
);
expect(capturedCommand).toEqual([
'xcrun',
'devicectl',
'device',
'install',
'app',
'--device',
'different-device-uuid',
'/apps/MyApp.app',
]);
});
it('should generate correct command with paths containing spaces', async () => {
let capturedCommand: unknown[] = [];
const mockExecutor = createMockExecutor({
success: true,
output: 'App installation successful',
process: { pid: 12345 },
});
const trackingExecutor = async (command: unknown[]) => {
capturedCommand = command;
return mockExecutor(command);
};
await install_app_deviceLogic(
{
deviceId: 'test-device-123',
appPath: '/path/to/My App.app',
},
trackingExecutor,
);
expect(capturedCommand).toEqual([
'xcrun',
'devicectl',
'device',
'install',
'app',
'--device',
'test-device-123',
'/path/to/My App.app',
]);
});
});
describe('Success Path Tests', () => {
it('should return successful installation response', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: 'App installation successful',
});
const result = await install_app_deviceLogic(
{
deviceId: 'test-device-123',
appPath: '/path/to/test.app',
},
mockExecutor,
);
expect(result).toEqual({
content: [
{
type: 'text',
text: '✅ App installed successfully on device test-device-123\n\nApp installation successful',
},
],
});
});
it('should return successful installation with detailed output', async () => {
const mockExecutor = createMockExecutor({
success: true,
output:
'Installing app...\nApp bundle: /path/to/test.app\nInstallation completed successfully',
});
const result = await install_app_deviceLogic(
{
deviceId: 'device-456',
appPath: '/apps/TestApp.app',
},
mockExecutor,
);
expect(result).toEqual({
content: [
{
type: 'text',
text: '✅ App installed successfully on device device-456\n\nInstalling app...\nApp bundle: /path/to/test.app\nInstallation completed successfully',
},
],
});
});
it('should return successful installation with empty output', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: '',
});
const result = await install_app_deviceLogic(
{
deviceId: 'empty-output-device',
appPath: '/path/to/app.app',
},
mockExecutor,
);
expect(result).toEqual({
content: [
{
type: 'text',
text: '✅ App installed successfully on device empty-output-device\n\n',
},
],
});
});
});
describe('Error Handling', () => {
it('should return installation failure response', async () => {
const mockExecutor = createMockExecutor({
success: false,
error: 'Installation failed: App not found',
});
const result = await install_app_deviceLogic(
{
deviceId: 'test-device-123',
appPath: '/path/to/nonexistent.app',
},
mockExecutor,
);
expect(result).toEqual({
content: [
{
type: 'text',
text: 'Failed to install app: Installation failed: App not found',
},
],
isError: true,
});
});
it('should return exception handling response', async () => {
const mockExecutor = createMockExecutor(new Error('Network error'));
const result = await install_app_deviceLogic(
{
deviceId: 'test-device-123',
appPath: '/path/to/test.app',
},
mockExecutor,
);
expect(result).toEqual({
content: [
{
type: 'text',
text: 'Failed to install app on device: Network error',
},
],
isError: true,
});
});
it('should return string error handling response', async () => {
const mockExecutor = createMockExecutor('String error');
const result = await install_app_deviceLogic(
{
deviceId: 'test-device-123',
appPath: '/path/to/test.app',
},
mockExecutor,
);
expect(result).toEqual({
content: [
{
type: 'text',
text: 'Failed to install app on device: String error',
},
],
isError: true,
});
});
});
});