Skip to content

Commit f113c37

Browse files
authored
refactor(toolsets): remove unused matchesFilter method (#229)
* refactor(toolsets): remove unused matchesFilter method Remove the private matchesFilter method from StackOneToolSet class as it was never called anywhere in the codebase. The filterTools method implements filtering directly using matchGlob without delegating to matchesFilter. Changes: - Remove matchesFilter method (lines 355-371) - Remove unused import of Arrayable from type-fest - Remove unused import of toArray from utils/array - Remove testMatchesFilter helper from test class - Remove associated test cases for matchesFilter - Rename describe block from 'glob and filter matching' to 'glob matching' * chore(deps): add typescript as devDependency Add typescript to enable vitest type checking during test runs. Previously vitest's typecheck feature would fail with 'spawn tsc ENOENT' because typescript was not installed as a dependency. - Add typescript ^5.8.3 to pnpm-workspace.yaml catalog - Add typescript: catalog:dev to package.json devDependencies * test: remove useless test(it is test for msw lol)
1 parent faf1ac2 commit f113c37

5 files changed

Lines changed: 8 additions & 77 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"publint": "catalog:dev",
6060
"tsdown": "catalog:dev",
6161
"type-fest": "catalog:dev",
62+
"typescript": "catalog:dev",
6263
"unplugin-unused": "catalog:dev",
6364
"vitest": "catalog:dev"
6465
},

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ catalogs:
2424
publint: ^0.3.12
2525
tsdown: ^0.17.2
2626
type-fest: ^4.41.0
27+
typescript: ^5.8.3
2728
unplugin-unused: ^0.5.4
2829
vitest: ^4.0.15
2930
zod: ^4.1.13

src/toolsets.test.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ import { type McpToolDefinition, createMcpApp } from '../mocks/mcp-server';
1212
import { server } from '../mocks/node';
1313
import { StackOneToolSet, ToolSetConfigError } from './toolsets';
1414

15-
/**
16-
* Test helper: Extends StackOneToolSet to expose private methods for testing
17-
*/
18-
class TestableStackOneToolSet extends StackOneToolSet {
19-
// Expose private methods for testing
20-
public testMatchesFilter(toolName: string, filterPattern: string | string[]): boolean {
21-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Accessing private method for testing
22-
return (this as any).matchesFilter(toolName, filterPattern);
23-
}
24-
25-
public testMatchGlob(str: string, pattern: string): boolean {
26-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Accessing private method for testing
27-
return (this as any).matchGlob(str, pattern);
28-
}
29-
}
30-
3115
describe('StackOneToolSet', () => {
3216
beforeEach(() => {
3317
vi.stubEnv('STACKONE_API_KEY', 'test_key');
@@ -174,41 +158,6 @@ describe('StackOneToolSet', () => {
174158
});
175159
});
176160

177-
describe('glob and filter matching', () => {
178-
it('should correctly match glob patterns', () => {
179-
const toolset = new TestableStackOneToolSet({ apiKey: 'test_key' });
180-
181-
expect(toolset.testMatchGlob('bamboohr_get_employee', 'bamboohr_*')).toBe(true);
182-
expect(toolset.testMatchGlob('bamboohr_get_employee', 'salesforce_*')).toBe(false);
183-
expect(toolset.testMatchGlob('bamboohr_get_employee', '*_get_*')).toBe(true);
184-
expect(toolset.testMatchGlob('bamboohr_get_employee', 'bamboohr_get_?mployee')).toBe(true);
185-
expect(toolset.testMatchGlob('bamboohr.get.employee', 'bamboohr.get.employee')).toBe(true);
186-
});
187-
188-
it('should correctly filter tools with a pattern', () => {
189-
const toolset = new TestableStackOneToolSet({ apiKey: 'test_key' });
190-
191-
expect(toolset.testMatchesFilter('bamboohr_get_employee', 'bamboohr_*')).toBe(true);
192-
expect(toolset.testMatchesFilter('salesforce_get_contact', 'bamboohr_*')).toBe(false);
193-
expect(
194-
toolset.testMatchesFilter('bamboohr_get_employee', ['bamboohr_*', 'salesforce_*']),
195-
).toBe(true);
196-
expect(
197-
toolset.testMatchesFilter('salesforce_get_contact', ['bamboohr_*', 'salesforce_*']),
198-
).toBe(true);
199-
expect(
200-
toolset.testMatchesFilter('workday_get_candidate', ['bamboohr_*', 'salesforce_*']),
201-
).toBe(false);
202-
203-
// Test negative patterns
204-
expect(toolset.testMatchesFilter('bamboohr_get_employee', ['*', '!salesforce_*'])).toBe(true);
205-
expect(toolset.testMatchesFilter('salesforce_get_contact', ['*', '!salesforce_*'])).toBe(
206-
false,
207-
);
208-
expect(toolset.testMatchesFilter('bamboohr_get_employee', ['*', '!bamboohr_*'])).toBe(false);
209-
});
210-
});
211-
212161
describe('fetchTools (MCP integration)', () => {
213162
it('creates tools from MCP catalog and wires RPC execution', async () => {
214163
const toolset = new StackOneToolSet({

src/toolsets.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { defu } from 'defu';
2-
import type { Arrayable } from 'type-fest';
32
import { DEFAULT_BASE_URL, UNIFIED_API_PREFIX } from './consts';
43
import { createFeedbackTool } from './feedback';
54
import { type StackOneHeaders, normaliseHeaders, stackOneHeadersSchema } from './headers';
@@ -13,7 +12,6 @@ import type {
1312
RpcExecuteConfig,
1413
ToolParameters,
1514
} from './types';
16-
import { toArray } from './utils/array';
1715
import { StackOneError } from './utils/errors';
1816

1917
/**
@@ -346,30 +344,6 @@ export class StackOneToolSet {
346344
return new Tools(filteredTools);
347345
}
348346

349-
/**
350-
* Check if a tool name matches a filter pattern
351-
* @param toolName Tool name to check
352-
* @param filterPattern Filter pattern or array of patterns
353-
* @returns True if the tool name matches the filter pattern
354-
*/
355-
private matchesFilter(toolName: string, filterPattern: Arrayable<string>): boolean {
356-
// Convert to array to handle both single string and array patterns
357-
const patterns = toArray(filterPattern);
358-
359-
// Split into positive and negative patterns
360-
const positivePatterns = patterns.filter((p) => !p.startsWith('!'));
361-
const negativePatterns = patterns.filter((p) => p.startsWith('!')).map((p) => p.substring(1));
362-
363-
// If no positive patterns, treat as match all
364-
const matchesPositive =
365-
positivePatterns.length === 0 || positivePatterns.some((p) => this.matchGlob(toolName, p));
366-
367-
// If any negative pattern matches, exclude the tool
368-
const matchesNegative = negativePatterns.some((p) => this.matchGlob(toolName, p));
369-
370-
return matchesPositive && !matchesNegative;
371-
}
372-
373347
/**
374348
* Check if a string matches a glob pattern
375349
* @param str String to check

0 commit comments

Comments
 (0)