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

@@ -0,0 +1,77 @@
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import {
ChangesetSchema,
EQUINE_CURATION_DIR,
ReferencesFileSchema,
needsConfirmation,
} from '../src'
import { REPO_ROOT } from './helpers'
async function committed(file: string): Promise<unknown> {
return JSON.parse(
await readFile(join(REPO_ROOT, EQUINE_CURATION_DIR, file), 'utf8'),
)
}
const CHANGE = {
id: 'CHG-002',
level: 'B',
kind: 'terminology',
title: { fr: 'Titre', en: 'Title' },
rationale: 'Raison',
reference_ids: [],
ops: [{ op: 'remove', target: 'zone:x' }],
}
describe('curation schemas', () => {
it('parse the committed curation files', async () => {
const changeset = ChangesetSchema.parse(await committed('changes.json'))
expect(changeset.changes.map((c) => [c.id, c.priority])).toEqual([
['CHG-001', 'medium'],
])
const refs = ReferencesFileSchema.parse(await committed('references.json'))
expect(refs.references.map((r) => r.id)).toEqual(['legacy-catalog'])
})
it.each([
[
'an unknown op',
{ ...CHANGE, ops: [{ op: 'replace', target: 'zone:x' }] },
],
['a level C change without question', { ...CHANGE, level: 'C' }],
['a bad change id', { ...CHANGE, id: 'CHANGE-1' }],
['a change without ops', { ...CHANGE, ops: [] }],
['an unknown key', { ...CHANGE, needs_confirmation: true }],
])('rejects %s', (_label, change) => {
expect(ChangesetSchema.safeParse({ changes: [change] }).success).toBe(false)
})
it('accepts a level C change with its question', () => {
const change = {
...CHANGE,
level: 'C',
question: 'Faut-il ?',
priority: 'high',
}
expect(ChangesetSchema.safeParse({ changes: [change] }).success).toBe(true)
})
it('rejects duplicate change ids and duplicate reference ids', () => {
expect(
ChangesetSchema.safeParse({ changes: [CHANGE, CHANGE] }).success,
).toBe(false)
const ref = { id: 'a', type: 'web', citation: 'A', url: null, doi: null }
expect(
ReferencesFileSchema.safeParse({ references: [ref, ref] }).success,
).toBe(false)
})
it('derives needs_confirmation from the level', () => {
expect(['A', 'B', 'C'].map((l) => needsConfirmation(l as 'A'))).toEqual([
false,
true,
true,
])
})
})