Files
Rosea/tools/art-prep/test/prompt.test.ts
T
mnovak f24597dfdb [art-prep] ArtBoard: Build prompts, stand-ins and the art board from the manifest, and accept pictures into art/final
tools/art-prep reads art/STYLE.md (draft) and art/manifest.json (25 Phase 1
pictures), refuses forbidden words in any prompt, writes 29 stand-ins and the
board files, and cuts and encodes accepted pictures as WebP within budget.
2026-11-01 20:16:59 +01:00

97 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 eight review points, a point split over two lines read as one', () => {
const points = reviewPoints(readStyle());
expect(points).toHaveLength(8);
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: 11 cards and 18 one-at-a-time prompts', () => {
expect(allPrompts).toHaveLength(11 + 18);
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 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');
});
});