MCPcopy Index your code
hub / github.com/BlockRunAI/ClawRouter / runLocalSuite

Function runLocalSuite

test/test-e2e.ts:430–814  ·  view source on GitHub ↗
(startProxy: StartProxy)

Source from the content-addressed store, hash-verified

428}
429
430async function runLocalSuite(startProxy: StartProxy): Promise<boolean> {
431 console.log("\n=== Local deterministic e2e (mock upstream) ===\n");
432
433 const mock = await startMockUpstream();
434 let proxy: ProxyHandle | undefined;
435 let allPassed = true;
436
437 try {
438 proxy = await startProxy({
439 wallet: LOCAL_WALLET_KEY,
440 apiBase: mock.url,
441 port: 0,
442 skipBalanceCheck: true,
443 requestTimeoutMs: REQUEST_TIMEOUT_MS,
444 onReady: (port) => console.log(`Proxy ready on port ${port}`),
445 onError: (err) => console.error(`Proxy error: ${err.message}`),
446 onRouted: (d) =>
447 console.log(
448 ` [routed] ${d.model} (${d.tier}, ${d.method}, confidence=${d.confidence.toFixed(2)})`,
449 ),
450 });
451
452 allPassed =
453 (await runTest("Health check", async () => {
454 const res = await fetchWithTimeout(`${proxy!.baseUrl}/health`);
455 const payload = await readResponseBody(res);
456 if (res.status !== 200) throw new Error(`Expected 200, got ${res.status}`);
457 const body = asRecord(payload.json);
458 if (body.status !== "ok") throw new Error(`Expected status ok, got ${body.status}`);
459 if (!body.wallet) throw new Error("Missing wallet in health response");
460 return `(wallet=${String(body.wallet)})`;
461 })) && allPassed;
462
463 allPassed =
464 (await runTest("Non-streaming request through proxy", async () => {
465 const res = await postJson(proxy!, "/v1/chat/completions", {
466 model: "deepseek/deepseek-chat",
467 messages: [{ role: "user", content: "What is 2+2? Reply with just the number." }],
468 max_tokens: 10,
469 stream: false,
470 });
471 const content = await expectChatContent(res);
472 if (!content.includes("4")) throw new Error(`Expected "4" in response, got: ${content}`);
473 return `(response="${content.trim()}")`;
474 })) && allPassed;
475
476 allPassed =
477 (await runTest("Streaming request through proxy", async () => {
478 const res = await postJson(proxy!, "/v1/chat/completions", {
479 model: "google/gemini-2.5-flash",
480 messages: [{ role: "user", content: "Say hello in one word." }],
481 max_tokens: 10,
482 stream: true,
483 });
484 if (res.status !== 200) throw new Error(`Expected 200, got ${res.status}`);
485 const ct = res.headers.get("content-type");
486 if (!ct?.includes("text/event-stream")) {
487 throw new Error(`Expected text/event-stream, got ${ct}`);

Callers 1

mainFunction · 0.85

Calls 14

startProxyFunction · 0.85
fetchWithTimeoutFunction · 0.85
readResponseBodyFunction · 0.85
asRecordFunction · 0.85
expectChatContentFunction · 0.85
collectSseFunction · 0.85
countMockChatRequestsFunction · 0.85
extractErrorMessageFunction · 0.85
getMethod · 0.80
closeMethod · 0.80
startMockUpstreamFunction · 0.70

Tested by

no test coverage detected