GEN-1: expose CATALOG seed view (Name/CanonicalGenotype/SortOrder) for DATA-2 + round-trip test

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-05 23:47:11 +02:00
parent 3cf6413fcc
commit 3629e89e87
3 changed files with 65 additions and 4 deletions

View File

@@ -17,7 +17,14 @@ import {
wildType,
} from '../genotype'
import { combineLocus } from '../punnett'
import { farbschlagFor, genotypeToFarbschlag, CATALOG_SIZE } from '../catalog'
import {
farbschlagFor,
genotypeToFarbschlag,
representativeGenotype,
BASE_COLORS,
CATALOG,
CATALOG_SIZE,
} from '../catalog'
import { breed } from '../breed'
import { GeneticsWarningCode } from '../warnings'
@@ -170,6 +177,22 @@ describe('Farbschlag catalog', () => {
expect(CATALOG_SIZE).toBe(18)
})
it('every catalog entry round-trips: its representative genotype maps back to its own name', () => {
// Guards the DB seed (DATA-2): a representative genotype that resolved to a
// DIFFERENT (earlier) variety would mean overlapping/mis-ordered patterns.
for (const entry of BASE_COLORS) {
expect(genotypeToFarbschlag(representativeGenotype(entry))).toBe(entry.name)
}
})
it('CATALOG seed view mirrors the ColorVariety table shape', () => {
expect(CATALOG).toHaveLength(CATALOG_SIZE)
expect(CATALOG[0]).toMatchObject({ name: 'Pink Eyed White (PEW)', sortOrder: 0 })
// Every row has a non-empty canonical genotype display string and unique name.
expect(new Set(CATALOG.map((c) => c.name)).size).toBe(CATALOG.length)
expect(CATALOG.every((c) => /^[A-Za-z?]+( [A-Za-z?]+){7}$/.test(c.canonicalGenotype))).toBe(true)
})
it('genotypeToFarbschlag (DATA-1 denormalization contract) returns the plain name', () => {
expect(genotypeToFarbschlag(wildType())).toBe('Agouti')
expect(genotypeToFarbschlag(fromDisplayString('aa CC DD EE GG pp spsp rere'))).toBe('Platin')

View File

@@ -14,8 +14,8 @@
* - rennmaus-info.jimdoweb.com (loci & colourpoint series)
* - clan-of-topolino.ch, rennmauswelten.jimdofree.com (Zobel, Schimmel)
*/
import type { LocusKey } from './loci'
import type { Genotype } from './genotype'
import { LOCUS_ORDER, type LocusKey } from './loci'
import { makeGenotype, toDisplayString, wildType, type AllelePair, type Genotype } from './genotype'
import { phenotypeTokens, type PhenotypeTokens } from './phenotype'
export interface FarbschlagEntry {
@@ -105,5 +105,41 @@ export function genotypeToFarbschlag(g: Genotype): string {
return farbschlagFor(g).name
}
/**
* A representative full genotype for a catalog entry: each specified locus is
* homozygous for its token allele; unspecified loci take the wild-type allele.
* This is the entry's CanonicalGenotype for DB seeding.
*/
export function representativeGenotype(entry: FarbschlagEntry): Genotype {
const base = wildType()
const out = {} as Record<LocusKey, AllelePair>
for (const locus of LOCUS_ORDER) {
const token = entry.tokens[locus]
out[locus] = token ? [token, token] : base[locus]
}
return makeGenotype(out)
}
/**
* DB seed view for DATA-2's ColorVariety table. Each row mirrors the table
* shape (Name, CanonicalGenotype, SortOrder). SortOrder = catalog position.
*
* IMPORTANT: `name` values become DB keys the UI filters on — renames are
* BREAKING changes and must be routed through god. Adding new varieties is safe.
*/
export interface ColorVarietySeed {
readonly name: string
readonly english?: string
readonly canonicalGenotype: string
readonly sortOrder: number
}
export const CATALOG: readonly ColorVarietySeed[] = BASE_COLORS.map((entry, i) => ({
name: entry.name,
english: entry.english,
canonicalGenotype: toDisplayString(representativeGenotype(entry)),
sortOrder: i,
}))
/** Number of base-colour varieties currently catalogued. */
export const CATALOG_SIZE = BASE_COLORS.length

View File

@@ -33,11 +33,13 @@ export type { PhenotypeTokens } from './phenotype'
export {
farbschlagFor,
genotypeToFarbschlag,
representativeGenotype,
BASE_COLORS,
CATALOG,
CATALOG_SIZE,
UNKNOWN_FARBSCHLAG,
} from './catalog'
export type { FarbschlagEntry, FarbschlagMatch } from './catalog'
export type { FarbschlagEntry, FarbschlagMatch, ColorVarietySeed } from './catalog'
export { GeneticsWarningCode } from './warnings'
export type { GeneticsWarning } from './warnings'