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 状态、错误恢复和无障碍反馈;诊断默认保留在本地,仅在用户明确勾选时附加桌面摘要。
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { ipcChannels } from '../../shared/ipc-channels'
|
|
import { registerFeedbackIpcHandler } from './feedback-ipc'
|
|
|
|
type InvokeHandler = (event: unknown, input: unknown) => unknown
|
|
|
|
const electronMocks = vi.hoisted(() => ({
|
|
handlers: new Map<string, InvokeHandler>(),
|
|
handle: vi.fn((channel: string, handler: InvokeHandler) => {
|
|
electronMocks.handlers.set(channel, handler)
|
|
}),
|
|
removeHandler: vi.fn((channel: string) => {
|
|
electronMocks.handlers.delete(channel)
|
|
})
|
|
}))
|
|
|
|
vi.mock('electron', () => ({
|
|
ipcMain: {
|
|
handle: electronMocks.handle,
|
|
removeHandler: electronMocks.removeHandler
|
|
}
|
|
}))
|
|
|
|
describe('feedback IPC', () => {
|
|
it('validates input and accepts only the trusted main frame', async () => {
|
|
const webContents = {
|
|
mainFrame: {
|
|
url: 'file:///goodbuddy/index.html'
|
|
},
|
|
getURL: vi.fn(() => 'file:///goodbuddy/index.html')
|
|
}
|
|
const window = { webContents }
|
|
const submit = vi.fn(async () => ({
|
|
ok: true as const,
|
|
reference: 'GOODBUDDY-000001',
|
|
duplicate: false
|
|
}))
|
|
const remove = registerFeedbackIpcHandler(
|
|
window as never,
|
|
{ submit }
|
|
)
|
|
const handler = electronMocks.handlers.get(
|
|
ipcChannels.feedbackSubmit
|
|
)!
|
|
const event = {
|
|
sender: webContents,
|
|
senderFrame: webContents.mainFrame
|
|
}
|
|
const input = {
|
|
category: 'bug',
|
|
title: ' Feedback title ',
|
|
description: 'A useful feedback description.',
|
|
includeDiagnostics: false,
|
|
locale: 'zh-CN',
|
|
clientRequestId:
|
|
'00000000-0000-4000-8000-000000000501'
|
|
}
|
|
|
|
await expect(handler(event, input)).resolves.toMatchObject({
|
|
ok: true,
|
|
reference: 'GOODBUDDY-000001'
|
|
})
|
|
expect(submit).toHaveBeenCalledWith({
|
|
...input,
|
|
title: 'Feedback title'
|
|
})
|
|
expect(() =>
|
|
handler(
|
|
{
|
|
sender: {},
|
|
senderFrame: webContents.mainFrame
|
|
},
|
|
input
|
|
)
|
|
).toThrow('拒绝来自未知窗口的 IPC 请求')
|
|
expect(() =>
|
|
handler(event, {
|
|
...input,
|
|
endpoint: 'https://attacker.example/api/v1/feedback'
|
|
})
|
|
).toThrow()
|
|
expect(() =>
|
|
handler(event, {
|
|
...input,
|
|
diagnostics: [{ message: 'renderer supplied content' }]
|
|
})
|
|
).toThrow()
|
|
expect(submit).toHaveBeenCalledOnce()
|
|
|
|
remove()
|
|
expect(
|
|
electronMocks.handlers.has(ipcChannels.feedbackSubmit)
|
|
).toBe(false)
|
|
})
|
|
})
|