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

+38 -2
View File
@@ -1,5 +1,5 @@
import { CoreRuntime } from '@faunosteo/core-wasm'
import { nodeCoreRuntime } from '@faunosteo/core-wasm/node'
import { CoreRuntime, type CoreSource } from '@faunosteo/core-wasm'
import { nodeCoreRuntime, nodeCoreSource } from '@faunosteo/core-wasm/node'
/** A loaded runtime on the shipped build (the package's Node source). */
export function testCoreRuntime(): Promise<CoreRuntime> {
@@ -26,3 +26,39 @@ export function unavailableCoreRuntime(): CoreRuntime {
importGlue: () => Promise.reject(new TypeError('blocked')),
})
}
/**
* A real runtime on the shipped module whose `SheetHandle.call` throws a
* `WebAssembly.RuntimeError` (as an out-of-memory trap does) for `draft.restore`
* calls whose input contains `marker`; `traps.count` counts them. The runtime
* poisons and recovers exactly as in production (three recoveries).
*/
export async function trappingCoreRuntime(marker: string) {
const source = nodeCoreSource('pkg')
const traps = { count: 0 }
const wrapped: CoreSource = {
compile: () => source.compile(),
importGlue: async (instance) => {
const glue = await source.importGlue(instance)
const Real = glue.SheetHandle
class Trapping extends Real {
call(op: string, input: string): string {
if (op === 'draft.restore' && input.includes(marker)) {
traps.count += 1
throw new WebAssembly.RuntimeError('unreachable')
}
return super.call(op, input)
}
}
return {
default: glue.default,
core_version: glue.core_version,
call: glue.call,
SheetHandle: Trapping,
}
},
}
const runtime = new CoreRuntime(wrapped)
if (!(await runtime.ready())) throw new Error('trapping runtime failed to load')
return { runtime, traps }
}