Files
faunosteo/apps/app/tests/unit/migration.leaves.test.ts
T
bchanot 74fcb37564 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.
2026-10-14 00:41:34 +02:00

70 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The 612 legacy leaves through the application itself: migrated with the
* bundled sheet's map, resolved by the sheet index the editor and the PDF
* use, exported to a v3 PDF and read back without loss.
*/
import { describe, it, expect, vi, beforeAll } from 'vitest'
import type { Finding, Report } from '@faunosteo/core-wasm/types'
import { exportReportToPdf } from '@/pdf/export'
import { importAttachment, importReportFromPdf } from '@/pdf/import'
import type { SheetIndex } from '@/services/sheetIndex'
import { findingNodeAt, loadTestSheet } from '../helpers/sheet'
import {
leavesAsV2Report,
legacyLeaves,
loadLegacyBaseline,
} from '../helpers/legacyLeaves'
// The factory runs when the engine first loads the adapter: fixed 1×1 PNG.
vi.mock('@/pdf/browserRasterizer', async () => {
const { ONE_PX_PNG } = await import('../helpers/goldens')
return { browserRasterizer: vi.fn(async () => ONE_PX_PNG) }
})
let sheet: SheetIndex
let report: Report
let findings: Finding[]
let unresolvedFindings: number
beforeAll(async () => {
sheet = await loadTestSheet()
const leaves = legacyLeaves(loadLegacyBaseline())
const v2 = leavesAsV2Report(leaves)
// Read as the application reads an attachment: the core migrates the v2 report.
const outcome = importAttachment(v2, sheet).read
report = outcome.report
findings = report.observations.flatMap((o) => o.findings)
unresolvedFindings = outcome.unresolvedFindings
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
})
describe('the 612 legacy leaves in the application', () => {
it('resolves every migrated leaf to a leaf node of the bundled sheet', () => {
expect(findings).toHaveLength(612)
expect(unresolvedFindings).toBe(29)
for (const f of findings) {
const node = findingNodeAt(sheet, f.findingZoneId, f.path)
const where = `${f.findingZoneId}/${f.path.join('/')}`
expect(sheet.hasNode(f.findingZoneId, f.path), where).toBe(!f.unresolved)
if (f.unresolved) expect(node, where).toBeUndefined()
else {
expect(node, where).toBeDefined()
expect(node!.children, where).toHaveLength(0)
}
}
})
it('keeps every finding, resolved or not, through an archive PDF export and import', async () => {
const { pdf: bytes } = await exportReportToPdf(report, sheet, {
locale: 'fr',
})
const { read: back } = await importReportFromPdf(bytes, sheet)
expect(back.migrated).toBe(false)
expect(back.origin).toBe('envelope_v1')
expect(back.archive).not.toBeNull()
expect(back.report).toEqual(report)
const again = back.report.observations.flatMap((o) => o.findings)
expect(again.filter((f) => f.unresolved)).toHaveLength(29)
}, 30_000)
})