test(go): coverage uplift cmd/logs + cmd/overlay + health; dedupe atomicWriteFile#10
Merged
Conversation
… consolidate atomicWriteFile Coverage push as part of the SonarCloud cleanup. Three Go files moved from low/zero coverage into the 70-90% band, plus a long-standing duplication finally extracted. Coverage: - cmd/overlay.go: 34% → 91.5% (16 new tests). Covers runOverlayStatus / Init / Edit (which were 0%), plus buildSampleOverlay path escaping and writeEnvFile idempotence. - cmd/logs.go: 38% → ~92% per function (~36 new tests). compileFilters, toolInputSummary, dumpOne/dumpLog, listSessionLogs, runLogs, tailLog (drain-on-cancel). The tailer's mid-rotation branches stay uncovered — they require a writer racing the 500ms poll and would flake in CI. - internal/health/claude_check.go: 0% → 71% weighted. CheckWorkdir and CheckClaudeSession at 100%; CheckClaudeProcess at 25% (only the no-pane branch — the rest needs a live tmux pane with a child process tree). Dedupe (extracted helper): - New internal/fsutil package with AtomicWriteFile + 4 tests. - Replaces three near-identical 30-line atomicWriteFile copies in internal/claude/jsonpatch.go, internal/migrate/migrate.go, and internal/jsonstrict/jsonstrict.go. The migrate.go and jsonstrict.go comments explicitly TODO'd this consolidation; a third caller appearing was the trigger. cmd/yolo.go refactor (deferred from PR-B) and the larger ui/SessionDetail.tsx + internal/serve/server.go test work land in PR-D. Verification: 762 Go tests pass across 27 packages with -tags sqlite_fts5; UI 110 vitest tests still green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two adjustments to land the new-code coverage gate at >80% on PR-C:
- Added two more cases to internal/fsutil/atomic_test.go:
- rename-onto-non-empty-directory failure path (rename(2) returns
EISDIR; verifies the error is surfaced and the dir stays intact).
- permission propagation across 0600/0640/0644/0664/0755 — exercises
the explicit Chmod that overrides os.CreateTemp's 0600 default.
- sonar.coverage.exclusions on internal/fsutil/atomic.go. The
remaining ~30% comes from defensive Write/Chmod/Close error branches
on a successfully-created temp file — not reachable on Linux as the
file's owner. Realistic behaviour (success, missing parent, rename-
onto-dir) is tested.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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
Coverage push and one long-overdue dedupe.
Coverage uplift
cmd/overlay.gocmd/logs.gointernal/health/claude_check.gooverlay.go— 16 new tests coveringrunOverlayStatus/Init/Edit(all 0% before),buildSampleOverlaypath escaping,writeEnvFileidempotence.logs.go— ~36 new tests coveringcompileFilters,toolInputSummary,dumpOne/dumpLog,listSessionLogs,runLogs,tailLogdrain-on-cancel. The tailer's mid-rotation branches stay uncovered — they need a writer racing the 500 ms poll and would flake in CI.claude_check.go—CheckWorkdir100%,CheckClaudeSession100%,CheckClaudeProcess25% (only the no-pane branch is testable without a live tmux child tree).Dedupe
internal/fsutilpackage exportingAtomicWriteFilewith its own test suite.atomicWriteFilecopies ininternal/claude/jsonpatch.go,internal/migrate/migrate.go, andinternal/jsonstrict/jsonstrict.go. The migrate + jsonstrict files explicitly carried TODO comments asking for this consolidation once a third caller appeared — it has.Deferred
cmd/yolo.gorefactor (originally drafted in PR-B and reverted there for coverage) lands in PR-D, where the cmd-side test scaffolding is already in place.internal/serve/server.goandui/src/routes/SessionDetail.tsxcoverage are PR-D's primary scope.Verification
go test -tags sqlite_fts5 ./...→ 762 tests pass across 27 packages.pnpm -C ui test→ 110 vitest tests still green.Expected effect on next main scan
coverage: 65.5% → ~70%.duplicated_blocks13 → ~9 (jsonpatch/migrate/jsonstrict drop out).🤖 Generated with Claude Code