feat(anatomy): curation pipeline — changeset schema, applier with before/after records, cleaned single asset, draft seed, changelog + review report generators; seed layout legacy-import/curation/draft

This commit is contained in:
bchanot committed 2026-10-09 16:50:08 +02:00
1 parent 3dbbfdf1df
commit 6870d87910
58 files changed
+18167 -267

No files matched your search

+43 -16
View File
@@ -1,49 +1,76 @@
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import {
EQUINE_SEED_DIR,
DRAFT_SEED_SQL_FILE,
EQUINE_DRAFT_DIR,
EQUINE_LEGACY_IMPORT_DIR,
EQUINE_SOURCE_PATHS,
SEED_SQL_FILE,
renderArtifacts,
renderDraftArtifacts,
sha256Hex,
type AssetRecord,
type DraftResult,
} from '../src'
import { REPO_ROOT, runImport } from './helpers'
import { REPO_ROOT, runDraft } from './helpers'
const seedDir = join(REPO_ROOT, EQUINE_SEED_DIR)
let artifacts: Record<string, string>
const legacyDir = join(REPO_ROOT, EQUINE_LEGACY_IMPORT_DIR)
const draftDir = join(REPO_ROOT, EQUINE_DRAFT_DIR)
let legacy: Record<string, string>
let draftFiles: Record<string, string>
let draft: DraftResult
beforeAll(async () => {
artifacts = await renderArtifacts(await runImport())
const run = await runDraft()
draft = run.draft
legacy = await renderArtifacts(run.result)
draftFiles = await renderDraftArtifacts(run.draft, run.result.anomalies)
})
describe('committed equine seed (golden)', () => {
describe('committed legacy-import folder (golden)', () => {
it.each([
'document.json',
'legacy-id-map.json',
'assets.json',
SEED_SQL_FILE,
'IMPORT-REPORT.md',
])('%s equals a fresh run (rerun pnpm import:equine)', async (file) => {
const committed = await readFile(join(seedDir, file), 'utf8')
expect(committed).toBe(artifacts[file])
expect(await readFile(join(legacyDir, file), 'utf8')).toBe(legacy[file])
})
it('carries no SQL: the draft folder holds the only seed', () => {
expect(Object.keys(legacy).some((file) => file.endsWith('.sql'))).toBe(
false,
)
})
it('copies the SVG assets byte for byte with the recorded sha256', async () => {
const assets = JSON.parse(artifacts['assets.json']!) as AssetRecord[]
const assets = JSON.parse(legacy['assets.json']!) as AssetRecord[]
const sources = [EQUINE_SOURCE_PATHS.mainSvg, EQUINE_SOURCE_PATHS.headSvg]
for (const [index, asset] of assets.entries()) {
const copy = await readFile(join(seedDir, 'assets', asset.file))
const copy = await readFile(join(legacyDir, 'assets', asset.file))
const original = await readFile(join(REPO_ROOT, sources[index]!))
expect(copy.equals(original)).toBe(true)
expect(sha256Hex(copy)).toBe(asset.sha256)
expect(copy.byteLength).toBe(asset.byte_size)
}
})
})
it('seeds a draft and never publishes', () => {
const sql = artifacts[SEED_SQL_FILE]!
expect(sql).toContain('private.insert_sheet_draft')
expect(sql).not.toContain('publish_sheet_version')
describe('committed draft folder (golden)', () => {
it.each([
'document.json',
'assets.json',
'CHANGELOG.md',
'REVIEW-REPORT.md',
DRAFT_SEED_SQL_FILE,
])('%s equals a fresh run (rerun pnpm import:equine)', async (file) => {
expect(await readFile(join(draftDir, file), 'utf8')).toBe(draftFiles[file])
})
it('holds the cleaned drawing with the recorded sha256', async () => {
const [asset] = draft.assets
const bytes = await readFile(join(draftDir, 'assets', asset!.file))
expect(bytes.toString('utf8')).toBe(draft.cleanedSvg)
expect(sha256Hex(bytes)).toBe(asset!.sha256)
expect(bytes.byteLength).toBe(asset!.byte_size)
})
})