With #3372, Open at login on Linux reads a package's own autostart entry in $XDG_CONFIG_DIRS (nixpkgs ships one). JoeyWu-tech's #3756 asked what `magpie daemon install`'s guard and `magpie tui`'s hand-off as it quits should count on a box no desktop logs into (NixOS-WSL, a server over SSH), where nothing ever starts that entry. Decided: both keep counting what Open at login shows (autostart.Enabled). A session check can't tell (an SSH login into a desktop box has no DISPLAY either), and counting less than the switch shows would install the service beside an app the desktop does start. The install already refuses with "run `magpie autostart off` first", which is the way out. The terminal's quit only said "the gateway stopped", with nothing about why or what to do; it now says magpie opens at login and serves it then, and that `magpie autostart off` has magpie tui hand it on where no desktop logs in (atLoginNote). Off Linux and with nothing connected the note is as before. What was run (wsl-run, magpie-desktop Ubuntu 24.04, go1.26.8): go test -tags nogui -count=1 ./internal/autostart ./internal/daemon ./internal/testenv ./internal/tui: ok With keep.go as before (the test kept): TestKeepGatewayAsTheTerminalQuits red, "app at login: ... the gateway stopped with magpie tui; ..." gofmt -l: nothing Not tried: a real NixOS-WSL login; mtul0729 ran the #3372 patch on real NixOS + COSMIC, at the systemd generator's level. Batch run, at tree 104d75f0a (the twelve coffemon ports together, on origin/main7d022bdb6), mote, macOS, go1.26.8: - go test -tags nogui -count=1 -timeout 45m on the packages the batch changes (agent, autostart, daemon, gateway, library, proc, provider, sessions, testenv, tui, gui): ok each. - GUI, node --test with Playwright 1.62.0, Chromium and WebKit: library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass. - gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same batch on origin/main00098f12bone rebase before. - The whole go test ./... at cdd7c8e46: 86 packages ok, one red, internal/cli TestEveryRouteHasACommandOrIsNamed (GET /api/context/reply has no command), red on main too (#5026). - Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch onf4c664a09): proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp) pass. - Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv, tui ok; library and agent red in the same tests as on origin/mainf4c664a09(#4115, #1827, #4786; #5068, #5069, #5070 filed now). - Rebased onto origin/mainfb1f4856a(three commits, no file in common with the batch) and run again at the pushed tree: gofmt -l nothing, go build ./... and go vet ./... ok; go test -tags nogui sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and library-* 1044 of 1044 pass. - Not run before the push: the whole GUI suite (a run at cdd7c8e46 was cut off at 1170 of ~1174 tests when mote rebooted; it runs again after the tag and any red is filed).
74 lines
2.8 KiB
Go
74 lines
2.8 KiB
Go
package tui
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/daemon"
|
|
)
|
|
|
|
// zaidu259434 on X: magpie in WSL, its agents failed once magpie tui was
|
|
// closed, nothing serving the gateway. The terminal quitting with an agent
|
|
// connected hands the gateway to magpie's service, installing it where
|
|
// systemd runs it and the user never removed it, starting it where it is
|
|
// installed, else to a magpie serve in the background. Off Linux, with
|
|
// nothing connected, or where the app opens at login, it only says the
|
|
// gateway stopped.
|
|
func TestKeepGatewayAsTheTerminalQuits(t *testing.T) {
|
|
was := keep
|
|
t.Cleanup(func() { keep = was })
|
|
type did struct{ installed, started, bg bool }
|
|
setup := func(goos string, auto, installed, removed bool, installErr error) *did {
|
|
d := &did{}
|
|
keep = keeper{
|
|
goos: goos,
|
|
autostartOn: func() bool { return auto },
|
|
status: func() (daemon.Status, error) { return daemon.Status{Installed: installed}, nil },
|
|
removed: func() bool { return removed },
|
|
start: func() error { d.started = true; return nil },
|
|
install: func() error { d.installed = true; return installErr },
|
|
linger: func() string { return "" },
|
|
background: func() (int, string, error) { d.bg = true; return 42, "/x/serve.log", nil },
|
|
}
|
|
return d
|
|
}
|
|
gone := gatewayGoneNote()
|
|
|
|
d := setup("linux", false, false, false, nil)
|
|
if msg := keepGateway(true); !d.installed || d.bg || !strings.Contains(msg, "magpie daemon uninstall") {
|
|
t.Errorf("no service: %+v %q", *d, msg)
|
|
}
|
|
d = setup("linux", false, true, false, nil)
|
|
if msg := keepGateway(true); !d.started || d.installed || d.bg || msg == gone {
|
|
t.Errorf("installed: %+v %q", *d, msg)
|
|
}
|
|
d = setup("linux", false, false, true, nil)
|
|
if msg := keepGateway(true); d.installed || !d.bg || !strings.Contains(msg, "pid 42") {
|
|
t.Errorf("removed by the user: %+v %q", *d, msg)
|
|
}
|
|
d = setup("linux", false, false, false, errors.New("this system has no systemd"))
|
|
if msg := keepGateway(true); !d.bg || !strings.Contains(msg, "background") {
|
|
t.Errorf("no systemd: %+v %q", *d, msg)
|
|
}
|
|
for name, c := range map[string]struct {
|
|
goos string
|
|
auto, con bool
|
|
}{
|
|
"mac": {"darwin", false, true},
|
|
"nothing on": {"linux", false, false},
|
|
} {
|
|
d = setup(c.goos, c.auto, false, false, nil)
|
|
if msg := keepGateway(c.con); msg != gone || d.installed || d.bg || d.started {
|
|
t.Errorf("%s: %+v %q", name, *d, msg)
|
|
}
|
|
}
|
|
// magpie opens at login: the gateway is left to the app, and the
|
|
// note says how to have it handed on where no desktop logs in, as
|
|
// with a package's entry on NixOS-WSL (#3756)
|
|
d = setup("linux", true, false, false, nil)
|
|
if msg := keepGateway(true); d.installed || d.bg || d.started || !strings.HasPrefix(msg, gone) || !strings.Contains(msg, "magpie autostart off") {
|
|
t.Errorf("app at login: %+v %q", *d, msg)
|
|
}
|
|
}
|