test: drop the export aliases that re-cover their callers - #457
Open
retr0h wants to merge 2 commits into
Open
Conversation
An export_test.go alias may not re-cover behavior the caller's own test already reaches. Thirty-six did. Established by measurement rather than reading: for each package, run the tests twice -- once fully, once with the alias-using suites excluded -- and compare per-function coverage. A function that stays at 100% without its alias test was already covered by its caller. Thirty-three were in pkg/sdk/client: the deref helpers and the FromGen converters, all reached by the service methods' own httptest-driven tests. Three more in internal/agent, api/node/docker, and api/file. Coverage is unchanged at 100% against a 99.9% gate, which is what makes the removal safe to assert rather than hope. Sixty-eight other aliases stay. They are load-bearing: parsePortMappings drops to 18.2% without its own test, and several drop to zero, so the caller's test never reaches them at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #457 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 484 484
Lines 24935 24935
=======================================
Hits 24921 24921
Misses 14 14 Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Isolating this package needed a finer measurement than the rest: its caller test and its alias tests share a file, so excluding the file excluded both. Running the caller test alone by name shows registryKey already fully covered by it, while writeRegistration reaches 46.2% and deregister 60.0% -- so only the first alias was redundant. The identity package was checked the same way. Both its aliases drop to zero without their own tests, because every other test swaps the function variables out, so they are the only thing exercising the real default implementations. Co-Authored-By: Claude Opus 5 <noreply@anthropic.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.
Implements the last open task in
specify-go-code-standards— "confirm no test uses an exported alias to re-cover behavior the caller's own test already reaches."2,508 lines deleted. Coverage unchanged at 100% against a 99.9% gate.
Measured, not read
The rule turns on whether the caller's test already reaches the code, which no search can decide. So for each package: run the tests twice — once fully, once with the alias-using suites excluded — and compare per-function coverage.
Result
gohaineeded nothing: 0 aliases, 53 boundary seams across its 32export_test.gofiles. Every one replaces a dependency with a setter, which is the pattern the requirement endorses.What went
33 in
pkg/sdk/client— thederef*helpers and the*FromGenconverters, every one already reached by its service method'shttptest-driven test. PluscheckSudoAccess(internal/agent),stringPtrOrNil(api/node/docker),validateFileName(api/file).31 test methods and 7 now-empty test files went with them.
What stayed, and why
Removing these would lose real coverage:
parsePortMappingsenvSliceToMapagentFromGenparseRegistryKeywrapInSignedEnvelopeSeveral drop to zero — the caller's test never reaches them, so they cannot be re-covering anything. These are the pure helpers with their own contract that the requirement explicitly permits.
Correcting my earlier estimate
I reported this as "132 aliases needing cleanup." That counted every alias rather than every violation. The real number is 36, and the difference is not bookkeeping — most of the 132 are doing work no other test does.
Two packages could not be isolated by measurement (
internal/controller,internal/agent/identity): every suite in them uses an alias. Reviewed by hand —internal/agent/identityexposes default function values, which are seams;internal/controllerwraps three heartbeat steps and is left alone pending a closer look.🤖 Generated with Claude Code