Skip to content

Commit 9fddce8

Browse files
author
gitlab-aibot
committed
feat: #44 desktop: What's New popup never appears after updates (changelog.json has no highlights) #60134
Feature: #44 Changelog-Feature: 修复 Desktop 更新后 What's New 弹窗永不出现的问题:changelog.json 生成器只识别旧版 <highlight source> HTML 块和 ## 小节,无法解析 v2 release notes 的 ### Highlights 列表和 ### 产品小节,导致每个版本都输出空 highlights;桌面端又在 highlights 为空时无条件标记版本已见,更新被静默消费。现在 Console feed 生成器同时解析 v1/v2 两种格式,将 v2 的 Highlights 条目作为 Desktop 分组输出,并在无桌面条目时用 Desktop 小节回填;桌面 updater 读取 Desktop sections 作为兜底,且仅当 feed 中确实包含当前版本但无桌面内容时才标记已见——feed 解析失败或不含当前版本时记录告警并留给下次启动,避免坏发布静默吞掉更新。
1 parent 4d9e4de commit 9fddce8

8 files changed

Lines changed: 774 additions & 255 deletions

File tree

‎packages/app/e2e/regression/whats-new.spec.ts‎

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,29 @@ const changelog = {
6060
}
6161

6262
// The list form, whose one release in range has no desktop highlights.
63-
const cliOnly = [{ tag: current, highlights: [{ source: "cli", title: "Terminal only", description: "Not here." }] }]
63+
const cliOnly = [
64+
{ tag: current, highlights: [{ source: "mobile", title: "Phone only", description: "Not here." }] },
65+
]
66+
67+
// The V2 feed shape: no highlight groups, the release notes live in Desktop sections.
68+
const sections = {
69+
releases: [
70+
{
71+
tag: `v${current}`,
72+
highlights: [],
73+
sections: [
74+
{
75+
title: "Desktop",
76+
items: ["**Worktree picker**: Click the branch on the new-session screen to open the picker."],
77+
},
78+
{ title: "Core", items: ["A server change."] },
79+
],
80+
},
81+
],
82+
}
83+
84+
// A present but unreadable feed that does not even name the current release.
85+
const broken = { releases: [{ tag: "v0.0.1", highlights: [] }] }
6486

6587
// A user who last saw 1.9.1, stored where the app kept it before the updater plugin owned What's New.
6688
const upgraded = { storage: { "highlights.v1": { version: "1.9.1" } } }
@@ -170,6 +192,29 @@ test("a failed changelog request leaves What's New for the next start", async ({
170192
await expect(page.getByRole("dialog").getByRole("heading", { level: 1 })).toHaveText("Split panes")
171193
})
172194

195+
test("a feed present but missing the current release leaves What's New for the next start", async ({ page }) => {
196+
const requests = await serveChangelog(page, broken)
197+
await start(page, upgraded)
198+
expect(await stored(page, SEEN)).toEqual({ version: "1.9.1" })
199+
await expect(page.getByRole("dialog")).toHaveCount(0)
200+
201+
await page.route("https://opencode.ai/changelog.json", async (route) =>
202+
route.fulfill({ headers: cors, json: changelog }),
203+
)
204+
await page.reload()
205+
await expect(page.getByRole("dialog").getByRole("heading", { level: 1 })).toHaveText("Split panes")
206+
expect(requests.length).toBeGreaterThan(0)
207+
})
208+
209+
test("a V2 feed without highlight groups falls back to its Desktop section", async ({ page }) => {
210+
await serveChangelog(page, sections)
211+
await start(page, upgraded)
212+
const dialog = page.getByRole("dialog")
213+
await expect(dialog.getByRole("heading", { level: 1 })).toHaveText("Worktree picker")
214+
await expect(dialog.getByText("Click the branch on the new-session screen to open the picker.")).toBeVisible()
215+
await expect.poll(() => stored(page, SEEN)).toEqual({ version: current })
216+
})
217+
173218
// Each start ends with the current version seen and no dialog; only a release in range is worth a changelog request.
174219
for (const row of [
175220
{ name: "the first run only remembers the version", seed: {}, requests: 0 },
@@ -200,7 +245,11 @@ for (const row of [
200245
}
201246

202247
/** Serves this changelog and records each request for it. */
203-
async function serveChangelog(page: Page, body: typeof changelog | typeof cliOnly = changelog, held?: Promise<void>) {
248+
async function serveChangelog(
249+
page: Page,
250+
body: typeof changelog | typeof cliOnly | typeof sections | typeof broken = changelog,
251+
held?: Promise<void>,
252+
) {
204253
const requests: string[] = []
205254

206255
await page.route("https://opencode.ai/changelog.json", async (route) => {
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
export type HighlightMedia =
2+
| { type: "video"; src: string }
3+
| { type: "image"; src: string; width: string; height: string }
4+
5+
export type HighlightItem = {
6+
title: string
7+
description: string
8+
shortDescription?: string
9+
media?: HighlightMedia
10+
}
11+
12+
export type HighlightGroup = {
13+
source: string
14+
items: HighlightItem[]
15+
}
16+
17+
export type ChangelogSection = { title: string; items: string[] }
18+
19+
export type ChangelogRelease = {
20+
tag: string
21+
name: string
22+
date: string
23+
url: string
24+
highlights: HighlightGroup[]
25+
sections: ChangelogSection[]
26+
}
27+
28+
export type ChangelogData = {
29+
ok: boolean
30+
releases: ChangelogRelease[]
31+
}
32+
33+
/**
34+
* Parses one GitHub release body into the highlight groups and detail sections the feed carries. V2 notes open with a
35+
* `### Highlights` bullet list and group details under `### <Product>` sections; older notes use `<highlight
36+
* source="…">` HTML blocks and `## <Product>` sections. Both shapes are kept, as the feed still serves old releases.
37+
*/
38+
export function parseReleaseBody(body: string): { highlights: HighlightGroup[]; sections: ChangelogSection[] } {
39+
const htmlHighlights = parseHtmlHighlights(body)
40+
const { highlights, sections } = parseMarkdown(body)
41+
42+
const groups = [...htmlHighlights]
43+
44+
// V2 notes carry no <highlight> HTML: their `### Highlights` bullets are what the desktop app shows.
45+
if (htmlHighlights.length === 0) groups.push({ source: "Desktop", items: highlights })
46+
47+
const hasDesktop = groups.some(
48+
(group) => group.source.toLowerCase().includes("desktop") && group.items.length > 0,
49+
)
50+
51+
// Backfill from the Desktop section when nothing names Desktop, so a release whose Highlights bullets could not be
52+
// attributed to Desktop still shows its Desktop bullets in What's New.
53+
if (!hasDesktop) {
54+
const desktop = sections.find((section) => section.title.toLowerCase() === "desktop")
55+
56+
if (desktop) groups.push({ source: "Desktop", items: desktop.items.flatMap(sectionHighlight) })
57+
}
58+
59+
return { highlights: mergeGroups(groups), sections }
60+
}
61+
62+
/** Splits a `- **Title**: description.` detail bullet into a highlight when it carries both parts. */
63+
function sectionHighlight(item: string): HighlightItem[] {
64+
const match = /^\*\*(.+?)\*\*:?\s*(.*)$/.exec(item.trim())
65+
66+
if (!match) return []
67+
68+
const title = inlineText(match[1].replace(/:$/, ""))
69+
const description = stripTrailingReferences(inlineText(match[2]))
70+
71+
if (!title || !description) return []
72+
73+
return [{ title, description }]
74+
}
75+
76+
function mergeGroups(groups: HighlightGroup[]): HighlightGroup[] {
77+
const merged = new Map<string, HighlightItem[]>()
78+
79+
for (const group of groups) {
80+
if (!group.items.length) continue
81+
82+
const items = merged.get(group.source) ?? []
83+
items.push(...group.items)
84+
merged.set(group.source, items)
85+
}
86+
87+
return Array.from(merged, ([source, items]) => ({ source, items: dedupeItems(items) }))
88+
}
89+
90+
function dedupeItems(items: HighlightItem[]): HighlightItem[] {
91+
const seen = new Set<string>()
92+
93+
return items.filter((item) => {
94+
const key = `${item.title}\n${item.description}\n${item.media?.src ?? ""}`
95+
96+
if (seen.has(key)) return false
97+
98+
seen.add(key)
99+
100+
return true
101+
})
102+
}
103+
104+
function parseHtmlHighlights(body: string): HighlightGroup[] {
105+
const groups = new Map<string, HighlightItem[]>()
106+
const regex = /<highlight\s+source="([^"]+)">([\s\S]*?)<\/highlight>/g
107+
let match
108+
109+
while ((match = regex.exec(body)) !== null) {
110+
const source = match[1]
111+
const content = match[2]
112+
113+
const titleMatch = content.match(/<h2>([^<]+)<\/h2>/)
114+
const pMatch = content.match(/<p(?:\s+short="([^"]*)")?>([^<]+)<\/p>/)
115+
const imgMatch = content.match(/<img\s+width="([^"]+)"\s+height="([^"]+)"\s+alt="[^"]*"\s+src="([^"]+)"/)
116+
const videoMatch = content.match(/^\s*(https:\/\/github\.com\/user-attachments\/assets\/[a-f0-9-]+)\s*$/m)
117+
118+
const media = (() => {
119+
if (videoMatch) return { type: "video", src: videoMatch[1] } satisfies HighlightMedia
120+
if (imgMatch) {
121+
return {
122+
type: "image",
123+
src: imgMatch[3],
124+
width: imgMatch[1],
125+
height: imgMatch[2],
126+
} satisfies HighlightMedia
127+
}
128+
})()
129+
130+
if (!titleMatch || !media) continue
131+
132+
const item: HighlightItem = {
133+
title: titleMatch[1],
134+
description: pMatch?.[2] || "",
135+
shortDescription: pMatch?.[1],
136+
media,
137+
}
138+
139+
if (!groups.has(source)) groups.set(source, [])
140+
groups.get(source)!.push(item)
141+
}
142+
143+
return Array.from(groups.entries()).map(([source, items]) => ({ source, items }))
144+
}
145+
146+
/**
147+
* Parses the Markdown portions of a release body. V2 notes use `### Highlights` and `### <Product>` headings; old
148+
* notes use `## <Product>` headings, so any heading from level two down starts a block.
149+
*/
150+
function parseMarkdown(body: string): { highlights: HighlightItem[]; sections: ChangelogSection[] } {
151+
const lines = body.replace(/\r\n?/g, "\n").split("\n")
152+
const blocks: { level: number; title: string; items: string[] }[] = []
153+
let current: (typeof blocks)[number] | undefined
154+
let skip = false
155+
156+
for (const line of lines) {
157+
const heading = /^(#{2,3})\s+(.+?)\s*$/.exec(line)
158+
159+
if (heading) {
160+
current = { level: heading[1].length, title: inlineText(heading[2]), items: [] }
161+
blocks.push(current)
162+
skip = false
163+
continue
164+
}
165+
166+
if (line.startsWith("**Thank you")) {
167+
skip = true
168+
continue
169+
}
170+
171+
if (/^[-*]\s+/.test(line) && !skip) current?.items.push(line.replace(/^[-*]\s+/, "").trim())
172+
}
173+
174+
const highlights = blocks
175+
.filter((block) => block.level === 3 && block.title.toLowerCase() === "highlights")
176+
.flatMap((block) => block.items.flatMap(parseHighlightBullet))
177+
const sections = blocks
178+
.filter((block) => !(block.level === 3 && block.title.toLowerCase() === "highlights"))
179+
.map((block) => ({ title: block.title, items: block.items }))
180+
181+
return { highlights, sections }
182+
}
183+
184+
/** Reads one `### Highlights` bullet as `- **Title**: One or two sentences. ([#1](https://…))`. */
185+
function parseHighlightBullet(item: string): HighlightItem[] {
186+
const match = /^\*\*(.+?)\*\*:?\s*([\s\S]*)$/.exec(item.trim())
187+
188+
if (!match) return []
189+
190+
const title = inlineText(match[1].replace(/:$/, ""))
191+
const description = stripTrailingReferences(inlineText(match[2]))
192+
193+
if (!title || !description) return []
194+
195+
return [{ title, description }]
196+
}
197+
198+
/** Reduces inline Markdown to plain text, keeping the words behind links, images and emphasis. */
199+
function inlineText(value: string) {
200+
return value
201+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
202+
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
203+
.replace(/`([^`]+)`/g, "$1")
204+
.replace(/\*\*([^*]+)\*\*/g, "$1")
205+
.replace(/\s+/g, " ")
206+
.trim()
207+
}
208+
209+
/** Removes a trailing pull request reference such as `([#1](https://…), [#2](https://…))`. */
210+
function stripTrailingReferences(value: string) {
211+
const reference = /(?:\[[^\]]*\]\([^)]*\)|<[^>]+>|#\d+)/
212+
213+
return value.replace(
214+
new RegExp(`\\s*\\(\\s*${reference.source}(?:\\s*,\\s*${reference.source})*\\s*\\)\\s*$`),
215+
"",
216+
)
217+
}

0 commit comments

Comments
 (0)