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

Function runTests

test/fallback.ts:129–935  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128// Import after mock server is ready (to avoid wallet key requirement during import)
129async function runTests() {
130 const { startProxy } = await import("../src/proxy.js");
131
132 console.log("\n═══ Fallback Logic Tests ═══\n");
133
134 let passed = 0;
135 let failed = 0;
136
137 function assert(condition: boolean, msg: string) {
138 if (condition) {
139 console.log(` ✓ ${msg}`);
140 passed++;
141 } else {
142 console.error(` ✗ FAIL: ${msg}`);
143 failed++;
144 }
145 }
146
147 // Start mock BlockRun API
148 const mockApi = await startMockServer();
149 console.log(`Mock API started on port ${mockApi.port}`);
150
151 // Generate an ephemeral test wallet key
152 const testWalletKey = generatePrivateKey();
153
154 // Start ClawRouter proxy pointing to mock API
155 const proxy = await startProxy({
156 wallet: testWalletKey,
157 apiBase: `http://127.0.0.1:${mockApi.port}`,
158 port: 0,
159 skipBalanceCheck: true, // Skip balance check for testing
160 onReady: (port) => console.log(`ClawRouter proxy started on port ${port}`),
161 onRouted: (d) => console.log(` [Routed] ${d.model} (${d.tier}) - ${d.reasoning}`),
162 });
163
164 // Helper to generate unique message content (prevents dedup cache hits)
165 let testCounter = 0;
166 const uniqueMessage = (base: string) => `${base} [test-${++testCounter}-${Date.now()}]`;
167 const reasoningPrompt = () => uniqueMessage("Prove step by step that sqrt(2) is irrational");
168
169 // Test 1: Primary model succeeds - no fallback needed
170 {
171 console.log("\n--- Test 1: Primary model succeeds ---");
172 modelCalls.length = 0;
173 failModels = [];
174 failAllModels = false;
175
176 const res = await fetch(`${proxy.baseUrl}/v1/chat/completions`, {
177 method: "POST",
178 headers: { "Content-Type": "application/json" },
179 body: JSON.stringify({
180 model: "auto",
181 messages: [{ role: "user", content: uniqueMessage("Hello") }],
182 max_tokens: 50,
183 }),
184 });
185
186 assert(res.ok, `Response OK: ${res.status}`);

Callers 1

fallback.tsFile · 0.70

Calls 8

startProxyFunction · 0.85
uniqueMessageFunction · 0.85
reasoningPromptFunction · 0.85
getMethod · 0.80
closeMethod · 0.80
startMockServerFunction · 0.70
assertFunction · 0.70
clearMethod · 0.45

Tested by

no test coverage detected