From cec54c1d01f64cc0dd846d8561ab6dd92877b300 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 25 Oct 2026 23:15:45 +0800 Subject: [PATCH] proc: main's two reds, the TUI's serve start through proc.Command (#3567) and an RSS read before the loader ran Test (ubuntu, macos) on main has been red since 75e78a5a0 on two tests. TestNoCommandBypassesProc: internal/tui/keep.go's serveInBackground started `magpie serve` with os/exec. It is proc.Command now, the fix skygunner gave on #3567 (64bd29fa on their fork). Off Windows proc.Command is exec.Command, and this path runs on Linux only, so nothing else changes. TestTreeRSS (ubuntu only): the test read sleep's VmRSS right after StartTree and wanted at least 64 KiB. Just after its exec a command holds a few pages until its loader maps libc: CI read 16384 bytes. The test now reads again until it holds 64 KiB, for up to 10s. Tree.RSS itself is unchanged. Run at this head: - golang:1.26 docker (Linux, CI's Go): TestTreeRSS -count=50, old test red 13 of 50 ("a running sleep holds ..."), new 50 of 50 ok. - macOS: go test -count=3 ./internal/proc ./internal/tui ok (the old keep.go is the guard's red on CI's runs 40199986992 and earlier). - GOOS=linux and GOOS=windows go vet -tags nogui on both packages, gofmt clean. Not run: the full suite. Co-authored-by: skygunner --- internal/proc/rss_test.go | 7 +++++++ internal/tui/keep.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/proc/rss_test.go b/internal/proc/rss_test.go index 2d2198065..f6f197587 100644 --- a/internal/proc/rss_test.go +++ b/internal/proc/rss_test.go @@ -4,6 +4,7 @@ import ( "os/exec" "runtime" "testing" + "time" ) // A running tree's resident memory is read, and none once it was waited @@ -20,7 +21,13 @@ func TestTreeRSS(t *testing.T) { if err != nil { t.Fatal(err) } + // just after its exec a command holds a few pages, until its loader + // maps what it runs on (16KiB on ubuntu CI), so it is read until it does rss, ok := tree.RSS() + for end := time.Now().Add(10 * time.Second); ok && rss < 64<<10 && time.Now().Before(end); { + time.Sleep(20 * time.Millisecond) + rss, ok = tree.RSS() + } if !ok || rss < 64<<10 || rss > 1<<30 { t.Fatalf("a running %s holds %d bytes (%v)", name, rss, ok) } diff --git a/internal/tui/keep.go b/internal/tui/keep.go index ae35c97e2..079309d49 100644 --- a/internal/tui/keep.go +++ b/internal/tui/keep.go @@ -3,7 +3,6 @@ package tui import ( "fmt" "os" - "os/exec" "path/filepath" "runtime" "strings" @@ -12,6 +11,7 @@ import ( "github.com/yetone/magpie/internal/appdir" "github.com/yetone/magpie/internal/autostart" "github.com/yetone/magpie/internal/daemon" + "github.com/yetone/magpie/internal/proc" ) // On Linux with no desktop session (a WSL distro, a server over SSH) @@ -99,7 +99,7 @@ func serveInBackground() (int, string, error) { return 0, "", err } defer f.Close() - cmd := exec.Command(exe, "serve") + cmd := proc.Command(exe, "serve") cmd.Stdout, cmd.Stderr = f, f detach(cmd) if err := cmd.Start(); err != nil {