Skip to content

refactor(cli): add IO-seam test overrides, raise coverage 58.3% → 72.9%#75

Merged
tzone85 merged 3 commits into
mainfrom
refactor/cli-io-seam
Jun 12, 2026
Merged

refactor(cli): add IO-seam test overrides, raise coverage 58.3% → 72.9%#75
tzone85 merged 3 commits into
mainfrom
refactor/cli-io-seam

Conversation

@tzone85

@tzone85 tzone85 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the cli IO-seam follow-up tracked in CLAUDE.md "Still open" since PR #72. Two new package-level test seams replace the chdir-based test setup; the production code path is unchanged. Existing tests continue to pass.

Coverage delta

Before After Delta
`internal/cli` 58.3% 72.9% +14.6

Falls short of the 80% target. The remaining gap is dominated by cobra `RunE` flows that require live docker / gh / claude CLI to reach their happy paths; closing the rest of the way needs fakes for those subsystems rather than more test code at this layer. CLAUDE.md records the remaining work as a separate follow-up.

IO-seam refactor

File Change
`internal/cli/improve.go` `auditDirOverride` package var; `auditDir()` checks it before falling through to `os.Getwd()`.
`internal/cli/autoresearch.go` `stateDirOverride` package var; `defaultStateDir()` checks it before `VXD_STATE_DIR` / `$HOME`.
`internal/cli/improve_commands_test.go` `withChdir` replaced by `withAuditDir` + simplified `seedAuditDir`.

New test files (8)

  • `autoresearch_io_test.go` — `loadConfigForAutoresearch` (missing, parse error, valid), `openEventStore` (success + unwritable parent), `countWinsLosses` (empty bank).
  • `backup_logs_test.go` — `runBackup` end-to-end against a seeded `vxd.yaml`; `runLogs` missing-file and stream-success.
  • `db_helpers_test.go` — `findDBByNameOrID` (by name, by ID, not found, empty slice), `isTerminal` (buffer + regular file rejected), `dbProviderFor`/`dockerProviderFor` failure paths.
  • `db_subcommands_test.go` — every `vxd db ` drives its early-error branch with devdb disabled (list / connect / sql / schema / delete with-and-without `--confirm` / gc no-op / ping / template list / template create).
  • `devdb_provider_test.go` — `newDevDBProvider` (null default + explicit, docker, ghost-no-key, unknown).
  • `extra_commands_test.go` — `Execute()` `--help`, autoresearch `stop`/`evolve`/`start` (dry-run)/`hypotheses`/`status` against an empty store.
  • `resume_helpers_test.go` — `pickRuntime` (prefers claude-code, falls back to any, empty map), `newDevDBLifecycle` (disabled / docker / bad ghost), `runDevDBOrphanRecovery` early-return, `runResume` no-active-requirements path.
  • `req_helpers_test.go` — `buildPlanningClient` (anthropic with API key, anthropic no creds, godmode propagation, openai/google no creds).

Test plan

  • `go build ./...` clean
  • `go vet ./...` clean
  • `go test ./... -count=1` — all 30 packages pass
  • `golangci-lint run --timeout=5m ./...` — 0 issues
  • CLAUDE.md items 55 → 56 added with the full breakdown
  • Obsidian launch playbook updated with the new cli figure

tzone85 added 3 commits June 12, 2026 18:36
Background

internal/cli stopped at 66.2% after PR #72 because cobra RunE functions
read CWD via auditDir() (improve.go) and HOME via defaultStateDir()
(autoresearch.go) directly. Tests had to chdir the whole process,
which broke parallel-test isolation and made driving multiple commands
in one test binary fragile.

IO-seam refactor

Two package-level test seams replace the chdir gymnastics:

- internal/cli/improve.go: auditDirOverride is a package var. The
  production auditDir() function checks it first; when empty falls
  through to the os.Getwd() path.

- internal/cli/autoresearch.go: stateDirOverride mirrors the same
  pattern for defaultStateDir(), still honouring VXD_STATE_DIR and
  $HOME when the override is empty.

improve_commands_test.go now uses withAuditDir() + the seedAuditDir()
helper instead of withChdir. Existing tests still pass, no production
behaviour changes.

New test coverage

autoresearch_io_test.go — loadConfigForAutoresearch (missing file,
  parse error, valid YAML), openEventStore (success + unwritable
  parent), countWinsLosses (empty bank).

backup_logs_test.go — runBackup end-to-end against a seeded vxd.yaml
  with state_dir in t.TempDir(); runLogs missing-file error path
  and successful-stream path.

db_helpers_test.go — findDBByNameOrID (by name, by ID, not found,
  empty slice), isTerminal (buffer + regular file both rejected),
  dbProviderFor / dockerProviderFor failure paths.

db_subcommands_test.go — every vxd db subcommand drives its early
  branch with devdb disabled (list, connect, sql, schema, delete
  with and without --confirm, gc no-op, ping, template list,
  template create).

devdb_provider_test.go — newDevDBProvider (null default + explicit,
  docker, ghost without API key, unknown provider).

extra_commands_test.go — Execute() --help path, autoresearch stop /
  evolve / start (dry-run) / hypotheses / status against empty store.

resume_helpers_test.go — pickRuntime (prefers claude-code, falls
  back to any, empty map), newDevDBLifecycle (disabled, docker,
  bad ghost), runDevDBOrphanRecovery early-return, runResume
  no-active-requirements path.

req_helpers_test.go — buildPlanningClient (anthropic with API key,
  anthropic no creds, godmode propagation, openai/google no creds).

Coverage delta

  internal/cli: 58.3% → 72.9% (+14.6 points)

Falls short of the 80% target. The remaining gap is dominated by
cobra RunE flows that need live docker / gh / claude CLI to reach
their happy paths; closing the rest of the way requires fakes for
those subsystems rather than more test code at this layer. CLAUDE.md
records the remaining work as a separate follow-up.

Verified

go build ./..., go vet ./..., go test ./... -count=1 — all 30
packages pass. golangci-lint run --timeout=5m ./... — 0 issues.
CI fails preflight earlier ("aborting: critical pre-flight issues")
than the local box does, and the previous test only allowed a fixed
list of substrings. The wired-up entry point either errors or succeeds
— that's the only invariant the test actually needs.
@tzone85 tzone85 merged commit c22264c into main Jun 12, 2026
5 checks passed
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