112 lines
5.7 KiB
TypeScript
112 lines
5.7 KiB
TypeScript
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('Soft, hand-made 2D storybook illustration painted in matte gouache')).toBe(true);
|
||
expect(style).toContain('\n');
|
||
expect(style).not.toMatch(/^>/m);
|
||
expect(style.endsWith('book, illustrator or film.')).toBe(true);
|
||
});
|
||
|
||
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: 18 cards and 45 one-at-a-time prompts', () => {
|
||
expect(allPrompts).toHaveLength(18 + 45);
|
||
for (const p of allPrompts) expect(p.startsWith(style + '\n\nAsset: ')).toBe(true);
|
||
});
|
||
|
||
it('every one carries the shared avoid list, so the likeness guard is never left out', () => {
|
||
for (const p of allPrompts) expect(p).toMatch(/Must avoid: .*a glass dome or bell jar; a folding screen; a tiny round planet/);
|
||
});
|
||
|
||
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('Attach the character sheet');
|
||
for (const id of ['rose-stages-sheet', 'rose-care-sheet', 'rose-moments-sheet', 'app-icon']) {
|
||
expect(by.get(id)?.attach).toEqual(['rose-sheet']);
|
||
expect(by.get(id)?.prompt).toContain('Attach the character sheet rose-sheet as the reference picture');
|
||
}
|
||
expect(by.get('care-props-sheet')?.attach).toEqual([]);
|
||
});
|
||
|
||
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']) {
|
||
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('Attach the character sheet fox-sheet as the reference picture');
|
||
expect(p).not.toContain('rose-sheet');
|
||
}
|
||
}
|
||
for (const id of ['berries-sheet', 'berry-bush-sheet', 'paths-sheet', 'lanterns-sheet']) 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 gives each cell the numbers cellBoxes computes", () => {
|
||
const props = data.assets.find((a) => a.id === 'care-props-sheet');
|
||
expect(props?.prompt).toContain('Cut lines down the image at x = 512, 1024. Cut lines across the image at y = 512.');
|
||
expect(props?.prompt).toContain('- Cell 5, petal-folded: starts at (512, 512), ends at (1024, 1024); centre the drawing on (768, 768); safe box x 573–963, y 573–963.');
|
||
const stages = data.assets.find((a) => a.id === 'rose-stages-sheet');
|
||
expect(stages?.prompt).toContain('each 384 × 1024 px');
|
||
expect(stages?.prompt).not.toContain('Cut lines across');
|
||
});
|
||
|
||
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, fully transparent background. One subject, centred on (512, 768)');
|
||
expect(bud?.prompt).toContain('This picture: a tight bud');
|
||
});
|
||
});
|