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

Method indirectTestNote

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

4356 * claiming anything — and even then claim only what was measured.
4357 */
4358 private indirectTestNote(cg: CodeGraph, directCallers: Node[], rel: (p: string) => string, isTest: (n: Node) => boolean): string {
4359 const MAX_HOPS = 3; // direct callers are hop 1
4360 const BUDGET = 64; // getCallers lookups per entry — bounds god-fan-in symbols
4361 const FILE_CAP = 2;
4362 let budget = BUDGET;
4363 const visited = new Set(directCallers.map((n) => n.id));
4364 let frontier = directCallers;
4365 for (let hop = 2; hop <= MAX_HOPS && frontier.length > 0 && budget > 0; hop++) {
4366 const next: Node[] = [];
4367 const found = new Set<string>();
4368 for (const node of frontier) {
4369 if (budget-- <= 0) break;
4370 let callers: Array<{ node: Node }> = [];
4371 try { callers = cg.getCallers(node.id) as Array<{ node: Node }>; } catch { continue; }
4372 for (const c of callers) {
4373 const n = c?.node;
4374 if (!n || visited.has(n.id)) continue;
4375 visited.add(n.id);
4376 if (isTest(n)) found.add(rel(n.filePath));
4377 else next.push(n);
4378 }
4379 }
4380 if (found.size > 0) {
4381 const files = [...found];
4382 const shown = files.slice(0, FILE_CAP).map((f) => `\`${f}\``).join(', ');
4383 const more = files.length > FILE_CAP ? ` +${files.length - FILE_CAP}` : '';
4384 return `; tested via callers: ${shown}${more}`;
4385 }
4386 frontier = next;
4387 }
4388 // Budget exhaustion means hops 2-3 weren't fully searched — fall back to
4389 // the weaker claim that IS established by the direct-caller check.
4390 return budget > 0
4391 ? `; no tests found within ${MAX_HOPS} caller hops`
4392 : '; no test calls this directly';
4393 }
4394
4395 /**
4396 * 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