59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { resolve } from 'node:path'
|
|
import type { Report } from '@faunosteo/core-wasm/types'
|
|
import { importAttachment } from './pdfImport'
|
|
import type { SheetIndex } from '@/services/sheetIndex'
|
|
import { FIXTURES_DIR } from './goldens'
|
|
import {
|
|
leavesAsV2Report,
|
|
legacyLeaves,
|
|
loadLegacyBaseline,
|
|
} from './legacyLeaves'
|
|
|
|
/**
|
|
* The three reports the Step 6 goldens and the R2 envelope freeze are drawn
|
|
* from: the Step 5 v2 archive fixture migrated, the v3 demo report, and a v2
|
|
* report whose sphenoid and ssb findings the migration cannot place. Since
|
|
* R2 they are read the way the application reads an attachment: the core's
|
|
* layered reading (v3 parsed, v2 migrated through the sheet's map).
|
|
*/
|
|
|
|
export const GOLDEN_REPORTS = ['v2full', 'demo', 'v2unresolved'] as const
|
|
export type GoldenReportName = (typeof GOLDEN_REPORTS)[number]
|
|
|
|
export interface GoldenReports {
|
|
reports: Record<GoldenReportName, Report>
|
|
/** Findings the migration flagged in `v2unresolved`. */
|
|
unresolvedOfV2Unresolved: number
|
|
}
|
|
|
|
const readJson = (name: string): unknown =>
|
|
JSON.parse(readFileSync(resolve(FIXTURES_DIR, name), 'utf8'))
|
|
|
|
/** sphenoid + ssb (the families the migration cannot place) plus one leaf that resolves. */
|
|
function buildV2Unresolved(sheet: SheetIndex) {
|
|
const leaves = legacyLeaves(loadLegacyBaseline())
|
|
const unresolvedFamilies = leaves.filter(
|
|
(l) => l.zoneId === 'sphenoid' || l.zoneId === 'ssb',
|
|
)
|
|
const resolved = leaves.find((l) => l.zoneId === 'frontal')!
|
|
return importAttachment(
|
|
leavesAsV2Report([...unresolvedFamilies, resolved]),
|
|
sheet,
|
|
).read
|
|
}
|
|
|
|
export function buildGoldenReports(sheet: SheetIndex): GoldenReports {
|
|
const v2unresolved = buildV2Unresolved(sheet)
|
|
return {
|
|
reports: {
|
|
v2full: importAttachment(readJson('report-v2.full.json'), sheet).read
|
|
.report,
|
|
demo: importAttachment(readJson('report-v3.demo.json'), sheet).read
|
|
.report,
|
|
v2unresolved: v2unresolved.report,
|
|
},
|
|
unresolvedOfV2Unresolved: v2unresolved.unresolvedFindings,
|
|
}
|
|
}
|