Files
magpie/internal/cli/update_container_cli_test.go
yetone 598bc45346 update: a container's hint names the found version's own image, not :latest (fishmagic80 on X)
In Docker, Settings › About on the Daily channel said "0.1.4479 is out
… docker pull ghcr.io/yetone/magpie:latest". :latest is the newest
release (docker.yml), daily and stable the Daily and Stable channels'
(docker-daily.yml, docker-stable.yml), so :latest held 0.1.4504, not the
0.1.4479 announced; on Stable it is weeks apart. docker.yml writes every
release's own tag (ghcr.io/yetone/magpie:0.1.4479; checked on ghcr: 4479,
4395, latest, daily, stable, 0.1 all resolve, daily = 4479's digest).

update.Image(version) is that tag, and every place that printed the
command names it now, with "recreate the container from it" (a compose
file on :latest would otherwise run the old tag again):
- the GUI's Version row and Update pill (/api/update's new `image`,
  stuck "container"; app.js updateStuck);
- `magpie update` in a container (internal/cli);
- a Remote magpie row's tip for a container: UpdateRemotes now keeps the
  version it asked for on an "unsupported" answer too, so the tip names
  that version's image;
- i18n zh, zh-TW, ja, de for both strings;
- docs/docker (en, zh, ja): Updates says Settings › About names the
  version's own image and that latest may be ahead of the channel;
  llms-full and search indexes rebuilt (site/docs-index.mjs).

Run at this tree (mica, through mica-run):
- red on origin/main 14b6b9555 with the new tests copied in:
  TestUpdateInContainerSaysPullTheImage (cli: ":latest" in the error),
  TestRemoteMagpieAskedToFollow (gateway: Version v0.1.100, not the asked
  v0.1.200), update-stuck.test.cjs container cases and
  remote-update.test.cjs, both engines;
- green here: go test ./internal/update ./internal/cli, internal/gateway
  and internal/provider -run TestRemote*, internal/gui except
  TestGatewayModeListsNoOwnSessions, which fails the same on
  14b6b9555 alone (#7064);
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build, gofmt -l (nothing);
- node --test site/docker-tags.test.mjs; GUI files in chromium and
  webkit: update-stuck, remote-update, update-channel,
  update-stable-newest, update-release-page, update-check, lan-docker,
  i18n-keys, gui-de, gui-zh-tw, i18n-en-no-cjk (216 pass, 0 fail);
  gui-ja's "ja has every zh string" is red on main for another string
  (#7144).

Not run before the push: the full `go test -tags nogui ./...` (mote and
mica each had another session's full suite running); it runs after.
Not tried: a real container pulling the new tag. Not checked at runtime:
whether the version's image is already on ghcr; docker.yml pushes it in
~6 minutes, before the release is published, and a missing one makes
docker pull fail with "manifest unknown", not pull another version.
2026-11-19 10:26:23 +08:00

58 lines
2.1 KiB
Go

package cli
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/yetone/magpie/internal/update"
)
// `magpie update` in the Docker image (/magpie, run as nonroot) failed with
// the rename's "permission denied"; it now says to pull the new image:
// the found release's own tag, not :latest, which on the Daily or Stable
// channel holds another release (fishmagic80 on X). Outside a container
// it goes on to the download as before.
func TestUpdateInContainerSaysPullTheImage(t *testing.T) {
if runtime.GOOS == "windows" || os.Geteuid() == 0 {
t.Skip("needs a folder this user may not write to")
}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// no checksum: a download is refused before anything is fetched or written
json.NewEncoder(w).Encode(update.Release{Version: "0.1.11", URL: "https://github.com/yetone/magpie-releases/releases/tag/v0.1.11",
Assets: map[string]update.Asset{update.BinaryAsset(): {URL: "http://" + r.Host + "/asset"}}})
}))
defer srv.Close()
t.Setenv("MAGPIE_UPDATE_FEED", srv.URL)
dir := t.TempDir()
exe := filepath.Join(dir, "magpie")
if err := os.WriteFile(exe, []byte("magpie"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.Chmod(dir, 0o555); err != nil {
t.Fatal(err)
}
defer os.Chmod(dir, 0o755)
wasV, wasX, wasE, wasC := version, updateExecutable, updateCanElevate, updateInContainer
t.Cleanup(func() { version, updateExecutable, updateCanElevate, updateInContainer = wasV, wasX, wasE, wasC })
version = "0.1.10"
updateExecutable = func() (string, error) { return exe, nil }
updateCanElevate = func() bool { return false }
updateInContainer = func() bool { return true }
err := updateCmd([]string{"update"})
if err == nil || !strings.Contains(err.Error(), "the image of 0.1.11 (docker pull ghcr.io/yetone/magpie:0.1.11)") {
t.Fatalf("in a container: %v", err)
}
updateInContainer = func() bool { return false }
if err := updateCmd([]string{"update"}); err == nil || strings.Contains(err.Error(), "docker pull") {
t.Fatalf("outside one: %v", err)
}
}