Skip to content

feat(doctor): real safe --fix remediations - #95

Merged
gustavobertoi merged 1 commit into
mainfrom
feat/doctor-fix
Jul 1, 2026
Merged

feat(doctor): real safe --fix remediations#95
gustavobertoi merged 1 commit into
mainfrom
feat/doctor-fix

Conversation

@gustavobertoi

Copy link
Copy Markdown
Contributor

What

Replaces the doctor --fix no-op stub (which only printed "applying safe remediations…") with real, safe, idempotent, per-probe-gated remediations, implementing the spec 13 safe subset.

Real remediations (each gated on its failing check, each reversible/non-destructive)

  • net.shared — create the missing tool-owned devstack_shared external bridge via docker.EnsureNetwork, under lock.WithLock (compose refuses to create external networks, so devstack owns it).
  • state.refs — prune stale ledger service_ref rows for projects with no live container via workspace.Reconcile (takes the flock internally; prunes derived rows only, never data).
  • fs.xdg — create missing / tighten group-or-world-writable private XDG dirs to 0700 (SQLite ledger + flock integrity). Filesystem-only, no lock needed.
  • dns.resolver / trust.host — diagnose-only: the sudo /etc/hosts write and the mkcert/NSS trust-store drive are out of --fix by construction; each keeps its exact manual remediation.

Mechanics

  • Each check is now a probe carrying Fixable + a fix + a recheck. applyFixes runs only fixable, non-OK probes, re-probes each, and reports fixed/still-failing — updating the report and exit code to the post-fix state.
  • A passing check's fix is never invoked. Nothing destructive (volume/container/network/db/CA removal) is ever run — those stay in the teardown verbs.
  • docker.Check gains additive id/category/fixable/fixed JSON fields; the existing {"checks":[...]} envelope is preserved and gains a "fixes" array under --fix. --quiet now prints only non-OK lines.

Why

doctor --fix is the "make it green where safe" verb in spec 13; it previously did nothing. This wires the three reconstructible repairs and keeps the safe/destroy boundary absolute.

How tested

  • CGO_ENABLED=0 go build ./..., CGO_ENABLED=1 go test ./internal/..., gofmt -l clean, go vet ./..., make determinism — all green.
  • Table-driven TestApplyFixes: failing-then-fixed, non-fixable-left-with-remediation, passing-fix-never-run, failing-fix-still-failing, mixed matrix.
  • Wiring tests exercising the real fixes: net.shared (EnsureNetwork via MockClient), state.refs (Reconcile prunes stale rows / keeps live refs against a real SQLite ledger), fs.xdg (creates dirs 0700 + re-probes green), plus dirSecure.
  • Manual smoke: doctor, doctor --json, doctor --fix, doctor --fix --json against a real daemon.

🤖 Generated with Claude Code

Replace the no-op `--fix` stub with real, safe, idempotent, reversible
remediations gated per failing probe (spec 13):

- net.shared: create the missing tool-owned external bridge network via
  docker.EnsureNetwork under the flock (compose refuses external nets).
- state.refs: prune stale ledger ref rows for projects with no live
  container via workspace.Reconcile (locks internally; derived rows only).
- fs.xdg: create missing / tighten group-or-world-writable XDG dirs to 0700.
- dns.resolver / trust.host: diagnose-only — the sudo /etc/hosts write and
  the mkcert/NSS trust-store drive are out of --fix by construction; each
  keeps its manual remediation.

Each probe now carries Fixable + a fix + recheck; applyFixes runs ONLY
fixable, non-OK probes, re-probes, and reports fixed/still-failing, updating
the report + exit code to the post-fix state. A passing check's fix is never
invoked; nothing destructive (volume/container/network/db/CA removal) is ever
run. docker.Check gains additive id/category/fixable/fixed JSON fields; the
existing {"checks":[...]} envelope is preserved and gains a "fixes" key under
--fix. --quiet now prints only non-OK lines.

Table-driven tests: failing-then-fixed, non-fixable-left-with-remediation,
passing-fix-never-run, failing-fix-still-failing, mixed matrix, plus wiring
tests for the real net.shared / state.refs / fs.xdg fixes and dirSecure.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gustavobertoi
gustavobertoi merged commit c7d6ed3 into main Jul 1, 2026
4 checks passed
@gustavobertoi
gustavobertoi deleted the feat/doctor-fix branch July 1, 2026 12:40
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