round6-client: restore HTTP_PROXY support (transport regression) + status flags daemon-not-running

- internal/transport/client.go: replace bare &http.Transport{} with
  DefaultTransport.Clone() so HTTP_PROXY/HTTPS_PROXY/NO_PROXY, ForceAttemptHTTP2,
  IdleConnTimeout, and ExpectContinueTimeout are preserved; only intentionally-tuned
  fields (DialContext, TLSHandshakeTimeout, ResponseHeaderTimeout, DisableCompression,
  MaxIdleConnsPerHost) are overridden.
- cmd/devbox/main.go: statusCmd disk path now calls control.DialState once upfront;
  prints "⚠️  daemon not running — showing last-known disk state (run: devbox start)"
  when daemon is absent so users aren't silently misled.
- Tests: TestTransportHonorsProxyEnv asserts Proxy!=nil + ForceAttemptHTTP2=true;
  TestStatusDaemonNotRunning asserts warning appears on joined-but-no-daemon device.
This commit is contained in:
shoemoney 2026-06-30 16:24:23 -05:00
parent f8fb8564b2
commit 6cf8846544
4 changed files with 94 additions and 38 deletions

View file

@ -833,38 +833,42 @@ func statusCmd() *cobra.Command {
return writeJSON(out, s) return writeJSON(out, s)
} }
// Prefer the LIVE daemon when it's running AND stdout is a terminal: // Attempt live daemon state once; used for both TTY enrichment and the
// the socket can show paused state and the applied snapshot, which disk // disk-path "daemon not running" warning.
// can't. Piped/non-TTY output must stay byte-identical to v1 (scripts live, dialErr := control.DialState(dir)
// parse it), so the enrichment is gated behind isTTY — the disk path is
// the unchanged v1 output. // TTY + live: enriched output (paused state, applied snapshot, sync age).
if isTTY(cmd) { // Piped/non-TTY callers skip this block — enrichment gated behind isTTY
if live, err := control.DialState(dir); err == nil { // so script-parseable fields stay stable.
fmt.Fprintf(out, "device: %s\n", id.Fingerprint()) if isTTY(cmd) && dialErr == nil {
fmt.Fprintf(out, "hub: %s\n", orNone(d.Hub)) fmt.Fprintf(out, "device: %s\n", id.Fingerprint())
paused := "" fmt.Fprintf(out, "hub: %s\n", orNone(d.Hub))
if live.Paused { paused := ""
paused = " ⏸️ PAUSED" if live.Paused {
} paused = " ⏸️ PAUSED"
fmt.Fprintf(out, "mounts: %d (live)%s\n", len(live.Mounts), paused)
for _, m := range live.Mounts {
mode := "rw"
if m.ReadOnly {
mode = "ro"
}
if m.Pinned {
mode += ",pinned"
}
fmt.Fprintf(out, " - %s/%s -> %s [%s] @%s (%s)\n",
m.Share, m.Subpath, m.Local, mode, short(orNone(m.BaseSnapshot)), syncAge(m.LastSyncUnix))
if m.LastErr != "" {
fmt.Fprintf(out, " ⚠️ last sync failed: %s\n", m.LastErr)
}
}
return nil
} }
fmt.Fprintf(out, "mounts: %d (live)%s\n", len(live.Mounts), paused)
for _, m := range live.Mounts {
mode := "rw"
if m.ReadOnly {
mode = "ro"
}
if m.Pinned {
mode += ",pinned"
}
fmt.Fprintf(out, " - %s/%s -> %s [%s] @%s (%s)\n",
m.Share, m.Subpath, m.Local, mode, short(orNone(m.BaseSnapshot)), syncAge(m.LastSyncUnix))
if m.LastErr != "" {
fmt.Fprintf(out, " ⚠️ last sync failed: %s\n", m.LastErr)
}
}
return nil
} }
// Disk path (non-TTY or TTY with daemon not running).
if dialErr != nil {
fmt.Fprintln(out, "⚠️ daemon not running — showing last-known disk state (run: devbox start)")
}
fmt.Fprintf(out, "device: %s\n", id.Fingerprint()) fmt.Fprintf(out, "device: %s\n", id.Fingerprint())
fmt.Fprintf(out, "hub: %s\n", orNone(d.Hub)) fmt.Fprintf(out, "hub: %s\n", orNone(d.Hub))
fmt.Fprintf(out, "mounts: %d\n", len(d.Mounts)) fmt.Fprintf(out, "mounts: %d\n", len(d.Mounts))

View file

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/shoemoney/devbox/internal/config" "github.com/shoemoney/devbox/internal/config"
"github.com/shoemoney/devbox/internal/identity"
) )
// TestStatusJSON proves `status --json` emits valid JSON and reports not-joined // TestStatusJSON proves `status --json` emits valid JSON and reports not-joined
@ -174,3 +175,35 @@ func TestWritePidArbitration(t *testing.T) {
t.Fatal("pidfile still live after removePid") t.Fatal("pidfile still live after removePid")
} }
} }
// TestStatusDaemonNotRunning proves that `status` (non-JSON) warns the user
// when the device is joined but the daemon is not running.
func TestStatusDaemonNotRunning(t *testing.T) {
cfg := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", cfg)
dir := filepath.Join(cfg, "devbox")
// Create identity so identity.Load succeeds (device is "joined").
if _, err := identity.LoadOrCreate(dir); err != nil {
t.Fatalf("LoadOrCreate identity: %v", err)
}
// Write daemon config with a hub and one mount.
if err := config.SaveDaemon(dir, config.Daemon{
Hub: "http://hub.local:8080",
Bearer: "tok",
Mounts: []config.Mount{{Share: "proj", Local: t.TempDir(), Hub: "http://hub.local:8080"}},
}); err != nil {
t.Fatalf("SaveDaemon: %v", err)
}
// No socket in dir → DialState returns ErrNotRunning → disk path with warning.
var buf bytes.Buffer
cmd := statusCmd()
cmd.SetOut(&buf)
if err := cmd.Execute(); err != nil {
t.Fatalf("status: %v", err)
}
if !strings.Contains(buf.String(), "daemon not running") {
t.Fatalf("expected 'daemon not running' in output; got:\n%s", buf.String())
}
}

View file

@ -53,15 +53,18 @@ func New(base string) *Client {
// phases that SHOULD be fast instead (connect, TLS, time-to-first-byte) and let // phases that SHOULD be fast instead (connect, TLS, time-to-first-byte) and let
// TCP keepalive reap a dead peer. ponytail: a mid-body stall isn't bounded here; // TCP keepalive reap a dead peer. ponytail: a mid-body stall isn't bounded here;
// add a stall-timeout reader if a flaky link ever hangs transfers. // add a stall-timeout reader if a flaky link ever hangs transfers.
hc: &http.Client{ hc: func() *http.Client {
Transport: &http.Transport{ // Clone preserves Proxy (ProxyFromEnvironment), ForceAttemptHTTP2,
DialContext: (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext, // IdleConnTimeout and ExpectContinueTimeout from DefaultTransport, then
TLSHandshakeTimeout: 10 * time.Second, // we override only the fields we intentionally tune.
ResponseHeaderTimeout: 30 * time.Second, tr := http.DefaultTransport.(*http.Transport).Clone()
DisableCompression: true, // we negotiate gzip explicitly so the rate limiter sees wire bytes tr.DialContext = (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext
MaxIdleConnsPerHost: 16, // reuse connections for parallel blob transfers tr.TLSHandshakeTimeout = 10 * time.Second
}, tr.ResponseHeaderTimeout = 30 * time.Second
}, tr.DisableCompression = true // we negotiate gzip explicitly so the rate limiter sees wire bytes
tr.MaxIdleConnsPerHost = 16 // reuse connections for parallel blob transfers
return &http.Client{Transport: tr}
}(),
} }
} }

View file

@ -392,6 +392,22 @@ func TestHubDateMissingHeader(t *testing.T) {
} }
} }
// TestTransportHonorsProxyEnv asserts that Clone()-based transport preserves
// Proxy (ProxyFromEnvironment) and ForceAttemptHTTP2 from DefaultTransport.
func TestTransportHonorsProxyEnv(t *testing.T) {
c := New("http://x")
tr, ok := c.hc.Transport.(*http.Transport)
if !ok {
t.Fatal("transport must be *http.Transport")
}
if tr.Proxy == nil {
t.Fatal("transport must honor HTTP_PROXY env (Proxy was nil)")
}
if !tr.ForceAttemptHTTP2 {
t.Fatal("transport must have ForceAttemptHTTP2 (lost from DefaultTransport)")
}
}
func TestErrorSurfaced(t *testing.T) { func TestErrorSurfaced(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
writeJSON(t, w, http.StatusConflict, proto.Error{Error: "share exists"}) writeJSON(t, w, http.StatusConflict, proto.Error{Error: "share exists"})