Skip to content

Commit 2a18f34

Browse files
committed
refactor: use shared runLogic helper in device and macOS test files
Replace 7 identical local runLogic definitions with the shared import from test-helpers.ts.
1 parent 9acaabb commit 2a18f34

File tree

7 files changed

+14
-238
lines changed

7 files changed

+14
-238
lines changed

src/mcp/tools/device/__tests__/get_device_app_path.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,8 @@ import {
77
} from '../../../../test-utils/mock-executors.ts';
88
import { schema, handler, get_device_app_pathLogic } from '../get_device_app_path.ts';
99
import { sessionStore } from '../../../../utils/session-store.ts';
10-
import { 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 { runLogic } from '../../../../test-utils/test-helpers.ts';
11+
4412

4513
describe('get_device_app_path plugin', () => {
4614
beforeEach(() => {

src/mcp/tools/device/__tests__/install_app_device.test.ts

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

419
describe('install_app_device plugin', () => {
4210
beforeEach(() => {

src/mcp/tools/device/__tests__/launch_app_device.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 { schema, handler, launch_app_deviceLogic } from '../launch_app_device.ts';
88
import { sessionStore } from '../../../../utils/session-store.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('launch_app_device plugin (device-shared)', () => {
4513
beforeEach(() => {

src/mcp/tools/device/__tests__/stop_app_device.test.ts

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

419
describe('stop_app_device plugin', () => {
4210
beforeEach(() => {

src/mcp/tools/macos/__tests__/get_mac_app_path.test.ts

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

4614
describe('get_mac_app_path plugin', () => {
4715
beforeEach(() => {

src/mcp/tools/macos/__tests__/launch_mac_app.test.ts

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

4311
describe('launch_mac_app plugin', () => {
4412
describe('Export Field Validation (Literal)', () => {

src/mcp/tools/macos/__tests__/stop_mac_app.test.ts

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

386
describe('stop_mac_app plugin', () => {
397
describe('Export Field Validation (Literal)', () => {

0 commit comments

Comments
 (0)