Skip to content

Commit 8ac7392

Browse files
committed
feat: unit test cli list parsing
1 parent 9a61b34 commit 8ac7392

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

packages/mcp-server-supabase/src/transports/stdio.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { parseArgs } from 'node:util';
55
import packageJson from '../../package.json' with { type: 'json' };
66
import { createSupabaseApiPlatform } from '../platform/api-platform.js';
77
import { createSupabaseMcpServer } from '../server.js';
8+
import { parseList } from './util.js';
89

910
const { version } = packageJson;
1011

@@ -16,7 +17,7 @@ async function main() {
1617
['read-only']: readOnly,
1718
['api-url']: apiUrl,
1819
['version']: showVersion,
19-
['features']: features,
20+
['features']: cliFeatures,
2021
},
2122
} = parseArgs({
2223
options: {
@@ -47,18 +48,17 @@ async function main() {
4748
process.exit(0);
4849
}
4950

50-
// Use access token from CLI argument or environment variable
5151
const accessToken = cliAccessToken ?? process.env.SUPABASE_ACCESS_TOKEN;
5252

53-
const featureList = features?.split(',') ?? [];
54-
5553
if (!accessToken) {
5654
console.error(
5755
'Please provide a personal access token (PAT) with the --access-token flag or set the SUPABASE_ACCESS_TOKEN environment variable'
5856
);
5957
process.exit(1);
6058
}
6159

60+
const features = cliFeatures ? parseList(cliFeatures) : undefined;
61+
6262
const platform = createSupabaseApiPlatform({
6363
accessToken,
6464
apiUrl,
@@ -68,7 +68,7 @@ async function main() {
6868
platform,
6969
projectId,
7070
readOnly,
71-
features: featureList,
71+
features,
7272
});
7373

7474
const transport = new StdioServerTransport();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, test } from 'vitest';
2+
import { parseList } from './util.js';
3+
4+
describe('parseList', () => {
5+
test('should parse comma-delimited list', () => {
6+
const result = parseList('item1,item2,item3');
7+
expect(result).toEqual(['item1', 'item2', 'item3']);
8+
});
9+
10+
test('should handle spaces around items', () => {
11+
const result = parseList('item1, item2 , item3');
12+
expect(result).toEqual(['item1', 'item2', 'item3']);
13+
});
14+
15+
test('should filter out empty items', () => {
16+
const result = parseList('item1,,item2,');
17+
expect(result).toEqual(['item1', 'item2']);
18+
});
19+
20+
test('should handle custom delimiter', () => {
21+
const result = parseList('item1|item2|item3', '|');
22+
expect(result).toEqual(['item1', 'item2', 'item3']);
23+
});
24+
25+
test('should handle single item', () => {
26+
const result = parseList('item1');
27+
expect(result).toEqual(['item1']);
28+
});
29+
30+
test('should handle empty string', () => {
31+
const result = parseList('');
32+
expect(result).toEqual([]);
33+
});
34+
35+
test('should handle string with only delimiters', () => {
36+
const result = parseList(',,,');
37+
expect(result).toEqual([]);
38+
});
39+
40+
test('should handle semicolon delimiter', () => {
41+
const result = parseList('item1; item2; item3', ';');
42+
expect(result).toEqual(['item1', 'item2', 'item3']);
43+
});
44+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Parses a delimited list of items into an array,
3+
* trimming whitespace and filtering out empty items.
4+
*
5+
* Default delimiter is a comma (`,`).
6+
*/
7+
export function parseList(list: string, delimiter = ','): string[] {
8+
const items = list.split(delimiter).map((feature) => feature.trim());
9+
return items.filter((feature) => feature !== '');
10+
}

0 commit comments

Comments
 (0)