feat(doctor): real safe --fix remediations - #95
Merged
Conversation
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>
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.
What
Replaces the
doctor --fixno-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-owneddevstack_sharedexternal bridge viadocker.EnsureNetwork, underlock.WithLock(compose refuses to create external networks, so devstack owns it).state.refs— prune stale ledgerservice_refrows for projects with no live container viaworkspace.Reconcile(takes the flock internally; prunes derived rows only, never data).fs.xdg— create missing / tighten group-or-world-writable private XDG dirs to0700(SQLite ledger + flock integrity). Filesystem-only, no lock needed.dns.resolver/trust.host— diagnose-only: the sudo/etc/hostswrite and the mkcert/NSS trust-store drive are out of--fixby construction; each keeps its exact manual remediation.Mechanics
probecarryingFixable+ afix+ arecheck.applyFixesruns only fixable, non-OK probes, re-probes each, and reportsfixed/still-failing — updating the report and exit code to the post-fix state.fixis never invoked. Nothing destructive (volume/container/network/db/CA removal) is ever run — those stay in the teardown verbs.docker.Checkgains additiveid/category/fixable/fixedJSON fields; the existing{"checks":[...]}envelope is preserved and gains a"fixes"array under--fix.--quietnow prints only non-OK lines.Why
doctor --fixis 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 -lclean,go vet ./...,make determinism— all green.TestApplyFixes: failing-then-fixed, non-fixable-left-with-remediation, passing-fix-never-run, failing-fix-still-failing, mixed matrix.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), plusdirSecure.doctor,doctor --json,doctor --fix,doctor --fix --jsonagainst a real daemon.🤖 Generated with Claude Code