MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / summarizeTestCallers

Function summarizeTestCallers

src/ui-server/api/node.ts:333–396  ·  view source on GitHub ↗

* Which tests reach this symbol — the same question, and the same method, * behind `codegraph_explore`'s "tests:" line. * * Direct test callers first; failing that, walk up to two more caller hops, * because a helper called only by production code is still tested through * whatever calls it. Th

(cg: CodeGraph, directCallers: readonly Node[])

Source from the content-addressed store, hash-verified

331 * viewer exists to avoid.
332 */
333function summarizeTestCallers(cg: CodeGraph, directCallers: readonly Node[]): WireTestSummary {
334 const directFiles = [
335 ...new Set(directCallers.map((n) => toPosixPath(n.filePath)).filter(isTestFile)),
336 ];
337 if (directFiles.length > 0) {
338 return {
339 reached: true,
340 hops: 1,
341 fileCount: directFiles.length,
342 files: directFiles.slice(0, MAX_TEST_FILES),
343 exhaustive: true,
344 hopsSearched: 1,
345 };
346 }
347
348 let budget = TEST_CALLER_BUDGET;
349 const visited = new Set(directCallers.map((n) => n.id));
350 let frontier: Node[] = [...directCallers];
351 let hopsSearched = 1;
352
353 for (let hop = 2; hop <= TEST_CALLER_HOPS && frontier.length > 0 && budget > 0; hop++) {
354 hopsSearched = hop;
355 const next: Node[] = [];
356 const found = new Set<string>();
357 for (const current of frontier) {
358 if (budget-- <= 0) break;
359 let callers: Array<{ node: Node }>;
360 try {
361 callers = cg.getCallers(current.id) as Array<{ node: Node }>;
362 } catch {
363 continue;
364 }
365 for (const caller of callers) {
366 const source = caller?.node;
367 if (!source || visited.has(source.id)) continue;
368 visited.add(source.id);
369 const file = toPosixPath(source.filePath);
370 if (isTestFile(file)) found.add(file);
371 else next.push(source);
372 }
373 }
374 if (found.size > 0) {
375 const files = [...found];
376 return {
377 reached: true,
378 hops: hop,
379 fileCount: files.length,
380 files: files.slice(0, MAX_TEST_FILES),
381 exhaustive: true,
382 hopsSearched: hop,
383 };
384 }
385 frontier = next;
386 }
387
388 return {
389 reached: false,
390 hops: null,

Callers 1

buildNodeFunction · 0.85

Calls 6

isTestFileFunction · 0.90
mapMethod · 0.80
hasMethod · 0.80
pushMethod · 0.80
getCallersMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected