From 36eebea13675cfafbb79de573f533ed0e7b8f4af Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 12 Nov 2026 17:53:38 +0800 Subject: [PATCH] update: the header's Update pill waits until it is news (certhon520, jkd6688, Yuyuaneth, milianxinqi on X) A release comes every few minutes, so a downloaded update was always waiting and the pill (window and tray panel) never went out. /api/update now says "quiet" while this version has been behind for less than 3 days (update.Quiet, the Stable channel's soak; counted from the first newer version seen, kept in update-behind.json for the version running), and the pill stays away. An urgent release ("**Urgent release:**" in the latest's notes or any release between, fetched once per check) lights it at once and a dismissal does not hide it. The x dismissal now also starts the quiet over, so the pill is not back with the next release. Settings > Version, the tray's Restart to update, quit and Restart automatically are unchanged. Plugins' dot is for plugins that do not update by themselves; left alone. Run (mote): go test ./internal/update (ok), go test -run Update|Asset|Budget|Script ./internal/gui (ok), gofmt, go vet darwin / linux nogui / windows clean, update-quiet.test.cjs 21/21 in chromium and webkit across en, zh, zh-TW, ja, de, panel and window. Broken by hand: dropping !u.quiet in app.js (11 red), forcing Quiet=false in jsonIn (TestUpdateQuietUntilBehindAWhile red). Not tried: a real 3-day wait, and the urgent range lookup against the live site. --- docs/subsystems/gui-shell.md | 21 ++++ internal/gui/api.go | 3 + internal/gui/assets/app.js | 6 +- internal/gui/fx_main_test.go | 1 + internal/gui/tests/update-quiet.test.cjs | 76 ++++++++++++++ internal/gui/update.go | 51 ++++++++- internal/gui/update_quiet_test.go | 42 ++++++++ internal/update/behind.go | 126 +++++++++++++++++++++++ internal/update/behind_test.go | 118 +++++++++++++++++++++ 9 files changed, 441 insertions(+), 3 deletions(-) create mode 100644 internal/gui/tests/update-quiet.test.cjs create mode 100644 internal/gui/update_quiet_test.go create mode 100644 internal/update/behind.go create mode 100644 internal/update/behind_test.go diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 3cc8ab747..13cb7f612 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -891,6 +891,27 @@ See `TestGatewayPauseAndResume`, `TestGatewayPauseRollsBack`, `TestGatewayResumesOnWire`, `TestGatewayPauseFileUnreadable`, `TestTrayMenuLabels` and `gateway-pause.test.cjs`. +### The Update pill waits until it is news + +A release comes every few minutes, so a newer one is nearly always out and +downloaded, and a pill lit for each was never out (certhon520, jkd6688, +Yuyuaneth and milianxinqi on X, 11-12). The header's Update pill (window and +tray panel alike) lights only when `/api/update` has no `quiet`: +this version has been behind for `update.Quiet` (3 days, the Stable +channel's soak), counted from the first newer version seen and kept across +restarts in `update-behind.json` (`update.Behind`, for the version running, +so an update starts it over), or an urgent release is out (a line starting +"**Urgent release:**" in the latest's notes, or in any release between this +one and it, `urgentBetween`). An urgent release lights the pill at once and +a dismissal does not hide it. Dismissing with the × hides that version and +starts the quiet over (`quietAgain`), so the pill is not back with the next +release. The pill waiting changes nothing else: Settings › Version, the +tray's Restart to update, quitting and Restart automatically work at any +time. Plugin updates have their own dot on Plugins, which lights only for +a plugin that does not update by itself. See `TestPillWaitsForTheQuiet`, +`TestUrgentLightsThePillAtOnce`, `TestDismissalStartsTheQuietOver`, +`TestUpdateQuietUntilBehindAWhile` and `update-quiet.test.cjs`. + ### A restart to update hands the gateway over On a Mac and on Linux, a restart into a downloaded update (the Update pill, diff --git a/internal/gui/api.go b/internal/gui/api.go index cc1d81db8..ffdb6ae85 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -1779,6 +1779,9 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { } s := settings.Load() s.UpdateSkip = strings.TrimSpace(in.Version) + if s.UpdateSkip != "" { + updates.quietAgain() // a dismissal holds for the quiet, not only the next release + } if err := settings.Save(s); err != nil { fail(rw, err) return diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index ce89cbcb3..c232b0506 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -4350,7 +4350,9 @@ for (const k of "pointerdown keydown input wheel".split(" ")) addEventListener(k }, true); // renderUpdateBadge shows the header's Update pill once a newer magpie is -// downloaded or out; Settings or its × keeps it away. +// downloaded or out and has been for a while (u.quiet: releases come every +// few minutes, so a pill lit for each is never out; an urgent one lights it +// at once); Settings or its × keeps it away. async function renderUpdateBadge() { const b = $("#update"), label = b.querySelector("span"); @@ -4364,7 +4366,7 @@ async function renderUpdateBadge() { b.classList.remove("busy"); } // a package manager's magpie: Settings names its command, no pill - const on = pulling || (!!u && !updatePillOff(u.latest) && (u.state === "ready" || (u.state === "available" && !u.packaged) || u.state === "found" || (u.state === "error" && u.retry))); + const on = pulling || (!!u && !u.quiet && !updatePillOff(u.latest) && (u.state === "ready" || (u.state === "available" && !u.packaged) || u.state === "found" || (u.state === "error" && u.retry))); if (b.hidden !== !on) b.hidden = !on; if (!on) return; const hide = $("#updateHide"); diff --git a/internal/gui/fx_main_test.go b/internal/gui/fx_main_test.go index 0de61ca4b..239207894 100644 --- a/internal/gui/fx_main_test.go +++ b/internal/gui/fx_main_test.go @@ -24,6 +24,7 @@ func TestMain(m *testing.M) { addr := l.Addr().String() l.Close() // refused at once from here on fx.SetRateURL("http://" + addr + "/") + os.Setenv("MAGPIE_NOTES_FEED", "http://"+addr+"/") // no test asks the site for notes } os.Exit(testenv.Run(m)) } diff --git a/internal/gui/tests/update-quiet.test.cjs b/internal/gui/tests/update-quiet.test.cjs new file mode 100644 index 000000000..eff36d644 --- /dev/null +++ b/internal/gui/tests/update-quiet.test.cjs @@ -0,0 +1,76 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// "红点都快焊死了" (certhon520, jkd6688, Yuyuaneth, milianxinqi on X): a release +// comes every few minutes, so a downloaded update was always waiting and the +// header's Update pill was always lit. /api/update says quiet for a version +// not behind for long and with no urgent release out: the pill stays away, +// while Settings' version row still offers the restart. Not quiet (behind +// for days, or urgent), it shows. Every language, tray panel and +// window; no backend, the API is faked. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); + +function server(lang, ctl) { + return async (route) => { + const url = new URL(route.request().url()); + const json = (data) => route.fulfill({ json: data }); + const settings = { + theme: "light", lang, tray: "panel", currency: "usd", redactWords: [], trayUsageEvery: 3, + version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", + proxyNow: "none", proxySource: "none", visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], + fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, + }; + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings, fx: settings.fx }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/update") return json({ state: "ready", current: "0.1.400", latest: "0.1.401", ...ctl }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": the Update pill waits until the update has been out a while", async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const open = async (lang, ctl, query) => { + const errors = []; + const page = await (await browser.newContext({ viewport: { width: query.includes("panel") ? 420 : 900, height: 560 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.on("pageerror", (e) => { if (!/^ResizeObserver loop completed with undelivered notifications/.test(e.message)) errors.push(e.message); }); + await page.route("**/*", server(lang, ctl)); + await page.goto("http://magpie.test/" + query); + return { page, errors }; + }; + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const mode of ["?mode=panel", ""]) { + await t.test(lang + (mode ? " panel" : " window") + ": quiet keeps the pill away, and its version row still restarts", async () => { + const { page, errors } = await open(lang, { quiet: true }, mode); + await page.locator("#sync").waitFor(); + await page.waitForTimeout(500); + assert.equal(await page.locator("#update").isHidden(), true, "a fresh update lit the pill"); + const v = await open(lang, { quiet: true }, "?view=settings&tab=about"); + await v.page.locator("#about .row.pref .val button.text").first().waitFor(); // the version row's restart + assert.equal(await v.page.locator("#update").isHidden(), true); + assert.deepEqual([...errors, ...v.errors], []); + }); + await t.test(lang + (mode ? " panel" : " window") + ": not quiet (days behind, or urgent) shows the pill", async () => { + const { page, errors } = await open(lang, {}, mode); + await page.locator("#update").waitFor({ state: "visible" }); + assert.deepEqual(errors, []); + }); + } + } + }); +} diff --git a/internal/gui/update.go b/internal/gui/update.go index 74d05bee8..c6f2ae1b2 100644 --- a/internal/gui/update.go +++ b/internal/gui/update.go @@ -33,6 +33,9 @@ type updater struct { mu sync.Mutex state string // checking | latest | found | downloading | ready | available | source | error | blocked latest *update.Release + // behind: since when a newer version has been out for this one, and + // whether it is urgent; the pill waits for it (update.Behind) + behind update.Behind err string bundle string // the .app to replace, "" when not in one or stuck stuck string // why the .app or binary can't be replaced where it is (update.Stuck, exeStuck) @@ -138,7 +141,12 @@ type updateJSON struct { Speed int64 `json:"speed,omitempty"` // blocked: the version this computer wouldn't start, and why (#894) Blocked *update.Blocked `json:"blocked,omitempty"` - Total int64 `json:"total,omitempty"` + + // Quiet: a newer version is out but this one has not been behind long + // enough, and none is urgent, so the header's pill stays out (the + // Version row and Restart to update still offer it) + Quiet bool `json:"quiet,omitempty"` + Total int64 `json:"total,omitempty"` // found: the size of the file Download update would fetch, in bytes // (0 when the feed doesn't say) Size int64 `json:"size,omitempty"` @@ -168,6 +176,7 @@ func updateDue(s settings.Settings, last, now time.Time) bool { } func (u *updater) start() { + u.behind = update.ReadBehind(Version) u.place(runtime.GOOS, update.GUI) gateway.SetRestarter(u.restartBesideAsked) // magpie update in a terminal gateway.SetForceRestarter(u.restartBesideNow) @@ -493,6 +502,14 @@ func (u *updater) run() { return } u.latest, u.notesIn, u.stable = rel, lang, stable + if update.Released(Version) && update.Newer(rel.Version, Version) { + u.behind = update.NoteBehind(Version, rel.Version, update.UrgentIn(rel.Notes), time.Now()) + if u.behind.Urgent == "" { + // an urgent release between this one and the latest: its + // notes aren't the latest's + go u.urgentBetween(rel.Version, lang) + } + } switch { case !update.Released(Version): u.state = "source" @@ -687,6 +704,10 @@ func (u *updater) jsonIn(lang string) updateJSON { if u.state == "blocked" { j.Blocked = u.blocked } + switch j.State { + case "ready", "found", "available": + j.Quiet = !u.behind.Lit(Version, time.Now()) + } if u.state == "found" && u.latest != nil { j.Size = u.assetSize(u.latest) } @@ -705,6 +726,34 @@ func (u *updater) jsonIn(lang string) updateJSON { return j } +// urgentBetween notes it when a release after this one up to latest is +// urgent: a security fix a few releases back isn't in the latest's notes. +func (u *updater) urgentBetween(latest, lang string) { + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + notes, err := update.NotesBetween(ctx, Version, latest, lang) + if err != nil { + return + } + for _, n := range notes { + if update.UrgentIn(n.Notes) { + b := update.NoteUrgent(Version, n.Version, time.Now()) + u.mu.Lock() + u.behind = b + u.mu.Unlock() + return + } + } +} + +// quietAgain starts the pill's quiet over: it was dismissed. +func (u *updater) quietAgain() { + b := update.QuietAgain(Version, time.Now()) + u.mu.Lock() + u.behind = b + u.mu.Unlock() +} + // inLang has the next checks ask for the notes in lang ("" leaves it). func (u *updater) inLang(lang string) { if lang == "" { diff --git a/internal/gui/update_quiet_test.go b/internal/gui/update_quiet_test.go new file mode 100644 index 000000000..09a138a9d --- /dev/null +++ b/internal/gui/update_quiet_test.go @@ -0,0 +1,42 @@ +package gui + +import ( + "path/filepath" + "testing" + "time" + + "github.com/yetone/magpie/internal/update" +) + +// "红点都快焊死了" (certhon520 and others on X): with a release every few +// minutes, a downloaded update was always there and the header's pill was +// always lit. /api/update says quiet for a version not behind for long, +// and not quiet for an urgent one. +func TestUpdateQuietUntilBehindAWhile(t *testing.T) { + h := t.TempDir() + t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) + t.Setenv("APPDATA", filepath.Join(h, "AppData")) + was := Version + Version = "0.1.100" + t.Cleanup(func() { Version = was }) + now := time.Now() + for _, c := range []struct { + name string + b update.Behind + state string + quiet bool + }{ + {"just found", update.Behind{Base: "0.1.100", Since: now.Add(-time.Hour)}, "ready", true}, + {"behind for days", update.Behind{Base: "0.1.100", Since: now.Add(-update.Quiet - time.Minute)}, "ready", false}, + {"urgent at once", update.Behind{Base: "0.1.100", Since: now, Urgent: "0.1.104"}, "ready", false}, + {"found, held download", update.Behind{Base: "0.1.100", Since: now}, "found", true}, + {"up to date says nothing", update.Behind{Base: "0.1.100", Since: now}, "latest", false}, + } { + u := &updater{state: c.state, behind: c.b, latest: &update.Release{Version: "0.1.105"}} + if got := u.json().Quiet; got != c.quiet { + t.Errorf("%s: quiet %v, want %v", c.name, got, c.quiet) + } + } +} diff --git a/internal/update/behind.go b/internal/update/behind.go new file mode 100644 index 000000000..5d926d231 --- /dev/null +++ b/internal/update/behind.go @@ -0,0 +1,126 @@ +package update + +// How long this version has been behind (users on X, 11-12: the header's +// Update pill was "always lit"). A release comes every few minutes, so a +// newer one is nearly always out, downloaded and ready; lighting the pill +// for each of them is a pill that never goes out. The pill lights once this +// version has been behind for Quiet, or at once for an urgent release (a +// security hole, a ban risk, lost data: the notes' "**Urgent release:**" +// line, see Stable). The Version row in Settings, Restart to update in the +// tray's menu and a restart or quit all work at any time. + +import ( + "encoding/json" + "os" + "path/filepath" + "regexp" + "sync" + "time" + + "github.com/yetone/magpie/internal/appdir" +) + +// Quiet is how long a version has to be behind before the pill lights, and +// how long a dismissal holds: the Stable channel's soak. +const Quiet = 72 * time.Hour + +// Behind is what is kept of being behind, for the version running (Base). +type Behind struct { + Base string `json:"base"` + // Since is when a newer version was first seen, or when the pill was + // last dismissed: the quiet runs from it. + Since time.Time `json:"since"` + // Urgent is the newest version known to be urgent, "" for none. + Urgent string `json:"urgent,omitempty"` +} + +var behindMu sync.Mutex + +func behindFile() string { return filepath.Join(appdir.Config(), "update-behind.json") } + +// readBehind is the kept note for current; one for another version (this +// one was updated since), or one that can't be read, is none. +func readBehind(current string) Behind { + data, err := os.ReadFile(behindFile()) + if err != nil { + return Behind{Base: current} + } + var b Behind + if json.Unmarshal(data, &b) != nil || b.Base != current { + return Behind{Base: current} + } + return b +} + +func writeBehind(b Behind) { + data, err := json.Marshal(b) + if err != nil { + return + } + f := behindFile() + if os.MkdirAll(filepath.Dir(f), 0o755) != nil { + return + } + tmp := f + ".tmp" + if os.WriteFile(tmp, data, 0o600) != nil { + return + } + if os.Rename(tmp, f) != nil { + os.Remove(tmp) + } +} + +// ReadBehind is the note for current. +func ReadBehind(current string) Behind { + behindMu.Lock() + defer behindMu.Unlock() + return readBehind(current) +} + +// NoteBehind notes that latest is out while current runs: the quiet starts +// at the first time, and an urgent latest is kept until current has +// caught up with it. A note that can't be read starts the quiet again, but +// the urgent one is read again from the next check's notes. +func NoteBehind(current, latest string, urgent bool, now time.Time) Behind { + behindMu.Lock() + defer behindMu.Unlock() + b := readBehind(current) + if b.Since.IsZero() { + b.Since = now + } + if urgent && (b.Urgent == "" || Newer(latest, b.Urgent)) { + b.Urgent = latest + } + writeBehind(b) + return b +} + +// NoteUrgent notes that version, newer than current, is urgent. +func NoteUrgent(current, version string, now time.Time) Behind { + return NoteBehind(current, version, true, now) +} + +// QuietAgain starts the quiet over: the pill was dismissed. +func QuietAgain(current string, now time.Time) Behind { + behindMu.Lock() + defer behindMu.Unlock() + b := readBehind(current) + b.Since = now + writeBehind(b) + return b +} + +// Lit is whether the pill may light at now: an urgent release newer than +// current is out, or the quiet has passed. +func (b Behind) Lit(current string, now time.Time) bool { + if b.Urgent != "" && Newer(b.Urgent, current) { + return true + } + return !b.Since.IsZero() && now.Sub(b.Since) >= Quiet +} + +var urgentLine = regexp.MustCompile(`(?im)^[ \t]*(?:>[ \t]*)?\*\*urgent release:\*\*`) + +// UrgentIn is whether a release's notes mark it urgent, as the site reads +// them (site/worker.js, urgentIn). +func UrgentIn(notes string) bool { return urgentLine.MatchString(notes) } diff --git a/internal/update/behind_test.go b/internal/update/behind_test.go new file mode 100644 index 000000000..581487a62 --- /dev/null +++ b/internal/update/behind_test.go @@ -0,0 +1,118 @@ +package update + +import ( + "os" + "testing" + "time" +) + +func behindHome(t *testing.T) { + t.Helper() + h := t.TempDir() + t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) + t.Setenv("XDG_CONFIG_HOME", h+"/.config") + t.Setenv("APPDATA", h+"/AppData") +} + +// Releases come every few minutes, so the header's pill (users on X, +// 11-12: "always lit") waits until this version has been behind for Quiet. +func TestPillWaitsForTheQuiet(t *testing.T) { + behindHome(t) + t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC) + b := NoteBehind("0.1.100", "0.1.101", false, t0) + if b.Lit("0.1.100", t0.Add(time.Minute)) { + t.Error("lit a minute after the first newer version") + } + // ten newer versions later, the clock still runs from the first + for i := 2; i < 12; i++ { + b = NoteBehind("0.1.100", "0.1.1"+string(rune('0'+i%10))+"0", false, t0.Add(time.Duration(i)*time.Hour)) + } + if b.Lit("0.1.100", t0.Add(Quiet-time.Minute)) { + t.Error("lit before the quiet passed") + } + if !b.Lit("0.1.100", t0.Add(Quiet)) { + t.Error("not lit once the quiet passed") + } + // the clock is kept across a restart without an update + if !ReadBehind("0.1.100").Lit("0.1.100", t0.Add(Quiet)) { + t.Error("the note was not kept") + } + // updated: the note is for the version it was + if ReadBehind("0.1.200").Lit("0.1.200", t0.Add(10*Quiet)) { + t.Error("a note for another version counted") + } +} + +// A security fix is never held back (the pill lights at once), and stays +// lit until this version has caught up with it. +func TestUrgentLightsThePillAtOnce(t *testing.T) { + behindHome(t) + t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC) + b := NoteBehind("0.1.100", "0.1.105", true, t0) + if !b.Lit("0.1.100", t0) { + t.Fatal("an urgent release did not light the pill") + } + b = NoteBehind("0.1.100", "0.1.106", false, t0.Add(time.Hour)) + if !b.Lit("0.1.100", t0.Add(time.Hour)) { + t.Error("a later plain release put out the urgent one's pill") + } + // a dismissal does not hide it either + if !QuietAgain("0.1.100", t0.Add(2*time.Hour)).Lit("0.1.100", t0.Add(2*time.Hour)) { + t.Error("a dismissal hid an urgent release") + } + if b.Lit("0.1.105", t0) && b.Urgent != "0.1.105" { + t.Error("urgent not kept") + } + if (Behind{Base: "0.1.105", Urgent: "0.1.105", Since: t0}).Lit("0.1.105", t0) { + t.Error("lit for an urgent release already running") + } +} + +// A dismissal holds for the quiet, not only until the next release. +func TestDismissalStartsTheQuietOver(t *testing.T) { + behindHome(t) + t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC) + NoteBehind("0.1.100", "0.1.101", false, t0) + later := t0.Add(Quiet + time.Hour) + if !ReadBehind("0.1.100").Lit("0.1.100", later) { + t.Fatal("not lit after the quiet") + } + b := QuietAgain("0.1.100", later) + if b.Lit("0.1.100", later.Add(Quiet-time.Minute)) { + t.Error("lit again before the quiet passed after a dismissal") + } + if !b.Lit("0.1.100", later.Add(Quiet)) { + t.Error("never lit again") + } +} + +// An unreadable note is unknown: it starts the quiet, it doesn't light. +func TestUnreadableBehindNoteIsNone(t *testing.T) { + behindHome(t) + t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC) + writeBehind(Behind{Base: "0.1.100", Since: t0}) + if err := writeFileForTest(behindFile(), "{half"); err != nil { + t.Fatal(err) + } + if ReadBehind("0.1.100").Lit("0.1.100", t0.Add(10*Quiet)) { + t.Error("a half-written note lit the pill") + } +} + +func TestUrgentIn(t *testing.T) { + for md, want := range map[string]bool{ + "**Urgent release:** keys leaked": true, + "fixes\n\n> **urgent release:** x": true, + " **Urgent release:** x": true, + "an urgent release: not at the line's start": false, + "fixed the **Urgent release:** label in notes": false, + "": false, + } { + if UrgentIn(md) != want { + t.Errorf("UrgentIn(%q) = %v", md, !want) + } + } +} + +func writeFileForTest(path, s string) error { return os.WriteFile(path, []byte(s), 0o600) }