Anoninz on #2120: Settings said Open at login was On while System Settings › General › Login Items › Allow in the Background had magpie switched off, so magpie never opened at login. autostart.Enabled now returns a State: off, on, or needs allowing. - macOS 13+: with the plist present, Enabled asks Background Task Management through SMAppService statusForLegacyURL: (cgo, ServiceManagement weak-linked, minos stays 12.0). RequiresApproval reads as needs allowing. Any other answer, a failed ask (-1), macOS 12 or a build without cgo (the darwin CLI release) leaves the plist alone deciding, as before: a failed read is never "off". launchctl print-disabled did not follow the switch on macOS 26.2, so it isn't used. - BTM matches the item by the plist's Label, not its path: the tests ask about a label of their own, and TestMain stubs the ask so no test reads the user's real item. - GUI: Settings › General keeps On and adds one line, "Switched off in System Settings’ Login Items…", with an "Open Login Items" button that opens x-apple.systempreferences:com.apple.LoginItems-Settings.extension through /api/open (that one URL is allowed; other x-apple URLs aren't). The window's focus reload clears it once switched back on. The row is hidden in magpie web, as before. Strings in zh, zh-TW, ja, de. - CLI `magpie autostart` says where to switch it on. The daemon counts a held-back record as on (it is the user's choice, held by the system). Part B (SMAppService.mainApp) is not in this commit: it can't be verified here without registering in the user's real login items and logging out to see a login launch stay tray-only. Run: - go test ./internal/autostart (cgo and CGO_ENABLED=0), cli, daemon, gui after rebasing on origin/maine4ac5e871: ok except gui's TestSetAnswersWhileDevinAndProvidersHang, red the same alone on origin/maine4ac5e871at load ~400 (1 of 2), #1375. - set -o pipefail; go test -timeout 45m ./... (basedd70c5e6a): every package ok but internal/agent, past 45m at load ~300; alone: ok (1761s). - gofmt -l clean; go vet darwin; GOOS=linux -tags nogui and GOOS=windows go vet ./... clean. - Broken by hand, each red: the binding always -1 (TestLegacyStatusAsksTheSystem), heldBack always false and heldBack "!= Enabled" (TestEnabledFollowsTheSystemsSwitch); renderLoginAllow not called, the line not removed on focus, a wrong URL opened (login-allow.test.cjs). - Real use, macOS 26.2, a build with the label patched to com.yetone.magpie-autostart-probe and the user's own HOME: autostart on -> "opens at login"; its Allow in the Background switch turned off in System Settings -> the needs-allowing message; back on -> "opens at login"; autostart off -> plist gone. com.yetone.magpie.plist untouched. - GUI (playwright 1.62.0, chromium + webkit): login-allow.test.cjs new, 40 of 40 (5 languages, 1000/440px, app and web). The 106 GUI files that load Settings or open URLs, 6 wide: reds were codex-predictions (#2624), segs-glide (#2683), lightweight (#2638), usage-checkin (#2549) - each the same alone on origin/maine4ac5e871-, mobile-web (compares to origin/main, which had moved; 30 of 30 after the rebase), and account-alias and fonts under load only (#2984, pass alone). After the rebase: mobile-web, login-allow, settings-general, i18n-keys all green. The other ~700 GUI files were not run: at load 200-400 the whole suite was going at ~1000 tests an hour.
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package autostart
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
func TestBootScript(t *testing.T) {
|
|
home := t.TempDir()
|
|
testenv.SetHome(t, home)
|
|
// Spaces, quotes and shell expansions must stay part of the file name.
|
|
exe := filepath.Join(home, "magpie ' $not_a_variable")
|
|
out := filepath.Join(home, "args")
|
|
if err := os.WriteFile(exe, []byte("#!/system/bin/sh\nprintf '%s' \"$1\" > \"$HOME/args\"\n"), 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := enable(exe); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Chmod(record(), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if Enabled() != Off {
|
|
t.Fatal("non-executable script reported as enabled")
|
|
}
|
|
if err := enable(exe); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if Enabled() == Off {
|
|
t.Fatal("enable did not restore executable permission")
|
|
}
|
|
if err := exec.Command("/system/bin/sh", record()).Run(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
deadline := time.Now().Add(3 * time.Second)
|
|
for {
|
|
b, err := os.ReadFile(out)
|
|
if err == nil && string(b) == "serve" {
|
|
break
|
|
}
|
|
if time.Now().After(deadline) {
|
|
t.Fatalf("boot script did not launch the gateway: args=%q, error=%v", b, err)
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
if err := disable(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|