test(tests): R4.6 session suite imports every R4 export back through the module's reader (export Rust → import Rust, no loss)
This commit is contained in:
1 parent
d492bf7112
commit
9cb3cb75d4
1 file changed
+61
-8
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* R4.6: the export session through the shipped module and the runtime wrapper
|
||||
* (`CoreExportSession`): driven request by request on the O2 runs it writes the native
|
||||
* bytes (`goldens/r4/pdf.*.sha256`); every view it asks for is the SVG the TypeScript
|
||||
* engine composes (`composeHighlightedViewSvg`) and, on the real-raster run, the digests
|
||||
* and sizes the R4.1 rasteriser recorded (`pdf/r3/real/manifest.json`); the refusals are
|
||||
* closed kinds; a trap mid-session poisons the instance and the session answers
|
||||
* `core_unavailable` from then on, `free()` included; the memory held by a fresh instance
|
||||
* after an export is printed against the file's size (OD-2, RUST.md §10.8).
|
||||
* bytes (`goldens/r4/pdf.*.sha256`), which the module's own reader imports back onto the
|
||||
* bundled sheet as the report they carry (export Rust → import Rust, no loss); every view
|
||||
* it asks for is the SVG the TypeScript engine composes (`composeHighlightedViewSvg`)
|
||||
* and, on the real-raster run, the digests and sizes the R4.1 rasteriser recorded
|
||||
* (`pdf/r3/real/manifest.json`); the refusals are closed kinds; a trap mid-session
|
||||
* poisons the instance and the session answers `core_unavailable` from then on, `free()`
|
||||
* included; the memory held by a fresh instance after an export is printed against the
|
||||
* file's size (OD-2, RUST.md §10.8).
|
||||
*/
|
||||
import { createHash } from 'node:crypto'
|
||||
import { readFileSync } from 'node:fs'
|
||||
@@ -26,6 +28,31 @@ import { readAttachedDocument } from './n-1/scanner/attachment/read'
|
||||
|
||||
const ROOT = fileURLToPath(new URL('../../../', import.meta.url))
|
||||
const FIXTURES = join(ROOT, 'apps/app/tests/fixtures')
|
||||
const SEED = join(ROOT, 'supabase/seed/anatomical-sheets/equine/draft')
|
||||
const read = (path: string) => readFileSync(path, 'utf8')
|
||||
|
||||
/** The bundled draft exactly as `apps/app/vite/sheet-bundle.ts` embeds it. */
|
||||
function draftBundle(): string {
|
||||
const manifest = JSON.parse(read(join(SEED, 'assets.json'))) as Array<{
|
||||
file: string
|
||||
sha256: string
|
||||
svg_asset_id: string
|
||||
}>
|
||||
const assets: Record<string, string> = {}
|
||||
const assetHashes: Record<string, string> = {}
|
||||
for (const asset of manifest) {
|
||||
assets[asset.svg_asset_id] = read(join(SEED, 'assets', asset.file))
|
||||
assetHashes[asset.svg_asset_id] = asset.sha256
|
||||
}
|
||||
return JSON.stringify({
|
||||
status: 'draft',
|
||||
ref: JSON.parse(read(join(SEED, 'sheet-ref.json'))),
|
||||
document: JSON.parse(read(join(SEED, 'document.json'))),
|
||||
migrationMap: JSON.parse(read(join(SEED, 'report-migration-map.json'))),
|
||||
assets,
|
||||
assetHashes,
|
||||
})
|
||||
}
|
||||
const sha256 = (data: Uint8Array | string) =>
|
||||
createHash('sha256').update(data).digest('hex')
|
||||
const ONE_PX_PNG = Buffer.from(
|
||||
@@ -51,6 +78,15 @@ interface Envelope {
|
||||
exportedAt: string
|
||||
}
|
||||
|
||||
interface ImportEnvelope {
|
||||
ok: boolean
|
||||
kind?: string
|
||||
value?: {
|
||||
read: { origin: string; snapshotRejected?: string }
|
||||
rebase: { report: unknown; rebased: boolean }
|
||||
}
|
||||
}
|
||||
|
||||
interface Run {
|
||||
name: string
|
||||
r3: string
|
||||
@@ -145,8 +181,12 @@ function drive(session: CoreExportSession, raster: Run['raster']): Driven {
|
||||
}
|
||||
|
||||
describe('R4.6 export session through the shipped module', () => {
|
||||
it('writes the native bytes on every O2 run, asking for the SVGs the engine composes', async () => {
|
||||
it('writes the native bytes on every O2 run, asking for the SVGs the engine composes; the module imports them back', async () => {
|
||||
const runtime = await nodeCoreRuntime('pkg')
|
||||
const sheet = unwrap(
|
||||
runtime.invoke((glue) => ({ ok: true as const, value: new glue.SheetHandle(draftBundle()) })),
|
||||
'sheet',
|
||||
)
|
||||
for (const run of RUNS) {
|
||||
const envelope = await envelopeOf(run.r3)
|
||||
const session = unwrap(
|
||||
@@ -165,10 +205,23 @@ describe('R4.6 export session through the shipped module', () => {
|
||||
).trim()
|
||||
expect(sha256(driven.pdf), run.name).toBe(expected)
|
||||
expect(driven.warnings, run.name).toEqual([])
|
||||
// Every view request is the TypeScript composition of that view for that observation.
|
||||
const report = run.report
|
||||
? (JSON.parse(readFileSync(join(FIXTURES, run.report), 'utf8')) as Envelope['report'])
|
||||
: envelope.report
|
||||
// Export Rust → import Rust: the module's reader gives the report back, the archive
|
||||
// kept, on the sheet the fixtures were written on (same reference: not rebased).
|
||||
const outcome = unwrap(
|
||||
runtime.invoke(() => ({
|
||||
ok: true as const,
|
||||
value: JSON.parse(sheet.import_pdf(driven.pdf)) as ImportEnvelope,
|
||||
})),
|
||||
run.name,
|
||||
)
|
||||
expect(outcome.ok, `${run.name}: ${JSON.stringify(outcome).slice(0, 200)}`).toBe(true)
|
||||
expect(outcome.value!.read.origin, run.name).toBe('envelope_v1')
|
||||
expect(outcome.value!.read.snapshotRejected, run.name).toBeUndefined()
|
||||
expect(outcome.value!.rebase.report, run.name).toEqual(report)
|
||||
// Every view request is the TypeScript composition of that view for that observation.
|
||||
let views = 0
|
||||
for (const request of driven.requests) {
|
||||
if (!request.key.startsWith('view:')) continue
|
||||
|
||||
Reference in new issue
Block a user