Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { normalizeDesktopUpdateReleaseNotes } from "./releaseNotes.ts";
4
5describe("normalizeDesktopUpdateReleaseNotes", () => {
6 it("shows the newest changes and counts all real changes", () => {
7 const result = normalizeDesktopUpdateReleaseNotes(
8 [
9 "- feat: first change",
10 "- fix: second change",
11 "- fix: third change",
12 "- fix: fourth change",
13 "- fix: fifth change",
14 "- fix: sixth change",
15 "- fix: seventh change",
16 "- fix: eighth change",
17 "- fix(web): keep long task drawers usable on small screens by @human in #8313",
18 "- fix(opencode): handle child approvals, stops, and model catalogs by @human in #8480",
19 "## New Contributors",
20 "- @human made their first contribution in #8435",
21 "**Full Changelog**: https://github.com/pingdotgg/t3code/compare/old...new",
22 ].join("\n"),
23 "0.0.36-nightly.20260828.1213",
24 "nightly",
25 );
26
27 expect(result).toEqual({
28 releaseNotes: [
29 {
30 version: "0.0.36-nightly.20260828.1213",
31 releasedAt: "2026-08-28",
32 items: [
33 "fix(opencode): handle child approvals, stops, and model catalogs by @human in #8480",
34 "fix(web): keep long task drawers usable on small screens by @human in #8313",
35 "fix: eighth change",
36 "fix: seventh change",
37 "fix: sixth change",
38 "fix: fifth change",
39 "fix: fourth change",
40 "fix: third change",
41 ],
42 totalItems: 10,
43 },
44 ],
45 omittedReleaseCount: 0,
46 });
47 });
48
49 it("excludes a GitHub HTML contributor section", () => {
50 const result = normalizeDesktopUpdateReleaseNotes(
51 "<h2>What's Changed</h2><ul><li>Older fix</li><li>Newer fix</li></ul>" +
52 "<h2>New Contributors</h2><ul><li>@human made their first contribution</li></ul>" +
53 "<h2>Full Changelog</h2>",
54 "1.2.3",
55 "latest",
56 );
57
58 expect(result).toEqual({
59 releaseNotes: [{ version: "1.2.3", items: ["Newer fix", "Older fix"], totalItems: 2 }],
60 omittedReleaseCount: 0,
61 });
62 });
63
64 it("reads a generated summary as a note and skips the folded full list", () => {
65 const fixes = Array.from({ length: 9 }, (_, index) => `- Fix ${index + 1} (#${index + 1})`);
66 const result = normalizeDesktopUpdateReleaseNotes(
67 [
68 "**v1.2.4** · 12 changes from 3 contributors",
69 "## Highlights",
70 "Link machines (beta).",
71 "## Fixes",
72 ...fixes,
73 "<details>",
74 "<summary>Full changelog</summary>",
75 "* fix: raw entry by @human in https://github.com/pingdotgg/t3code/pull/1",
76 "</details>",
77 ].join("\n"),
78 "1.2.4",
79 "latest",
80 "2026-10-29T10:00:00.000Z",
81 );
82
83 expect(result.releaseNotes).toEqual([
84 {
85 version: "1.2.4",
86 releasedAt: "2026-10-29T10:00:00.000Z",
87 stats: "12 changes from 3 contributors",
88 intro: "Link machines (beta).",
89 items: fixes.map((_, index) => `Fix ${index + 1}`),
90 totalItems: 10,
91 },
92 ]);
93 });
94
95 it("does not count Markdown or HTML section headings as changes", () => {
96 const changes = Array.from({ length: 8 }, (_, index) => `Change ${index + 1}`);
97 const result = normalizeDesktopUpdateReleaseNotes(
98 [
99 { version: "1.2.4", note: ["### Features", ...changes].join("\n- ") },
100 {
101 version: "1.2.3",
102 note: `<h3>Fixes</h3><ul>${changes.map((change) => `<li>${change}</li>`).join("")}</ul>`,
103 },
104 ],
105 "1.2.4",
106 "latest",
107 );
108
109 expect(result.releaseNotes).toEqual([
110 { version: "1.2.4", items: changes.toReversed(), totalItems: 8 },
111 { version: "1.2.3", items: changes.toReversed(), totalItems: 8 },
112 ]);
113 });
114
115 it("reads handwritten notes with their own <details> as a list", () => {
116 const result = normalizeDesktopUpdateReleaseNotes(
117 "- Older fix\n- Newer fix\n<details><summary>Logs</summary>\n- hidden\n</details>",
118 "1.2.3",
119 "latest",
120 );
121
122 expect(result.releaseNotes).toEqual([
123 { version: "1.2.3", items: ["hidden", "Logs", "Newer fix", "Older fix"], totalItems: 4 },
124 ]);
125 });
126
127 it("dates the offered release from the feed and older nightlies by their build day", () => {
128 const result = normalizeDesktopUpdateReleaseNotes(
129 [
130 { version: "0.0.41-nightly.20260914.1707", note: "- Nightly change 2" },
131 { version: "0.0.41-nightly.20260913.1700", note: "- Nightly change 1" },
132 ],
133 "0.0.41-nightly.20260914.1707",
134 "nightly",
135 "2026-09-14T18:30:00.000Z",
136 );
137
138 expect(result.releaseNotes.map(({ releasedAt }) => releasedAt)).toEqual([
139 "2026-09-14T18:30:00.000Z",
140 "2026-09-13",
141 ]);
142 });
143
144 it("drops releases from other trains before grouping on nightly", () => {
145 const releaseNotes = [
146 { version: "0.0.41-preview.20260914.1683", note: "- Maintainer test build" },
147 { version: "0.0.41-preview.20260913.1669", note: "- Maintainer test build" },
148 { version: "0.0.41-nightly.20260914.1707", note: "- Nightly change 2" },
149 { version: "0.0.41-nightly.20260914.1700", note: "- Nightly change 1" },
150 ];
151
152 const result = normalizeDesktopUpdateReleaseNotes(
153 releaseNotes,
154 "0.0.41-nightly.20260914.1707",
155 "nightly",
156 );
157
158 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
159 "0.0.41-nightly.20260914.1707",
160 "0.0.41-nightly.20260914.1700",
161 ]);
162 expect(result.omittedReleaseCount).toBe(0);
163 });
164
165 // regression: #11753 prerelease entries leaked into a channel's update changelog
166 it("keeps only stable releases on the latest channel", () => {
167 const result = normalizeDesktopUpdateReleaseNotes(
168 [
169 { version: "0.0.42", note: "- Stable change" },
170 { version: "0.0.42-nightly.20260915.1710", note: "- Nightly change" },
171 ],
172 "0.0.42",
173 "latest",
174 );
175
176 expect(result.releaseNotes.map(({ version }) => version)).toEqual(["0.0.42"]);
177 });
178
179 it("counts valid groups before applying the six-release limit", () => {
180 const releaseNotes = [
181 { version: "1.3.9", note: "- Change 9" },
182 { version: "1.3.8", note: "Full changelog: https://example.com/compare/x...y" },
183 { version: "1.3.7", note: "- Change 7" },
184 { version: "1.3.6", note: "- Change 6" },
185 { version: "1.3.5", note: "- Change 5" },
186 { version: "1.3.4", note: "- Change 4" },
187 { version: "1.3.3", note: "- Change 3" },
188 { version: "1.3.2", note: "- Change 2" },
189 ];
190
191 const result = normalizeDesktopUpdateReleaseNotes(releaseNotes, "1.3.9", "latest");
192
193 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
194 "1.3.9",
195 "1.3.7",
196 "1.3.6",
197 "1.3.5",
198 "1.3.4",
199 "1.3.3",
200 ]);
201 expect(result.omittedReleaseCount).toBe(1);
202 });
203
204 it("ignores malformed and empty entries instead of throwing", () => {
205 const result = normalizeDesktopUpdateReleaseNotes(
206 [
207 { version: "1.2.3", note: "- Valid change" },
208 { version: "1.2.2", note: "" },
209 { version: 42, note: "- Bad version type" },
210 { version: "1.2.1", note: { html: "<p>object note</p>" } },
211 "not an object",
212 null,
213 ],
214 "1.2.3",
215 "latest",
216 );
217
218 expect(result).toEqual({
219 releaseNotes: [{ version: "1.2.3", items: ["Valid change"], totalItems: 1 }],
220 omittedReleaseCount: 0,
221 });
222 });
223
224 it("does not throw on out-of-range numeric entities and keeps the literal", () => {
225 const result = normalizeDesktopUpdateReleaseNotes(
226 "- Broken entity �",
227 "1.0.0",
228 "latest",
229 );
230 expect(result).toEqual({
231 releaseNotes: [{ version: "1.0.0", items: ["Broken entity �"], totalItems: 1 }],
232 omittedReleaseCount: 0,
233 });
234 });
235});