test: raise codex package coverage to ≥80%#24
Merged
Conversation
procscan had zero test coverage prior. Adds unit tests for both public entry points and the unexported helpers: - IsAlive: empty PID, non-numeric/non-positive PID, missing /proc/<pid>, and self-PID happy path - FindChild: empty-input guard and no-match scan - isNumeric: empty, all-digit, mixed, negative, non-ASCII rune cases - readStatus: self path success and missing-file fallthrough Brings package from 0.0% -> 88.9% statement coverage with no fakes beyond the running test process itself.
process.go was at 0.0% coverage. Adds the same shape of unit tests as procscan_test.go for the codex-package copy (IsCodexAlive, FindCodexChild, isNumeric, readProcStatus), exercising the validation / missing-PID / self-PID happy paths. discover_extra_test.go fills three remaining gaps in discover.go: - dayDirsFor's midnight-clock-skew branch (00:02 UTC -> includes yesterday) and the outside-the-window negative branch (12:00 UTC, 00:05 UTC boundary) - newestMatchingRollout: directory-shaped-like-a-rollout-file is skipped via the IsDir() guard - newestMatchingRollout: non-.jsonl filename is skipped Brings package from 54.8% -> 92.6%.
CheckWorkdir is the pure-stdlib half of agent_check.go; the sibling CheckAgentProcess shells out to a live tmux server and walks /proc and is intentionally left to integration tests (it takes *tmux.Client by concrete type so no test seam is available without a production-code refactor outside the scope of this change). Covered branches: - empty workdir -> fail with 'not set' message + Fix hint - missing dir -> fail with 'does not exist' + mkdir Fix hint - file-not-dir -> fail with 'not a directory' - happy path -> pass with success message - stat error -> non-ENOENT path via unreadable parent (skipped on root) Brings agent_check.go coverage roughly half-of-file (CheckAgentProcess remains at 0%; documented above).
config/config.go: HookTimeout was uncovered. Adds tests for the
zero/negative -> default fallback and the explicit-seconds passthrough.
config.rewriteRequiredPathClaude: covers the early-return branches the
v1->v2 migration step needs to be defensive about:
- missing required_in_path key
- empty raw value
- malformed value (not a JSON array) -> step is no-op, not an error
- non-string entries inside the array are passed through verbatim
alongside the targeted 'claude' -> 'codex' rewrite
migrate/migrate.go: adds two parser branches that were not exercised:
- literal JSON 'null' parses into a nil map; the runner must re-init
to {} and stamp schema_version, not panic
- 'schema_version' present but not an integer -> clear parse error,
not silent re-stamp
config 75.0% -> 85.0%; migrate 81.4% -> 86.0%.
UpdateAgentSessionID's idempotent-noop branch (id already equals stored value) and not-found branch were the only uncovered branches. Adds happy-path, no-op, and missing-row tests. Migration step coverage: - stampAgentClaude with no 'sessions' key (early-return) - stampAgentClaude with a malformed 'sessions' blob (list instead of map) -> step surfaces a parse error - rewriteClaudeToCodex with no 'sessions' key (idempotency) Brings session package from 82.5% -> 84.4%.
|
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.



Summary
Adds targeted unit tests across the six packages introduced or modified by PR #23 to raise Sonar's "Coverage on New Code" gate from 55.1% to ≥80%. No production code changes.
Coverage delta (per package, statement-level)
internal/agent/codexinternal/procscaninternal/migrateinternal/healthinternal/sessioninternal/configWhat got tested
procscan_test.go(new):IsAlive,FindChild,readStatus,isNumeric— empty/invalid/missing/self-PID, no-match scan, helper edge cases.agent/codex/process_test.go(new): same shape against the codex copy of the /proc scanner.agent/codex/discover_extra_test.go(new):dayDirsFormidnight-skew branch (00:02 UTC and the 00:05 boundary),newestMatchingRolloutdirectory-shaped-rollout and non-jsonl skip branches.health/agent_check_test.go(new): all fourCheckWorkdirbranches plus the non-ENOENT stat-error path (via unreadable parent, skipped on root).config/config_test.go:HookTimeoutzero/explicit,rewriteRequiredPathClaudemissing-key / empty-raw / malformed-array / non-string-entry branches.migrate/migrate_test.go: literalnullJSON re-init, non-integerschema_versionparse error.session/state_more_test.go(new):UpdateAgentSessionIDhappy / idempotent-noop / not-found;stampAgentClaudeno-sessions and malformed-sessions branches;rewriteClaudeToCodexno-sessions branch.What is intentionally NOT covered
health.CheckAgentProcess(~46 statements) — takes*tmux.Clientby concrete type and shells out to a live tmux server + walks/proc. Reaching this would require either a production refactor introducing an interface (out of scope per the task constraints) or a tmux integration harness. The CheckWorkdir half of the same file IS covered.codex.IsCodexAliveFindCodexChildandprocscan.FindChildsuccess-when-matched branches that require synthesizing a child process with a controlledcomm— fragile in CI, low value beyond the no-match scan already covered.Constraints satisfied
sonar-project.propertiesor CI workflows.go build ./...clean, fullgo test ./...green (all prior tests + 50+ new test cases),govulncheck ./...reports 0 reachable vulns.Test plan
go build ./...go test -count=1 ./...(all packages pass)govulncheck ./...(no reachable vulnerabilities)go test -coverand confirmed ≥80% for the targeted set, exceptinternal/healthwhich is limited by an exec-bound function as documented above🤖 Generated with Claude Code