1import { describe, it, expect, beforeEach, vi } from "vitest";234const store: Record<string, unknown> = {};56vi.stubGlobal("chrome", {7 storage: {8 local: {9 get: vi.fn(async (key: string | string[]) => (Array.isArray(key)10 ? Object.fromEntries(key.map((item) => [item, store[item]]))11 : { [key]: store[key] })),12 set: vi.fn(async (entries: Record<string, unknown>) => {13 Object.assign(store, entries);14 }),15 remove: vi.fn(async (key: string | string[]) => {16 for (const item of Array.isArray(key) ? key : [key]) delete store[item];17 }),18 },19 },20});212223const {24 PEACH_VERSION,25 RELEASES,26 importantReleasesSince,27 selectImportantReleases,28 pendingImportantReleases,29 recordInstalledVersion,30 hasReleaseNotes,31 shouldShowWhatsNew,32 markWhatsNewSeen,33} = await import("./release-notes");3435describe("release-notes", () => {36 beforeEach(() => {37 Object.keys(store).forEach((k) => delete store[k]);38 vi.clearAllMocks();39 });4041 it("PEACH_VERSION is a non-empty string", () => {42 expect(typeof PEACH_VERSION).toBe("string");43 expect(PEACH_VERSION.length).toBeGreaterThan(0);44 });4546 it("keeps sync recovery as its own breaking release", () => {47 const syncRecovery = RELEASES.find((release) =>48 release.notes.some((note) => {49 const body = note.body.toLowerCase();50 return body.includes("revoke") && body.includes("pair");51 })52 );53 expect(syncRecovery?.importance).toBe("breaking");54 expect(syncRecovery?.version).toBe("5.2.17");5556 const vaultV4 = RELEASES.find((release) => release.version === "5.1.3");57 expect(vaultV4?.importance).toBe("breaking");58 expect(vaultV4?.notes.some((note) => note.body.toLowerCase().includes("revoke"))).toBe(false);59 });6061 it("shows the sync recovery release for upgrades from 5.2.15", () => {62 expect(importantReleasesSince("5.2.15").map((release) => release.version)).toEqual(["5.2.17"]);63 });6465 it("hasReleaseNotes returns true when notes exist", () => {66 expect(hasReleaseNotes()).toBe(true);67 });6869 it("combines every important release newer than the installed version", () => {70 expect(importantReleasesSince("5.0.0").map((release) => release.version)).toEqual(["5.2.17", "5.1.3"]);71 });7273 it("combines several important patches across a skipped upgrade interval", () => {74 const selected = selectImportantReleases([75 { version: "3.0.0", releasedAt: "2026-03-03", importance: "critical", notes: [] },76 { version: "2.1.0", releasedAt: "2026-02-02", notes: [] },77 { version: "2.0.0", releasedAt: "2026-02-01", importance: "breaking", notes: [] },78 { version: "1.5.0", releasedAt: "2026-01-15", importance: "critical", notes: [] },79 ], "1.0.0", "3.0.0");80 expect(selected.map((release) => release.version)).toEqual(["3.0.0", "2.0.0", "1.5.0"]);81 });8283 it("shouldShowWhatsNew returns true when an important release was skipped", async () => {84 store["peach_release_notes_from"] = "5.0.0";85 expect(await shouldShowWhatsNew()).toBe(true);86 });8788 it("does not show the interruptive view after the current breaking release", async () => {89 store["peach_release_notes_from"] = "5.2.17";90 expect(await shouldShowWhatsNew()).toBe(false);91 });9293 it("preserves the earliest upgrade boundary across multiple updates", async () => {94 await recordInstalledVersion({ reason: "update", previousVersion: "5.0.0" } as chrome.runtime.InstalledDetails);95 await recordInstalledVersion({ reason: "update", previousVersion: "5.1.0" } as chrome.runtime.InstalledDetails);96 expect(store["peach_release_notes_from"]).toBe("5.0.0");97 expect((await pendingImportantReleases()).map((release) => release.version)).toEqual(["5.2.17", "5.1.3"]);98 });99100 it("shouldShowWhatsNew returns false on a fresh install (nothing seen yet)", async () => {101 expect(await shouldShowWhatsNew()).toBe(false);102 });103104 it("markWhatsNewSeen stores the current version and suppresses reshowing", async () => {105 store["peach_release_notes_from"] = "5.0.0";106 expect(await shouldShowWhatsNew()).toBe(true);107 await markWhatsNewSeen();108 expect(await shouldShowWhatsNew()).toBe(false);109 expect(store["peach_release_notes_from"]).toBeUndefined();110 });111});