Files
magpie/internal/shortcut/shortcut_windows_test.go
T
yetone 92e8edd7fc windows: magpie is listed in Installed apps, and its Uninstall puts every agent back
Jevik_AI on X uninstalled magpie and rebooted, and Codex's config.toml
still had openai_base_url = "http://127.0.0.1:3425/backend-api/codex";
Rk1ngggg asked whether an update cleans it. magpie's own uninstall
(Settings › About › Uninstall magpie, `magpie uninstall`) already
disconnects every agent and takes Codex's leftovers (#3866), but on
Windows magpie wasn't in Settings › Apps › Installed apps, so it was
removed the way Windows offers for a program it doesn't list: by
deleting the exe and folders, which runs no code.

shortcut.Ensure now writes
HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\magpie
(DisplayName, DisplayIcon, Publisher, InstallLocation, UninstallString,
URLInfoAbout, NoModify, NoRepair) at every installed start, beside App
Paths, and Remove (uninstall's System step) takes it out the same way:
only while it names this exe, or an exe that is gone. Its Uninstall
runs `magpie.exe uninstall --window` (shortcut.UninstallArgs). magpie.exe
has no console, where the terminal's `magpie uninstall` would refuse
for want of one to ask on, so those exact args open the app's window
(or forward to the running app, OnSecondInstanceLaunch) on Settings ›
About with Uninstall magpie's question asked (uninstallView,
?uninstall=1). It asks once: a redraw of Settings doesn't ask again,
and Cancel removes nothing. magpie web opened at that link asks
nothing. Deleting the app by hand still runs no code (macOS
drag-to-Trash included); agent-wiring.md says so.

Run on mote at the pushed head (rebased onto be9dbce02):
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. go build, GOOS=linux go build -tags
  nogui, GOOS=windows go build: ok.
- go test -tags nogui ./internal/gui ./internal/cli ./internal/shortcut
  ./internal/uninstall: ok (TestCoreScriptBudget included).
- uninstall-settings.test.cjs and i18n-keys.test.cjs: 40 of 40
  (chromium and webkit; the new Installed-apps cases in en and zh at
  1100 and 420).
At d3f40bedd, the same change on c7ebb6f8d, under suite.lock:
- go test -tags nogui -timeout 45m ./...: ok, every package.
- The whole GUI suite (--test-concurrency=4): 22518 of 22800; the 282
  reds are in 53 files the change doesn't reach (model-chip-steady 40,
  usage-agents-hide 22, zero-priced-free 20, provider-fetch-again 14,
  ...), the full-suite reds of #5475; the numbers are on that issue.
  Their run at c7ebb6f8d alone is queued behind other sessions' suites.
- The first full run found the core scripts 147 bytes over
  TestCoreScriptBudget; the page's part was cut to one line (the
  budget is not raised).
On xiaomi-gpu (win-run): go test ./internal/shortcut, incl.
TestInstalledAppsEntry on the real HKCU registry under a test key: ok.

Broken by hand, each red:
- registerAppPath not calling registerUninstall: TestInstalledAppsEntry
  (UninstallString = "") on Windows.
- main.go not taking UninstallArgs to the window:
  TestInstalledAppsUninstallOpensTheWindow (unknown "--window").
- app.js not asking on ?uninstall=1: 4 of 4 Installed-apps GUI cases.
- app.js asking without its once guard (params.delete): the same 4
  ("asked again").

Not tried: a real Settings › Apps › Uninstall click on Windows with an
installed magpie (the test box's install belongs to other sessions); the
second-instance forward (OnSecondInstanceLaunch) has no test of its own.
2026-11-09 22:33:31 +08:00

102 lines
3.2 KiB
Go

package shortcut
import (
"os"
"path/filepath"
"testing"
"golang.org/x/sys/windows/registry"
)
// A shortcut is made, left be while it opens this exe, and pointed at the
// exe again once that was moved.
func TestWrite(t *testing.T) {
dir := t.TempDir()
lnk := filepath.Join(dir, Name+".lnk")
exe := filepath.Join(dir, "a", "magpie.exe")
moved := filepath.Join(dir, "b", "magpie.exe")
for _, f := range []string{exe, moved} {
os.MkdirAll(filepath.Dir(f), 0o755)
os.WriteFile(f, []byte("MZ"), 0o755)
}
for i, c := range []struct {
exe string
written bool
}{{exe, true}, {exe, false}, {moved, true}, {moved, false}} {
written, err := write(lnk, c.exe)
if err != nil {
t.Fatal(i, err)
}
if written != c.written {
t.Fatalf("%d: written = %v, want %v", i, written, c.written)
}
}
if _, err := os.Stat(lnk); err != nil {
t.Fatal("no shortcut:", err)
}
}
// magpie is in Installed apps (Jevik_AI on X deleted it by hand, which
// runs no code, and Codex kept pointing at a gateway that was gone): the
// entry opens this exe's Uninstall, follows an exe that moved, goes with
// Remove, and one another magpie's exe still holds stays.
func TestInstalledAppsEntry(t *testing.T) {
was, wasApp := uninstallKey, appPath
uninstallKey = `Software\magpie-test\` + t.Name() + `\Uninstall\magpie`
appPath = `Software\magpie-test\` + t.Name() + `\App Paths\magpie.exe`
t.Cleanup(func() {
registry.DeleteKey(registry.CURRENT_USER, uninstallKey)
registry.DeleteKey(registry.CURRENT_USER, appPath)
registry.DeleteKey(registry.CURRENT_USER, `Software\magpie-test\`+t.Name()+`\Uninstall`)
registry.DeleteKey(registry.CURRENT_USER, `Software\magpie-test\`+t.Name()+`\App Paths`)
registry.DeleteKey(registry.CURRENT_USER, `Software\magpie-test\`+t.Name())
uninstallKey, appPath = was, wasApp
})
read := func(name string) string {
k, err := registry.OpenKey(registry.CURRENT_USER, uninstallKey, registry.QUERY_VALUE)
if err != nil {
return ""
}
defer k.Close()
v, _, _ := k.GetStringValue(name)
return v
}
dir := t.TempDir()
exe := filepath.Join(dir, "a", "magpie.exe")
other := filepath.Join(dir, "b", "magpie.exe")
for _, f := range []string{exe, other} {
os.MkdirAll(filepath.Dir(f), 0o755)
os.WriteFile(f, []byte("MZ"), 0o755)
}
// written where every installed start writes App Paths
registerAppPath(exe)
if got := read("UninstallString"); got != UninstallCommand(exe) {
t.Fatalf("UninstallString = %q", got)
}
if read("DisplayName") != Name || read("InstallLocation") != filepath.Dir(exe) || read("DisplayIcon") != exe+",0" {
t.Fatalf("entry: %q %q %q", read("DisplayName"), read("InstallLocation"), read("DisplayIcon"))
}
// another magpie, still there, keeps its entry
if err := unregisterAppPath(other); err != nil {
t.Fatal(err)
}
if read("UninstallString") == "" {
t.Fatal("removed another magpie's entry")
}
if err := unregisterAppPath(exe); err != nil {
t.Fatal(err)
}
if read("UninstallString") != "" {
t.Fatal("the entry stayed after Remove")
}
// one whose exe is gone goes with any magpie's uninstall
registerUninstall(other)
os.Remove(other)
if err := unregisterUninstall(exe); err != nil {
t.Fatal(err)
}
if read("UninstallString") != "" {
t.Fatal("an entry for an exe that is gone stayed")
}
}