Files
magpie/internal/shortcut/shortcut_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

51 lines
2.0 KiB
Go

package shortcut
import "testing"
func TestTarget(t *testing.T) {
for in, want := range map[string]string{
`C:\Tools\magpie-windows-amd64.exe`: `C:\Tools\magpie-windows-amd64.exe`,
`C:\Tools\magpie.exe.old`: `C:\Tools\magpie.exe`,
`C:\Tools\magpie.exe.old-3`: `C:\Tools\magpie.exe`,
`C:\Tools\magpie.exe.new`: `C:\Tools\magpie.exe`,
`C:\Tools\MAGPIE.EXE.OLD`: `C:\Tools\MAGPIE.EXE`,
`C:\old\magpie.exe`: `C:\old\magpie.exe`,
`C:\Tools\magpie.exe.older`: `C:\Tools\magpie.exe.older`,
`/usr/local/bin/magpie`: `/usr/local/bin/magpie`,
`C:\Users\me\Downloads\magpie (1).exe.old-2`: `C:\Users\me\Downloads\magpie (1).exe`,
} {
if got := Target(in); got != want {
t.Errorf("Target(%q) = %q, want %q", in, got, want)
}
}
}
func TestStale(t *testing.T) {
exe := "/tools/magpie.exe"
for _, c := range []struct {
target, dir string
stale bool
}{
{"", "", true}, // no shortcut yet
{"/tools/magpie.exe", "/tools", false}, // already this one
{"/TOOLS/Magpie.EXE", "/Tools/", false}, // the same, in another case
{"/downloads/magpie.exe", "/tools", true}, // the exe was moved
{"/tools/magpie.exe", "/downloads", true}, // starts in another folder
{"/tools/magpie.exe", "", true}, // in no folder
} {
if got := Stale(c.target, c.dir, exe); got != c.stale {
t.Errorf("Stale(%q, %q) = %v, want %v", c.target, c.dir, got, c.stale)
}
}
}
// Installed apps runs the exe it names, quoted, with the arguments the
// CLI opens the window on (the path has spaces under a user's name).
func TestUninstallCommand(t *testing.T) {
got := UninstallCommand(`C:\Users\Ann Lee\AppData\Local\Programs\magpie\magpie.exe`)
want := `"C:\Users\Ann Lee\AppData\Local\Programs\magpie\magpie.exe" uninstall --window`
if got != want {
t.Fatalf("UninstallCommand = %s, want %s", got, want)
}
}