You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Guidance needed for 'multiple target functions detected' warnings #45
This meant gaze could not determine which function the test was targeting, so contract coverage was diluted or lost. But there was no guidance on how to fix this.
Questions I had:
Should I rename helper functions? Use a naming convention?
Should I use subtests where the parent does setup?
Should I move setup to TestMain or init?
Does t.Helper() affect target detection?
Are there naming patterns that gaze recognizes as "setup" vs "target"?
What would help
Documentation on how gaze determines test targets and what causes ambiguity
Actionable suggestions in the report — e.g., "17 tests have ambiguous targets. Consider: (a) using t.Helper() on setup functions, (b) naming test functions to match their target: TestFuncName_Scenario, (c) extracting setup into TestMain"
A way to annotate tests with the intended target if automatic detection fails — e.g., a comment convention like // gaze:target=ClientFromStore
Impact
Many test functions in real codebases call helper functions for setup (creating temp dirs, writing fixture files, constructing mock servers). If every helper counts as a "target function," most tests will have ambiguous targets, making contract coverage unreliable.
Priority: Medium Label: documentation Related: Spec 007 (assertion-mapping-depth) covers the mapping algorithm
Analysis: This is primarily a documentation gap. Gaze's target inference algorithm (InferTargets in internal/quality/pairing.go) walks SSA basic blocks to find function calls from the test function. When a test calls multiple non-test functions, all are reported as potential targets, producing the "multiple target functions detected" warning.
What causes ambiguity in practice:
Test helper functions that create fixtures (e.g., writeCredentials(), writeToken()) are detected as call targets alongside the actual function under test
Setup functions that aren't marked with t.Helper()
Tests that exercise multiple functions in sequence (integration-style)
What doesn't help (important to document):
t.Helper() does NOT affect SSA call graph analysis — it only affects testing.T stack frame reporting
Function naming conventions (TestFoo -> Foo) are NOT currently used for target inference — gaze uses SSA call graph, not name matching
Actionable fixes:
Add a "Target Inference" section to README or a docs/target-inference.md explaining the algorithm and common patterns
Document that the direct call from the test function body is what matters — setup in helper functions called from the test body still counts as a call target
Consider a future enhancement: exclude functions that match common setup patterns (e.g., functions only called with t as an argument, functions that return no values matching the target's signature)
Activity
jflowers commentedon Mar 15, 2026
Triage
Priority: Medium
Label: documentation
Related: Spec 007 (assertion-mapping-depth) covers the mapping algorithm
Analysis: This is primarily a documentation gap. Gaze's target inference algorithm (
InferTargetsininternal/quality/pairing.go) walks SSA basic blocks to find function calls from the test function. When a test calls multiple non-test functions, all are reported as potential targets, producing the "multiple target functions detected" warning.What causes ambiguity in practice:
writeCredentials(),writeToken()) are detected as call targets alongside the actual function under testt.Helper()What doesn't help (important to document):
t.Helper()does NOT affect SSA call graph analysis — it only affectstesting.Tstack frame reportingActionable fixes:
docs/target-inference.mdexplaining the algorithm and common patternstas an argument, functions that return no values matching the target's signature)docs: document target inference algorithm and best practices (issue u…
docs: document target inference algorithm and best practices (issue u…