Skip to content

Commit c202819

Browse files
committed
test: decoupling common logic
1 parent 3c31ddc commit c202819

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

tests/index.test.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {Client} from '@modelcontextprotocol/sdk/client/index.js';
1212
import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js';
1313
import {executablePath} from 'puppeteer';
1414

15+
import type {ToolCategory} from '../src/tools/categories.js';
1516
import {OFF_BY_DEFAULT_CATEGORIES} from '../src/tools/categories.js';
1617
import type {ToolDefinition} from '../src/tools/ToolDefinition.js';
1718

@@ -162,7 +163,7 @@ describe('e2e', () => {
162163
});
163164

164165
async function getToolsWithFilteredCategories(
165-
filterOutCategories: string[] = [],
166+
filterOutCategories: ToolCategory[] = [],
166167
): Promise<string[]> {
167168
const files = fs.readdirSync('build/src/tools');
168169
const definedNames = [];
@@ -176,40 +177,39 @@ async function getToolsWithFilteredCategories(
176177
}
177178
const fileTools = await import(`../src/tools/${file}`);
178179
for (const maybeTool of Object.values<unknown>(fileTools)) {
180+
let tool;
179181
if (typeof maybeTool === 'function') {
180-
const tool = (maybeTool as (val: boolean) => ToolDefinition)(false);
181-
if (tool && typeof tool === 'object' && 'name' in tool) {
182-
if (tool.annotations?.conditions) {
183-
continue;
184-
}
185-
if (
186-
tool.annotations?.category &&
187-
filterOutCategories.includes(tool.annotations?.category)
188-
) {
189-
continue;
190-
}
191-
definedNames.push(tool.name);
192-
}
193-
continue;
182+
tool = (maybeTool as (val: boolean) => ToolDefinition)(false);
183+
} else {
184+
tool = maybeTool as ToolDefinition;
194185
}
195-
if (
196-
typeof maybeTool === 'object' &&
197-
maybeTool !== null &&
198-
'name' in maybeTool
199-
) {
200-
const tool = maybeTool as ToolDefinition;
201-
if (tool.annotations?.conditions) {
202-
continue;
203-
}
204-
if (
205-
tool.annotations?.category &&
206-
filterOutCategories.includes(tool.annotations?.category)
207-
) {
208-
continue;
209-
}
210-
definedNames.push(tool.name);
186+
187+
if (toolShouldBeSkipped(tool, filterOutCategories)) {
188+
continue;
211189
}
190+
definedNames.push(tool.name);
212191
}
213192
}
214193
return definedNames;
215194
}
195+
196+
function toolShouldBeSkipped(
197+
tool: ToolDefinition,
198+
filteredOutCategories: ToolCategory[],
199+
) {
200+
if (tool === null || typeof tool !== 'object' || !('name' in tool)) {
201+
return true;
202+
}
203+
204+
if (tool.annotations?.conditions) {
205+
return true;
206+
}
207+
if (
208+
tool.annotations?.category &&
209+
filteredOutCategories.includes(tool.annotations?.category)
210+
) {
211+
return true;
212+
}
213+
214+
return false;
215+
}

0 commit comments

Comments
 (0)