Skip to content

Guidance needed for 'multiple target functions detected' warnings #45

Closed

Description

@jflowers

Problem

During CI quality analysis, gaze produced dozens of warnings like:

warning: TestClientFromStore_ValidToken: multiple target functions detected:
  ClientFromStore, LoadTokenFromStore, testFileStore, writeCredentials, writeToken

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

  1. Documentation on how gaze determines test targets and what causes ambiguity
  2. 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"
  3. 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.

Activity

  1. added
    documentation
    on Mar 15, 2026
  2. jflowers commented on Mar 15, 2026

    @jflowers
    CollaboratorAuthor

    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 (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:

    1. Add a "Target Inference" section to README or a docs/target-inference.md explaining the algorithm and common patterns
    2. 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
    3. 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)
  3. added this to the v1.4.0 milestone on Mar 15, 2026
  4. moved this from Todo to In Progress in Gaze Roadmapon Mar 15, 2026
  5. moved this from In Progress to Done in Gaze Roadmapon Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions