Skip to content

Multiple target functions warning needs guidance or annotation support (follow-up to #45) #61

Closed

Description

@jflowers

Context

Follow-up to #45. Gaze v1.4.2 still produces "multiple target functions detected" warnings during quality analysis with no guidance on how to resolve them. This remains one of the most confusing aspects of using gaze quality analysis.

Problem

During CI quality analysis of a real project (get-out), gaze produces warnings like:

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

warning: TestLoadConversations_ContractAssertions: multiple target functions
detected: (*ConversationsConfig).FilterByExport, (*ConversationsConfig).GetByID,
LoadConversations, isValidConversationType, isValidExportMode, validateConversationConfig

These warnings mean gaze cannot determine which function the test targets, so contract coverage is diluted or unmapped. The developer sees the warning but has no idea:

  1. Why setup helpers like testFileStore and writeToken are detected as targets
  2. How to restructure tests to have unambiguous targets
  3. Whether t.Helper() affects target detection
  4. Whether naming conventions matter (e.g., TestFuncName_Scenario)

Real-world impact

In the get-out project, 30+ tests produced this warning. The total quality analysis had 207 test reports but many had diluted contract coverage because of ambiguous target resolution. This directly contributed to the low contract coverage score (11% in CI) despite tests having explicit assertions on every return value.

What would help

Option A: Documentation

A section in gaze docs explaining:

  • How gaze determines which function a test targets
  • What causes a test to have multiple detected targets
  • Best practices for test structure that gaze can analyze cleanly

Option B: Report guidance

When warnings exceed a threshold, include a summary in the report:

Quality Analysis Warnings:
- 30 tests have ambiguous targets (multiple functions detected)
- This reduces contract coverage accuracy
- Tip: Extract setup code into helper functions marked with t.Helper(),
  and name tests as TestTargetFunction_Scenario

Option C: Annotation support

A comment convention that lets developers explicitly declare the target:

func TestClientFromStore_ValidToken(t *testing.T) {
    // gaze:target=ClientFromStore
    ...
}

Any of these would significantly reduce confusion.

Activity

  1. added
    enhancement
    documentation
    on Mar 16, 2026
  2. added this to the v1.5.0 milestone on Mar 16, 2026
  3. jflowers commented on Mar 16, 2026

    @jflowers
    CollaboratorAuthor

    Triage

    Priority: Medium
    Milestone: v1.5.0
    Effort: Small (warning hint) to Medium (annotation support)

    What already exists (v1.4.2):

    • PR docs: document target inference algorithm and best practices #57 added "How Target Inference Works" section to README covering:
      • How gaze determines targets (SSA call graph analysis)
      • Common causes of multiple-target warnings (setup helpers, multi-function integration tests)
      • What does NOT affect detection (t.Helper(), naming conventions)
      • Best practices (t.Run sub-tests, --target flag)

    What's missing:
    The warning message itself doesn't reference the documentation. A user seeing warning: TestFoo: multiple target functions detected: A, B, C has no idea where to look for help.

    Recommended fixes (two phases):

    Phase 1 (Low effort — do now):
    Update the warning message in internal/quality/pairing.go:198 to include a hint:
    "warning: %s: multiple target functions detected: %s. See README 'How Target Inference Works' for guidance."

    Phase 2 (Medium effort — future):
    Add // gaze:target=FuncName annotation support. When present in a test function, gaze uses the declared target instead of SSA call graph inference. This gives users explicit control without restructuring their tests.

    Related: #45 (target inference docs — closed), #6 (AST-to-SSA bridge — partially addressed)

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

    documentationenhancement

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions