MCPcopy
hub / github.com/colbymchenry/codegraph / run

Function run

__tests__/evaluation/runner.ts:33–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31console.log('');
32
33async function run() {
34 const cg = CodeGraph.openSync(resolvedPath);
35 const results: EvalResult[] = [];
36
37 for (const tc of testCases) {
38 const start = performance.now();
39
40 if (tc.api === 'searchNodes') {
41 const searchResults = cg.searchNodes(tc.query, {
42 limit: 10,
43 kinds: tc.kinds,
44 ...(tc.options as Record<string, unknown>),
45 });
46 const latency = performance.now() - start;
47 const result = scoreSearchNodes(tc.id, tc.expectedSymbols, searchResults, latency);
48 results.push(result);
49 } else {
50 const subgraph = await cg.findRelevantContext(tc.query, {
51 searchLimit: 8,
52 traversalDepth: 3,
53 maxNodes: 80,
54 minScore: 0.2,
55 ...(tc.options as Record<string, unknown>),
56 });
57 const latency = performance.now() - start;
58 const result = scoreFindRelevantContext(tc.id, tc.expectedSymbols, subgraph, latency);
59 results.push(result);
60 }
61 }
62
63 cg.close();
64
65 // Print results table
66 const maxIdLen = Math.max(...results.map((r) => r.caseId.length));
67
68 for (const r of results) {
69 const status = r.pass ? '\x1b[32mPASS\x1b[0m' : '\x1b[31mFAIL\x1b[0m';
70 const id = r.caseId.padEnd(maxIdLen);
71 const recall = `recall=${r.recall.toFixed(2)}`;
72 const extra =
73 r.edgeDensity !== undefined
74 ? `density=${r.edgeDensity.toFixed(2)}`
75 : `mrr=${r.mrr.toFixed(2)}`;
76 const latency = `${Math.round(r.latencyMs)}ms`;
77
78 console.log(` ${id} ${status} ${recall} ${extra} ${latency}`);
79
80 if (r.missedSymbols.length > 0) {
81 console.log(` ${' '.repeat(maxIdLen)} missed: ${r.missedSymbols.join(', ')}`);
82 }
83 }
84
85 // Summary
86 const passed = results.filter((r) => r.pass).length;
87 const failed = results.length - passed;
88 const meanRecall = results.reduce((s, r) => s + r.recall, 0) / results.length;
89 const mrrResults = results.filter((r) => r.mrr > 0 || r.caseId.startsWith('search-'));
90 const meanMRR =

Callers 1

runner.tsFile · 0.70

Calls 7

scoreSearchNodesFunction · 0.85
scoreFindRelevantContextFunction · 0.85
openSyncMethod · 0.80
joinMethod · 0.80
closeMethod · 0.65
searchNodesMethod · 0.45
findRelevantContextMethod · 0.45

Tested by

no test coverage detected