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.
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
/**
|
|
* Replaces pdf.attachment.test.ts and pdf.attachment.inflate.test.ts on the
|
|
* engine read API: the typed ImportError kinds the home route maps. The
|
|
* attachment roundtrip moved to pdf.roundtrip.test.ts ("attaches the
|
|
* envelope and roundtrips") and the engine's tests/read.test.ts (T4); the
|
|
* inflate bomb cap lives in the engine's tests/security.test.ts.
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest'
|
|
import { PDFDocument } from 'pdf-lib'
|
|
import { importReportFromPdf, ImportError, MAX_PDF_BYTES } from '@/pdf/import'
|
|
import type { SheetIndex } from '@/services/sheetIndex'
|
|
import { loadTestSheet } from '../helpers/sheet'
|
|
|
|
let sheet: SheetIndex
|
|
beforeAll(async () => {
|
|
sheet = await loadTestSheet()
|
|
})
|
|
|
|
/** Saved like the export (no object streams, BLK-009) so the keyword stamp is in clear. */
|
|
async function pdfWithoutAttachment(keywords?: string[]): Promise<Uint8Array> {
|
|
const doc = await PDFDocument.create()
|
|
doc.addPage()
|
|
if (keywords) doc.setKeywords(keywords)
|
|
return doc.save({ useObjectStreams: false })
|
|
}
|
|
|
|
async function rejectsWith(bytes: Uint8Array, kind: string): Promise<void> {
|
|
const promise = importReportFromPdf(bytes, sheet)
|
|
await expect(promise).rejects.toBeInstanceOf(ImportError)
|
|
await expect(promise).rejects.toMatchObject({ kind })
|
|
}
|
|
|
|
describe('importReportFromPdf error kinds', () => {
|
|
it('no_attachment for a PDF without the attachment', async () => {
|
|
await rejectsWith(await pdfWithoutAttachment(), 'no_attachment')
|
|
})
|
|
|
|
it('attachment_stripped for a stamped archive whose attachment was removed', async () => {
|
|
await rejectsWith(
|
|
await pdfWithoutAttachment(['faunosteo-archive/1']),
|
|
'attachment_stripped',
|
|
)
|
|
})
|
|
|
|
it('invalid_pdf for an oversized file, before parsing it', async () => {
|
|
await rejectsWith(new Uint8Array(MAX_PDF_BYTES + 1), 'invalid_pdf')
|
|
})
|
|
})
|