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:
bchanot committed 2026-10-14 00:41:34 +02:00
1 parent 794dfd9d0b
commit 74fcb37564
65 files changed
+2227 -1678

No files matched your search

@@ -9,7 +9,7 @@ import {
} from 'vitest'
import { cleanup, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { Finding } from '@faunosteo/domain'
import type { Finding, LateralSide } from '@faunosteo/core-wasm/types'
import FindingsTreePicker from '@/components/observation/FindingsTreePicker'
import { useLocaleStore } from '@/state/localeStore'
import type { SheetIndex } from '@/services/sheetIndex'
@@ -22,18 +22,51 @@ beforeAll(async () => {
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
afterEach(cleanup)
/**
* The picker reports the clicked leaf; the core builds or removes the finding
* (R2), as ObservationCard wires it. `onChange` receives the observation's
* findings after the toggle, which is what the picker handed out before R2.
*/
function CorePicker({
side,
selected,
onChange,
}: {
side?: LateralSide
selected: Finding[]
onChange: (next: Finding[]) => void
}) {
return (
<FindingsTreePicker
zone={sheet.findingZone('hip')!}
side={side}
selected={selected}
onToggle={(path, leafPosition) => {
const out = sheet.ops.toggleFinding({
observation: {
id: 'obs',
zones: [],
findings: selected,
freeTextFindings: [],
comment: '',
},
findingZoneId: 'hip',
path,
leafPosition,
...(side ? { side } : {}),
})
if (!out.ok) throw new Error(out.kind)
onChange(out.value.findings)
}}
/>
)
}
describe('FindingsTreePicker on a sheet finding zone', () => {
it('drills down the hip zone and selects a leaf as a v3 finding with snapshots and side', async () => {
const user = userEvent.setup()
const onChange = vi.fn()
render(
<FindingsTreePicker
zone={sheet.findingZone('hip')!}
side="left"
selected={[]}
onChange={onChange}
/>,
)
render(<CorePicker side="left" selected={[]} onChange={onChange} />)
expect(screen.getByText('Hanche (coxo-fémorale)')).toBeInTheDocument()
await user.click(
screen.getByRole('button', {
@@ -72,13 +105,7 @@ describe('FindingsTreePicker on a sheet finding zone', () => {
},
]
const onChange = vi.fn()
render(
<FindingsTreePicker
zone={sheet.findingZone('hip')!}
selected={selected}
onChange={onChange}
/>,
)
render(<CorePicker selected={selected} onChange={onChange} />)
expect(screen.getByLabelText('1 finding selected')).toBeInTheDocument()
await user.click(
screen.getByRole('button', { name: 'Open Osteopathic dysfunctions' }),
@@ -113,13 +140,7 @@ describe('FindingsTreePicker on a sheet finding zone', () => {
it('flags a vet-referral leaf and omits the key on other leaves', async () => {
const user = userEvent.setup()
const onChange = vi.fn()
render(
<FindingsTreePicker
zone={sheet.findingZone('hip')!}
selected={[]}
onChange={onChange}
/>,
)
render(<CorePicker selected={[]} onChange={onChange} />)
await user.click(
screen.getByRole('button', {
name: 'Ouvrir Dysfonctions ostéopathiques',
@@ -162,14 +183,7 @@ describe('FindingsTreePicker on a sheet finding zone', () => {
]
function renderPicker(selected: Finding[]) {
render(
<FindingsTreePicker
zone={sheet.findingZone('hip')!}
side="left"
selected={selected}
onChange={vi.fn()}
/>,
)
render(<CorePicker side="left" selected={selected} onChange={vi.fn()} />)
}
it('counts selected findings per level, none on a clean sibling', async () => {
@@ -223,13 +237,7 @@ describe('FindingsTreePicker on a sheet finding zone', () => {
})
it('the findings list carries no permanent compositing hint (text stays crisp)', () => {
render(
<FindingsTreePicker
zone={sheet.findingZone('hip')!}
selected={[]}
onChange={() => {}}
/>,
)
render(<CorePicker selected={[]} onChange={() => {}} />)
const ul = document.querySelector('ul') as HTMLElement
expect(ul.getAttribute('style') ?? '').not.toContain('will-change')
expect(ul.style.willChange).toBe('')