Add test seams at I/O boundaries to raise coverage to ~90% - #22
Merged
Conversation
The untested code was structurally unreachable from tests because the
network, the git/gh subprocess, and os.Exit were hardwired and the program
spine sat in one large main(). This threads test seams through those
boundaries without changing production behavior.
- main: extract run(args, stdout, stderr, deps) int from main(); inject the
I/O boundaries (repo resolve, cookie resolve, upload, extract/check-token)
via a deps struct. The upload client is built once per run (shared cookie
jar), matching prior behavior. Remove now-dead handle* wrappers.
- upload: introduce a *Client{http, baseURL} with methods so requestPolicy,
finalizeUpload, and getUploadToken hit an httptest server instead of the
hardcoded github.com URL.
- repo: inject a command runner so git/gh URL and ID parsing are testable
without a real repo or authenticated gh.
- cookies: split pure chooseSession and mapKookyCookies out of the kooky read.
- session: add a profileURL var seam so CheckValidity is exercised end-to-end.
- docs: update architecture.md for the changed signatures.
Pooled statement coverage 24%/14%/0% across the weak packages -> ~90% overall.
…affold - Narrow deps.resolveCookie to (cookie, error); run() never used the source string (check-token resolves its own source via the separate checkToken seam). productionDeps wraps resolveSessionCookie with a small adapter. - Add newServer/newJSONServer helpers in upload_test.go and use them across the request-policy, finalize, S3, and token tests. - Fold TestUpload_FullFlow into TestUpload_Flow as the failStep=="" happy path, removing the duplicated four-route mux.
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.
Why
Coverage was low not because of too few tests, but because the code doing the real work had no test seam: the network, the
git/ghsubprocess, andos.Exitwere hardwired, and the program spine sat in one largemain(). Those parts were structurally unreachable from tests.Before → after (pooled statement coverage):
.(main)internal/uploadinternal/repointernal/sessioninternal/cookiesWhat
Strictly behavior-preserving seams (no user-facing change — same flags, output, exit codes, URLs, and headers):
run(args, stdout, stderr, deps) intfrommain(); inject the I/O boundaries via adepsstruct so the full CLI spine is tested without network/subprocess/exit. The upload client is built once per run (shared cookie jar), matching prior behavior. DeadhandleExtractToken/handleCheckTokenremoved.*Client{http, baseURL}with methods sorequestPolicy/finalizeUpload/getUploadTokenrun against anhttptestserver instead of a hardcodedgithub.comURL.runnerso remote-URL and ID parsing are testable without a real git repo or authenticatedgh.chooseSession+mapKookyCookiesout of thekookybrowser read (now the only untested unit).profileURLvar seam soCheckValidityis exercised end-to-end.architecture.mdupdated for the changed signatures.Accepted coverage gaps
internal/httputil(a single const),cookies.readRawCookies(live browser read via kooky), a few unreachable defensive branches, and thin production wiring (main,productionDeps,resolveSessionCookie).Validation
gofmt -l .clean ·go vet ./...clean ·go test -race ./...pass · pooled coverage 90.1%.