fix(app): rescue copy importable, trapping draft held, replace confirmed

The JSON rescue copy could not be restored in the app, a draft that traps
the engine left the tab on a reload screen and spent a recovery on every
read, and an unsaved or in-progress report could be lost by a reload
outside the editor or by New report / Import without warning.

Home import reads the copy (content-sniffed, 16 MiB cap, strict UTF-8)
through the core's draft.restore before any session change; a trapping
(draft, archive) pair is held in the resolution panel and only re-read
on Retry; ReplaceSessionDialog guards New report and Import; the
beforeunload guard is app-wide while unsaved. Supersedes BDR-055's
"never held" for `internal` only.
This commit is contained in:
bchanot committed 2026-10-17 12:58:57 +02:00
1 parent 9464651140
commit 9bd9acaf58
22 files changed
+1090 -68

No files matched your search

@@ -2,7 +2,7 @@
* The engine stopped for good (three recoveries spent, owner decision 2026-10-15): the
* stopped notice on every core page, its two variants (tab copy saved: reload; tab storage
* full: download a copy), no retry anywhere, the editor's save banner with its copy button,
* the beforeunload guard while the report is unsaved, and the stopped alerts.
* and the stopped alerts (the beforeunload guard has its own hook test).
*/
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
@@ -167,24 +167,6 @@ describe('EditorRoute', () => {
expect(await blobs[0]!.text()).toBe(JSON.stringify(useReportStore.getState().report))
})
it('guards the page with beforeunload exactly while the report is unsaved', async () => {
setStopped(false)
mountEditor()
await screen.findByTestId('sheet-status')
const leave = () => {
const event = new Event('beforeunload', { cancelable: true })
window.dispatchEvent(event)
return event.defaultPrevented
}
expect(leave()).toBe(false)
fillStorage()
await waitFor(() => expect(leave()).toBe(true))
vi.restoreAllMocks()
act(() => useReportStore.getState().setConclusion('saved again'))
expect(useReportStore.getState().saveFailed).toBe(false)
await waitFor(() => expect(leave()).toBe(false))
})
it('says the stopped text when the export fails once the engine stopped', async () => {
vi.spyOn(console, 'error').mockImplementation(() => undefined)
vi.mocked(exportReportToPdf).mockRejectedValue(new Error('core_unavailable'))
@@ -244,6 +226,8 @@ describe('the stopped text on the Home import line and the New report alert', ()
const submit = screen.getByRole('button', { name: fr['new_report.submit']! })
await waitFor(() => expect(submit).toBeEnabled())
await user.click(submit)
// A report is in progress (beforeEach): replacing it is confirmed first.
await user.click(await screen.findByRole('button', { name: fr['session.replace.confirm']! }))
}
it('Home import: the engine error line says the stopped text', async () => {