mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-13 21:33:32 +08:00
test: wait for http mcp fixtures to accept connections
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const http = require('http');
|
||||||
|
const https = require('https');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { spawn, spawnSync } = require('child_process');
|
const { spawn, spawnSync } = require('child_process');
|
||||||
@@ -109,6 +111,39 @@ function waitForFile(filePath, timeoutMs = 5000) {
|
|||||||
}
|
}
|
||||||
throw new Error(`Timed out waiting for ${filePath}`);
|
throw new Error(`Timed out waiting for ${filePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waitForHttpReady(urlString, timeoutMs = 5000) {
|
||||||
|
const deadline = Date.now() + timeoutMs;
|
||||||
|
const { protocol } = new URL(urlString);
|
||||||
|
const client = protocol === 'https:' ? https : http;
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const attempt = () => {
|
||||||
|
const req = client.request(urlString, { method: 'GET' }, res => {
|
||||||
|
res.resume();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
req.setTimeout(250, () => {
|
||||||
|
req.destroy(new Error('timeout'));
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', error => {
|
||||||
|
if (Date.now() >= deadline) {
|
||||||
|
reject(new Error(`Timed out waiting for ${urlString}: ${error.message}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(attempt, 25);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
|
};
|
||||||
|
|
||||||
|
attempt();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function runTests() {
|
async function runTests() {
|
||||||
console.log('\n=== Testing mcp-health-check.js ===\n');
|
console.log('\n=== Testing mcp-health-check.js ===\n');
|
||||||
|
|
||||||
@@ -329,6 +364,7 @@ async function runTests() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const port = waitForFile(portFile).trim();
|
const port = waitForFile(portFile).trim();
|
||||||
|
await waitForHttpReady(`http://127.0.0.1:${port}/mcp`);
|
||||||
|
|
||||||
writeConfig(configPath, {
|
writeConfig(configPath, {
|
||||||
mcpServers: {
|
mcpServers: {
|
||||||
@@ -391,6 +427,7 @@ async function runTests() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const port = waitForFile(portFile).trim();
|
const port = waitForFile(portFile).trim();
|
||||||
|
await waitForHttpReady(`http://127.0.0.1:${port}/mcp`);
|
||||||
|
|
||||||
writeConfig(configPath, {
|
writeConfig(configPath, {
|
||||||
mcpServers: {
|
mcpServers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user