(data: SelectionImpact)
| 185 | |
| 186 | /** An explicit review-priority heuristic, never a calibrated defect prediction. */ |
| 187 | export function selectionRisk(data: SelectionImpact): SelectionRisk { |
| 188 | const graph = data.structural, history = data.history; |
| 189 | const reasons: string[] = [], uncertainties: string[] = []; |
| 190 | let level: SelectionRisk['level'] = 'unresolved'; |
| 191 | if (graph.available && (graph.direct >= 10 || graph.reachable >= 25)) { |
| 192 | level = 'high'; |
| 193 | reasons.push(`${graph.direct} direct and ${graph.reachable} total indexed dependents meet the broad-impact rule (10 direct or 25 total).`); |
| 194 | } else if (graph.available && graph.reachable > 0) { |
| 195 | level = 'elevated'; |
| 196 | reasons.push(`${graph.reachable} indexed dependent${graph.reachable === 1 ? '' : 's'} could be affected; inspect direct paths first.`); |
| 197 | } |
| 198 | if (history.available && history.selection_commits >= 10) { |
| 199 | reasons.push(`This file changed in ${history.selection_commits} sampled ordinary commits (frequent-change threshold: 10).`); |
| 200 | if (level === 'unresolved') level = 'elevated'; |
| 201 | } |
| 202 | const repeated = history.cochanges.filter(row => row.shared_commits >= 3); |
| 203 | if (history.available && repeated.length > 0) |
| 204 | reasons.push(`${repeated.length} file${repeated.length === 1 ? '' : 's'} changed together with this selection in at least 3 sampled commits; review these historical associations separately.`); |
| 205 | if (reasons.length === 0) reasons.push('No elevated signal was established in the available sample. This does not establish low risk.'); |
| 206 | if (!graph.available) uncertainties.push(graph.error ?? 'The selection has no usable indexed dependency evidence.'); |
| 207 | if (graph.truncated) uncertainties.push('The graph walk or evidence list reached a bound; further dependents may exist.'); |
| 208 | if (data.snapshot.coverage_recording !== 'complete') uncertainties.push('Index coverage recording is incomplete or unavailable.'); |
| 209 | const gaps = data.snapshot.coverage.reduce((sum, row) => sum + row.count, 0); |
| 210 | if (gaps > 0) uncertainties.push(`${gaps} persisted index coverage records identify excluded, unsupported, or partially indexed paths; inspect Diagnostics.`); |
| 211 | if (data.snapshot.index_revision === 'unknown') uncertainties.push(data.snapshot.freshness); |
| 212 | if (!history.available) uncertainties.push(history.error ?? 'Historical evidence is unavailable or contains read failures.'); |
| 213 | if (history.shallow) uncertainties.push('This is a shallow checkout; earlier co-changes are missing.'); |
| 214 | if (history.truncated) uncertainties.push('The history scan reached a count, time, or file bound.'); |
| 215 | if (history.available && history.selection_commits < 3) uncertainties.push('Fewer than 3 sampled ordinary commits touch this file; historical evidence is sparse.'); |
| 216 | if (history.selection_uncommitted) uncertainties.push('The selected file has uncommitted changes; Git history describes committed versions, and graph freshness is unverified.'); |
| 217 | if (history.worktree_status_known !== true) uncertainties.push('Working-tree status of the selection could not be established.'); |
| 218 | const next = [ |
| 219 | 'Inspect the nearest dependent paths and check the interfaces used by their callers or importers.', |
| 220 | graph.test_candidates > 0 |
| 221 | ? `Review and run the ${graph.test_candidates} indexed test candidate${graph.test_candidates === 1 ? '' : 's'} that reach the selection. Test-file classification is heuristic.` |
| 222 | : 'No test dependency was found within this walk. Search for integration tests and add a focused regression check; this is not a coverage measurement.', |
| 223 | 'Compare the local change with the indexed source and reindex before relying on absence of downstream findings.', |
| 224 | ]; |
| 225 | if (history.cochanges.length > 0) next.push('Inspect the linked local commit evidence for repeated co-changes; shared commits alone do not establish a dependency.'); |
| 226 | return { level, label: level === 'high' ? 'Broad impact · high review priority' |
| 227 | : level === 'elevated' ? 'Review needed · elevated change risk' : 'Risk unresolved', reasons, uncertainties, next }; |
| 228 | } |
| 229 | |
| 230 | export function evidenceTarget(node: ImpactEvidenceNode): SelectionImpactTarget { |
| 231 | return { filePath: node.file_path, name: node.name, id: node.id, |
no test coverage detected