risk

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package risk joins what the coverage index knows with what git knows: a function is exposed when its code changes often and few tests execute it. Neither signal alone ranks anything useful — untested-but-frozen code is a dormant liability, and heavily-tested hot code is fine — the product of the two is where the next regression is most likely to land unseen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FunctionRisk

type FunctionRisk struct {
	Package         string `json:"package"`
	Function        string `json:"function"`
	File            string `json:"file"`
	StartLine       int    `json:"startLine"`
	EndLine         int    `json:"endLine"`
	ExecutableLines int    `json:"executableLines"`
	UncoveredLines  int    `json:"uncoveredLines"`
	Commits         int    `json:"commits"`
	LinesChanged    int    `json:"linesChanged"`
	// Score is commits × uncovered executable lines: no weights, no tuning,
	// both factors visible in the report so the ranking can be argued with.
	Score int `json:"score"`
}

FunctionRisk is one function's exposure.

type Options

type Options struct {
	Root   string
	Commit string
	Graph  *graph.Graph
	Loader *index.Loader
	// Churn is keyed by slash-separated path relative to Root.
	Churn map[string]vcs.ChurnStat
	// Packages restricts analysis to these import paths; empty means every
	// package in the graph.
	Packages []string
}

type Report

type Report struct {
	Functions []FunctionRisk `json:"functions"`
	// CoveredChurning counts churned functions every line of which is covered
	// — change is landing where tests are watching.
	CoveredChurning int `json:"coveredChurning"`
	// UncoveredStable counts functions with uncovered lines in files no commit
	// touched inside the window. Dormant, not safe; below every churning entry
	// in priority.
	UncoveredStable int `json:"uncoveredStable"`
	// Unindexed counts packages none of whose covering test packages have a
	// usable record at this commit. Their functions are invisible to the
	// report, and pretending otherwise would make missing data look like
	// safety.
	Unindexed int `json:"unindexed"`
	// Partial counts packages analyzed with some covering records missing.
	// Coverage can only be under-counted there, so their risk may be
	// overstated — the honest direction, but worth a note.
	Partial  int `json:"partial"`
	Analyzed int `json:"analyzedPackages"`
}

Report is the ranked exposure analysis.

func Analyze

func Analyze(opts Options) (Report, error)

Analyze walks every package's production files, intersects each function's executable lines with the covered lines the index attributes, and scores the uncovered remainder by the owning file's churn.

Coverage is unioned across every test package that can reach the analyzed one: with -coverpkg spanning the workspace, a package with no tests of its own is routinely covered by its importers, and reading only its own record would report tested code as exposed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL