shuhai (Arch) installs magpie from the AUR's magpie-bin, which puts the desktop build at /usr/bin/magpie. magpie's own updater saw a folder it can't write and pkexec on the machine, so it downloaded the release and, on restart, replaced the package's file as root. pacman's database then no longer matched the file, and the next `yay` upgrade (magpie-bin lags the releases, 0.1.2342 against 0.1.2357 today) put an older magpie back. The two updaters fought each other. Now magpie asks first who owns the binary it runs from (update.PackagedBy): pacman's local database, dpkg's .list files, rpm (`rpm -qf`, only where /var/lib/rpm exists), a Homebrew Cellar path or /nix/store. Only a system path counts (/usr but not /usr/local, /bin, /sbin, /opt), with merged-/usr aliases, and packages named magpie* are looked at first. A packaged binary: - GUI: the update is shown as available with "pacman installed magpie (magpie-bin), so pacman updates it, not magpie: yay -S magpie-bin" (apt, dnf, brew likewise; Nix with no command). Nothing is downloaded, there is no Download or Install, the Update pill isn't lit, and /api/update/install does nothing (state available, stuck "package"). - `magpie update` says the same and exits 1 before downloading. This takes the place of the Homebrew-only check it had. An unpackaged magpie (~/.local/bin, /usr/local/bin, a file pacman doesn't list in /opt) updates itself as before. Run: - mote: go test -tags nogui -run 'Packaged|Homebrew|NotWritable|InContainer' ./internal/update ./internal/gui ./internal/cli ok; full go test -tags nogui -count=1 -timeout 45m ./... atb1a1b950f: 81 ok, 3 red. Two are on main and filed: TestNoCommandBypassesProc (claudetui, #4491) and TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll, #4514). The third, TestCoreScriptBudget, was this change: app.js is now 460 bytes more (its comments cut to one line, one helper call per path), and both budgets are raised by exactly that, with no room added. After the rebase onbb5e68cea: TestCoreScriptBudget and the Packaged, NotWritable, InContainer and Homebrew tests ok on mote. - mote: gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; go build for darwin, linux (nogui), windows. - WSL magpie-desktop (Ubuntu 24.04), real package: built a 0.1.2300 nogui magpie, packaged it as a .deb (magpie-aurpk-test) at /usr/bin/magpie, dpkg -i. `magpie update` as the user, through /bin/magpie, and as root each printed "magpie 0.1.2355 is out" and "this magpie was installed with apt (package magpie-aurpk-test), which updates it, not magpie: sudo apt install --only-upgrade magpie-aurpk-test", exit 1; the file's sha256 was unchanged and dpkg -V clean. Package removed after. An unpackaged copy in ~ still checked and offered the update. - WSL GUI, both engines: every update-* file, i18n-keys, gui-de/ja/zh-tw, whats-new*, about-*: 390 pass. Reds: i18n-keys "Unmarked" (#4524, on main) and update-check's WebKit ResizeObserver notice (the previous commit). Rerun of every update-* file after it: 294 pass, 4 red, all timing reds filed as #4554 and #4555, none in update-stuck. After app.js was cut down, after the rebase: update-stuck, update-auto, update-hide and i18n-keys, both engines: 93 pass, 1 red (#4524). Broken by hand: - placeExe's and the CLI's package check turned off: TestUpdatePackagedLeavesItToTheManager red ("a packaged binary is to be replaced"), TestUpdatePackagedSaysTheManager red (it went on to the download). - origin's app.js: the new update-stuck case times out (no text); only the pill condition reverted: red in WebKit. Not tried: - A real pacman/Arch install: the omarchy VM didn't answer ssh (banner exchange timed out twice), so pacman detection is from the database layout in tests only. - rpm and Nix on a real system; Homebrew only through the existing path test. - The whole GUI suite.
136 lines
5.1 KiB
Go
136 lines
5.1 KiB
Go
package update
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func writeFile(t *testing.T, path, body string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// pacman's local database as the AUR's magpie-bin 0.1.2342-1 leaves it
|
|
// (its PKGBUILD installs /usr/bin/magpie), beside a package that doesn't
|
|
// own magpie.
|
|
func pacmanRoot(t *testing.T) string {
|
|
root := t.TempDir()
|
|
local := filepath.Join(root, "var/lib/pacman/local")
|
|
writeFile(t, filepath.Join(local, "ALPM_DB_VERSION"), "9\n")
|
|
writeFile(t, filepath.Join(local, "bash-5.3.3-2/files"), "%FILES%\nusr/\nusr/bin/\nusr/bin/bash\nusr/bin/sh\n\n%BACKUP%\netc/bash.bashrc\t0b5ab6a3\n")
|
|
writeFile(t, filepath.Join(local, "bash-5.3.3-2/desc"), "%NAME%\nbash\n\n%VERSION%\n5.3.3-2\n")
|
|
writeFile(t, filepath.Join(local, "magpie-bin-0.1.2342-1/files"), "%FILES%\nusr/\nusr/bin/\nusr/bin/magpie\nusr/share/\nusr/share/applications/\nusr/share/applications/magpie.desktop\nusr/share/icons/hicolor/256x256/apps/magpie.png\nusr/share/licenses/magpie-bin/LICENSE\n\n")
|
|
writeFile(t, filepath.Join(local, "magpie-bin-0.1.2342-1/desc"), "%NAME%\nmagpie-bin\n\n%VERSION%\n0.1.2342-1\n\n%BASE%\nmagpie-bin\n")
|
|
return root
|
|
}
|
|
|
|
func TestPackagedByPacman(t *testing.T) {
|
|
root := pacmanRoot(t)
|
|
p := packagedIn(root, "linux", "/usr/bin/magpie")
|
|
if p == nil || p.Manager != "pacman" || p.Package != "magpie-bin" {
|
|
t.Fatalf("/usr/bin/magpie from magpie-bin: %+v", p)
|
|
}
|
|
if c := p.Command(); c != "yay -S magpie-bin" {
|
|
t.Fatalf("command %q", c)
|
|
}
|
|
if s := p.Say(); !strings.Contains(s, "pacman") || !strings.Contains(s, "yay -S magpie-bin") {
|
|
t.Fatalf("said %q", s)
|
|
}
|
|
// /bin is /usr/bin on Arch: the same file
|
|
if p := packagedIn(root, "linux", "/bin/magpie"); p == nil || p.Package != "magpie-bin" {
|
|
t.Fatalf("/bin/magpie: %+v", p)
|
|
}
|
|
// a copy in /usr/local, ~/.local/bin or /opt that no package lists is
|
|
// the user's own, and updates itself
|
|
for _, exe := range []string{"/usr/local/bin/magpie", "/home/u/.local/bin/magpie", "/opt/magpie/magpie", "/usr/lib/magpie/magpie"} {
|
|
if p := packagedIn(root, "linux", exe); p != nil {
|
|
t.Fatalf("%s: %+v", exe, p)
|
|
}
|
|
}
|
|
// not Linux: pacman's files aren't read
|
|
if p := packagedIn(root, "darwin", "/usr/bin/magpie"); p != nil {
|
|
t.Fatalf("darwin: %+v", p)
|
|
}
|
|
}
|
|
|
|
// A package named otherwise is found too, its name from the folder when
|
|
// its desc can't be read.
|
|
func TestPackagedByPacmanOtherName(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeFile(t, filepath.Join(root, "var/lib/pacman/local/ai-tools-2.0-3/files"), "%FILES%\nopt/ai/bin/magpie\n")
|
|
p := packagedIn(root, "linux", "/opt/ai/bin/magpie")
|
|
if p == nil || p.Package != "ai-tools" {
|
|
t.Fatalf("%+v", p)
|
|
}
|
|
}
|
|
|
|
// dpkg lists absolute paths, and on a merged /usr may list /bin for the
|
|
// /usr/bin the binary resolves to.
|
|
func TestPackagedByDpkg(t *testing.T) {
|
|
root := t.TempDir()
|
|
info := filepath.Join(root, "var/lib/dpkg/info")
|
|
writeFile(t, filepath.Join(info, "coreutils.list"), "/.\n/bin\n/bin/ls\n")
|
|
writeFile(t, filepath.Join(info, "magpie:amd64.list"), "/.\n/usr\n/usr/bin\n/usr/bin/magpie\n")
|
|
p := packagedIn(root, "linux", "/usr/bin/magpie")
|
|
if p == nil || p.Manager != "dpkg" || p.Package != "magpie" || p.Name() != "apt" || p.Command() != "sudo apt install --only-upgrade magpie" {
|
|
t.Fatalf("%+v", p)
|
|
}
|
|
if p := packagedIn(root, "linux", "/usr/bin/ls"); p == nil || p.Package != "coreutils" {
|
|
t.Fatalf("merged /usr: %+v", p)
|
|
}
|
|
if p := packagedIn(root, "linux", "/usr/sbin/magpie"); p != nil {
|
|
t.Fatalf("not listed: %+v", p)
|
|
}
|
|
}
|
|
|
|
func TestPackagedByRpm(t *testing.T) {
|
|
root := t.TempDir()
|
|
was := rpmOwner
|
|
t.Cleanup(func() { rpmOwner = was })
|
|
asked := ""
|
|
rpmOwner = func(path string) string { asked = path; return "magpie" }
|
|
// no rpm database: rpm isn't asked
|
|
if p := packagedIn(root, "linux", "/usr/bin/magpie"); p != nil || asked != "" {
|
|
t.Fatalf("no rpm here: %+v, asked %q", p, asked)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(root, "var/lib/rpm"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := packagedIn(root, "linux", "/usr/bin/magpie")
|
|
if p == nil || p.Manager != "rpm" || asked != "/usr/bin/magpie" || p.Command() != "sudo dnf upgrade magpie" {
|
|
t.Fatalf("%+v, asked %q", p, asked)
|
|
}
|
|
rpmOwner = func(string) string { return "" }
|
|
if p := packagedIn(root, "linux", "/usr/bin/magpie"); p != nil {
|
|
t.Fatalf("not owned: %+v", p)
|
|
}
|
|
}
|
|
|
|
func TestPackagedByHomebrewAndNix(t *testing.T) {
|
|
root := t.TempDir()
|
|
for exe, want := range map[string]string{
|
|
"/opt/homebrew/Cellar/magpie/0.1.126/bin/magpie": "homebrew magpie brew upgrade magpie",
|
|
"/home/linuxbrew/.linuxbrew/Cellar/magpie/0.1.126/bin/magpie": "homebrew magpie brew upgrade magpie",
|
|
"/nix/store/abc123-magpie-0.1.2342/bin/magpie": "nix ",
|
|
} {
|
|
goos := "linux"
|
|
if strings.HasPrefix(exe, "/opt/homebrew") {
|
|
goos = "darwin"
|
|
}
|
|
p := packagedIn(root, goos, exe)
|
|
if p == nil || p.Manager+" "+p.Package+" "+p.Command() != want {
|
|
t.Fatalf("%s: %+v", exe, p)
|
|
}
|
|
}
|
|
if p := packagedIn(root, "darwin", "/Applications/magpie.app/Contents/MacOS/magpie"); p != nil {
|
|
t.Fatalf("the app: %+v", p)
|
|
}
|
|
}
|