round9-client: log swallowed hook failures, doctor free-disk check, validate devbox ignore pattern 🩺⚠️🙈
Some checks are pending
CI / vet-build-test (push) Waiting to run

This commit is contained in:
shoemoney 2026-06-30 18:07:26 -05:00
parent e05f4da87d
commit 4727d3d7f3
8 changed files with 124 additions and 13 deletions

6
cmd/devbox/disk_other.go Normal file
View file

@ -0,0 +1,6 @@
//go:build !unix
package main
// freeBytes is not implemented on non-unix platforms; callers skip the check silently.
func freeBytes(_ string) (uint64, bool) { return 0, false }

15
cmd/devbox/disk_unix.go Normal file
View file

@ -0,0 +1,15 @@
//go:build unix
package main
import "syscall"
// freeBytes returns the number of bytes available to an unprivileged process
// on the filesystem containing path. Returns ok=false if the stat fails.
func freeBytes(path string) (uint64, bool) {
var s syscall.Statfs_t
if err := syscall.Statfs(path, &s); err != nil {
return 0, false
}
return s.Bavail * uint64(s.Bsize), true // ponytail: Bsize is int32 on macOS, int64 on Linux; always positive
}

View file

@ -0,0 +1,15 @@
//go:build unix
package main
import "testing"
func TestFreeBytesBasic(t *testing.T) {
free, ok := freeBytes(t.TempDir())
if !ok {
t.Fatal("freeBytes on TempDir must return ok=true on unix")
}
if free == 0 {
t.Fatal("freeBytes returned 0; expected > 0 for a real filesystem")
}
}

View file

@ -557,15 +557,19 @@ func ignoreCmd() *cobra.Command {
Short: "🙈 append a pattern to ./.devignore (run from inside a mount)", Short: "🙈 append a pattern to ./.devignore (run from inside a mount)",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
pat := args[0]
if _, err := ignore.Compile([]string{pat}); err != nil {
return fmt.Errorf("invalid ignore pattern %q: %w", pat, err)
}
f, err := os.OpenFile(".devignore", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644) f, err := os.OpenFile(".devignore", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil { if err != nil {
return err return err
} }
defer f.Close() defer f.Close()
if _, err := fmt.Fprintln(f, args[0]); err != nil { if _, err := fmt.Fprintln(f, pat); err != nil {
return err return err
} }
fmt.Fprintf(cmd.OutOrStdout(), "🙈 added %q to ./.devignore (applies on next sync)\n", args[0]) fmt.Fprintf(cmd.OutOrStdout(), "🙈 added %q to ./.devignore (applies on next sync)\n", pat)
return nil return nil
}, },
} }
@ -1101,6 +1105,23 @@ func doctorCmd() *cobra.Command {
} }
} }
// Disk space: warn (not fail) when a mount dir or the config dir has < 1 GiB free.
diskPaths := []string{dir}
for _, m := range d.Mounts {
diskPaths = append(diskPaths, m.Local)
}
for _, p := range diskPaths {
free, ok := freeBytes(p)
if !ok {
continue // unsupported platform or stat failed; skip silently
}
if free < 1<<30 {
check(false, true, "disk space", fmt.Sprintf("%s has only %d MiB free", p, free>>20))
} else {
check(true, false, "disk space", fmt.Sprintf("%s has %d MiB free", p, free>>20))
}
}
if failed { if failed {
if !asJSON { if !asJSON {
fmt.Fprintln(out) fmt.Fprintln(out)

View file

@ -176,6 +176,22 @@ func TestWritePidArbitration(t *testing.T) {
} }
} }
// TestIgnoreCmdValidatesPattern proves `ignore` accepts valid patterns and writes to .devignore.
func TestIgnoreCmdValidatesPattern(t *testing.T) {
t.Chdir(t.TempDir())
var buf bytes.Buffer
cmd := ignoreCmd()
cmd.SetOut(&buf)
cmd.SetArgs([]string{"*.go"})
if err := cmd.Execute(); err != nil {
t.Fatalf("valid pattern *.go rejected: %v", err)
}
b, _ := os.ReadFile(".devignore")
if !strings.Contains(string(b), "*.go") {
t.Fatalf(".devignore missing pattern, got: %q", string(b))
}
}
// TestStatusDaemonNotRunning proves that `status` (non-JSON) warns the user // TestStatusDaemonNotRunning proves that `status` (non-JSON) warns the user
// when the device is joined but the daemon is not running. // when the device is joined but the daemon is not running.
func TestStatusDaemonNotRunning(t *testing.T) { func TestStatusDaemonNotRunning(t *testing.T) {

View file

@ -385,9 +385,7 @@ func (d *Daemon) syncMount(c *transport.Client, m config.Mount) {
} }
func (d *Daemon) report(m config.Mount, pr syncer.PullResult) { func (d *Daemon) report(m config.Mount, pr syncer.PullResult) {
if len(pr.Written)+len(pr.Deleted)+len(pr.Conflicts)+len(pr.Skipped) == 0 { if len(pr.Written)+len(pr.Deleted)+len(pr.Conflicts)+len(pr.Skipped) > 0 {
return
}
d.logf("📥 %s: %d written, %d deleted, %d conflicts, %d skipped", d.logf("📥 %s: %d written, %d deleted, %d conflicts, %d skipped",
m.Share, len(pr.Written), len(pr.Deleted), len(pr.Conflicts), len(pr.Skipped)) m.Share, len(pr.Written), len(pr.Deleted), len(pr.Conflicts), len(pr.Skipped))
for _, cf := range pr.Conflicts { for _, cf := range pr.Conflicts {
@ -396,4 +394,8 @@ func (d *Daemon) report(m config.Mount, pr syncer.PullResult) {
for _, sk := range pr.Skipped { for _, sk := range pr.Skipped {
d.logf(" ⚠️ skipped (filesystem clash): %s", sk) d.logf(" ⚠️ skipped (filesystem clash): %s", sk)
} }
}
for _, w := range pr.Warnings {
d.logf("⚠️ %s: %s", m.Share, w)
}
} }

View file

@ -65,6 +65,37 @@ func TestPostPullHookFires(t *testing.T) {
} }
} }
// TestPostPullHookWarningOnFailure proves a failing post-pull hook surfaces in
// PullResult.Warnings without aborting the sync.
func TestPostPullHookWarningOnFailure(t *testing.T) {
db, _ := meta.Open(":memory:")
defer db.Close()
store, _ := blobstore.NewDisk(t.TempDir())
srv := httptest.NewServer(hub.NewServer(db, store).Handler())
defer srv.Close()
guard, _ := secret.New(nil)
ig, _ := LoadIgnore(t.TempDir())
A := joinDevice(t, db, srv.URL, "alice")
B := joinDevice(t, db, srv.URL, "bob")
_ = A.Publish("s")
rootA := t.TempDir()
writeFile(t, rootA, "app.txt", "v1\n")
if _, _, err := Sync(A, rootA, "s", "", "", "alice", 1, ig, guard, nil); err != nil {
t.Fatal(err)
}
rootB := t.TempDir()
writeExecHook(t, rootB, "post-pull", "#!/usr/bin/env bash\nexit 1\n")
_, pr, err := Sync(B, rootB, "s", "", "", "bob", 2, ig, guard, quietRunner(rootB, "s"))
if err != nil {
t.Fatalf("sync must not fail when post-pull exits non-zero: %v", err)
}
if len(pr.Warnings) == 0 {
t.Fatal("expected Warnings from the failing post-pull hook, got none")
}
}
func TestPrePushHookVetoes(t *testing.T) { func TestPrePushHookVetoes(t *testing.T) {
db, _ := meta.Open(":memory:") db, _ := meta.Open(":memory:")
defer db.Close() defer db.Close()

View file

@ -22,6 +22,7 @@ type PullResult struct {
Conflicts []string // conflict copies created (local edits preserved beside canonical) Conflicts []string // conflict copies created (local edits preserved beside canonical)
Skipped []string // paths a filesystem error skipped (e.g. file<->dir clash) Skipped []string // paths a filesystem error skipped (e.g. file<->dir clash)
Vetoed bool // a pre-pull hook aborted applying inbound changes Vetoed bool // a pre-pull hook aborted applying inbound changes
Warnings []string // non-fatal hook errors (e.g. post-pull timed out)
} }
// Pull fetches the hub head manifest for share, three-way merges it against the // Pull fetches the hub head manifest for share, three-way merges it against the
@ -152,9 +153,13 @@ func Pull(c *transport.Client, root, share, subpath, base, host string, now int6
} }
if len(res.Conflicts) > 0 { if len(res.Conflicts) > 0 {
_ = hk.Run(hooks.OnConflict, res.Conflicts, head) if err := hk.Run(hooks.OnConflict, res.Conflicts, head); err != nil {
res.Warnings = append(res.Warnings, err.Error())
}
}
if err := hk.Run(hooks.PostPull, append(append([]string{}, res.Written...), res.Deleted...), head); err != nil {
res.Warnings = append(res.Warnings, err.Error())
} }
_ = hk.Run(hooks.PostPull, append(append([]string{}, res.Written...), res.Deleted...), head)
res.Base = head res.Base = head
return res, nil return res, nil