Skip to content

Add 36 tests for runners and cmd packages - #22

Merged
5uck1ess merged 2 commits into
mainfrom
fix/improve-test-coverage
Apr 5, 2026
Merged

Add 36 tests for runners and cmd packages#22
5uck1ess merged 2 commits into
mainfrom
fix/improve-test-coverage

Conversation

@5uck1ess

@5uck1ess 5uck1ess commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Summary

Add unit tests for pure functions in the two lowest-coverage packages.

Before: 143 tests, cmd 9.5%, runners 28%
After: 179 tests, cmd ~11%, runners ~28%

Coverage % didn't jump much because remaining untested code is cobra handlers and exec.Command calls requiring real CLIs — integration test territory.

New tests

runners/claude_test.go (18 tests)

  • Claude JSON response parsing: full, error, empty, invalid JSON, missing fields
  • TruncStr edge cases: empty, exact length, one over, zero limit, unicode
  • RunOpts/RunResult zero-value defaults
  • All 3 runner Name() methods

cmd/workflow_test.go (18 tests)

  • Workflow name validation: 12 cases including path traversal, shell injection, backticks, dollar signs
  • formatAge: 4 duration ranges + 3 boundary cases (minute/hour/day edges)

Test plan

  • go test -v -race ./... passes locally (179 tests, 0 failures)
  • CI passes

5uck1ess added 2 commits April 5, 2026 18:43
runners/claude_test.go:
- Claude JSON response parsing (full, error, empty, invalid, partial)
- TruncStr edge cases (empty, exact, one-over, zero-limit, unicode)
- RunOpts/RunResult zero-value defaults
- Runner Name() for all 3 runners

cmd/workflow_test.go:
- Workflow name validation regex (12 cases incl path traversal, shell injection)
- formatAge (4 duration ranges + 3 boundary cases)
- Extract validWorkflowName regex to package-level var in workflow.go
  so tests validate production code, not a copy (critical review finding)
- Fix formatAge boundary tests: add true boundaries (59s, 59m, 23h)
  and label 61s/61m/25h correctly as post-boundary
- Add 5 more security vectors: null byte, pipe, newline, lone dot, double dot
- Add TestResolveRunnerFrom_EmptyName for empty --agent flag path
- Remove TestRunOptsDefaults and TestRunResultDefaults (tested Go
  zero-value guarantees, not application logic)

143 → 183 total tests.
@5uck1ess
5uck1ess merged commit 9e97f55 into main Apr 5, 2026
2 checks passed
@5uck1ess
5uck1ess deleted the fix/improve-test-coverage branch April 5, 2026 22:52
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