feat(schema): add findings tree + parse species JSON via Zod

Replaces the flat Pathology[] model with a hierarchical SpeciesFindings
tree (zones → categories → nested children → leaves) authored as JSON and
validated at boot. Equine catalog JSON is now wired through
SpeciesFindingsSchema.parse() so malformed data fails loudly instead of
corrupting an observation later.

Species manifest swaps `pathologies` loader for `findings`. JSON species
id renamed equin → equine to match the registry. Old equine pathology
test deleted; new findings test covers parse + FR/EN label coverage +
zone/category/leaf structure.

Foundational step of the v2 domain pivot; callers in observation/store/
UI/PDF migrated in follow-up commits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-20 03:48:43 +02:00
1 parent 31be3155ef
commit f80e161d61
7 files changed
+135 -52

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import { describe, it, expect } from 'vitest'
import EQUINE_FINDINGS from '@/domain/species/equine/pathologies'
import {
SpeciesFindingsSchema,
type FindingNode,
} from '@/domain/schema/findings'
function walkLeaves(node: FindingNode, fn: (leaf: FindingNode) => void): void {
if (!node.children || node.children.length === 0) {
fn(node)
return
}
for (const child of node.children) walkLeaves(child, fn)
}
describe('equine findings tree', () => {
it('parses against SpeciesFindingsSchema', () => {
expect(() => SpeciesFindingsSchema.parse(EQUINE_FINDINGS)).not.toThrow()
})
it('species id matches the registry id', () => {
expect(EQUINE_FINDINGS.species.id).toBe('equine')
})
it('scope_disclaimer is non-empty', () => {
expect(EQUINE_FINDINGS.scope_disclaimer.length).toBeGreaterThan(0)
})
it('has at least one zone with at least one category with at least one leaf', () => {
const zoneIds = Object.keys(EQUINE_FINDINGS.zones)
expect(zoneIds.length).toBeGreaterThanOrEqual(1)
const someZone = EQUINE_FINDINGS.zones[zoneIds[0]]
expect(someZone.categories.length).toBeGreaterThanOrEqual(1)
let leafCount = 0
walkLeaves(someZone.categories[0], () => {
leafCount += 1
})
expect(leafCount).toBeGreaterThanOrEqual(1)
})
it('every leaf carries both FR and EN labels', () => {
const missing: string[] = []
for (const zone of Object.values(EQUINE_FINDINGS.zones)) {
for (const category of zone.categories) {
walkLeaves(category, (leaf) => {
if (!leaf.name_fr || !leaf.name_en) missing.push(leaf.id)
})
}
}
expect(missing).toEqual([])
})
})
@@ -1,39 +0,0 @@
import { describe, it, expect } from 'vitest'
import { PathologySchema } from '@/domain/schema/pathology'
import EQUINE_PATHOLOGIES from '@/domain/species/equine/pathologies'
describe('equine pathologies database', () => {
it('has between 0 and 100 entries (empty allowed for v1)', () => {
expect(EQUINE_PATHOLOGIES.length).toBeGreaterThanOrEqual(0)
expect(EQUINE_PATHOLOGIES.length).toBeLessThanOrEqual(100)
})
it('every entry parses against the schema', () => {
for (const p of EQUINE_PATHOLOGIES) {
const r = PathologySchema.safeParse(p)
if (!r.success) throw new Error(`${p.id}: ${r.error.message}`)
}
})
it('every entry has at least one source', () => {
for (const p of EQUINE_PATHOLOGIES) {
expect(p.sources.length).toBeGreaterThanOrEqual(1)
}
})
it('every entry is tagged for equine when species-scoped', () => {
for (const p of EQUINE_PATHOLOGIES) {
if (p.speciesIds.length > 0) {
expect(p.speciesIds).toContain('equine')
}
}
})
it('every entry has a unique id', () => {
const ids = new Set<string>()
for (const p of EQUINE_PATHOLOGIES) {
expect(ids.has(p.id)).toBe(false)
ids.add(p.id)
}
})
})