feat(app): R4.3b/c import worker, client, controller; HomeRoute on the disposable worker

Protocol v1 (task → ready → result | failed with phase and kind), the worker entry with
the glue bundled statically and the page's compiled Module posted, the file streamed into
the module's memory; client with start and task timers (paused while hidden), settle-once,
terminate always, error events never masked; module-level controller (one import at a
time, cancel on leaving Home, worker chunk prefetched once the engine is loaded); the
settlement mapped to the B.1.8 messages (OD-5: a trap, a timeout or an unreadable file is
« Erreur de lecture du PDF. », never a corrupt PDF). HomeRoute keeps its routing and size
pre-checks, loads its own index after acceptance, drops a result when the session changed.
Tests: handler and client in-process, the corpus message test (O8 51, O7 stored inputs,
O2/O3/Step 5), the six existing suites migrated to the real worker logic.
This commit is contained in:
bchanot committed 2026-10-18 18:10:42 +02:00
1 parent 52471dbbc0
commit 6d1cce6e06
26 files changed
+2164 -247

No files matched your search

+13 -12
View File
@@ -2,8 +2,11 @@
* R2 plan rev 2 (robustness 7): a store action whose core call fails changes
* nothing and answers `{ ok: false }`, and the callers stop: the new-report
* page does not open the editor, the home page shows the import error instead
* of opening a report.
* of opening a report (R4.3: after the import worker, which loads its own
* module, read the file).
*/
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import {
afterEach,
beforeAll,
@@ -11,6 +14,7 @@ import {
describe,
expect,
it,
onTestFinished,
vi,
} from 'vitest'
import {
@@ -25,7 +29,6 @@ import { MemoryRouter, Route, Routes } from 'react-router-dom'
import HomeRoute from '@/app/routes/HomeRoute'
import NewReportRoute from '@/app/routes/NewReportRoute'
import { setCoreRuntime } from '@/core/runtime'
import { readAttachment } from '@/pdf/import'
import { bundledSheetProvider } from '@/sheets/provider'
import { setSheetProvider } from '@/sheets/useSheet'
import { useReportStore } from '@/state/reportStore'
@@ -33,18 +36,14 @@ import { useLocaleStore } from '@/state/localeStore'
import { fr } from '@/i18n/fr'
import type { SheetIndex } from '@/services/sheetIndex'
import { testCoreRuntime, unavailableCoreRuntime } from '../helpers/core'
import { FIXTURES_DIR } from '../helpers/goldens'
import { useInProcessImportWorker } from '../helpers/importWorker'
import {
emptyObservation,
loadTestSheet,
minimalReport,
} from '../helpers/sheet'
vi.mock('@/pdf/import', async (importOriginal) => ({
...(await importOriginal<typeof import('@/pdf/import')>()),
readAttachment: vi.fn(),
}))
const readMock = vi.mocked(readAttachment)
let sheet: SheetIndex
beforeAll(async () => {
sheet = await loadTestSheet()
@@ -152,7 +151,8 @@ describe('callers stop on a failed core call', () => {
})
it('the home page shows the import error when the core cannot load', async () => {
readMock.mockResolvedValue({ version: 3 })
const { workers, restore } = useInProcessImportWorker()
onTestFinished(restore)
setCoreRuntime(unavailableCoreRuntime())
setSheetProvider(bundledSheetProvider)
render(
@@ -165,13 +165,14 @@ describe('callers stop on a failed core call', () => {
)
const button = screen.getByRole('button', { name: fr['home.import.cta'] })
await waitFor(() => expect(button).toBeEnabled())
const file = new File([new Uint8Array([37, 80, 68, 70])], 'bilan.pdf', {
type: 'application/pdf',
})
const bytes = readFileSync(resolve(FIXTURES_DIR, 'report-v3.bare.pdf'))
const file = new File([bytes], 'bilan.pdf', { type: 'application/pdf' })
fireEvent.change(document.querySelector('input[type="file"]')!, {
target: { files: [file] },
})
await screen.findByText(fr['home.import.error_core_unavailable']!)
// The worker read the file; the page's core, needed to open it, did not load.
expect(workers[0]!.posted.map((m) => m.type)).toEqual(['ready', 'result'])
expect(screen.queryByTestId('editor-route')).toBeNull()
expect(useReportStore.getState().report).toBeNull()
})