import { describe, expect, it } from 'vitest'; import { findForbidden } from '@rosea/content'; import { boardData } from '../src/board.js'; import { cellBoxes, cutLines, soloCanvas } from '../src/prompt.js'; import { reviewPoints, stylePrompt } from '../src/style.js'; import { clone, readManifest, readStyle } from './fixtures.js'; const style = stylePrompt(readStyle()); const data = boardData(readManifest(), readStyle()); const allPrompts = data.assets.flatMap((a) => [a.prompt, ...(a.cells ?? []).map((c) => c.prompt)]); describe('STYLE.md', () => { it('§1 is the quoted system prompt, line breaks kept and the markers gone', () => { expect(style.startsWith('A hand-painted picture in opaque, matte gouache on warm off-white paper')).toBe(true); expect(style).toContain('\n'); expect(style).not.toMatch(/^>/m); expect(style.endsWith('in the manner of no existing artist, book or film.')).toBe(true); }); it('§1 says the look positively and asks for grown-ups, not a sticker (the 2026-11-07 rewrite)', () => { for (const words of ['dry-brush', 'paper showing through', 'plum-brown', 'from the left', 'for grown-ups', 'never a children\'s sticker', 'painted directly on them', 'Not watercolour']) { expect(style.replace(/\n/g, ' ')).toContain(words); } }); it('§7 has the ten review points, a point split over two lines read as one', () => { const points = reviewPoints(readStyle()); expect(points).toHaveLength(10); expect(points[8]).toBe("It reads as one young red-orange fox with a cream mask and a ringed tail, shy and gentle, and nothing like the book's sandy, long-eared fox."); expect(points[3]).toBe('Nothing from the book: no glass dome, screen, tiny planet, desert, child or scarf, and no look of its drawings.'); }); it('says so when a section is missing, instead of building prompts without a style', () => { expect(() => stylePrompt('# STYLE\n\n## 2. Palette\n')).toThrow(/no "## 1\." section/); expect(() => reviewPoints('## 7. Review points\n\nNone yet.\n')).toThrow(/no review points/); }); }); describe('the prompts', () => { it('every one starts with STYLE.md §1 word for word, then says what to make: 35 cards and 66 one-at-a-time prompts', () => { expect(allPrompts).toHaveLength(35 + 66); for (const p of allPrompts) expect(p.startsWith(style + '\n\nMake: ')).toBe(true); }); it('every one ends with the shared avoid list and its board id', () => { const shared = readManifest().avoid.join('; '); for (const a of data.assets) { expect(a.prompt).toContain(shared); expect(a.prompt.endsWith(`\nBoard id: ${a.id}`)).toBe(true); for (const c of a.cells ?? []) expect(c.prompt.endsWith(`\nBoard id: ${c.id} (one picture of ${a.id})`)).toBe(true); } }); it("never names the book's motifs, even to forbid them: naming one invites it; review checks them instead", () => { const motifs = /glass dome|bell jar|folding screen|tiny round planet|scarf|desert|golden hair|wheat/i; for (const p of allPrompts) expect(p).not.toMatch(motifs); expect(data.checklist[3]).toMatch(/glass dome, screen, tiny planet, desert, child or scarf/); }); it('carries no pixel coordinates a generator cannot use; the grid is said in words', () => { for (const p of allPrompts) expect(p).not.toMatch(/starts at \(|safe box|Cut lines|centre the drawing on/); }); it('none names the book, Tolkien, or a medical or unnamed word', () => { for (const p of allPrompts) expect(findForbidden(p)).toEqual([]); }); it('a rose picture asks for the rose sheet as its reference; the sheet itself does not', () => { const by = new Map(data.assets.map((a) => [a.id, a])); expect(by.get('rose-sheet')?.attach).toEqual([]); expect(by.get('rose-sheet')?.prompt).not.toContain('Reference:'); for (const id of ['rose-stages-sheet', 'rose-care-sheet', 'rose-moments-sheet', 'rose-touch-sheet', 'app-icon', 'app-icon-maskable']) { expect(by.get(id)?.attach).toEqual(['rose-sheet']); expect(by.get(id)?.prompt).toContain('Reference: attach the image rose-sheet'); } for (const id of ['care-props-sheet', 'favicon-mark', 'letter-header']) expect(by.get(id)?.attach).toEqual([]); }); it('every rose prompt puts her face on the petals, never on a round head', () => { for (const a of data.assets.filter((x) => x.attach.includes('rose-sheet') || x.id === 'rose-sheet')) { for (const p of [a.prompt, ...(a.cells ?? []).map((c) => c.prompt)]) { expect(p).toContain('Her face is painted directly on the inner petals'); expect(p).toContain('There is no round face, ball or bare patch inside the petals'); } } }); it('a fox picture asks for the fox sheet, never the rose sheet, and every one-at-a-time fox prompt does too', () => { const by = new Map(data.assets.map((a) => [a.id, a])); expect(by.get('fox-sheet')?.attach).toEqual([]); for (const id of ['fox-trust-sheet', 'fox-moments-sheet', 'foxes-meeting']) { const a = by.get(id); expect(a?.attach).toEqual(['fox-sheet']); for (const p of [a?.prompt ?? '', ...(a?.cells ?? []).map((c) => c.prompt)]) { expect(p).toContain('Reference: attach the image fox-sheet'); expect(p).not.toContain('rose-sheet'); } } for (const id of ['berries-sheet', 'berry-bush-sheet', 'paths-sheet', 'lanterns-sheet', 'visitors-sheet', 'planet-king']) expect(by.get(id)?.attach).toEqual([]); }); it('a manifest with a forbidden name never reaches the board', () => { const m = clone(readManifest()); (m.assets[1] as { purpose: string }).purpose = 'In the style of Saint-Exupéry'; expect(() => boardData(m, readStyle())).toThrow(/Saint-Exupéry/); }); }); describe('the grid', () => { it('cuts are rounded once and include both edges', () => { expect(cutLines(1536, 4)).toEqual([0, 384, 768, 1152, 1536]); expect(cutLines(1000, 3)).toEqual([0, 333, 667, 1000]); }); it('every safe box lies inside its cell, 12 % of the shorter side clear', () => { for (const b of cellBoxes(1536, 1024, 3, 2)) { expect(b.safe.x0 - b.x0).toBe(61); expect(b.x1 - b.safe.x1).toBe(61); expect(b.safe.y0).toBeGreaterThan(b.y0); expect(b.safe.y1).toBeLessThan(b.y1); } }); it("a sheet's prompt says its grid in words and lists its pictures in reading order", () => { const props = data.assets.find((a) => a.id === 'care-props-sheet'); expect(props?.prompt).toContain('Layout: 3 columns × 2 rows of equal, invisible cells, read left to right, top row first.'); expect(props?.prompt).toContain('\n5. one large rose petal folded over itself'); const stages = data.assets.find((a) => a.id === 'rose-stages-sheet'); expect(stages?.prompt).toContain('Layout: 4 columns × 1 row of equal'); }); it('a tall cell made on its own is made on the tall canvas, a square one on the square', () => { const m = readManifest(); expect(soloCanvas(m.assets.find((a) => a.id === 'rose-stages-sheet')!)).toEqual({ width: 1024, height: 1536 }); expect(soloCanvas(m.assets.find((a) => a.id === 'care-props-sheet')!)).toEqual({ width: 1024, height: 1024 }); const bud = data.assets.find((a) => a.id === 'rose-stages-sheet')?.cells?.[0]; expect(bud?.prompt).toContain('Canvas: 1024 × 1536 px, transparent background. One subject, whole and centred'); expect(bud?.prompt).toContain('Subject: a tight bud'); }); });