Files
magpie/internal/cli/update_channel_cli_test.go
T
yetone b466aa2803 update: a Daily channel, one release a day that passed its tests, for the app and Docker (fishmagic80 on X)
fishmagic80 on X: Stable is too slow (community plugins need a newer
magpie than it has), every release is too fast, and Docker users have
nothing in between. Daily sits between them.

What it is:
- site/worker.js keepDaily: at the daily cut (20:00 UTC, the quarter-hour
  cron) the newest tag whose commit has a successful Test run and whose
  release has all 17 assets is picked and kept in LEDGER "daily". A day
  with none keeps the day before's; a failed GitHub read writes nothing.
  /api/latest?channel=daily (503 until a pick exists), /download/daily/<p>,
  and an urgent release overlays it as on Stable.
- .github/workflows/docker-daily.yml reads that feed and points
  ghcr.io/yetone/magpie:daily at the picked version's image.
- App: settings.UpdateDaily ("daily"); update.Channel()/Picked() (Stable()
  kept); the feed is asked channel=daily, never falls back to GitHub's
  latest, What's new lists every change since yours. Settings > About >
  Update channel has Every version / Daily / Stable; the version row says
  "Up to date on Daily (· {v} is out on Every version)". CLI: magpie
  update channel [stable|daily|every].
- Words in en, zh, zh-TW, ja, de, on top of 7f832b2f2's 尝鲜版/搶先版/先行版
  for Every version (kept as it landed).
- The channel row wraps its switch under its name when narrow (ja at
  420px was 18px past the window with three segments).
- app.js budget +338: the segment, its line and the two Up to date on
  Daily words, packed to one t() per choice; Settings and renderUpdate
  draw on every window, nothing lazy to move them to.
- Docs: docs/reference.md, site docs (docker, privacy in en/zh/ja),
  llms-full.txt, search indexes.

Red on the old code (a daily-old worktree, then only settings allowing
"daily"): the feed was not asked channel=daily, 40 notes instead of all,
Picked false, notesKey "zh" not "zh|daily", the Daily row showed
"available"; the GUI tests had no Daily segment.

Run on mote at this commit's tree (on origin/main ec1a1a7a5; the Daily pick itself is live on the deployed worker: /api/latest?channel=daily answers 0.1.4171, /download/daily 302s to its dmg):
- go test -count=1 ./internal/settings ./internal/settingsapi
  ./internal/update ./internal/cli ./internal/gui: all ok (TestCoreScriptBudget
  included).
- GUI, chromium and webkit, every language: update-*.test.cjs (22 files),
  i18n-*.test.cjs, settings-search.test.cjs: 554 of 554 pass.
- site: node --test site/*.test.mjs, 132 of 132 (130 before the rebuild).
- gofmt -l clean; go vet darwin, windows (gui/update/cli) and
  GOOS=linux -tags nogui.

Also: site/public/search/*.json and llms-full.txt rebuilt
(search-index.mjs, llms-full.mjs); they still listed Antigravity's old
sign-in after 9cd5f3652, so the two site freshness tests were red.

Filed: #6730, engines.magpie is never read, so a plugin needing a newer
magpie installs on Stable (0.1.3078) and fails without saying why
(page-amp-usage >=0.1.3681, middleware-company-guard >=0.1.3841,
page-day-card >=0.1.3427).

Not tried: a real self-update on Daily, a real docker-daily workflow run,
the whole GUI suite, the worker's unauthenticated GitHub reads under a
rate limit.
2026-11-15 13:10:18 +08:00

60 lines
1.9 KiB
Go

package cli
import (
"bytes"
"os"
"testing"
"github.com/yetone/magpie/internal/settings"
)
// magpie update channel stable|daily|every saves Settings' Update channel
// (ssharpcc on X); with nothing after it, it only says which; anything
// else is refused and nothing is saved.
func TestUpdateChannelCmd(t *testing.T) {
groupsHome(t)
for _, c := range []struct {
args []string
want string
bad bool
}{
{[]string{"update", "channel"}, "", false},
{[]string{"update", "channel", "stable"}, "stable", false},
{[]string{"update", "channel"}, "stable", false},
{[]string{"update", "channel", "beta"}, "stable", true},
{[]string{"update", "channel", "stable", "every"}, "stable", true},
{[]string{"update", "channel", "every"}, "", false},
{[]string{"update", "channel", "Stable"}, "stable", false},
{[]string{"update", "channel", "all"}, "", false},
{[]string{"update", "channel", "daily"}, "daily", false},
{[]string{"update", "channel", "Daily"}, "daily", false},
{[]string{"update", "channel", "weekly"}, "daily", true},
} {
err := updateCmd(c.args)
if (err != nil) != c.bad {
t.Fatalf("%v: %v", c.args, err)
}
if got := settings.Load().UpdateChannel; got != c.want {
t.Fatalf("%v: saved %q, want %q", c.args, got, c.want)
}
}
}
// A settings.json that can't be read is never written over by it.
func TestUpdateChannelKeepsCorruptSettings(t *testing.T) {
groupsHome(t)
if err := os.MkdirAll(settings.Dir(), 0o755); err != nil {
t.Fatal(err)
}
original := []byte(`{"theme":"dark","githubToken":"SYNTHETIC_PRIVATE_TOKEN"`)
if err := os.WriteFile(settings.Path(), original, 0o600); err != nil {
t.Fatal(err)
}
if err := updateCmd([]string{"update", "channel", "stable"}); err == nil {
t.Error("the command reported success with corrupt settings")
}
if after, err := os.ReadFile(settings.Path()); err != nil || !bytes.Equal(after, original) {
t.Errorf("the command overwrote the corrupt settings: %v", err)
}
}