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

Function runTests

test/compression.ts:78–275  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76
77// Import after mock server is ready
78async function runTests() {
79 const { startProxy } = await import("../src/proxy.js");
80
81 console.log("\n═══ Compression & Size Validation Tests ═══\n");
82
83 let passed = 0;
84 let failed = 0;
85
86 function assert(condition: boolean, msg: string) {
87 if (condition) {
88 console.log(` ✓ ${msg}`);
89 passed++;
90 } else {
91 console.error(` ✗ FAIL: ${msg}`);
92 failed++;
93 }
94 }
95
96 // Start mock BlockRun API
97 const mockApi = await startMockServer();
98 console.log(`Mock API started on port ${mockApi.port}`);
99
100 // Generate an ephemeral test wallet key
101 const testWalletKey = generatePrivateKey();
102
103 // Start ClawRouter proxy pointing to mock API
104 const proxy = await startProxy({
105 wallet: testWalletKey,
106 apiBase: `http://127.0.0.1:${mockApi.port}`,
107 port: 0,
108 skipBalanceCheck: true,
109 autoCompressRequests: true, // Enable compression
110 compressionThresholdKB: 50, // Lower threshold for testing
111 onReady: (port) => console.log(`ClawRouter proxy started on port ${port}`),
112 });
113
114 // Test 1: Small request - no compression needed
115 {
116 console.log("\n--- Test 1: Small request (no compression) ---");
117 modelCalls.length = 0;
118 paymentAttempts.length = 0;
119 requestBodies.length = 0;
120
121 const res = await fetch(`${proxy.baseUrl}/v1/chat/completions`, {
122 method: "POST",
123 headers: { "Content-Type": "application/json" },
124 body: JSON.stringify({
125 model: "auto",
126 messages: [{ role: "user", content: "Hello" }],
127 max_tokens: 50,
128 }),
129 });
130
131 assert(res.ok, `Small request succeeds: ${res.status}`);
132 assert(modelCalls.length === 1, `One model called: ${modelCalls.join(", ")}`);
133 }
134
135 // Test 2: Large request - compression attempted

Callers 1

compression.tsFile · 0.70

Calls 4

startProxyFunction · 0.85
closeMethod · 0.80
startMockServerFunction · 0.70
assertFunction · 0.70

Tested by

no test coverage detected