Skip to content

Commit 49a99fd

Browse files
olaservoclaude
andcommitted
chore(cli): improve test infrastructure
- Move express from dependencies to devDependencies (only used in tests) - Add defensive check for child.pid in cli-runner.ts - Extract test URIs to constants (TEST_URI_ENV, TEST_URI_RESOURCE) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 44d0e58 commit 49a99fd

6 files changed

Lines changed: 22 additions & 15 deletions

File tree

cli/__tests__/cli.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "./helpers/assertions.js";
88
import {
99
NO_SERVER_SENTINEL,
10+
TEST_URI_ENV,
1011
createSampleTestConfig,
1112
createTestConfig,
1213
createInvalidConfig,
@@ -75,7 +76,7 @@ describe("CLI Tests", () => {
7576
"--method",
7677
"resources/read",
7778
"--uri",
78-
"test://env",
79+
TEST_URI_ENV,
7980
]);
8081

8182
expectCliSuccess(result);
@@ -114,7 +115,7 @@ describe("CLI Tests", () => {
114115
"--method",
115116
"resources/read",
116117
"--uri",
117-
"test://env",
118+
TEST_URI_ENV,
118119
]);
119120

120121
expectCliSuccess(result);
@@ -134,7 +135,7 @@ describe("CLI Tests", () => {
134135
"--method",
135136
"resources/read",
136137
"--uri",
137-
"test://env",
138+
TEST_URI_ENV,
138139
]);
139140

140141
expectCliSuccess(result);
@@ -427,7 +428,7 @@ describe("CLI Tests", () => {
427428
"--method",
428429
"resources/read",
429430
"--uri",
430-
"test://env",
431+
TEST_URI_ENV,
431432
]);
432433

433434
expectCliSuccess(result);
@@ -522,7 +523,7 @@ describe("CLI Tests", () => {
522523
"--method",
523524
"resources/read",
524525
"--uri",
525-
"test://env",
526+
TEST_URI_ENV,
526527
]);
527528

528529
expectCliSuccess(envResult);
@@ -630,7 +631,7 @@ describe("CLI Tests", () => {
630631
"--method",
631632
"resources/read",
632633
"--uri",
633-
"test://env",
634+
TEST_URI_ENV,
634635
]);
635636

636637
expectCliSuccess(envResult);

cli/__tests__/helpers/cli-runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export async function runCli(
5050
try {
5151
if (process.platform === "win32") {
5252
child.kill("SIGTERM");
53-
} else {
53+
} else if (child.pid) {
5454
// On Unix, kill the process group
55-
process.kill(-child.pid!, "SIGTERM");
55+
process.kill(-child.pid, "SIGTERM");
5656
}
5757
} catch (e) {
5858
// Process might already be dead, try direct kill

cli/__tests__/helpers/fixtures.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { getTestMcpServerCommand } from "./test-server-stdio.js";
1010
*/
1111
export const NO_SERVER_SENTINEL = "invalid-command-that-does-not-exist";
1212

13+
/**
14+
* Test resource URIs used across test files
15+
*/
16+
export const TEST_URI_ENV = "test://env";
17+
export const TEST_URI_RESOURCE = "test://resource";
18+
1319
/**
1420
* Create a sample test config with test-stdio and test-http servers
1521
* Returns a temporary config file path that should be cleaned up with deleteConfigFile()

cli/__tests__/metadata.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
createAddTool,
1212
createTestServerInfo,
1313
} from "./helpers/test-fixtures.js";
14-
import { NO_SERVER_SENTINEL } from "./helpers/fixtures.js";
14+
import { NO_SERVER_SENTINEL, TEST_URI_RESOURCE } from "./helpers/fixtures.js";
1515

1616
describe("Metadata Tests", () => {
1717
describe("General Metadata", () => {
@@ -57,7 +57,7 @@ describe("Metadata Tests", () => {
5757
serverInfo: createTestServerInfo(),
5858
resources: [
5959
{
60-
uri: "test://resource",
60+
uri: TEST_URI_RESOURCE,
6161
name: "test-resource",
6262
text: "test content",
6363
},
@@ -146,7 +146,7 @@ describe("Metadata Tests", () => {
146146
serverInfo: createTestServerInfo(),
147147
resources: [
148148
{
149-
uri: "test://resource",
149+
uri: TEST_URI_RESOURCE,
150150
name: "test-resource",
151151
text: "test content",
152152
},
@@ -163,7 +163,7 @@ describe("Metadata Tests", () => {
163163
"--method",
164164
"resources/read",
165165
"--uri",
166-
"test://resource",
166+
TEST_URI_RESOURCE,
167167
"--metadata",
168168
"client=test-client",
169169
"--transport",
@@ -653,7 +653,7 @@ describe("Metadata Tests", () => {
653653
serverInfo: createTestServerInfo(),
654654
resources: [
655655
{
656-
uri: "test://resource",
656+
uri: TEST_URI_RESOURCE,
657657
name: "test-resource",
658658
text: "test content",
659659
},

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
},
2727
"devDependencies": {
2828
"@types/express": "^5.0.6",
29+
"express": "^5.2.1",
2930
"tsx": "^4.7.0",
3031
"vitest": "^4.0.17"
3132
},
3233
"dependencies": {
3334
"@modelcontextprotocol/sdk": "^1.25.2",
3435
"commander": "^13.1.0",
35-
"express": "^5.2.1",
3636
"spawn-rx": "^5.1.2"
3737
}
3838
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)