Files
magpie/internal/settings/lightweight_test.go
T
yetone ae23ad83f7 awake, gateway, gui: Settings › General › Keep awake while agents work keeps the computer from sleeping by itself while agents work through magpie (xiao_wang24004 on X) — the computer went to sleep in the middle of an agent's task. With the new setting on (off by default, this computer's own: KeepOwn), the magpie serving the gateway holds the system's idle sleep off while a request is in flight or a Claude Code turn waits on its tool results, and for ten minutes after the last request ended (an agent running a build or the tests between requests), looking every 5 s, and lets go once idle or turned off. On a Mac it runs caffeinate -i -w <magpie's pid> (PreventUserIdleSystemSleep, gone with magpie), on Windows SetThreadExecutionState(ES_CONTINUOUS|ES_SYSTEM_REQUIRED) from a thread of its own, on Linux systemd-inhibit --what=idle:sleep (Pdeathsig; said once in the log and nothing else where it is missing). The display may still turn off, and closing the lid still sleeps. en/zh/ja/de. Tested with a real DeepSeek account through magpie web --gateway in a sandbox HOME: a streamed request had caffeinate asserting on behalf of magpie's pid in pmset -g assertions, and turning the setting off through /api/settings released it within a tick. TestKeep (held once while busy and within the grace, let go past it, when off and when Keep ends; -race) and TestKeepAwakeKeptAndOwn are new; keep-awake.test.cjs (WebKit and Chromium, en and zh: off by default, On/Off post keepAwake, another setting's save keeps it, no scroll, no left border, shown on a browser's page) fails without the change; lightweight and click-scroll pass in WebKit. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
2026-10-05 19:46:02 +08:00

58 lines
1.3 KiB
Go

package settings
import "testing"
// Lightweight mode (#580) is saved and read back, off by default, and is
// this computer's own: a sync or a restored backup keeps it as it is here.
func TestLightweightKeptAndOwn(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().Lightweight {
t.Fatal("on by default")
}
s := Load()
s.Lightweight = true
if err := Save(s); err != nil {
t.Fatal(err)
}
if !Load().Lightweight {
t.Fatal("not kept")
}
from := Settings{Theme: "dark"}
from.KeepOwn(Load())
if !from.Lightweight || from.Theme != "dark" {
t.Fatalf("KeepOwn: %+v", from)
}
from = Settings{Lightweight: true}
from.KeepOwn(Settings{})
if from.Lightweight {
t.Fatal("another computer's turned on here")
}
}
// Keep awake (xiao_wang24004 on X) is off by default, saved, and this
// computer's own.
func TestKeepAwakeKeptAndOwn(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().KeepAwake {
t.Fatal("on by default")
}
s := Load()
s.KeepAwake = true
if err := Save(s); err != nil {
t.Fatal(err)
}
if !Load().KeepAwake {
t.Fatal("not kept")
}
from := Settings{}
from.KeepOwn(Load())
if !from.KeepAwake {
t.Fatal("KeepOwn dropped it")
}
from = Settings{KeepAwake: true}
from.KeepOwn(Settings{})
if from.KeepAwake {
t.Fatal("another computer's turned on here")
}
}