perf: track execution duration by state and bound summary I/O

This commit is contained in:
mesalogo
2026-10-04 16:21:55 +08:00
parent 2c2b6c31eb
commit 4d18794e74
31 changed files with 987 additions and 1397 deletions
+8 -1
View File
@@ -12,10 +12,17 @@ vi.mock('electron', () => electron)
it('reads execution statistics through the explicit typed bridge', async () => {
await import('./index')
const api = electron.contextBridge.exposeInMainWorld.mock.calls[0]![1] as DesktopApi
const summary = { durationMs: 1000, requestCount: 1, incompleteRequestCount: 0, activeRequestCount: 0, asOf: 2000, taskDurations: [{ id: 'task', durationMs: 1000, incompleteRequestCount: 0 }] }
const summary = { durationMs: 1000, runningCount: 0, incomplete: false, asOf: 2000, taskDurations: [{ id: 'task', durationMs: 1000, runningCount: 0, incomplete: false }] }
electron.ipcRenderer.invoke.mockResolvedValue(summary)
for (const scope of [{ conversationId: 'conversation' }, { projectId: 'project' }]) {
expect(await api.tasks.getExecutionStats(scope)).toBe(summary)
expect(electron.ipcRenderer.invoke).toHaveBeenLastCalledWith(ipcChannels.tasksExecutionStats, scope)
}
const listener = vi.fn()
const unsubscribe = api.tasks.onExecutionStatsChanged(listener)
const handler = electron.ipcRenderer.on.mock.calls.find(([channel]) => channel === ipcChannels.tasksExecutionStatsChanged)![1]
handler()
expect(listener).toHaveBeenCalledOnce()
unsubscribe()
expect(electron.ipcRenderer.removeListener).toHaveBeenCalledWith(ipcChannels.tasksExecutionStatsChanged, handler)
})
+5
View File
@@ -1273,6 +1273,11 @@ const desktopApi: DesktopApi = {
ipcRenderer.invoke(ipcChannels.tasksList) as Promise<AssistantTask[]>,
getExecutionStats: (input) =>
ipcRenderer.invoke(ipcChannels.tasksExecutionStats, input) as Promise<ExecutionStats>,
onExecutionStatsChanged: (listener) => {
const handler = (): void => listener()
ipcRenderer.on(ipcChannels.tasksExecutionStatsChanged, handler)
return () => { ipcRenderer.removeListener(ipcChannels.tasksExecutionStatsChanged, handler) }
},
setStatus: async (
taskId: string,
status: 'completed' | 'cancelled'