Skip to content

test: add testing infrastructure and improve coverage (16% to 51%) - #16

Merged
timimsms merged 3 commits into
mainfrom
chore/testing-infrastructure
Jul 15, 2026
Merged

test: add testing infrastructure and improve coverage (16% to 51%)#16
timimsms merged 3 commits into
mainfrom
chore/testing-infrastructure

Conversation

@timimsms

Copy link
Copy Markdown
Owner

Summary

Focused extraction of valuable testing infrastructure from the test coverage audit (PR #15), without the over-engineered factory pattern that bloated it to 24K lines.

What's Included

Testing infrastructure:

  • Mock infrastructure (internal/auth/mock/) — concurrency-safe, token expiry simulation, behavioral verification
  • Interface definitions (internal/interfaces/) for API, Auth, Config, Output — enables future dependency injection
  • Simple mocks (internal/mocks/) for auth, config, output
  • Test utility helpers (internal/testutil/) for CI detection
  • stretchr/testify dependency

Test suites for:

  • API: rate limiter, retry logic, user lookup
  • Auth mock: comprehensive behavioral tests
  • Cache: get/set/delete/clear operations
  • Commands: all 15 commands (structure + helper function tests)
  • Config: loading, merging, project discovery
  • Errors: custom error types
  • Output: formatter, table, wrapper
  • Version: full version string

Standalone source additions:

  • internal/config/provider.go — ConfigProvider wrapper (useful for DI)
  • internal/output/wrapper.go — testable output formatting wrapper
  • Minor formatting fixes to cache, config, output

What's Excluded (from PR #15)

  • Factory pattern (internal/cmd/factory/) — ~9,600 LOC of duplicated command implementations
  • Base command abstraction (internal/cmd/base/)
  • 12 session-artifact documentation files
  • CI workflow rewrite (keeping the existing clean workflow)
  • Source code changes that modified function signatures for dependency injection

Coverage by Package

Package Before After
api 5.0% 24.4%
auth/mock 79.7%
cache 35.1% 35.1%
cmd 7.9% 18.8%
config 27.8% 69.5%
errors 0% 89.7%
output 0% 79.6%
version 0% 100%
total 16% 51%

Test plan

  • go build ./cmd/cu — builds cleanly
  • go vet ./... — no issues
  • go test ./... — all tests pass
  • CI passes on all platforms (Linux, macOS, Windows)

Context

This supersedes the testing portion of PR #15. After this merges, PR #15 should be closed — its remaining value (factory pattern) is better pursued as a separate, more focused effort if/when dependency injection is needed.

🤖 Generated with Claude Code

Cherry-pick valuable testing foundations from the test coverage audit
(PR #15), excluding the over-engineered factory pattern and session
documentation.

Included:
- Mock infrastructure (auth/mock package with concurrency-safe mocks)
- Interface definitions for API, Auth, Config, Output (for future DI)
- Simple mocks package for testing command layer
- Test utility helpers (CI detection)
- Config provider wrapper (standalone-useful abstraction)
- Output wrapper for testable formatting
- Test suites for: api (ratelimit, retry, users), auth/mock, cache,
  cmd (all 15 commands), config, errors, output (formatter, table,
  wrapper), version
- Testify dependency (stretchr/testify)

Excluded from PR #15:
- Factory pattern (~9,600 LOC of duplicated command implementations)
- Base command abstraction (internal/cmd/base/)
- 12 session-artifact documentation files
- CI workflow rewrite
- Source code changes that modified function signatures for DI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
timimsms and others added 2 commits July 14, 2026 23:52
On Windows, os.Mkdir ignores the 0555 permission mode (CreateDirectory
discards it), so the read-only setup in the "handles permission errors"
subtest never takes effect. The command then succeeds, assert.Error
fails non-fatally, and the subsequent err.Error() call panics on the
nil error, crashing the entire internal/cmd test binary.

Fixes:
- Skip the permission-bit subtest on Windows and upgrade assert.Error
  to require.Error so a nil error can never be dereferenced again.
- In the config symlink subtest, skip on Windows when os.Symlink fails,
  since symlink creation there can require elevation.
- gofmt cleanup of pre-existing trailing whitespace in both files.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@timimsms
timimsms merged commit 9ca210f into main Jul 15, 2026
16 checks passed
@timimsms
timimsms deleted the chore/testing-infrastructure branch July 15, 2026 06:57
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