feat: add bounded diagnostics and improve UX feedback
Ask and Execute guidance, Runtime state, live announcements, loading states, retry paths, settings focus, and update failures now provide consistent and accessible feedback across the desktop experience. Add bounded redacted Desktop and Agent diagnostic logs, a read-only Agent diagnostics command, and an explicit opt-in for attaching a small Desktop diagnostic summary to in-app feedback. Diagnostics stay local by default and the existing feedback v1 service contract remains compatible. Release note: 新增可选桌面诊断反馈与 Agent 诊断导出,并统一 Ask/Execute 状态、错误恢复和无障碍反馈;诊断默认保留在本地,仅在用户明确勾选时附加桌面摘要。
This commit is contained in:
@@ -50,6 +50,7 @@ describe('feedback IPC', () => {
|
||||
category: 'bug',
|
||||
title: ' Feedback title ',
|
||||
description: 'A useful feedback description.',
|
||||
includeDiagnostics: false,
|
||||
locale: 'zh-CN',
|
||||
clientRequestId:
|
||||
'00000000-0000-4000-8000-000000000501'
|
||||
@@ -78,6 +79,12 @@ describe('feedback IPC', () => {
|
||||
endpoint: 'https://attacker.example/api/v1/feedback'
|
||||
})
|
||||
).toThrow()
|
||||
expect(() =>
|
||||
handler(event, {
|
||||
...input,
|
||||
diagnostics: [{ message: 'renderer supplied content' }]
|
||||
})
|
||||
).toThrow()
|
||||
expect(submit).toHaveBeenCalledOnce()
|
||||
|
||||
remove()
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { FeedbackSubmitInput } from '../../shared/feedback-contracts'
|
||||
import {
|
||||
feedbackLimits,
|
||||
type FeedbackSubmitInput
|
||||
} from '../../shared/feedback-contracts'
|
||||
import { FeedbackIdentityStore } from './feedback-identity-store'
|
||||
import {
|
||||
FeedbackClientError,
|
||||
StrictFeedbackHttpClient
|
||||
} from './feedback-http-client'
|
||||
import { FeedbackService } from './feedback-service'
|
||||
import {
|
||||
FeedbackService,
|
||||
type FeedbackDiagnosticsProvider
|
||||
} from './feedback-service'
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
nativeImage: {
|
||||
@@ -17,6 +23,7 @@ const input: FeedbackSubmitInput = {
|
||||
category: 'feature',
|
||||
title: 'Feedback title',
|
||||
description: 'A useful feedback description.',
|
||||
includeDiagnostics: false,
|
||||
contactEmail: 'user@example.com',
|
||||
locale: 'en-US',
|
||||
clientRequestId: '00000000-0000-4000-8000-000000000401'
|
||||
@@ -24,7 +31,9 @@ const input: FeedbackSubmitInput = {
|
||||
|
||||
function service(
|
||||
submit: StrictFeedbackHttpClient['submit'],
|
||||
clear = vi.fn(async () => undefined)
|
||||
clear = vi.fn(async () => undefined),
|
||||
readRecent: FeedbackDiagnosticsProvider['readRecent'] =
|
||||
vi.fn(async () => [])
|
||||
) {
|
||||
const identityStore = {
|
||||
getInstallationId: vi.fn(
|
||||
@@ -42,10 +51,12 @@ function service(
|
||||
platform: 'win32',
|
||||
architecture: 'x64',
|
||||
identityStore: identityStore as unknown as FeedbackIdentityStore,
|
||||
client: client as unknown as StrictFeedbackHttpClient
|
||||
client: client as unknown as StrictFeedbackHttpClient,
|
||||
diagnosticsProvider: { readRecent }
|
||||
}),
|
||||
identityStore,
|
||||
client
|
||||
client,
|
||||
readRecent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,21 +75,176 @@ describe('FeedbackService', () => {
|
||||
duplicate: false
|
||||
})
|
||||
expect(submit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
{
|
||||
schemaVersion: 1,
|
||||
productKey: 'goodbuddy',
|
||||
category: input.category,
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
contactEmail: input.contactEmail,
|
||||
installationId:
|
||||
'00000000-0000-4000-8000-000000000402',
|
||||
clientRequestId: input.clientRequestId,
|
||||
environment: {
|
||||
appVersion: '0.11.0',
|
||||
platform: 'windows',
|
||||
architecture: 'x64',
|
||||
locale: 'en-US'
|
||||
}
|
||||
}),
|
||||
},
|
||||
undefined,
|
||||
expect.any(AbortSignal)
|
||||
)
|
||||
expect(fixture.readRecent).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('appends bounded desktop diagnostics without changing public fields', async () => {
|
||||
const submit = vi.fn<StrictFeedbackHttpClient['submit']>(
|
||||
async () => ({
|
||||
reference: 'GOODBUDDY-000013',
|
||||
duplicate: false
|
||||
})
|
||||
)
|
||||
const readRecent = vi.fn(async () => [
|
||||
{
|
||||
timestamp: '2026-08-25T01:02:03.000Z',
|
||||
component: 'runtime' as const,
|
||||
stage: 'run',
|
||||
code: 'runtime.run.failed',
|
||||
errorType: 'TimeoutError',
|
||||
message: 'password=hunter2'
|
||||
}
|
||||
])
|
||||
const fixture = service(
|
||||
submit,
|
||||
vi.fn(async () => undefined),
|
||||
readRecent
|
||||
)
|
||||
await expect(
|
||||
fixture.service.submit({
|
||||
...input,
|
||||
includeDiagnostics: true
|
||||
})
|
||||
).resolves.toMatchObject({ ok: true })
|
||||
expect(readRecent).toHaveBeenCalledWith(
|
||||
feedbackLimits.maximumDiagnosticRecords
|
||||
)
|
||||
const payload = submit.mock.calls[0]![0]
|
||||
expect(payload).toMatchObject({
|
||||
schemaVersion: 1,
|
||||
productKey: 'goodbuddy',
|
||||
category: input.category,
|
||||
title: input.title,
|
||||
contactEmail: input.contactEmail
|
||||
})
|
||||
expect(payload).not.toHaveProperty('includeDiagnostics')
|
||||
expect(payload.description).toContain(input.description)
|
||||
expect(payload.description).toContain(
|
||||
'[GOODBUDDY_DESKTOP_DIAGNOSTICS_V1_BEGIN]\n'
|
||||
)
|
||||
expect(payload.description).toContain(
|
||||
'{"timestamp":"2026-08-25T01:02:03.000Z","component":"runtime","stage":"run","code":"runtime.run.failed","errorType":"TimeoutError","message":"Runtime request failed"}'
|
||||
)
|
||||
expect(payload.description).not.toContain('hunter2')
|
||||
expect(payload.description).toMatch(
|
||||
/\n\[GOODBUDDY_DESKTOP_DIAGNOSTICS_V1_END\]$/u
|
||||
)
|
||||
expect(payload.description.length).toBeLessThanOrEqual(
|
||||
feedbackLimits.maximumDescriptionCharacters
|
||||
)
|
||||
})
|
||||
|
||||
it('states when no recent desktop diagnostics exist', async () => {
|
||||
const submit = vi.fn<StrictFeedbackHttpClient['submit']>(
|
||||
async () => ({
|
||||
reference: 'GOODBUDDY-000014',
|
||||
duplicate: false
|
||||
})
|
||||
)
|
||||
const fixture = service(submit)
|
||||
await fixture.service.submit({
|
||||
...input,
|
||||
includeDiagnostics: true
|
||||
})
|
||||
expect(submit.mock.calls[0]![0].description).toContain(
|
||||
'{"status":"no-recent-diagnostics"}'
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps a bounded summary on complete diagnostic lines', async () => {
|
||||
const submit = vi.fn<StrictFeedbackHttpClient['submit']>(
|
||||
async () => ({
|
||||
reference: 'GOODBUDDY-000017',
|
||||
duplicate: false
|
||||
})
|
||||
)
|
||||
const records = Array.from({ length: 20 }, (_, index) => ({
|
||||
timestamp: new Date(
|
||||
Date.UTC(2026, 7, 25, 1, index)
|
||||
).toISOString(),
|
||||
component: 'runtime' as const,
|
||||
stage: 'run',
|
||||
code: 'runtime.run.failed',
|
||||
errorType: 'TimeoutError',
|
||||
message: 'Runtime request failed'
|
||||
}))
|
||||
const fixture = service(
|
||||
submit,
|
||||
vi.fn(async () => undefined),
|
||||
vi.fn(async () => records)
|
||||
)
|
||||
await fixture.service.submit({
|
||||
...input,
|
||||
includeDiagnostics: true
|
||||
})
|
||||
const summary = submit.mock.calls[0]![0].description.split(
|
||||
'\n\n'
|
||||
)[1]!
|
||||
expect(summary.length).toBeLessThanOrEqual(
|
||||
feedbackLimits.maximumDiagnosticsSummaryCharacters
|
||||
)
|
||||
const lines = summary.split('\n')
|
||||
expect(lines[0]).toBe(
|
||||
'[GOODBUDDY_DESKTOP_DIAGNOSTICS_V1_BEGIN]'
|
||||
)
|
||||
expect(lines.at(-1)).toBe(
|
||||
'[GOODBUDDY_DESKTOP_DIAGNOSTICS_V1_END]'
|
||||
)
|
||||
const included = lines
|
||||
.slice(1, -1)
|
||||
.map((line) => JSON.parse(line) as { timestamp: string })
|
||||
expect(included.length).toBeGreaterThan(0)
|
||||
expect(included.length).toBeLessThan(records.length)
|
||||
expect(included.at(-1)?.timestamp).toBe(
|
||||
records.at(-1)?.timestamp
|
||||
)
|
||||
})
|
||||
|
||||
it('does not send when selected diagnostics cannot be read', async () => {
|
||||
const submit = vi.fn<StrictFeedbackHttpClient['submit']>(
|
||||
async () => ({
|
||||
reference: 'GOODBUDDY-000015',
|
||||
duplicate: false
|
||||
})
|
||||
)
|
||||
const readRecent = vi.fn(async () => {
|
||||
throw new Error('read failed')
|
||||
})
|
||||
const fixture = service(
|
||||
submit,
|
||||
vi.fn(async () => undefined),
|
||||
readRecent
|
||||
)
|
||||
await expect(
|
||||
fixture.service.submit({
|
||||
...input,
|
||||
includeDiagnostics: true
|
||||
})
|
||||
).resolves.toEqual({
|
||||
ok: false,
|
||||
error: 'diagnostics-unavailable'
|
||||
})
|
||||
expect(submit).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('coalesces concurrent submissions with the same client request ID', async () => {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import {
|
||||
feedbackLimits,
|
||||
feedbackPublicPayloadSchema,
|
||||
feedbackSubmitInputSchema,
|
||||
type FeedbackPublicPayload,
|
||||
type FeedbackSubmitInput,
|
||||
type FeedbackSubmitResult
|
||||
} from '../../shared/feedback-contracts'
|
||||
import {
|
||||
normalizeDesktopDiagnosticRecord,
|
||||
type DesktopDiagnosticRecord
|
||||
} from '../desktop-diagnostics'
|
||||
import { FeedbackIdentityStore } from './feedback-identity-store'
|
||||
import {
|
||||
FeedbackClientError,
|
||||
@@ -15,6 +20,57 @@ import {
|
||||
normalizeFeedbackScreenshot
|
||||
} from './feedback-screenshot'
|
||||
|
||||
const diagnosticsBeginMarker =
|
||||
'[GOODBUDDY_DESKTOP_DIAGNOSTICS_V1_BEGIN]'
|
||||
const diagnosticsEndMarker =
|
||||
'[GOODBUDDY_DESKTOP_DIAGNOSTICS_V1_END]'
|
||||
export type FeedbackDiagnosticsProvider = {
|
||||
readRecent: (
|
||||
limit: number
|
||||
) => Promise<readonly DesktopDiagnosticRecord[]>
|
||||
}
|
||||
|
||||
function formatDiagnosticsSummary(
|
||||
records: readonly DesktopDiagnosticRecord[]
|
||||
): string {
|
||||
const lines = records
|
||||
.map(normalizeDesktopDiagnosticRecord)
|
||||
.filter(
|
||||
(record): record is DesktopDiagnosticRecord =>
|
||||
record !== undefined
|
||||
)
|
||||
.map((record) => JSON.stringify(record))
|
||||
if (lines.length === 0) {
|
||||
return [
|
||||
diagnosticsBeginMarker,
|
||||
JSON.stringify({ status: 'no-recent-diagnostics' }),
|
||||
diagnosticsEndMarker
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
const included: string[] = []
|
||||
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
||||
const candidate = [lines[index]!, ...included]
|
||||
const summary = [
|
||||
diagnosticsBeginMarker,
|
||||
...candidate,
|
||||
diagnosticsEndMarker
|
||||
].join('\n')
|
||||
if (
|
||||
summary.length >
|
||||
feedbackLimits.maximumDiagnosticsSummaryCharacters
|
||||
) {
|
||||
break
|
||||
}
|
||||
included.unshift(lines[index]!)
|
||||
}
|
||||
return [
|
||||
diagnosticsBeginMarker,
|
||||
...included,
|
||||
diagnosticsEndMarker
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
function mapPlatform(
|
||||
platform: NodeJS.Platform
|
||||
): FeedbackPublicPayload['environment']['platform'] {
|
||||
@@ -56,6 +112,7 @@ export class FeedbackService {
|
||||
architecture: string
|
||||
identityStore: FeedbackIdentityStore
|
||||
client: StrictFeedbackHttpClient
|
||||
diagnosticsProvider: FeedbackDiagnosticsProvider
|
||||
}
|
||||
) {}
|
||||
|
||||
@@ -143,6 +200,23 @@ export class FeedbackService {
|
||||
signal: AbortSignal
|
||||
): Promise<FeedbackSubmitResult> {
|
||||
try {
|
||||
let description = input.description
|
||||
if (input.includeDiagnostics) {
|
||||
try {
|
||||
const records =
|
||||
await this.options.diagnosticsProvider.readRecent(
|
||||
feedbackLimits.maximumDiagnosticRecords
|
||||
)
|
||||
description = `${description}\n\n${formatDiagnosticsSummary(
|
||||
records
|
||||
)}`
|
||||
} catch {
|
||||
return {
|
||||
ok: false,
|
||||
error: 'diagnostics-unavailable'
|
||||
}
|
||||
}
|
||||
}
|
||||
const installationId =
|
||||
await this.options.identityStore.getInstallationId()
|
||||
const payload = feedbackPublicPayloadSchema.parse({
|
||||
@@ -150,7 +224,7 @@ export class FeedbackService {
|
||||
productKey: 'goodbuddy',
|
||||
category: input.category,
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
description,
|
||||
...(input.contactEmail
|
||||
? { contactEmail: input.contactEmail }
|
||||
: {}),
|
||||
|
||||
Reference in New Issue
Block a user