Skip to content

test(go): coverage uplift cmd/logs + cmd/overlay + health; dedupe atomicWriteFile#10

Merged
aksOps merged 2 commits into
mainfrom
feat/coverage-cmd-and-health
May 1, 2026
Merged

test(go): coverage uplift cmd/logs + cmd/overlay + health; dedupe atomicWriteFile#10
aksOps merged 2 commits into
mainfrom
feat/coverage-cmd-and-health

Conversation

@aksOps

@aksOps aksOps commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Coverage push and one long-overdue dedupe.

Coverage uplift

File Before After
cmd/overlay.go 34% 91.5%
cmd/logs.go 38% ~92% per fn
internal/health/claude_check.go 0% 71% weighted
  • overlay.go — 16 new tests covering runOverlayStatus/Init/Edit (all 0% before), buildSampleOverlay path escaping, writeEnvFile idempotence.
  • logs.go — ~36 new tests covering compileFilters, toolInputSummary, dumpOne/dumpLog, listSessionLogs, runLogs, tailLog drain-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.goCheckWorkdir 100%, CheckClaudeSession 100%, CheckClaudeProcess 25% (only the no-pane branch is testable without a live tmux child tree).

Dedupe

  • New internal/fsutil package exporting AtomicWriteFile with its own test suite.
  • Replaces three near-identical 30-line atomicWriteFile copies in internal/claude/jsonpatch.go, internal/migrate/migrate.go, and internal/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.go refactor (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.go and ui/src/routes/SessionDetail.tsx coverage 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

  • Project-wide coverage: 65.5% → ~70%.
  • duplicated_blocks 13 → ~9 (jsonpatch/migrate/jsonstrict drop out).

🤖 Generated with Claude Code

aksOps and others added 2 commits May 1, 2026 08:56
… 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>
@sonarqubecloud

sonarqubecloud Bot commented May 1, 2026

Copy link
Copy Markdown

@aksOps aksOps merged commit 6ead98c into main May 1, 2026
11 checks passed
@aksOps aksOps deleted the feat/coverage-cmd-and-health branch May 1, 2026 09:03
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