testgap

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testgap joins the two questions the other capabilities answer separately: "what does changing this reach" and "what covers that".

impact answers the first, tests answers the second, and until this package existed the join was left to the reader — who had to run an impact analysis, copy each symbol out of it, ask for its tests one at a time, and remember which ones came back empty. That is the mechanical part of preparing to make a change, and it is exactly the part a query layer should do.

What it is, and what it is not

It is a JOIN over two existing reports. It parses nothing, writes nothing and owns no schema, like everything else under internal/capability. It does not re-implement traversal, test discovery or risk scoring: impact.AnalyzeWith produces the blast radius, tests.FindTestsWith answers coverage per symbol, and impact.ScoreReachedSymbol ranks what is left over — the same constants, the same thresholds and the same Formula the impact report prints, so a "high" here and a "high" there are the same arithmetic.

It is NOT a coverage tool. Nothing in this package executes a test or reads a coverage profile. "Covered" here means a test symbol was DISCOVERED for the symbol, and the report always says by which signal — a recorded edge chain is evidence of execution, a matching filename is evidence of intent. Those are kept apart (CoverageProven vs CoverageConventionOnly) because collapsing them would let a naming convention discharge a risk.

Bounded, and honest about the bound

A blast radius can hold thousands of symbols and each coverage lookup is a traversal, so examination is capped (Options.MaxExamine). The symbols nearest the change are examined first and the remainder is reported as CoverageNotExamined with a count — never as uncovered, and never silently dropped. "Not looked at" and "looked at and found nothing" are different answers and this package refuses to render them the same way.

Index

Constants

View Source
const DefaultMaxExamine = 200

DefaultMaxExamine bounds how many reached symbols get a coverage lookup.

Each lookup is one bounded traversal plus a handful of index probes — measured at ~1.5 ms per symbol on the 100k-symbol fixture in capability/tests' benchmarks — so 200 is a few hundred milliseconds in the worst case, and this query sits in front of an interactive agent. Symbols beyond it are reported, not hidden; see Report.NotExamined.

View Source
const UncoveredCaveat = "\"Uncovered\" here means NO TEST WAS DISCOVERED for the symbol by call graph, naming " +
	"convention or sibling test file — not that the symbol is untested. Equally, \"covered\" means a test was " +
	"discovered, never that it asserts anything useful: this report counts discovered tests, it does not run " +
	"them and it does not read a coverage profile."

UncoveredCaveat is carried by every gap report. It states the one thing a reader is most likely to get wrong about it.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoveringTest

type CoveringTest struct {
	capability.Symbol

	Signal     tests.Signal     `json:"signal"`
	Detail     string           `json:"detail"`
	Confidence model.Confidence `json:"confidence"`
}

CoveringTest is one discovered test, reduced to what a gap report needs.

The full tests.TestHit carries every signal that matched; repeating all of them for every covered symbol in a 200-symbol report would bury the finding. The strongest signal is kept, with its own detail, so the claim stays checkable.

type Options

type Options struct {
	// Impact bounds the blast radius. Its confidence floor governs this report
	// too: a symbol the floor kept out of the impact report is not examined
	// here either, and Report.LowConfidenceHidden carries the count through.
	Impact impact.Options

	// Tests bounds each per-symbol coverage lookup.
	Tests tests.Options

	// MaxExamine caps coverage lookups. <= 0 uses DefaultMaxExamine.
	MaxExamine int
}

Options bounds one test-gap analysis.

type Reached

type Reached struct {
	capability.Symbol

	// Reach and Depth say how the change gets here: a direct caller, something
	// further out, or an implementation reached by dispatch. Carried through
	// from the impact report unchanged.
	Reach impact.Reach `json:"reach"`
	Depth int          `json:"depth"`

	// Confidence is the path minimum that reached this symbol.
	Confidence model.Confidence `json:"confidence"`

	// Coverage is the verdict. CoverageNone is a finding; CoverageNotExamined is
	// the absence of one.
	Coverage impact.Coverage `json:"coverage"`

	// Tests are the discovered tests, strongest signal first. Empty for
	// CoverageNone and CoverageNotExamined.
	Tests []CoveringTest `json:"tests,omitempty"`

	// Risk is populated for uncovered and convention-only symbols — the ones a
	// reader has to act on — and scored by impact.ScoreReachedSymbol so it uses
	// the same model as the impact report's own score.
	Risk *impact.Risk `json:"risk,omitempty"`

	// IsTest marks the reached symbol as test code itself. A test in the blast
	// radius that has no tests of its own is not a gap worth ranking, and saying
	// why beats silently omitting it.
	IsTest bool `json:"is_test"`
}

Reached is one symbol in the blast radius, with its coverage verdict.

type Report

type Report struct {
	Target capability.Target `json:"target"`

	// Reached is how many symbols the change reaches — the denominator every
	// other number here is a fraction of. Callers plus the dispatch expansion.
	Reached int `json:"reached"`

	// Examined is how many of them got a coverage lookup.
	Examined int `json:"examined"`

	// NotExamined is Reached - Examined, less the top levels of files that
	// reach the target (never examined, see AnalyzeWith): symbols in the radius whose coverage is
	// unknown because the budget ran out. Listed in NotExaminedSymbols up to the
	// same budget so the reader can re-ask about them.
	NotExamined        int       `json:"not_examined"`
	NotExaminedSymbols []Reached `json:"not_examined_symbols,omitempty"`

	// CoveredProven and CoveredByConventionOnly split "covered" by the strength
	// of the evidence. A reader who treats the second as the first has been
	// reassured by a filename.
	CoveredProven           int `json:"covered_proven"`
	CoveredByConventionOnly int `json:"covered_by_convention_only"`

	// Covered lists them, proven first.
	Covered []Reached `json:"covered,omitempty"`

	// Uncovered is the answer to the question this package exists for: reached,
	// examined, and nothing found. Ranked by Risk.Score descending, then by
	// depth, then by symbol id so the order is stable.
	Uncovered []Reached `json:"uncovered,omitempty"`

	// TestSymbolsReached counts reached symbols that are themselves test code.
	// They are excluded from Uncovered — a test with no test is not a gap — and
	// counted here so the exclusion is visible rather than a silent filter.
	TestSymbolsReached int `json:"test_symbols_reached"`

	// Unknown is carried through from the impact report unchanged: the gaps in
	// the blast radius are gaps in this report too, and re-deriving them would
	// let the two disagree.
	Unknown []impact.Unknown `json:"unknown"`

	// LowConfidenceHidden is impact's count of symbols the confidence floor kept
	// out of the radius. They were never examined for coverage either, so a
	// reader sizing this report's blind spots needs it here.
	LowConfidenceHidden int              `json:"low_confidence_hidden,omitempty"`
	ConfidenceFloor     model.Confidence `json:"confidence_floor,omitempty"`

	// Risk is the impact report's own risk score for the target, carried
	// through. The per-symbol scores rank the gaps; this one describes the
	// change as a whole.
	Risk impact.Risk `json:"risk"`

	Completeness capability.Completeness `json:"completeness"`

	Truncated       bool   `json:"truncated"`
	TruncatedReason string `json:"truncated_reason,omitempty"`
}

Report is one test-gap answer: the blast radius, split by whether anything covers it.

func Analyze

func Analyze(ctx context.Context, deps capability.Deps, runID int64, target string) (Report, error)

Analyze reports which of the symbols a change reaches are covered by a test.

func AnalyzeWith

func AnalyzeWith(ctx context.Context, deps capability.Deps, runID int64, target string, opts Options) (Report, error)

AnalyzeWith is Analyze under explicit bounds.

Jump to

Keyboard shortcuts

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