fix: time out stalled feedback submissions (#3778)

This commit is contained in:
Neil
2026-05-30 09:54:23 -07:00
committed by GitHub
parent be8e8cd22d
commit e5fcb2e2d1
2 changed files with 44 additions and 6 deletions
+29 -1
View File
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const { fetchMock, handlers } = vi.hoisted(() => ({
fetchMock: vi.fn(),
@@ -29,11 +29,16 @@ function postedBody(): Record<string, unknown> {
describe('submitFeedback', () => {
beforeEach(() => {
vi.useRealTimers()
handlers.clear()
fetchMock.mockReset()
fetchMock.mockResolvedValue(okResponse())
})
afterEach(() => {
vi.useRealTimers()
})
it('strips GitHub identity and anonymous contact fields when submitted anonymously', async () => {
const anonymousArgs = {
feedback: 'private bug report',
@@ -94,6 +99,29 @@ describe('submitFeedback', () => {
})
})
it('falls back when the primary feedback request stalls', async () => {
vi.useFakeTimers()
fetchMock.mockImplementation((url: string, init?: RequestInit) => {
if (url.includes('api.onorca.dev')) {
return new Promise((_resolve, reject) => {
init?.signal?.addEventListener('abort', () => reject(new Error('request aborted')))
})
}
return Promise.resolve(okResponse())
})
const result = submitFeedback({
feedback: 'stalled primary',
submitAnonymously: false,
githubLogin: 'trusted-user',
githubEmail: 'trusted@example.com'
})
await vi.advanceTimersByTimeAsync(10_000)
await expect(Promise.race([result, Promise.resolve('pending')])).resolves.toEqual({ ok: true })
expect(fetchMock).toHaveBeenCalledTimes(2)
})
it('forces renderer IPC submissions onto the feedback lane', async () => {
registerFeedbackHandlers()
await handlers.get('feedback:submit')?.(null, {