Skip to content

Commit 8d84711

Browse files
committed
refactor: use shared runLogic helper in simulator test files
Replace 12 identical local runLogic definitions with the shared import from test-helpers.ts.
1 parent ec79193 commit 8d84711

File tree

12 files changed

+23
-407
lines changed

12 files changed

+23
-407
lines changed

src/mcp/tools/simulator-management/__tests__/erase_sims.test.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
11
import { describe, it, expect } from 'vitest';
22
import { schema, erase_simsLogic } from '../erase_sims.ts';
33
import { createMockExecutor } from '../../../../test-utils/mock-executors.ts';
4-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
4+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
55

6-
const runLogic = async (logic: () => Promise<unknown>) => {
7-
const { result, run } = createMockToolHandlerContext();
8-
const response = await run(logic);
9-
10-
if (
11-
response &&
12-
typeof response === 'object' &&
13-
'content' in (response as Record<string, unknown>)
14-
) {
15-
return response as {
16-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
17-
isError?: boolean;
18-
nextStepParams?: unknown;
19-
};
20-
}
21-
22-
const text = result.text();
23-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
24-
const imageContent = result.attachments.map((attachment) => ({
25-
type: 'image' as const,
26-
data: attachment.data,
27-
mimeType: attachment.mimeType,
28-
}));
29-
30-
return {
31-
content: [...textContent, ...imageContent],
32-
isError: result.isError() ? true : undefined,
33-
nextStepParams: result.nextStepParams,
34-
attachments: result.attachments,
35-
text,
36-
};
37-
};
386

397
describe('erase_sims tool (single simulator)', () => {
408
describe('Plugin Structure', () => {

src/mcp/tools/simulator-management/__tests__/reset_sim_location.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,8 @@ import { describe, it, expect } from 'vitest';
22
import * as z from 'zod';
33
import { schema, reset_sim_locationLogic } from '../reset_sim_location.ts';
44
import { createMockExecutor } from '../../../../test-utils/mock-executors.ts';
5-
import { createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
6-
7-
const runLogic = async (logic: () => Promise<unknown>) => {
8-
const { result, run } = createMockToolHandlerContext();
9-
const response = await run(logic);
10-
11-
if (
12-
response &&
13-
typeof response === 'object' &&
14-
'content' in (response as Record<string, unknown>)
15-
) {
16-
return response as {
17-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
18-
isError?: boolean;
19-
nextStepParams?: unknown;
20-
};
21-
}
22-
23-
const text = result.text();
24-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
25-
const imageContent = result.attachments.map((attachment) => ({
26-
type: 'image' as const,
27-
data: attachment.data,
28-
mimeType: attachment.mimeType,
29-
}));
30-
31-
return {
32-
content: [...textContent, ...imageContent],
33-
isError: result.isError() ? true : undefined,
34-
nextStepParams: result.nextStepParams,
35-
attachments: result.attachments,
36-
text,
37-
};
38-
};
5+
import { runLogic } from '../../../../test-utils/test-helpers.ts';
6+
397

408
describe('reset_sim_location plugin', () => {
419
describe('Schema Validation', () => {

src/mcp/tools/simulator-management/__tests__/set_sim_appearance.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
11
import { describe, it, expect } from 'vitest';
22
import * as z from 'zod';
33
import { schema, handler, set_sim_appearanceLogic } from '../set_sim_appearance.ts';
4-
import { createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
5-
6-
const runLogic = async (logic: () => Promise<unknown>) => {
7-
const { result, run } = createMockToolHandlerContext();
8-
const response = await run(logic);
9-
10-
if (
11-
response &&
12-
typeof response === 'object' &&
13-
'content' in (response as Record<string, unknown>)
14-
) {
15-
return response as {
16-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
17-
isError?: boolean;
18-
nextStepParams?: unknown;
19-
};
20-
}
21-
22-
const text = result.text();
23-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
24-
const imageContent = result.attachments.map((attachment) => ({
25-
type: 'image' as const,
26-
data: attachment.data,
27-
mimeType: attachment.mimeType,
28-
}));
29-
30-
return {
31-
content: [...textContent, ...imageContent],
32-
isError: result.isError() ? true : undefined,
33-
nextStepParams: result.nextStepParams,
34-
attachments: result.attachments,
35-
text,
36-
};
37-
};
4+
import { runLogic } from '../../../../test-utils/test-helpers.ts';
5+
386

397
import {
408
createMockCommandResponse,

src/mcp/tools/simulator-management/__tests__/set_sim_location.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,8 @@ import {
66
createNoopExecutor,
77
} from '../../../../test-utils/mock-executors.ts';
88
import { schema, handler, set_sim_locationLogic } from '../set_sim_location.ts';
9-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
10-
11-
const runLogic = async (logic: () => Promise<unknown>) => {
12-
const { result, run } = createMockToolHandlerContext();
13-
const response = await run(logic);
14-
15-
if (
16-
response &&
17-
typeof response === 'object' &&
18-
'content' in (response as Record<string, unknown>)
19-
) {
20-
return response as {
21-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
22-
isError?: boolean;
23-
nextStepParams?: unknown;
24-
};
25-
}
26-
27-
const text = result.text();
28-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
29-
const imageContent = result.attachments.map((attachment) => ({
30-
type: 'image' as const,
31-
data: attachment.data,
32-
mimeType: attachment.mimeType,
33-
}));
34-
35-
return {
36-
content: [...textContent, ...imageContent],
37-
isError: result.isError() ? true : undefined,
38-
nextStepParams: result.nextStepParams,
39-
attachments: result.attachments,
40-
text,
41-
};
42-
};
9+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
10+
4311

4412
describe('set_sim_location tool', () => {
4513
describe('Export Field Validation (Literal)', () => {

src/mcp/tools/simulator-management/__tests__/sim_statusbar.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,8 @@ import {
66
type CommandExecutor,
77
} from '../../../../test-utils/mock-executors.ts';
88
import { schema, sim_statusbarLogic } from '../sim_statusbar.ts';
9-
import { createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
10-
11-
const runLogic = async (logic: () => Promise<unknown>) => {
12-
const { result, run } = createMockToolHandlerContext();
13-
const response = await run(logic);
14-
15-
if (
16-
response &&
17-
typeof response === 'object' &&
18-
'content' in (response as Record<string, unknown>)
19-
) {
20-
return response as {
21-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
22-
isError?: boolean;
23-
nextStepParams?: unknown;
24-
};
25-
}
26-
27-
const text = result.text();
28-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
29-
const imageContent = result.attachments.map((attachment) => ({
30-
type: 'image' as const,
31-
data: attachment.data,
32-
mimeType: attachment.mimeType,
33-
}));
34-
35-
return {
36-
content: [...textContent, ...imageContent],
37-
isError: result.isError() ? true : undefined,
38-
nextStepParams: result.nextStepParams,
39-
attachments: result.attachments,
40-
text,
41-
};
42-
};
9+
import { runLogic } from '../../../../test-utils/test-helpers.ts';
10+
4311

4412
describe('sim_statusbar tool', () => {
4513
describe('Schema Validation', () => {

src/mcp/tools/simulator/__tests__/boot_sim.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,8 @@ import {
66
} from '../../../../test-utils/mock-executors.ts';
77
import { sessionStore } from '../../../../utils/session-store.ts';
88
import { schema, handler, boot_simLogic } from '../boot_sim.ts';
9-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
10-
11-
const runLogic = async (logic: () => Promise<unknown>) => {
12-
const { result, run } = createMockToolHandlerContext();
13-
const response = await run(logic);
14-
15-
if (
16-
response &&
17-
typeof response === 'object' &&
18-
'content' in (response as Record<string, unknown>)
19-
) {
20-
return response as {
21-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
22-
isError?: boolean;
23-
nextStepParams?: unknown;
24-
};
25-
}
26-
27-
const text = result.text();
28-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
29-
const imageContent = result.attachments.map((attachment) => ({
30-
type: 'image' as const,
31-
data: attachment.data,
32-
mimeType: attachment.mimeType,
33-
}));
34-
35-
return {
36-
content: [...textContent, ...imageContent],
37-
isError: result.isError() ? true : undefined,
38-
nextStepParams: result.nextStepParams,
39-
attachments: result.attachments,
40-
text,
41-
};
42-
};
9+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
10+
4311

4412
describe('boot_sim tool', () => {
4513
beforeEach(() => {

src/mcp/tools/simulator/__tests__/get_sim_app_path.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,8 @@ import { sessionStore } from '../../../../utils/session-store.ts';
77
import { schema, handler, get_sim_app_pathLogic } from '../get_sim_app_path.ts';
88
import type { CommandExecutor } from '../../../../utils/CommandExecutor.ts';
99
import { XcodePlatform } from '../../../../types/common.ts';
10-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
11-
12-
const runLogic = async (logic: () => Promise<unknown>) => {
13-
const { result, run } = createMockToolHandlerContext();
14-
const response = await run(logic);
15-
16-
if (
17-
response &&
18-
typeof response === 'object' &&
19-
'content' in (response as Record<string, unknown>)
20-
) {
21-
return response as {
22-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
23-
isError?: boolean;
24-
nextStepParams?: unknown;
25-
};
26-
}
27-
28-
const text = result.text();
29-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
30-
const imageContent = result.attachments.map((attachment) => ({
31-
type: 'image' as const,
32-
data: attachment.data,
33-
mimeType: attachment.mimeType,
34-
}));
35-
36-
return {
37-
content: [...textContent, ...imageContent],
38-
isError: result.isError() ? true : undefined,
39-
nextStepParams: result.nextStepParams,
40-
attachments: result.attachments,
41-
text,
42-
};
43-
};
10+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
11+
4412

4513
describe('get_sim_app_path tool', () => {
4614
beforeEach(() => {

src/mcp/tools/simulator/__tests__/install_app_sim.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,8 @@ import {
99
import { sessionStore } from '../../../../utils/session-store.ts';
1010
import type { CommandExecutor } from '../../../../utils/execution/index.ts';
1111
import { schema, handler, install_app_simLogic } from '../install_app_sim.ts';
12-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
13-
14-
const runLogic = async (logic: () => Promise<unknown>) => {
15-
const { result, run } = createMockToolHandlerContext();
16-
const response = await run(logic);
17-
18-
if (
19-
response &&
20-
typeof response === 'object' &&
21-
'content' in (response as Record<string, unknown>)
22-
) {
23-
return response as {
24-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
25-
isError?: boolean;
26-
nextStepParams?: unknown;
27-
};
28-
}
29-
30-
const text = result.text();
31-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
32-
const imageContent = result.attachments.map((attachment) => ({
33-
type: 'image' as const,
34-
data: attachment.data,
35-
mimeType: attachment.mimeType,
36-
}));
37-
38-
return {
39-
content: [...textContent, ...imageContent],
40-
isError: result.isError() ? true : undefined,
41-
nextStepParams: result.nextStepParams,
42-
attachments: result.attachments,
43-
text,
44-
};
45-
};
12+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
13+
4614

4715
describe('install_app_sim tool', () => {
4816
beforeEach(() => {

src/mcp/tools/simulator/__tests__/launch_app_sim.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,8 @@ import { createMockExecutor } from '../../../../test-utils/mock-executors.ts';
44
import { sessionStore } from '../../../../utils/session-store.ts';
55
import { schema, handler, launch_app_simLogic, type SimulatorLauncher } from '../launch_app_sim.ts';
66
import type { LaunchWithLoggingResult } from '../../../../utils/simulator-steps.ts';
7-
import { createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
8-
9-
const runLogic = async (logic: () => Promise<unknown>) => {
10-
const { result, run } = createMockToolHandlerContext();
11-
const response = await run(logic);
12-
13-
if (
14-
response &&
15-
typeof response === 'object' &&
16-
'content' in (response as Record<string, unknown>)
17-
) {
18-
return response as {
19-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
20-
isError?: boolean;
21-
nextStepParams?: unknown;
22-
};
23-
}
24-
25-
const text = result.text();
26-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
27-
const imageContent = result.attachments.map((attachment) => ({
28-
type: 'image' as const,
29-
data: attachment.data,
30-
mimeType: attachment.mimeType,
31-
}));
32-
33-
return {
34-
content: [...textContent, ...imageContent],
35-
isError: result.isError() ? true : undefined,
36-
nextStepParams: result.nextStepParams,
37-
attachments: result.attachments,
38-
text,
39-
};
40-
};
7+
import { runLogic } from '../../../../test-utils/test-helpers.ts';
8+
419

4210
function createMockLauncher(overrides?: Partial<LaunchWithLoggingResult>): SimulatorLauncher {
4311
return async (_uuid, _bundleId, _opts?) => ({

0 commit comments

Comments
 (0)