Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

releaseNotes.test.ts

302 lines10.4 KB

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.each([
96 "**v1.2.4** · 3 changes from 2 contributors\n- **One-time tasks.** Pick a date.\n\n### Plus 2 more bug fixes and performance improvements.",
97 "<p><strong>v1.2.4</strong> · 3 changes from 2 contributors</p><ul><li><strong>One-time tasks.</strong> Pick a date.</li></ul><h3>Plus 2 more bug fixes and performance improvements.</h3>",
98 ])("keeps highlight labels and the remaining change count from the feed", (summary) => {
99 const { releaseNotes } = normalizeDesktopUpdateReleaseNotes(
100 summary + "\n<details><summary>Full changelog</summary>raw list</details>",
101 "1.2.4",
102 "latest",
103 );
104 expect(releaseNotes).toEqual([
105 {
106 version: "1.2.4",
107 stats: "3 changes from 2 contributors",
108 items: ["**One-time tasks.** Pick a date."],
109 totalItems: 1,
110 footer: "Plus 2 more bug fixes and performance improvements.",
111 },
112 ]);
113 });
114​
115 it("does not count Markdown or HTML section headings as changes", () => {
116 const changes = Array.from({ length: 8 }, (_, index) => `Change ${index + 1}`);
117 const result = normalizeDesktopUpdateReleaseNotes(
118 [
119 { version: "1.2.4", note: ["### Features", ...changes].join("\n- ") },
120 {
121 version: "1.2.3",
122 note: `<h3>Fixes</h3><ul>${changes.map((change) => `<li>${change}</li>`).join("")}</ul>`,
123 },
124 ],
125 "1.2.4",
126 "latest",
127 );
128​
129 expect(result.releaseNotes).toEqual([
130 { version: "1.2.4", items: changes.toReversed(), totalItems: 8 },
131 { version: "1.2.3", items: changes.toReversed(), totalItems: 8 },
132 ]);
133 });
134​
135 it("reads handwritten notes with their own <details> as a list", () => {
136 const result = normalizeDesktopUpdateReleaseNotes(
137 "- Older fix\n- Newer fix\n<details><summary>Logs</summary>\n- hidden\n</details>",
138 "1.2.3",
139 "latest",
140 );
141​
142 expect(result.releaseNotes).toEqual([
143 { version: "1.2.3", items: ["hidden", "Logs", "Newer fix", "Older fix"], totalItems: 4 },
144 ]);
145 });
146​
147 it("dates the offered release from the feed and older nightlies by their build day", () => {
148 const result = normalizeDesktopUpdateReleaseNotes(
149 [
150 { version: "0.0.41-nightly.20260914.1707", note: "- Nightly change 2" },
151 { version: "0.0.41-nightly.20260913.1700", note: "- Nightly change 1" },
152 ],
153 "0.0.41-nightly.20260914.1707",
154 "nightly",
155 "2026-09-14T18:30:00.000Z",
156 );
157​
158 expect(result.releaseNotes.map(({ releasedAt }) => releasedAt)).toEqual([
159 "2026-09-14T18:30:00.000Z",
160 "2026-09-13",
161 ]);
162 });
163​
164 it("drops releases from other trains before grouping on nightly", () => {
165 const releaseNotes = [
166 { version: "0.0.41-preview.20260914.1683", note: "- Maintainer test build" },
167 { version: "0.0.41-preview.20260913.1669", note: "- Maintainer test build" },
168 { version: "0.0.41-nightly.20260914.1707", note: "- Nightly change 2" },
169 { version: "0.0.41-nightly.20260914.1700", note: "- Nightly change 1" },
170 ];
171​
172 const result = normalizeDesktopUpdateReleaseNotes(
173 releaseNotes,
174 "0.0.41-nightly.20260914.1707",
175 "nightly",
176 );
177​
178 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
179 "0.0.41-nightly.20260914.1707",
180 "0.0.41-nightly.20260914.1700",
181 ]);
182 expect(result.omittedReleaseCount).toBe(0);
183 });
184​
185 // regression: #11753 prerelease entries leaked into a channel's update changelog
186 it("keeps only stable releases on the latest channel", () => {
187 const result = normalizeDesktopUpdateReleaseNotes(
188 [
189 { version: "0.0.42", note: "- Stable change" },
190 { version: "0.0.42-nightly.20260915.1710", note: "- Nightly change" },
191 ],
192 "0.0.42",
193 "latest",
194 );
195​
196 expect(result.releaseNotes.map(({ version }) => version)).toEqual(["0.0.42"]);
197 });
198​
199 it("counts valid groups before applying the six-release limit", () => {
200 const releaseNotes = [
201 { version: "1.3.9", note: "- Change 9" },
202 { version: "1.3.8", note: "Full changelog: https://example.com/compare/x...y" },
203 { version: "1.3.7", note: "- Change 7" },
204 { version: "1.3.6", note: "- Change 6" },
205 { version: "1.3.5", note: "- Change 5" },
206 { version: "1.3.4", note: "- Change 4" },
207 { version: "1.3.3", note: "- Change 3" },
208 { version: "1.3.2", note: "- Change 2" },
209 ];
210​
211 const result = normalizeDesktopUpdateReleaseNotes(releaseNotes, "1.3.9", "latest");
212​
213 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
214 "1.3.9",
215 "1.3.7",
216 "1.3.6",
217 "1.3.5",
218 "1.3.4",
219 "1.3.3",
220 ]);
221 expect(result.omittedReleaseCount).toBe(1);
222 });
223​
224 it("ignores malformed and empty entries instead of throwing", () => {
225 const result = normalizeDesktopUpdateReleaseNotes(
226 [
227 { version: "1.2.3", note: "- Valid change" },
228 { version: "1.2.2", note: "" },
229 { version: 42, note: "- Bad version type" },
230 { version: "1.2.1", note: { html: "<p>object note</p>" } },
231 "not an object",
232 null,
233 ],
234 "1.2.3",
235 "latest",
236 );
237​
238 expect(result).toEqual({
239 releaseNotes: [{ version: "1.2.3", items: ["Valid change"], totalItems: 1 }],
240 omittedReleaseCount: 0,
241 });
242 });
243​
244 it("keeps unsupported entities literal, including out-of-range and Object.prototype names", () => {
245 const result = normalizeDesktopUpdateReleaseNotes(
246 "- Broken entity &#9999999999;\n- Mentions &constructor; and &toString;",
247 "1.0.0",
248 "latest",
249 );
250 expect(result).toEqual({
251 releaseNotes: [
252 {
253 version: "1.0.0",
254 items: ["Mentions &constructor; and &toString;", "Broken entity &#9999999999;"],
255 totalItems: 2,
256 },
257 ],
258 omittedReleaseCount: 0,
259 });
260 });
261​
262 it("ignores the Full Changelog paragraph that ends GitHub's generated notes", () => {
263 const fullChangelog = (from: string, to: string) =>
264 `<p><strong>Full Changelog</strong>: <a class="commit-link" href="https://github.com/pingdotgg/t3code/compare/v${from}...v${to}"><tt>v${from}...v${to}</tt></a></p>`;
265 const result = normalizeDesktopUpdateReleaseNotes(
266 [
267 {
268 version: "0.1.3-nightly.20261024.3604",
269 note: fullChangelog("0.1.3-nightly.20261023.3592", "0.1.3-nightly.20261024.3604"),
270 },
271 {
272 version: "0.1.3-nightly.20261023.3592",
273 note:
274 "<h2>What's Changed</h2>\n<ul>\n" +
275 '<li>fix(web): A by <a href="https://github.com/a">@a</a> in <a href="https://github.com/pingdotgg/t3code/pull/1">#1</a></li>\n' +
276 '<li>fix(web): B by <a href="https://github.com/b">@b</a> in <a href="https://github.com/pingdotgg/t3code/pull/2">#2</a></li>\n' +
277 "<li>Full Changelog: links open in the browser in #3</li>\n" +
278 "</ul>\n" +
279 fullChangelog("0.1.3-nightly.20261023.3579", "0.1.3-nightly.20261023.3592"),
280 },
281 ],
282 "0.1.3-nightly.20261024.3604",
283 "nightly",
284 );
285​
286 expect(result).toEqual({
287 releaseNotes: [
288 {
289 version: "0.1.3-nightly.20261023.3592",
290 items: [
291 "Full Changelog: links open in the browser in #3",
292 "fix(web): B by @b in #2",
293 "fix(web): A by @a in #1",
294 ],
295 releasedAt: "2026-10-23",
296 totalItems: 3,
297 },
298 ],
299 omittedReleaseCount: 0,
300 });
301 });
302});