Skip to content

refactor: apply the Go style review's structure and test findings - #96

Merged
jferrl merged 3 commits into
mainfrom
fix/style-review-cleanup
Oct 31, 2026
Merged

jferrl merged 3 commits into
mainfrom
fix/style-review-cleanup

Conversation

@jferrl

@jferrl jferrl commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Summary

The Go style reviews behind #95 (Codex and Claude Fable, against the Google Go Style Guide) also found structure and test problems. #95 fixed the defects; this PR does the rest. It changes no behaviour except one error message. The largest parts: tokenCmd was a 145-line function, two test hooks were package globals, and the retry tests measured wall-clock time, so the suite was slow and timing-sensitive. Stacked on #95.

What this does

Area Before After
tokenCmd 145 lines, two flag styles, URL options built twice tokenFlags with resolve, urlOptions, mint
Test hooks Package globals swapped by tests Parameters: runChild, environWithout(env, foldCase, …)
Retry tests Assert elapsed time, really sleep Assert the recorded wait; library suite 11s → under 6s with -race
Signal tests Fire after a fixed 500ms, goroutine never joined Fire once the child has written, joined
Fake GitHub A transport that rewrote the caller's request httptest, like every other test

Changes

  • githubClient holds its throttle sleep (default sleepCtx); TestSleepCtx checks the real wait lasts its duration and ends mid-wait on cancellation.
  • Tests compare tokens by public fields, sentinels with errors.Is, request bodies as JSON; stdout matchers return errors; Test_ prefixes only for unexported symbols; got-before-want messages; testKeyPEM(t) replaces a helper eleven callers checked.
  • Naming and comments: writeToken, splitList, maxRedirects; rewrapped and stale comments fixed. NewPersonalAccessTokenSource("")'s error now reads "personal access token is required".

Rationale

resolve keeps the validation order exactly, so exit codes and error precedence are unchanged. An adversarial Codex pass confirmed that, and found one gap, fixed: once waits were recorded, nothing showed sleepCtx really waits. Coverage is 96.8%, from 96.7%.

Migration Notes

None, beyond the reworded error under Changed in the CHANGELOG.

🤖 Generated with Claude Code

No behaviour changes but one error message. Following the Google Go
Style Guide findings from the Codex and Claude Fable reviews:

- tokenCmd was 145 lines mixing two flag styles. It is now tokenFlags,
  bound like appFlags, with resolve (validation, in the same order),
  urlOptions (the one place the URL flags become options) and mint.
- The two package-level test hooks are parameters: runChild takes the
  foreground probe, environWithout whether to fold case.
- withEnterpriseURL/withBaseURL return only their error; githubClient
  holds its throttle sleep, so retry tests record the wait they asked
  for instead of measuring wall-clock time, and the cancellation test
  cancels from inside the wait. TestSleepCtx keeps checking the real
  wait. The library suite went from 11s to under 6s with -race.
- Signal tests signal once the child has written, and join the sender.
- The mock transport, which rewrote the caller's request, is replaced
  by httptest; tokens are compared by public fields; sentinels with
  errors.Is; request bodies as JSON; stdout matchers return errors.
- Naming and consistency: writeToken, splitList, maxRedirects, Test_
  only for unexported symbols, got-before-want messages, testKeyPEM,
  rewrapped and corrected comments. The empty-PAT error now reads
  "personal access token is required".
# Conflicts:
#	cmd/githubauth/main_test.go
The no-URL return was its own statement, which no test can reach without
minting against api.github.com. Accumulating into one slice, as the code
did before the split, keeps the function fully covered.
@jferrl
jferrl added this pull request to stack #97 October 31, 2026 15:32
Base automatically changed from fix/style-review-bugs to main October 31, 2026 15:34
@jferrl
jferrl merged commit 58374ff into main Oct 31, 2026
8 checks passed
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.75%. Comparing base (03a93a9) to head (a654d70).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
+ Coverage   97.72%   97.75%   +0.02%     
==========================================
  Files           9        9              
  Lines         923      935      +12     
==========================================
+ Hits          902      914      +12     
  Misses         21       21              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant