Skip to content

Commit d1f0682

Browse files
author
gitlab-aibot
committed
feat: anomalyco#44 desktop: What's New popup never appears after updates (changelog.json has no highlights) anomalyco#60134
Feature: anomalyco#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 d1f0682

9 files changed

Lines changed: 1930 additions & 255 deletions

File tree

‎0001-feat-44-desktop-What-s-New-popup-never-appears-after.patch‎

Lines changed: 1187 additions & 0 deletions
Large diffs are not rendered by default.

‎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: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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(parseHighlightBullet) })
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+
64+
function mergeGroups(groups: HighlightGroup[]): HighlightGroup[] {
65+
const merged = new Map<string, HighlightItem[]>()
66+
67+
for (const group of groups) {
68+
if (!group.items.length) continue
69+
70+
const items = merged.get(group.source) ?? []
71+
items.push(...group.items)
72+
merged.set(group.source, items)
73+
}
74+
75+
return Array.from(merged, ([source, items]) => ({ source, items: dedupeItems(items) }))
76+
}
77+
78+
function dedupeItems(items: HighlightItem[]): HighlightItem[] {
79+
const seen = new Set<string>()
80+
81+
return items.filter((item) => {
82+
const key = `${item.title}\n${item.description}\n${item.media?.src ?? ""}`
83+
84+
if (seen.has(key)) return false
85+
86+
seen.add(key)
87+
88+
return true
89+
})
90+
}
91+
92+
function parseHtmlHighlights(body: string): HighlightGroup[] {
93+
const groups = new Map<string, HighlightItem[]>()
94+
const regex = /<highlight\s+source="([^"]+)">([\s\S]*?)<\/highlight>/g
95+
let match
96+
97+
while ((match = regex.exec(body)) !== null) {
98+
const source = match[1]
99+
const content = match[2]
100+
101+
const titleMatch = content.match(/<h2>([^<]+)<\/h2>/)
102+
const pMatch = content.match(/<p(?:\s+short="([^"]*)")?>([^<]+)<\/p>/)
103+
const imgMatch = content.match(/<img\s+width="([^"]+)"\s+height="([^"]+)"\s+alt="[^"]*"\s+src="([^"]+)"/)
104+
const videoMatch = content.match(/^\s*(https:\/\/github\.com\/user-attachments\/assets\/[a-f0-9-]+)\s*$/m)
105+
106+
const media = (() => {
107+
if (videoMatch) return { type: "video", src: videoMatch[1] } satisfies HighlightMedia
108+
if (imgMatch) {
109+
return {
110+
type: "image",
111+
src: imgMatch[3],
112+
width: imgMatch[1],
113+
height: imgMatch[2],
114+
} satisfies HighlightMedia
115+
}
116+
})()
117+
118+
if (!titleMatch || !media) continue
119+
120+
const item: HighlightItem = {
121+
title: titleMatch[1],
122+
description: pMatch?.[2] || "",
123+
shortDescription: pMatch?.[1],
124+
media,
125+
}
126+
127+
if (!groups.has(source)) groups.set(source, [])
128+
groups.get(source)!.push(item)
129+
}
130+
131+
return Array.from(groups.entries()).map(([source, items]) => ({ source, items }))
132+
}
133+
134+
/**
135+
* Parses the Markdown portions of a release body. V2 notes use `### Highlights` and `### <Product>` headings; old
136+
* notes use `## <Product>` headings, so any heading from level two down starts a block.
137+
*/
138+
function parseMarkdown(body: string): { highlights: HighlightItem[]; sections: ChangelogSection[] } {
139+
const lines = body.replace(/\r\n?/g, "\n").split("\n")
140+
const blocks: { level: number; title: string; items: string[] }[] = []
141+
let current: (typeof blocks)[number] | undefined
142+
let skip = false
143+
144+
for (const line of lines) {
145+
const heading = /^(#{2,3})\s+(.+?)\s*$/.exec(line)
146+
147+
if (heading) {
148+
current = { level: heading[1].length, title: inlineText(heading[2]), items: [] }
149+
blocks.push(current)
150+
skip = false
151+
continue
152+
}
153+
154+
if (line.startsWith("**Thank you")) {
155+
skip = true
156+
continue
157+
}
158+
159+
if (/^[-*]\s+/.test(line) && !skip) current?.items.push(line.replace(/^[-*]\s+/, "").trim())
160+
}
161+
162+
const highlights = blocks
163+
.filter((block) => block.level === 3 && block.title.toLowerCase() === "highlights")
164+
.flatMap((block) => block.items.flatMap(parseHighlightBullet))
165+
const sections = blocks
166+
.filter((block) => !(block.level === 3 && block.title.toLowerCase() === "highlights"))
167+
.map((block) => ({ title: block.title, items: block.items }))
168+
169+
return { highlights, sections }
170+
}
171+
172+
/** Reads one `### Highlights` bullet as `- **Title**: One or two sentences. ([#1](https://…))`. */
173+
function parseHighlightBullet(item: string): HighlightItem[] {
174+
const match = /^\*\*(.+?)\*\*:?\s*([\s\S]*)$/.exec(item.trim())
175+
176+
if (!match) return []
177+
178+
const title = inlineText(match[1].replace(/:$/, ""))
179+
const description = stripTrailingReferences(inlineText(match[2]))
180+
181+
if (!title || !description) return []
182+
183+
return [{ title, description }]
184+
}
185+
186+
/** Reduces inline Markdown to plain text, keeping the words behind links, images and emphasis. */
187+
function inlineText(value: string) {
188+
return value
189+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
190+
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
191+
.replace(/`([^`]+)`/g, "$1")
192+
.replace(/\*\*([^*]+)\*\*/g, "$1")
193+
.replace(/\s+/g, " ")
194+
.trim()
195+
}
196+
197+
/** Removes a trailing pull request reference such as `([#1](https://…), [#2](https://…))`. */
198+
function stripTrailingReferences(value: string) {
199+
const reference = /(?:\[[^\]]*\]\([^)]*\)|<[^>]+>|#\d+)/
200+
201+
return value.replace(
202+
new RegExp(`\\s*\\(\\s*${reference.source}(?:\\s*,\\s*${reference.source})*\\s*\\)\\s*$`),
203+
"",
204+
)
205+
}

0 commit comments

Comments
 (0)