Skip to content

Add test seams at I/O boundaries to raise coverage to ~90% - #22

Merged
drogers0 merged 2 commits into
mainfrom
test-coverage-seams
Jun 25, 2026
Merged

Add test seams at I/O boundaries to raise coverage to ~90%#22
drogers0 merged 2 commits into
mainfrom
test-coverage-seams

Conversation

@drogers0

Copy link
Copy Markdown
Owner

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/gh subprocess, and os.Exit were hardwired, and the program spine sat in one large main(). Those parts were structurally unreachable from tests.

Before → after (pooled statement coverage):

Package Before After
. (main) 24.1% ~89%
internal/upload 14.3% ~91%
internal/repo 0.0% ~93%
internal/session 81.5% ~89%
internal/cookies 75.0% ~92%
pooled total 90.1%

What

Strictly behavior-preserving seams (no user-facing change — same flags, output, exit codes, URLs, and headers):

  • main: extract run(args, stdout, stderr, deps) int from main(); inject the I/O boundaries via a deps struct 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. Dead handleExtractToken/handleCheckToken removed.
  • upload: introduce *Client{http, baseURL} with methods so requestPolicy/finalizeUpload/getUploadToken run against an httptest server instead of a hardcoded github.com URL.
  • repo: inject a command runner so remote-URL and ID parsing are testable without a real git repo or authenticated gh.
  • cookies: split pure chooseSession + mapKookyCookies out of the kooky browser read (now the only untested unit).
  • session: add a profileURL var seam so CheckValidity is exercised end-to-end.
  • docs: architecture.md updated 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%.

drogers0 added 2 commits June 24, 2026 19:39
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.
@drogers0
drogers0 merged commit 7385c82 into main Jun 25, 2026
1 check passed
@drogers0
drogers0 deleted the test-coverage-seams branch June 25, 2026 04:54
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