Skip to content

Commit 5014e5f

Browse files
authored
fix(desktop): show newest changes in nightly previews (pingdotgg#9138)
1 parent fc53b27 commit 5014e5f

17 files changed

Lines changed: 804 additions & 181 deletions

‎apps/desktop/src/updates/DesktopUpdates.test.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ describe("DesktopUpdates", () => {
336336
version: "1.2.4-nightly.20260709.765",
337337
note: "- [codex] Upgrade Clerk stack by @juliusmarminge in #3821",
338338
},
339+
{ version: "1.2.4-nightly.20260709.764", note: "- Change 764" },
340+
{ version: "1.2.4-nightly.20260709.763", note: "- Change 763" },
341+
{ version: "1.2.4-nightly.20260709.762", note: "- Change 762" },
342+
{ version: "1.2.4-nightly.20260709.761", note: "- Change 761" },
343+
{ version: "1.2.4-nightly.20260709.760", note: "- Change 760" },
339344
],
340345
});
341346
yield* flushCallbacks;
@@ -346,13 +351,21 @@ describe("DesktopUpdates", () => {
346351
{
347352
version: "1.2.4-nightly.20260709.766",
348353
items: ["feat(client): persist offline environment data by @juliusmarminge in #3795"],
354+
totalItems: 1,
349355
},
350356
{
351357
version: "1.2.4-nightly.20260709.765",
352358
items: ["[codex] Upgrade Clerk stack by @juliusmarminge in #3821"],
359+
totalItems: 1,
353360
},
361+
{ version: "1.2.4-nightly.20260709.764", items: ["Change 764"], totalItems: 1 },
362+
{ version: "1.2.4-nightly.20260709.763", items: ["Change 763"], totalItems: 1 },
363+
{ version: "1.2.4-nightly.20260709.762", items: ["Change 762"], totalItems: 1 },
364+
{ version: "1.2.4-nightly.20260709.761", items: ["Change 761"], totalItems: 1 },
354365
]);
366+
assert.equal(state.omittedReleaseCount, 1);
355367
assert.deepEqual(harness.sentStates.at(-1)?.releaseNotes, state.releaseNotes);
368+
assert.equal(harness.sentStates.at(-1)?.omittedReleaseCount, 1);
356369
}),
357370
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
358371
});
@@ -383,8 +396,9 @@ describe("DesktopUpdates", () => {
383396
assert.equal(unchangedState.status, "downloaded");
384397
assert.equal(unchangedState.downloadedVersion, "1.2.4");
385398
assert.deepEqual(unchangedState.releaseNotes, [
386-
{ version: "1.2.4", items: ["fix: queued update"] },
399+
{ version: "1.2.4", items: ["fix: queued update"], totalItems: 1 },
387400
]);
401+
assert.equal(unchangedState.omittedReleaseCount, 0);
388402

389403
const nextResult = yield* updates.check("poll");
390404
assert.isTrue(nextResult.checked);
@@ -424,7 +438,10 @@ describe("DesktopUpdates", () => {
424438
assert.equal(state.status, "downloaded");
425439
assert.equal(state.availableVersion, "1.2.4");
426440
assert.equal(state.downloadedVersion, "1.2.4");
427-
assert.deepEqual(state.releaseNotes, [{ version: "1.2.4", items: ["fix: queued update"] }]);
441+
assert.deepEqual(state.releaseNotes, [
442+
{ version: "1.2.4", items: ["fix: queued update"], totalItems: 1 },
443+
]);
444+
assert.equal(state.omittedReleaseCount, 0);
428445
assert.equal(state.downloadPercent, 100);
429446
}),
430447
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
@@ -454,7 +471,10 @@ describe("DesktopUpdates", () => {
454471
assert.equal(state.status, "downloaded");
455472
assert.equal(state.availableVersion, "1.2.4");
456473
assert.equal(state.downloadedVersion, "1.2.4");
457-
assert.deepEqual(state.releaseNotes, [{ version: "1.2.4", items: ["fix: queued update"] }]);
474+
assert.deepEqual(state.releaseNotes, [
475+
{ version: "1.2.4", items: ["fix: queued update"], totalItems: 1 },
476+
]);
477+
assert.equal(state.omittedReleaseCount, 0);
458478
assert.equal(state.downloadPercent, 100);
459479
}),
460480
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));

‎apps/desktop/src/updates/DesktopUpdates.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,24 @@ export const make = Effect.gen(function* () {
593593
}
594594

595595
const checkedAt = yield* currentIsoTimestamp;
596-
const releaseNotes = normalizeDesktopUpdateReleaseNotes(info.releaseNotes, info.version);
596+
const { releaseNotes, omittedReleaseCount } = normalizeDesktopUpdateReleaseNotes(
597+
info.releaseNotes,
598+
info.version,
599+
);
597600
yield* setState(
598-
reduceDesktopUpdateStateOnUpdateAvailable(state, info.version, checkedAt, releaseNotes),
601+
reduceDesktopUpdateStateOnUpdateAvailable(
602+
state,
603+
info.version,
604+
checkedAt,
605+
releaseNotes,
606+
omittedReleaseCount,
607+
),
599608
);
600609
yield* Ref.set(lastLoggedDownloadMilestoneRef, -1);
601610
yield* logUpdaterInfo("update available", {
602611
version: info.version,
603612
releaseNoteGroups: releaseNotes.length,
613+
omittedReleaseCount,
604614
});
605615
}),
606616
),

‎apps/desktop/src/updates/releaseNotes.test.ts‎

Lines changed: 129 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,163 @@ import { describe, expect, it } from "vite-plus/test";
33
import { normalizeDesktopUpdateReleaseNotes } from "./releaseNotes.ts";
44

55
describe("normalizeDesktopUpdateReleaseNotes", () => {
6-
it("splits a plain string note into items under the fallback version", () => {
7-
const notes = normalizeDesktopUpdateReleaseNotes(
8-
"## What's changed\n- First fix\n- Second fix",
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+
);
25+
26+
expect(result).toEqual({
27+
releaseNotes: [
28+
{
29+
version: "0.0.36-nightly.20260828.1213",
30+
items: [
31+
"fix(opencode): handle child approvals, stops, and model catalogs by @human in #8480",
32+
"fix(web): keep long task drawers usable on small screens by @human in #8313",
33+
"fix: eighth change",
34+
"fix: seventh change",
35+
"fix: sixth change",
36+
"fix: fifth change",
37+
"fix: fourth change",
38+
"fix: third change",
39+
],
40+
totalItems: 10,
41+
},
42+
],
43+
omittedReleaseCount: 0,
44+
});
45+
});
46+
47+
it("excludes a GitHub HTML contributor section", () => {
48+
const result = normalizeDesktopUpdateReleaseNotes(
49+
"<h2>What's Changed</h2><ul><li>Older fix</li><li>Newer fix</li></ul>" +
50+
"<h2>New Contributors</h2><ul><li>@human made their first contribution</li></ul>" +
51+
"<h2>Full Changelog</h2>",
952
"1.2.3",
1053
);
11-
expect(notes).toEqual([{ version: "1.2.3", items: ["First fix", "Second fix"] }]);
54+
55+
expect(result).toEqual({
56+
releaseNotes: [{ version: "1.2.3", items: ["Newer fix", "Older fix"], totalItems: 2 }],
57+
omittedReleaseCount: 0,
58+
});
59+
});
60+
61+
it("does not count Markdown or HTML section headings as changes", () => {
62+
const changes = Array.from({ length: 8 }, (_, index) => `Change ${index + 1}`);
63+
const result = normalizeDesktopUpdateReleaseNotes(
64+
[
65+
{ version: "1.2.4", note: ["### Features", ...changes].join("\n- ") },
66+
{
67+
version: "1.2.3",
68+
note: `<h3>Fixes</h3><ul>${changes.map((change) => `<li>${change}</li>`).join("")}</ul>`,
69+
},
70+
],
71+
"1.2.4",
72+
);
73+
74+
expect(result.releaseNotes).toEqual([
75+
{ version: "1.2.4", items: changes.toReversed(), totalItems: 8 },
76+
{ version: "1.2.3", items: changes.toReversed(), totalItems: 8 },
77+
]);
1278
});
1379

14-
it("keeps per-version groups and drops empty ones", () => {
15-
const notes = normalizeDesktopUpdateReleaseNotes(
80+
it("keeps per-version order and drops empty groups", () => {
81+
const result = normalizeDesktopUpdateReleaseNotes(
1682
[
17-
{ version: "1.2.3", note: "- Newer change" },
83+
{ version: "1.2.3", note: "- Newer release" },
1884
{ version: "1.2.2", note: "Full changelog: https://example.com/compare/x...y" },
19-
{ version: "1.2.1", note: "- Older change" },
85+
{ version: "1.2.1", note: "- Older release" },
2086
],
2187
"1.2.3",
2288
);
23-
expect(notes).toEqual([
24-
{ version: "1.2.3", items: ["Newer change"] },
25-
{ version: "1.2.1", items: ["Older change"] },
89+
90+
expect(result).toEqual({
91+
releaseNotes: [
92+
{ version: "1.2.3", items: ["Newer release"], totalItems: 1 },
93+
{ version: "1.2.1", items: ["Older release"], totalItems: 1 },
94+
],
95+
omittedReleaseCount: 0,
96+
});
97+
});
98+
99+
it("counts valid groups before applying the six-release limit", () => {
100+
const releaseNotes = [
101+
{ version: "1.3.9", note: "- Change 9" },
102+
{ version: "1.3.8", note: "Full changelog: https://example.com/compare/x...y" },
103+
{ version: "1.3.7", note: "- Change 7" },
104+
{ version: "1.3.6", note: "- Change 6" },
105+
{ version: "1.3.5", note: "- Change 5" },
106+
{ version: "1.3.4", note: "- Change 4" },
107+
{ version: "1.3.3", note: "- Change 3" },
108+
{ version: "1.3.2", note: "- Change 2" },
109+
];
110+
111+
const result = normalizeDesktopUpdateReleaseNotes(releaseNotes, "1.3.9");
112+
113+
expect(result.releaseNotes.map(({ version }) => version)).toEqual([
114+
"1.3.9",
115+
"1.3.7",
116+
"1.3.6",
117+
"1.3.5",
118+
"1.3.4",
119+
"1.3.3",
26120
]);
121+
expect(result.omittedReleaseCount).toBe(1);
27122
});
28123

29124
it("decodes valid HTML entities", () => {
30-
const notes = normalizeDesktopUpdateReleaseNotes("- Fix &amp; polish &#128512;", "1.0.0");
31-
expect(notes).toEqual([{ version: "1.0.0", items: ["Fix & polish 😀"] }]);
125+
const result = normalizeDesktopUpdateReleaseNotes("- Fix &amp; polish &#128512;", "1.0.0");
126+
expect(result).toEqual({
127+
releaseNotes: [{ version: "1.0.0", items: ["Fix & polish 😀"], totalItems: 1 }],
128+
omittedReleaseCount: 0,
129+
});
32130
});
33131

34-
it("ignores malformed entries instead of throwing", () => {
35-
const notes = normalizeDesktopUpdateReleaseNotes(
132+
it("ignores malformed and empty entries instead of throwing", () => {
133+
const result = normalizeDesktopUpdateReleaseNotes(
36134
[
37135
{ version: "1.2.3", note: "- Valid change" },
136+
{ version: "1.2.2", note: "" },
38137
{ version: 42, note: "- Bad version type" },
39138
{ version: "1.2.1", note: { html: "<p>object note</p>" } },
40139
"not an object",
41140
null,
42141
],
43142
"1.2.3",
44143
);
45-
expect(notes).toEqual([{ version: "1.2.3", items: ["Valid change"] }]);
144+
145+
expect(result).toEqual({
146+
releaseNotes: [{ version: "1.2.3", items: ["Valid change"], totalItems: 1 }],
147+
omittedReleaseCount: 0,
148+
});
46149
});
47150

48-
it("returns non-empty groups even when preceded by many boilerplate-only groups", () => {
49-
const boilerplate = Array.from({ length: 7 }, (_, index) => ({
50-
version: `1.3.${9 - index}`,
51-
note: "Full changelog: https://example.com/compare/x...y",
52-
}));
53-
const notes = normalizeDesktopUpdateReleaseNotes(
54-
[...boilerplate, { version: "1.3.2", note: "- Older but real change" }],
55-
"1.3.9",
56-
);
57-
expect(notes).toEqual([{ version: "1.3.2", items: ["Older but real change"] }]);
151+
it("returns an empty result for an invalid payload", () => {
152+
expect(normalizeDesktopUpdateReleaseNotes({ note: "- Invalid" }, "1.0.0")).toEqual({
153+
releaseNotes: [],
154+
omittedReleaseCount: 0,
155+
});
58156
});
59157

60158
it("does not throw on out-of-range numeric entities and keeps the literal", () => {
61-
const notes = normalizeDesktopUpdateReleaseNotes("- Broken entity &#9999999999;", "1.0.0");
62-
expect(notes).toEqual([{ version: "1.0.0", items: ["Broken entity &#9999999999;"] }]);
159+
const result = normalizeDesktopUpdateReleaseNotes("- Broken entity &#9999999999;", "1.0.0");
160+
expect(result).toEqual({
161+
releaseNotes: [{ version: "1.0.0", items: ["Broken entity &#9999999999;"], totalItems: 1 }],
162+
omittedReleaseCount: 0,
163+
});
63164
});
64165
});

‎apps/desktop/src/updates/releaseNotes.ts‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function stripMarkup(input: string): string {
5959
input
6060
.replace(/<br\s*\/?>/gi, "\n")
6161
.replace(/<li\b[^>]*>/gi, "\n- ")
62+
.replace(/<h([1-6])\b[^>]*>/gi, (_, level: string) => `\n${"#".repeat(Number(level))} `)
6263
.replace(/<\/(?:p|div|li|h[1-6]|ul|ol|blockquote)>/gi, "\n")
6364
.replace(/<[^>]*>/g, "")
6465
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
@@ -71,55 +72,81 @@ function truncateReleaseNoteItem(item: string): string {
7172
return `${item.slice(0, MAX_RELEASE_NOTE_ITEM_LENGTH - 3).trimEnd()}...`;
7273
}
7374

74-
function isIgnoredReleaseNoteLine(line: string): boolean {
75-
const normalized = line
75+
function normalizeReleaseNoteLine(line: string): string {
76+
return line
7677
.toLowerCase()
7778
.replace(/[*_`#]/g, "")
7879
.trim();
80+
}
81+
82+
function isIgnoredReleaseNoteLine(line: string): boolean {
83+
const normalized = normalizeReleaseNoteLine(line);
7984
return (
8085
normalized === "" ||
8186
normalized === "what's changed" ||
8287
normalized === "whats changed" ||
83-
normalized === "full changelog" ||
84-
normalized === "new contributors" ||
8588
normalized.startsWith("compare: ") ||
8689
normalized.includes("/compare/")
8790
);
8891
}
8992

90-
function extractReleaseNoteItems(note: string | null | undefined): ReadonlyArray<string> {
91-
if (!note) return [];
93+
interface ExtractedReleaseNoteItems {
94+
readonly items: ReadonlyArray<string>;
95+
readonly totalItems: number;
96+
}
97+
98+
function extractReleaseNoteItems(note: string | null | undefined): ExtractedReleaseNoteItems {
99+
if (!note) return { items: [], totalItems: 0 };
92100

93101
const items: string[] = [];
102+
let totalItems = 0;
94103
for (const rawLine of stripMarkup(note).split("\n")) {
95104
const item = rawLine
96105
.trim()
97106
.replace(/^[-*]\s+/, "")
98107
.replace(/^\d+[.)]\s+/, "")
99108
.replace(/\s+/g, " ");
109+
const normalized = normalizeReleaseNoteLine(item);
110+
if (normalized === "new contributors" || normalized === "full changelog") break;
111+
if (/^#{1,6}\s+/.test(item)) continue;
100112
if (isIgnoredReleaseNoteLine(item)) continue;
113+
totalItems += 1;
101114
items.push(truncateReleaseNoteItem(item));
102-
if (items.length >= MAX_RELEASE_NOTE_ITEMS_PER_GROUP) break;
115+
if (items.length > MAX_RELEASE_NOTE_ITEMS_PER_GROUP) items.shift();
103116
}
104-
return items;
117+
return { items: items.toReversed(), totalItems };
118+
}
119+
120+
interface NormalizedDesktopUpdateReleaseNotes {
121+
readonly releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote>;
122+
readonly omittedReleaseCount: number;
105123
}
106124

107125
export function normalizeDesktopUpdateReleaseNotes(
108126
releaseNotes: unknown,
109127
fallbackVersion: string,
110-
): ReadonlyArray<DesktopUpdateReleaseNote> {
128+
): NormalizedDesktopUpdateReleaseNotes {
111129
const rawNotes =
112130
typeof releaseNotes === "string"
113131
? [{ version: fallbackVersion, note: releaseNotes }]
114132
: Array.isArray(releaseNotes)
115133
? releaseNotes.filter(isElectronReleaseNoteInfo)
116134
: [];
117135

118-
return rawNotes
119-
.map((entry) => ({
120-
version: entry.version,
121-
items: extractReleaseNoteItems(entry.note),
122-
}))
123-
.filter((entry) => entry.items.length > 0)
124-
.slice(0, MAX_RELEASE_NOTE_GROUPS);
136+
const normalizedNotes = rawNotes.flatMap((entry) => {
137+
const { items, totalItems } = extractReleaseNoteItems(entry.note);
138+
if (totalItems === 0) return [];
139+
return [
140+
{
141+
version: entry.version,
142+
items,
143+
totalItems,
144+
},
145+
];
146+
});
147+
148+
return {
149+
releaseNotes: normalizedNotes.slice(0, MAX_RELEASE_NOTE_GROUPS),
150+
omittedReleaseCount: Math.max(0, normalizedNotes.length - MAX_RELEASE_NOTE_GROUPS),
151+
};
125152
}

0 commit comments

Comments
 (0)