Skip to content

[Code Quality] Add t.Helper() to test helper functions for better debugging #12737

@github-actions

Description

@github-actions

Description

Test helper functions lack t.Helper() calls, causing test failure stack traces to point to helper internals instead of actual test cases. With 1,394 table-driven tests and complex setup functions, this severely degrades debugging experience.

Problem

Only 5 occurrences of t.Helper() exist across the entire 1,362-file test suite. When tests fail, stack traces point to internal helper lines instead of the actual test case, wasting developer time navigating to the real failure location.

Good Examples (5 files)

  • pkg/cli/compile_integration_test.go:91
  • pkg/cli/deps_test.go:237,252
  • pkg/cli/mcp_add_integration_test.go:21
  • pkg/cli/audit_report_test.go:55,76,87

Missing (100+ estimated files)

Any function taking *testing.T that performs assertions or setup

Suggested Changes

Audit all test helper functions and add t.Helper() as the first line:

Before

func setupTestEnvironment(t *testing.T) *TestEnv {
    // Missing t.Helper()
    tempDir := t.TempDir()
    // ... setup code ...
    return &TestEnv{Dir: tempDir}
}

After

func setupTestEnvironment(t *testing.T) *TestEnv {
    t.Helper()  // ✅ Marks this as a helper
    tempDir := t.TempDir()
    // ... setup code ...
    return &TestEnv{Dir: tempDir}
}

Implementation Steps

  1. Find candidates - Search for functions taking *testing.T:

    rg "func \w+\(.*\*testing\.T" --type go -g "*_test.go"
  2. Add t.Helper() - Semi-automated via ripgrep + manual review

  3. Enforce pattern - Add golangci-lint thelper linter rule

  4. Document - Add pattern to CONTRIBUTING.md

Files Affected

Estimated 100+ test files across the codebase (any function taking *testing.T)

Success Criteria

  • Run full test suite to ensure no regressions
  • Manually verify test failures now show correct line numbers
  • Add golangci-lint rule to enforce t.Helper() in future
  • Document pattern in CONTRIBUTING.md

Source

Extracted from Sergo Report: Table-Driven Test & Init Function Hygiene Analysis - 2026-01-30

Priority

High - Affects developer productivity and debugging experience

Estimated Effort

Medium (2-3 hours) - Semi-automated via ripgrep + manual review

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 13, 2026, 1:26 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions