* 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)
| 4287 | * claiming anything — and even then claim only what was measured. |
| 4288 | */ |
| 4289 | private indirectTestNote(cg: CodeGraph, directCallers: Node[], rel: (p: string) => string): string { |
| 4290 | const MAX_HOPS = 3; // direct callers are hop 1 |
| 4291 | const BUDGET = 64; // getCallers lookups per entry — bounds god-fan-in symbols |
| 4292 | const FILE_CAP = 2; |
| 4293 | let budget = BUDGET; |
| 4294 | const visited = new Set(directCallers.map((n) => n.id)); |
| 4295 | let frontier = directCallers; |
| 4296 | for (let hop = 2; hop <= MAX_HOPS && frontier.length > 0 && budget > 0; hop++) { |
| 4297 | const next: Node[] = []; |
| 4298 | const found = new Set<string>(); |
| 4299 | for (const node of frontier) { |
| 4300 | if (budget-- <= 0) break; |
| 4301 | let callers: Array<{ node: Node }> = []; |
| 4302 | try { callers = cg.getCallers(node.id) as Array<{ node: Node }>; } catch { continue; } |
| 4303 | for (const c of callers) { |
| 4304 | const n = c?.node; |
| 4305 | if (!n || visited.has(n.id)) continue; |
| 4306 | visited.add(n.id); |
| 4307 | const f = rel(n.filePath); |
| 4308 | if (isTestFile(f)) found.add(f); |
| 4309 | else next.push(n); |
| 4310 | } |
| 4311 | } |
| 4312 | if (found.size > 0) { |
| 4313 | const files = [...found]; |
| 4314 | const shown = files.slice(0, FILE_CAP).map((f) => `\`${f}\``).join(', '); |
| 4315 | const more = files.length > FILE_CAP ? ` +${files.length - FILE_CAP}` : ''; |
| 4316 | return `; tested via callers: ${shown}${more}`; |
| 4317 | } |
| 4318 | frontier = next; |
| 4319 | } |
| 4320 | // Budget exhaustion means hops 2-3 weren't fully searched — fall back to |
| 4321 | // the weaker claim that IS established by the direct-caller check. |
| 4322 | return budget > 0 |
| 4323 | ? `; no tests found within ${MAX_HOPS} caller hops` |
| 4324 | : '; no test calls this directly'; |
| 4325 | } |
| 4326 | |
| 4327 | /** |
| 4328 | * Graph-connectivity relevance via Random-Walk-with-Restart (personalized |
no test coverage detected