Skip to content

fix: constrain what a test does, not how a symbol is exposed - #80

Merged
retr0h merged 1 commit into
mainfrom
fix/export-test-alias
Aug 16, 2026
Merged

fix: constrain what a test does, not how a symbol is exposed#80
retr0h merged 1 commit into
mainfrom
fix/export-test-alias

Conversation

@retr0h

@retr0h retr0h commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Applying specify-go-code-standards showed this requirement is wrong. Correcting it on its own, before any code, per CONTRIBUTING.

What was wrong

The requirement said export_test.go "SHALL NOT expose an alias to an unexported function", permitting only setter functions.

That outlaws an idiomatic Go pattern. Twenty-two standard library packages use it. net/http/export_test.go alone:

DefaultUserAgent      = defaultUserAgent
NewLoggingConn        = newLoggingConn
ExportRefererForURL   = refererForURL
ExportServeFile       = serveFile
ExportScanETag        = scanETag

Verification 3.5 found ten such aliases across gohai and osapi, with eleven call sites. I reported that as debt to pay down. It was not — the rule was wrong.

Where the rule came from, and what it was actually protecting

gohai wrote it after aliases produced tests that re-covered paths the caller's own test already exercised. That concern is real. But it is a concern about what the test does, not about how the symbol was exposed. Banning the mechanism outlawed an idiom in order to prevent one misuse of it.

The corrected requirement

Names the misuse instead: a test SHALL NOT use an exported alias to re-cover behavior the caller's test already reaches. Seams still belong at the boundary with a dependency rather than partway through the code under test — that part was always about test design and is unchanged.

A third scenario now covers the case the pattern exists for: a pure helper with its own contract, independent of its callers — BytesToString, ParseOffset — is exactly what should be exposed and tested directly.

Task 3.5 is rewritten to check the behavior rather than the mechanism. No code changes; the ten aliases stay.

Alternative considered and rejected: keep the ban and remove the aliases — rewriting eleven working call sites to satisfy a rule the language's own standard library does not follow.

🤖 Generated with Claude Code

The requirement banned exposing an alias to an unexported function
from export_test.go. That is an idiomatic Go pattern; twenty-two
standard library packages use it, net/http most heavily.

The concern it came from is real but is about the test, not the
mechanism: an alias should not be used to re-cover behavior the
caller's own test already reaches. The requirement now says that,
and a scenario allows the case the pattern exists for.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thank you for contributing to this project! 😊🕹️

@retr0h
retr0h merged commit d571d68 into main Aug 16, 2026
6 checks passed
@retr0h
retr0h deleted the fix/export-test-alias branch August 16, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant