feat(app): R2 switch — the application runs its domain rules in the Rust core
Consumers now fed by the core (crates/core through @faunosteo/core-wasm):
- the sheet: the bundled payload is parsed and indexed by the core
(SheetHandle, SheetIndexData); SheetIndex reads precomputed tables only;
- the store: new report, add / remove / move observation, draft restore
(v2 migration + rebase) through the core, actions answering { ok };
- the editor click chain (zone.click), laterality and vertebra pickers
(zone.add_sides, vertebra.initial / sync / select), the findings picker
(finding.toggle by clicked leaf position), zone removal;
- the import: engine byte scan (TypeScript until R4), then the core's
layered reading and rebase in one call; the export: the core builds the
sheet snapshot, the frozen TypeScript engine writes the PDF (R4).
Lazy core: Home and the new-report form read the sheet availability from
the bundle and load the module on import / submit only; the auth shell
never references it. Degraded states (core_unavailable, invalid_sheet)
show the validated notice with a retry and never redirect or touch the
draft; an unreadable draft or archive is set aside under
osteo:quarantine:* (only content kinds; a failed write keeps it in place
and the editor stays), a rebase that flags items keeps the raw pre-rebase
draft. Four strings, wording validated by the owner.
Deleted: services/zoneInteraction.ts and its suite (13 cases ported to
cargo), the TypeScript Finding builder and vertebra selection rules of the
pickers, store rules, persistence parsing, hydrateReport. ESLint forbids
@faunosteo/domain in apps/app/src; the report:compare CLI keeps the frozen
domain until R4 (scripts/compare/sheet.ts). App suite 313/313 on the real
core (24 new tests: quarantine, degraded editor, core failures, N-1
reader); step6 goldens and the frozen envelopes unchanged.
This commit is contained in:
1 parent
794dfd9d0b
commit
74fcb37564
65 files changed
+2227
-1678
No files matched your search
@@ -1,8 +1,10 @@
|
||||
/**
|
||||
* Step 6 Phase 0 characterisation of the import flow on the home route, with
|
||||
* `importReportFromPdf` mocked: the migration alert (degraded headline, then
|
||||
* the count), the three ImportError kinds plus the generic error mapped to
|
||||
* the FR messages, and the navigation to /editor on success.
|
||||
* the two import steps mocked (R2: `readAttachment`, the engine's byte scan,
|
||||
* then `importAttachment`, the core's layered read and rebase on the loaded
|
||||
* sheet): the migration alert (degraded headline, then the count), the three
|
||||
* ImportError kinds plus the generic error mapped to the FR messages, and the
|
||||
* navigation to /editor on success.
|
||||
*/
|
||||
import {
|
||||
describe,
|
||||
@@ -21,9 +23,14 @@ import {
|
||||
waitFor,
|
||||
} from '@testing-library/react'
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
||||
import type { ArchiveReadOutcome } from '@faunosteo/domain'
|
||||
import type { ArchiveImport } from '@faunosteo/core-wasm/types'
|
||||
import HomeRoute from '@/app/routes/HomeRoute'
|
||||
import { ImportError, importReportFromPdf, MAX_PDF_BYTES } from '@/pdf/import'
|
||||
import {
|
||||
ImportError,
|
||||
importAttachment,
|
||||
MAX_PDF_BYTES,
|
||||
readAttachment,
|
||||
} from '@/pdf/import'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
@@ -32,9 +39,12 @@ import { loadTestSheet, minimalReport } from '../helpers/sheet'
|
||||
|
||||
vi.mock('@/pdf/import', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/pdf/import')>()),
|
||||
importReportFromPdf: vi.fn(),
|
||||
readAttachment: vi.fn(),
|
||||
importAttachment: vi.fn(),
|
||||
}))
|
||||
const importMock = vi.mocked(importReportFromPdf)
|
||||
const readMock = vi.mocked(readAttachment)
|
||||
const importMock = vi.mocked(importAttachment)
|
||||
const ATTACHMENT = { version: 3 }
|
||||
|
||||
let sheet: SheetIndex
|
||||
|
||||
@@ -49,6 +59,8 @@ beforeEach(() => {
|
||||
activeObservationIndex: 0,
|
||||
})
|
||||
vi.stubGlobal('alert', vi.fn())
|
||||
readMock.mockReset()
|
||||
readMock.mockResolvedValue(ATTACHMENT)
|
||||
importMock.mockReset()
|
||||
})
|
||||
afterEach(() => {
|
||||
@@ -56,19 +68,28 @@ afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** The outcome shape importReportFromPdf resolves with (bare report, no archive). */
|
||||
/** What the import resolves with: the read (bare report, no archive) and no rebase. */
|
||||
function outcome(patch: {
|
||||
migrated: boolean
|
||||
unresolvedZones?: number
|
||||
unresolvedFindings?: number
|
||||
}): ArchiveReadOutcome {
|
||||
}): ArchiveImport {
|
||||
const report = minimalReport(sheet)
|
||||
return {
|
||||
report: minimalReport(sheet),
|
||||
origin: patch.migrated ? 'v2' : 'bare_v3',
|
||||
archive: null,
|
||||
unresolvedZones: 0,
|
||||
unresolvedFindings: 0,
|
||||
...patch,
|
||||
read: {
|
||||
report,
|
||||
origin: patch.migrated ? 'v2' : 'bare_v3',
|
||||
archive: null,
|
||||
unresolvedZones: 0,
|
||||
unresolvedFindings: 0,
|
||||
...patch,
|
||||
},
|
||||
rebase: {
|
||||
report,
|
||||
unresolvedZones: 0,
|
||||
unresolvedFindings: 0,
|
||||
rebased: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,20 +119,22 @@ const alertMock = () => vi.mocked(window.alert)
|
||||
const errorText = () => screen.queryByText(/./, { selector: 'p.text-red-700' })
|
||||
|
||||
describe('HomeRoute import: success paths', () => {
|
||||
it('passes the file bytes and the sheet migration map, hydrates, navigates to /editor', async () => {
|
||||
importMock.mockResolvedValue(outcome({ migrated: false }))
|
||||
it('passes the file bytes to the scan and the attachment to the loaded sheet, hydrates, navigates to /editor', async () => {
|
||||
importMock.mockReturnValue(outcome({ migrated: false }))
|
||||
await mountAndPickPdf()
|
||||
await screen.findByTestId('editor-route')
|
||||
expect(readMock).toHaveBeenCalledTimes(1)
|
||||
expect(readMock.mock.calls[0]![0]).toBeInstanceOf(Uint8Array)
|
||||
expect(importMock).toHaveBeenCalledTimes(1)
|
||||
const [bytes, map] = importMock.mock.calls[0]!
|
||||
expect(bytes).toBeInstanceOf(Uint8Array)
|
||||
expect(map).toBe(sheet.sheet.migrationMap)
|
||||
const [attachment, index] = importMock.mock.calls[0]!
|
||||
expect(attachment).toBe(ATTACHMENT)
|
||||
expect(index).toBe(sheet)
|
||||
expect(useReportStore.getState().report?.id).toBe('r1')
|
||||
expect(alertMock()).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('alerts "degraded" then the unresolved count (zones + findings) after a lossy migration', async () => {
|
||||
importMock.mockResolvedValue(
|
||||
importMock.mockReturnValue(
|
||||
outcome({ migrated: true, unresolvedZones: 1, unresolvedFindings: 1 }),
|
||||
)
|
||||
await mountAndPickPdf()
|
||||
@@ -120,13 +143,11 @@ describe('HomeRoute import: success paths', () => {
|
||||
const message = alertMock().mock.calls[0]![0] as string
|
||||
const [headline, ...lines] = message.split('\n\n')
|
||||
expect(headline).toBe(fr['home.import.degraded'])
|
||||
expect(lines).toEqual([
|
||||
fr['home.import.migrated']!.replace('{count}', '2'),
|
||||
])
|
||||
expect(lines).toEqual([fr['home.import.migrated']!.replace('{count}', '2')])
|
||||
})
|
||||
|
||||
it('stays silent on a migration that lost nothing', async () => {
|
||||
importMock.mockResolvedValue(outcome({ migrated: true }))
|
||||
importMock.mockReturnValue(outcome({ migrated: true }))
|
||||
await mountAndPickPdf()
|
||||
await screen.findByTestId('editor-route')
|
||||
expect(alertMock()).not.toHaveBeenCalled()
|
||||
@@ -158,7 +179,9 @@ describe('HomeRoute import: error paths', () => {
|
||||
]
|
||||
|
||||
it.each(cases)('%s', async (_label, error, expected) => {
|
||||
importMock.mockRejectedValue(error)
|
||||
importMock.mockImplementation(() => {
|
||||
throw error
|
||||
})
|
||||
await mountAndPickPdf()
|
||||
await waitFor(() => expect(errorText()).not.toBeNull())
|
||||
expect(errorText()!.textContent).toBe(expected)
|
||||
@@ -177,6 +200,7 @@ describe('HomeRoute import: size gate', () => {
|
||||
await waitFor(() => expect(errorText()).not.toBeNull())
|
||||
expect(errorText()!.textContent).toBe(fr['home.import.error_invalid_pdf'])
|
||||
expect(read).not.toHaveBeenCalled()
|
||||
expect(readMock).not.toHaveBeenCalled()
|
||||
expect(importMock).not.toHaveBeenCalled()
|
||||
expect(screen.queryByTestId('editor-route')).toBeNull()
|
||||
expect(useReportStore.getState().report).toBeNull()
|
||||
|
||||
Reference in new issue
Block a user