Documentation
¶
Overview ¶
Package tests answers "which tests cover this?" over the shared code knowledge graph.
This is TestMind from the product spec, implemented — like impact — as a query layer rather than a separate product. It reads the same graph the same index produced.
Every finding records HOW it was found ¶
Test discovery combines three signals of very different strength, and an agent acting on the answer needs to know which one fired. A test found because a proven CALLS edge chain reaches the target is a fact. A test found because it happens to be named TestUpdateStatus is a convention that is usually right. A test found because it sits in the sibling test file is a guess about how the repository is organised. Collapsing all three into "3 tests cover this" would let the third masquerade as the first, and the whole point of GraphLume is that it does not do that.
So every TestHit carries the full list of Signals that matched it, each with its own confidence and its own detail, plus Strongest for the common case of wanting one label.
Absence is a real answer ¶
A symbol with no discovered tests reports Untested, not the nearest vaguely-related test file. Returning something loosely related when nothing matched is how a coverage tool becomes worse than useless: it converts "we don't know" into "you're covered".
This is also why co-location is defined narrowly — the sibling test file, not every test in the directory. See capability.IsSiblingTestFile for the reasoning.
Measured performance ¶
From bench_test.go on the same 100,000-symbol / 503,491-edge fixture internal/capability/impact uses (Apple M-series, -benchtime 50x), p95 for one complete FindTests:
all three signals, ordinary target 1.46 ms graph signal alone 1.00 ms naming signal alone 0.14 ms co-location signal alone 0.43 ms all three signals, 1,000-caller hub 41.25 ms
The naming signal is the cheapest despite issuing ten prefix probes per query, because SymbolIndex.WithPrefix binary-searches a sorted key set rather than scanning 100k map keys. The hub case is dominated by the graph traversal filtering a large frontier, not by the signals.
Index ¶
- Constants
- type ErrorPath
- type Options
- type Signal
- type SignalMatch
- type Suggestion
- type SuggestionKind
- type TestHit
- type TestReport
- func FindTests(ctx context.Context, deps capability.Deps, runID int64, target string) (TestReport, error)
- func FindTestsForTarget(ctx context.Context, deps capability.Deps, runID int64, tgt capability.Target, ...) (TestReport, error)
- func FindTestsWith(ctx context.Context, deps capability.Deps, runID int64, target string, ...) (TestReport, error)
Constants ¶
const ( // DefaultMaxDepth is deeper than impact's default because test code // routinely reaches production code through one or two helper layers // (setup functions, table drivers, assertion helpers), and stopping at 3 // would systematically miss the tests that matter most. DefaultMaxDepth = 4 DefaultMaxNodes = 5000 )
Default bounds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorPath ¶
type ErrorPath struct {
Callee capability.Symbol `json:"callee"`
Confidence model.Confidence `json:"confidence"`
Evidence model.Evidence `json:"evidence"`
}
ErrorPath is a proven outgoing call from the target to a symbol that constructs or raises an error.
Recorded during discovery so SuggestMissingScenarios can stay a pure function of facts already in the report. The CALLS edge is the evidence; the classification of the callee as error-constructing is a convention, and both halves are reported so the reader can judge the suggestion built on them.
type Options ¶
type Options struct {
MaxDepth int
MaxNodes int
MinConfidence model.Confidence
// HubDegreeLimit refuses to expand THROUGH a symbol wider than this many
// edges. Zero, the default, disables it.
//
// It matters more here than almost anywhere else: this walk is four hops
// deep, and a test-helper or assertion utility with a thousand callers is
// the normal shape of a test suite, not a pathology. Crossing one turns
// "which tests cover this symbol" into "which tests exist".
HubDegreeLimit int
// SkipNaming and SkipColocation disable individual signals. They exist so
// tests in this package can prove each signal finds its tests
// INDEPENDENTLY, rather than proving only that the union finds them.
SkipGraph bool
SkipNaming bool
SkipColocation bool
// CheckValueUse asks for the text check described in capability.ValueUse.
// Off by default for the same reason as impact.Options.CheckValueUse: it
// reads stored text, and a caller probing many symbols does not pay for it
// once per symbol.
CheckValueUse bool
// CoverageOnly answers only whether tests exist: Tests and Truncated are
// filled, and the evidence a reader of one symbol's report wants beside
// them (its error paths, and how the index bound references to it) is not
// gathered. A whole-repository audit probes hundreds of symbols and reads
// nothing else; the binding query alone was 0.8 s of one on a
// 26,000-file repository. Binding, Undetermined and ErrorPaths are zero.
CoverageOnly bool
}
Options bounds one discovery run.
func ProbeOptions ¶
func ProbeOptions() Options
ProbeOptions bounds a discovery run that only needs to know WHETHER tests exist near a symbol, not to enumerate them: two hops, a few hundred nodes, and no expansion through wide helpers.
A whole-repository audit asks that question of dozens of symbols in one call. With the default bounds each answer walks four hops and up to 5,000 nodes, which the scale suite measured at 5.5 seconds for blindspots on a 250,000-symbol index. The probe finds any test that calls the symbol or calls its caller, which is where almost every real test is.
A probe that comes back empty AND truncated has not looked far enough to say "untested". Callers must treat that as unknown; see Inconclusive.
type Signal ¶
type Signal string
Signal is how a candidate test was discovered. The values are ordered by strength; Strongest picks the highest.
const ( // SignalGraph: a test symbol transitively reaches the target through // recorded edges. The only signal that is evidence of execution rather than // evidence of intent. SignalGraph Signal = "graph" // SignalDispatch: a test reaches a method the target implements or // overrides (an interface method, a base-class method). The call is bound // to the declaration, so no edge leads to the implementation, yet the test // runs it whenever it holds this implementation. Which one it holds is // decided at run time, so this is weaker than a recorded call chain. SignalDispatch Signal = "interface_dispatch" // SignalNaming: the test's name follows a convention derived from the // target's name. Usually right, occasionally a coincidence, never proof. SignalNaming Signal = "naming_convention" // SignalColocation: the test lives in the sibling test file of the file // that defines the target. The weakest of the three: it says the repository // is organised conventionally, not that this test touches this symbol. SignalColocation Signal = "co_location" )
type SignalMatch ¶
type SignalMatch struct {
Signal Signal `json:"signal"`
// Detail says precisely what matched — which edge chain, which naming
// convention, which sibling file. Without it "naming_convention" is not
// checkable by the reader.
Detail string `json:"detail"`
// Confidence is how strongly THIS SIGNAL supports the claim. For the graph
// signal it is the path minimum from internal/graph, so it compounds along
// the chain rather than reporting the last hop.
Confidence model.Confidence `json:"confidence"`
// Depth is hops from the target, for the graph signal only.
Depth int `json:"depth,omitempty"`
}
SignalMatch is one signal firing on one candidate, with its justification.
type Suggestion ¶
type Suggestion struct {
Kind SuggestionKind `json:"kind"`
// Scenario is what to test, in one line.
Scenario string `json:"scenario"`
// Why is the structural argument for the gap existing.
Why string `json:"why"`
// Evidence is the specific fact in the index or graph that the suggestion
// rests on. A suggestion without one must not be emitted.
Evidence string `json:"evidence"`
// Confidence is how strongly the GAP is believed to be real — not how
// important the test would be. A gap derived from "this symbol is exported
// and no signal matched" is only as good as the discovery that found
// nothing.
Confidence model.Confidence `json:"confidence"`
}
Suggestion is a structural coverage gap, with the evidence that justifies it.
func SuggestMissingScenarios ¶
func SuggestMissingScenarios(target capability.Target, report TestReport) []Suggestion
SuggestMissingScenarios returns structural coverage gaps for target.
What this deliberately does NOT do ¶
It does not read names or doc comments and imagine scenarios from them. Spec §23 forbids generating suggestions from keywords alone, and for a good reason: a suggestion invented from the word "payment" in a function name is indistinguishable, to the reader, from one derived from an actual gap in the graph — and once one fabricated suggestion is in the list, none of them can be trusted.
Every suggestion here is therefore traceable to a fact already printed in the report: the target's export status, a recorded CALLS edge into error construction, or the complete absence of a graph-proven test. Branch coverage and state-transition scenarios are NOT emitted, even though the spec mentions them as desirable, because GraphLume has no control-flow graph — there is no evidence in the index from which to justify them, so emitting them would be invention.
Returning nil is a correct and common outcome. It means no gap could be justified, not that the code is well tested.
type SuggestionKind ¶
type SuggestionKind string
SuggestionKind names a structural coverage gap.
const ( // GapPublicAPIUntested: an exported symbol with no discovered test. GapPublicAPIUntested SuggestionKind = "public_api_untested" // GapErrorPathUntested: the target provably calls into error construction, // and nothing was found that exercises it. GapErrorPathUntested SuggestionKind = "error_path_untested" // GapNoProvenExecution: tests exist, but only naming and co-location found // them. Nothing in the graph shows any of them actually reaching the // target — so the coverage claim rests entirely on convention. GapNoProvenExecution SuggestionKind = "no_proven_execution" )
type TestHit ¶
type TestHit struct {
capability.Symbol
// Kind is unit / integration / e2e where inferable from path and name, and
// "unknown" where it is not. Guessing "unit" would be a claim.
Kind capability.TestKind `json:"test_kind"`
// Signals is every signal that matched, strongest first.
Signals []SignalMatch `json:"signals"`
// Strongest is Signals[0].Signal, hoisted for consumers that want one word.
Strongest Signal `json:"strongest_signal"`
// Confidence is the confidence of the strongest signal — never an average,
// and never upgraded because several weak signals agreed. Three guesses
// pointing the same way are still three guesses.
Confidence model.Confidence `json:"confidence"`
// Depth is how many calls lie between this test and the target on the
// shortest recorded path: 1 calls it directly. Zero when no call path was
// found (matched by name or by file only).
Depth int `json:"depth,omitempty"`
// Runnable is false for a helper in a test file that a test runner does
// not run itself (see capability.IsRunnableTest). A helper is listed
// apart: the tests that reach the target through it are what to run.
Runnable bool `json:"runnable"`
}
TestHit is one discovered test.
type TestReport ¶
type TestReport struct {
Target capability.Target `json:"target"`
// Tests are the discovered tests, strongest signal first.
Tests []TestHit `json:"tests"`
// Untested is true when NO signal matched anything. Reported as a positive
// finding rather than an empty list, because "we found nothing" and "we did
// not look" must not render identically.
Untested bool `json:"untested"`
// SignalCounts is how many tests each signal contributed to, so a reader can
// see at a glance whether the coverage claim rests on proven edges or on
// filenames.
SignalCounts map[Signal]int `json:"signal_counts"`
// ProvenByGraph is the count of tests reached through recorded edges — the
// only number here that is evidence of execution.
ProvenByGraph int `json:"proven_by_graph"`
// ErrorPaths are the target's proven calls into error construction. Input
// to SuggestMissingScenarios.
ErrorPaths []ErrorPath `json:"error_paths,omitempty"`
Completeness capability.Completeness `json:"completeness"`
// Binding is what the index did with the references spelled like the
// target. A test reaches the target through one of those references, so
// when they could not be bound, "no test found" says nothing about tests.
Binding capability.TargetBinding `json:"binding"`
// Undetermined is non-empty when the graph signal could not have found the
// tests even if they exist, and says why. It qualifies Untested: Untested
// with Undetermined set means "nothing was found, and the search could not
// see", not "nothing covers this".
Undetermined string `json:"undetermined,omitempty"`
// ValueUse is the text check for a function passed as a value. A test that
// reaches the target that way leaves no edge, so when it has a finding
// "no test reaches this" is not something the report can say. Zero when the
// check was not asked for.
ValueUse capability.ValueUse `json:"value_use"`
Truncated bool `json:"truncated"`
TruncatedReason string `json:"truncated_reason,omitempty"`
}
TestReport is one test-discovery answer.
func FindTests ¶
func FindTests(ctx context.Context, deps capability.Deps, runID int64, target string) (TestReport, error)
FindTests discovers the tests that cover target.
func FindTestsForTarget ¶
func FindTestsForTarget(ctx context.Context, deps capability.Deps, runID int64, tgt capability.Target, opts Options) (TestReport, error)
FindTestsForTarget is FindTestsWith for a caller that has already chosen the definition, by file and line or any other means. See impact.AnalyzeTarget for why a name is not always enough to choose one.
func FindTestsWith ¶
func FindTestsWith(ctx context.Context, deps capability.Deps, runID int64, target string, opts Options) (TestReport, error)
FindTestsWith is FindTests under explicit bounds and signal selection.
func (TestReport) Inconclusive ¶
func (r TestReport) Inconclusive() bool
Inconclusive reports whether r found no tests but stopped at a bound, so "no tests" is not something it can claim.