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

Method indirectTestNote

src/mcp/tools.ts:4475–4510  ·  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, isTest: (n: Node) => boolean)

Source from the content-addressed store, hash-verified

4473 * claiming anything — and even then claim only what was measured.
4474 */
4475 private indirectTestNote(cg: CodeGraph, directCallers: Node[], rel: (p: string) => string, isTest: (n: Node) => boolean): string {
4476 const MAX_HOPS = 3; // direct callers are hop 1
4477 const BUDGET = 64; // getCallers lookups per entry — bounds god-fan-in symbols
4478 const FILE_CAP = 2;
4479 let budget = BUDGET;
4480 const visited = new Set(directCallers.map((n) => n.id));
4481 let frontier = directCallers;
4482 for (let hop = 2; hop <= MAX_HOPS && frontier.length > 0 && budget > 0; hop++) {
4483 const next: Node[] = [];
4484 const found = new Set<string>();
4485 for (const node of frontier) {
4486 if (budget-- <= 0) break;
4487 let callers: Array<{ node: Node }> = [];
4488 try { callers = cg.getCallers(node.id) as Array<{ node: Node }>; } catch { continue; }
4489 for (const c of callers) {
4490 const n = c?.node;
4491 if (!n || visited.has(n.id)) continue;
4492 visited.add(n.id);
4493 if (isTest(n)) found.add(rel(n.filePath));
4494 else next.push(n);
4495 }
4496 }
4497 if (found.size > 0) {
4498 const files = [...found];
4499 const shown = files.slice(0, FILE_CAP).map((f) => `\`${f}\``).join(', ');
4500 const more = files.length > FILE_CAP ? ` +${files.length - FILE_CAP}` : '';
4501 return `; tested via callers: ${shown}${more}`;
4502 }
4503 frontier = next;
4504 }
4505 // Budget exhaustion means hops 2-3 weren't fully searched — fall back to
4506 // the weaker claim that IS established by the direct-caller check.
4507 return budget > 0
4508 ? `; no tests found within ${MAX_HOPS} caller hops`
4509 : '; no test calls this directly';
4510 }
4511
4512 /**
4513 * Graph-connectivity relevance via Random-Walk-with-Restart (personalized

Callers 2

exploreOneSymbolMethod · 0.95

Calls 7

relFunction · 0.85
mapMethod · 0.80
hasMethod · 0.80
pushMethod · 0.80
getCallersMethod · 0.45
addMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected