Skip to content

Commit 8630c88

Browse files
committed
added test for agents/mcp
1 parent cf39255 commit 8630c88

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

test/integration/mcp-connection.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ function getMCPServers() {
1818
throw new Error('hono-mcp port not found in test state')
1919
}
2020

21+
if (!state.cfAgentsPort) {
22+
throw new Error('cf-agents port not found in test state')
23+
}
24+
2125
return [
2226
{
2327
name: 'hono-mcp',
2428
url: `http://localhost:${state.honoPort}/mcp`,
2529
expectedTools: 1, // Minimum expected tools count
2630
},
27-
// Add more servers here as they become available
28-
// {
29-
// name: 'another-server',
30-
// url: 'http://localhost:9902/mcp',
31-
// expectedTools: 1,
32-
// },
31+
{
32+
name: 'cf-agents',
33+
url: `http://localhost:${state.cfAgentsPort}/mcp`,
34+
expectedTools: 1, // Minimum expected tools count
35+
},
3336
]
3437
} catch (error) {
3538
throw new Error(`Test environment not properly initialized: ${error}`)
@@ -161,6 +164,15 @@ describe('MCP Connection Integration Tests', () => {
161164
// Ignore errors - process might already be dead
162165
}
163166

167+
try {
168+
if (state?.cfAgentsServer && !state.cfAgentsServer.killed) {
169+
console.log('🔥 Force cleanup cf-agents server...')
170+
state.cfAgentsServer.kill('SIGKILL')
171+
}
172+
} catch (e) {
173+
// Ignore errors - process might already be dead
174+
}
175+
164176
try {
165177
if (state?.staticServer) {
166178
state.staticServer.close()

test/setup/global-setup.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const testStateFile = join(cacheDir, 'test-state.json')
1414

1515
interface GlobalState {
1616
honoServer?: ChildProcess
17+
cfAgentsServer?: ChildProcess
1718
staticServer?: Server
1819
staticPort?: number
1920
honoPort?: number
21+
cfAgentsPort?: number
2022
processGroupId?: number
2123
allChildProcesses?: Set<number>
2224
}
@@ -252,7 +254,48 @@ export default async function globalSetup() {
252254
await waitForOutput(honoServer, 'Ready on')
253255
state.honoServer = honoServer
254256

255-
// Step 4: Start simple static file server for inspector
257+
// Step 4: Find available port and start cf-agents server
258+
console.log('🔍 Finding available port starting from 9902...')
259+
const cfAgentsPort = await findAvailablePortFromBase(9902)
260+
console.log(`📍 Using port ${cfAgentsPort} for cf-agents server`)
261+
262+
console.log('🚀 Starting cf-agents server...')
263+
const cfAgentsDir = join(rootDir, 'examples/servers/cf-agents')
264+
const cfAgentsServer = spawn('pnpm', ['dev', `--port=${cfAgentsPort}`], {
265+
cwd: cfAgentsDir,
266+
stdio: ['ignore', 'pipe', 'pipe'],
267+
shell: true,
268+
detached: false,
269+
})
270+
271+
// Track all child processes
272+
if (cfAgentsServer.pid) {
273+
state.allChildProcesses!.add(cfAgentsServer.pid)
274+
}
275+
276+
state.cfAgentsPort = cfAgentsPort
277+
state.cfAgentsServer = cfAgentsServer
278+
279+
cfAgentsServer.stdout?.on('data', (data) => {
280+
console.log(`[cf-agents] ${data.toString()}`)
281+
})
282+
283+
cfAgentsServer.stderr?.on('data', (data) => {
284+
console.log(`[cf-agents] ${data.toString()}`)
285+
})
286+
287+
// Track when the process exits to remove it from our tracking
288+
cfAgentsServer.on('exit', () => {
289+
if (cfAgentsServer.pid) {
290+
state.allChildProcesses!.delete(cfAgentsServer.pid)
291+
}
292+
})
293+
294+
// Wait for cf-agents server to be ready
295+
await waitForOutput(cfAgentsServer, 'Ready on')
296+
state.cfAgentsServer = cfAgentsServer
297+
298+
// Step 5: Start simple static file server for inspector
256299
console.log('🌐 Starting static file server for inspector...')
257300
const inspectorDistDir = join(inspectorDir, 'dist')
258301
const staticPort = await findAvailablePort(8000)
@@ -315,6 +358,7 @@ export default async function globalSetup() {
315358
JSON.stringify(
316359
{
317360
honoPort: state.honoPort,
361+
cfAgentsPort: state.cfAgentsPort,
318362
staticPort: state.staticPort,
319363
},
320364
null,
@@ -330,6 +374,9 @@ export default async function globalSetup() {
330374
if (state.honoServer) {
331375
state.honoServer.kill()
332376
}
377+
if (state.cfAgentsServer) {
378+
state.cfAgentsServer.kill()
379+
}
333380
if (state.staticServer) {
334381
state.staticServer.close()
335382
}

0 commit comments

Comments
 (0)