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

Method indirectTestNote

src/mcp/tools.ts:4478–4513  ·  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

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