Skip to content

Commit 0ae8ed2

Browse files
committed
refactor: use shared runLogic helper in remaining tool test files
Replace 18 identical local runLogic definitions with the shared import from test-helpers.ts.
1 parent 1912ce5 commit 0ae8ed2

File tree

18 files changed

+31
-599
lines changed

18 files changed

+31
-599
lines changed

src/mcp/tools/coverage/__tests__/get_coverage_report.test.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,8 @@ import {
66
__clearTestExecutorOverrides,
77
} from '../../../../utils/execution/index.ts';
88
import { schema, handler, get_coverage_reportLogic } from '../get_coverage_report.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 (response && typeof response === 'object' && 'content' in (response as Record<string, unknown>)) {
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-
};
9+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
10+
3911

4012

4113
const sampleTargets = [

src/mcp/tools/coverage/__tests__/get_file_coverage.test.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,8 @@ import {
1010
__clearTestExecutorOverrides,
1111
} from '../../../../utils/execution/index.ts';
1212
import { schema, handler, get_file_coverageLogic } from '../get_file_coverage.ts';
13-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
14-
15-
const runLogic = async (logic: () => Promise<unknown>) => {
16-
const { result, run } = createMockToolHandlerContext();
17-
const response = await run(logic);
18-
19-
if (response && typeof response === 'object' && 'content' in (response as Record<string, unknown>)) {
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-
};
13+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
14+
4315

4416

4517
const sampleFunctionsJson = [

src/mcp/tools/debugging/__tests__/debugging-tools.test.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,40 +45,8 @@ import {
4545
handler as variablesHandler,
4646
debug_variablesLogic,
4747
} from '../debug_variables.ts';
48-
import { allText, createMockToolHandlerContext } from '../../../../test-utils/test-helpers.ts';
49-
50-
const runLogic = async (logic: () => Promise<unknown>) => {
51-
const { result, run } = createMockToolHandlerContext();
52-
const response = await run(logic);
53-
54-
if (
55-
response &&
56-
typeof response === 'object' &&
57-
'content' in (response as Record<string, unknown>)
58-
) {
59-
return response as {
60-
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
61-
isError?: boolean;
62-
nextStepParams?: Record<string, Record<string, unknown> | Record<string, unknown>[]>;
63-
};
64-
}
65-
66-
const text = result.text();
67-
const textContent = text.length > 0 ? [{ type: 'text' as const, text }] : [];
68-
const imageContent = result.attachments.map((attachment) => ({
69-
type: 'image' as const,
70-
data: attachment.data,
71-
mimeType: attachment.mimeType,
72-
}));
48+
import { allText, runLogic } from '../../../../test-utils/test-helpers.ts';
7349

74-
return {
75-
content: [...textContent, ...imageContent],
76-
isError: result.isError() ? true : undefined,
77-
nextStepParams: result.nextStepParams,
78-
attachments: result.attachments,
79-
text,
80-
};
81-
};
8250

8351
function createMockBackend(overrides: Partial<DebuggerBackend> = {}): DebuggerBackend {
8452
return {

src/mcp/tools/project-discovery/__tests__/discover_projs.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, handler, discover_projsLogic, discoverProjects } from '../discover_projs.ts';
44
import { createMockFileSystemExecutor } 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('discover_projs plugin', () => {
419
describe('Export Field Validation (Literal)', () => {

src/mcp/tools/project-discovery/__tests__/get_app_bundle_id.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, get_app_bundle_idLogic } from '../get_app_bundle_id.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
createMockFileSystemExecutor,

src/mcp/tools/project-discovery/__tests__/get_mac_bundle_id.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, get_mac_bundle_idLogic } from '../get_mac_bundle_id.ts';
3-
import { 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 { runLogic } from '../../../../test-utils/test-helpers.ts';
4+
375

386
import {
397
createMockFileSystemExecutor,

src/mcp/tools/project-discovery/__tests__/list_schemes.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, listSchemes, listSchemesLogic } from '../list_schemes.ts';
88
import { sessionStore } from '../../../../utils/session-store.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('list_schemes plugin', () => {
4513
beforeEach(() => {

src/mcp/tools/project-discovery/__tests__/show_build_settings.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, type CommandExecutor } from '../../../../test-utils/mock-executors.ts';
44
import { schema, handler, showBuildSettingsLogic } from '../show_build_settings.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('show_build_settings plugin', () => {
4210
beforeEach(() => {

src/mcp/tools/project-scaffolding/__tests__/scaffold_ios_project.test.ts

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

4816
const cwd = '/repo';
4917

0 commit comments

Comments
 (0)