MCPcopy Create free account
hub / github.com/EvoMap/evolver / withServer

Function withServer

test/proxyModelsE2E.test.js:27–53  ·  view source on GitHub ↗
(run)

Source from the content-addressed store, hash-verified

25}
26
27async function withServer(run) {
28 calls = [];
29 const silent = { log() {}, warn() {}, error() {} };
30 const handler = buildModelsHandler({ anthropicProxy: mockAnthropic, openAIProxy: mockOpenAI, logger: silent });
31 const srv = new ProxyHttpServer({ 'GET /v1/models': handler }, { port: 0, logger: silent });
32 srv.token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
33 srv.server = http.createServer((req, res) => srv._handleRequest(req, res));
34 const port = await new Promise((resolve) => srv.server.listen(0, '127.0.0.1', () => resolve(srv.server.address().port)));
35 srv.actualPort = port;
36
37 const get = (headers) => new Promise((resolve, reject) => {
38 const req = http.request({ host: '127.0.0.1', port, path: '/v1/models', method: 'GET',
39 headers: { authorization: 'Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', ...headers } }, (res) => {
40 const chunks = [];
41 res.on('data', (d) => chunks.push(d));
42 res.on('end', () => resolve({ status: res.statusCode, bytes: Buffer.concat(chunks) }));
43 });
44 req.on('error', reject);
45 req.end();
46 });
47
48 try {
49 await run({ get });
50 } finally {
51 await new Promise((r) => srv.server.close(r));
52 }
53}
54
55test('GET /v1/models with anthropic-version header → Anthropic /v1/models (GET, no body)', async () => {
56 await withServer(async ({ get }) => {

Callers 1

Calls 4

_handleRequestMethod · 0.95
buildModelsHandlerFunction · 0.85
closeMethod · 0.80
runFunction · 0.50

Tested by

no test coverage detected