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

Method indirectTestNote

src/mcp/tools.ts:2499–2535  ·  view source on GitHub ↗

* Test-coverage note for a blast-radius entry whose DIRECT callers include no * test file. A helper called only by production code can still be exercised * by tests further up the caller chain (#1475: 40% of directly-unflagged * symbols had a test within 2-3 hops), so walk up to 2 more hops

(cg: CodeGraph, directCallers: Node[], rel: (p: string) => string)

Source from the content-addressed store, hash-verified

2497 * claiming anything — and even then claim only what was measured.
2498 */
2499 private indirectTestNote(cg: CodeGraph, directCallers: Node[], rel: (p: string) => string): string {
2500 const MAX_HOPS = 3; // direct callers are hop 1
2501 const BUDGET = 64; // getCallers lookups per entry — bounds god-fan-in symbols
2502 const FILE_CAP = 2;
2503 let budget = BUDGET;
2504 const visited = new Set(directCallers.map((n) => n.id));
2505 let frontier = directCallers;
2506 for (let hop = 2; hop <= MAX_HOPS && frontier.length > 0 && budget > 0; hop++) {
2507 const next: Node[] = [];
2508 const found = new Set<string>();
2509 for (const node of frontier) {
2510 if (budget-- <= 0) break;
2511 let callers: Array<{ node: Node }> = [];
2512 try { callers = cg.getCallers(node.id) as Array<{ node: Node }>; } catch { continue; }
2513 for (const c of callers) {
2514 const n = c?.node;
2515 if (!n || visited.has(n.id)) continue;
2516 visited.add(n.id);
2517 const f = rel(n.filePath);
2518 if (isTestFile(f)) found.add(f);
2519 else next.push(n);
2520 }
2521 }
2522 if (found.size > 0) {
2523 const files = [...found];
2524 const shown = files.slice(0, FILE_CAP).map((f) => `\`${f}\``).join(', ');
2525 const more = files.length > FILE_CAP ? ` +${files.length - FILE_CAP}` : '';
2526 return `; tested via callers: ${shown}${more}`;
2527 }
2528 frontier = next;
2529 }
2530 // Budget exhaustion means hops 2-3 weren't fully searched — fall back to
2531 // the weaker claim that IS established by the direct-caller check.
2532 return budget > 0
2533 ? `; no tests found within ${MAX_HOPS} caller hops`
2534 : '; no test calls this directly';
2535 }
2536
2537 /**
2538 * Graph-connectivity relevance via Random-Walk-with-Restart (personalized

Callers 1

Calls 4

isTestFileFunction · 0.90
hasMethod · 0.80
getCallersMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected