[test-improver] Improve tests for auth package - #7650
Merged
Conversation
Fix bound asserter scoping in header_test.go: all seven table-driven test functions were creating assert/require bound to the outer *testing.T, then using those inside t.Run subtests. This caused: - Test failures to be reported against the outer test function instead of the specific failing subtest, making failures hard to identify - require.FailNow() (via require.NoError/require.ErrorIs) to call FailNow() on the outer t instead of the subtest's t, which could stop all subsequent subtests on the first require failure Fix by switching all inner assertions to the non-bound form (assert.Equal(t, ...) using the subtest's t parameter). Also add t.Parallel() to all top-level test functions and their subtests to catch data-race issues and speed up execution. Add missing edge-case test inputs: - ParseAuthHeader: "Bearer " (Bearer with empty token) and "Agent " (Agent with empty value) - ExtractSessionIDFromHeaders: both headers empty, valid X-Agent-ID with malformed Authorization, X-Agent-ID with Bearer Authorization - StripAuthScheme: "Bearer " and "Agent " (scheme prefix with no value) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 17, 2026
lpcox
marked this pull request as ready for review
June 17, 2026 14:00
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the internal/auth test suite by fixing incorrect testify bound-asserter usage in subtests, increasing parallelization, and adding coverage for additional auth header edge cases. These changes strengthen failure attribution and exercise more boundary behaviors in auth scheme parsing and session ID extraction.
Changes:
- Replaced bound
assert.New(t)/require.New(t)usage withassert.*(t, ...)/require.*(t, ...)insidet.Runsubtests. - Added
t.Parallel()to top-level tests and subtests. - Added new test cases for empty
Bearer/Agentvalues and additionalExtractSessionIDFromHeadersprecedence scenarios.
Show a summary per file
| File | Description |
|---|---|
| internal/auth/header_test.go | Refactors subtest assertion scoping, adds parallelization, and expands edge-case coverage for auth header parsing and session ID extraction. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 7
1 task
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Improvements:
internal/auth/header_test.goFile Analyzed
internal/auth/header_test.gointernal/auth1. Fix Bound Asserter Scoping (correctness fix)
All seven table-driven test functions in
header_test.goboundassert/requireto the outer*testing.T, then used those bound asserters insidet.Runsubtests:This caused two real problems:
TestIsMalformedHeaderinstead ofTestIsMalformedHeader/Null_byte_is_malformed, making failures much harder to diagnoseFailNowtarget:require.NoError/require.ErrorIscallt.FailNow()on the outer test, which can abort all remaining subtests when only one should stopFix: switched all inner assertions to the non-bound form using the subtest's own
t:Affected test functions:
TestIsMalformedHeaderTestTruncateSecretTestParseAuthHeader(also hadrequire.ErrorIs/require.NoErrorscoping issue)TestValidateAgentIDTestExtractAgentIDTestExtractSessionIDTestStripAuthScheme2. Add
t.Parallel()ThroughoutAll top-level test functions and their subtests now call
t.Parallel(). The auth functions under test are pure (no global state mutation), so parallel execution is safe and catches potential data-race issues.3. New Edge-Case Test Inputs
Added missing inputs that test boundary behaviour of the scheme-stripping logic:
TestParseAuthHeader— 2 new cases:"Bearer "(Bearer prefix with empty token) →apiKey="",agentID="""Agent "(Agent prefix with empty value) →apiKey="",agentID=""TestExtractSessionIDFromHeaders— 3 new cases:""X-Agent-IDwith malformedAuthorization→ returns the validX-Agent-IDX-Agent-IDpresent alongside aBearer Authorization→X-Agent-IDwinsTestStripAuthScheme— 2 new cases:"Bearer "→ scheme"Bearer", value"", matchedtrue"Agent "→ scheme"Agent", value"", matchedtrueTest Execution
All tests pass and are stable across multiple runs:
Subtests now report correctly:
Notes on Remaining Uncovered Lines
The two functions below
100%contain legitimately untestable paths:ExtractAgentID(83.3%): theif err != nilguard afterParseAuthHeaderis dead code —ParseAuthHeaderonly errors on empty input, which is already handled by the preceding nil-checkGenerateRandomAgentID(71.4%): the error path requirescrypto/randto fail, which needs dependency injection to testGenerated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.