f24597dfdb
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.
62 lines
3.0 KiB
TypeScript
62 lines
3.0 KiB
TypeScript
import { readFileSync, readdirSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { boardData } from '../src/board.js';
|
|
import { placeholders } from '../src/placeholders.js';
|
|
import { readManifest, readStyle, root } from './fixtures.js';
|
|
|
|
const manifest = readManifest();
|
|
const data = boardData(manifest, readStyle());
|
|
const stand = placeholders(manifest);
|
|
const page = readFileSync(`${root}tools/art-prep/board/index.html`, 'utf8');
|
|
|
|
describe('the board data', () => {
|
|
it('has the shape the board page reads', () => {
|
|
for (const a of data.assets) {
|
|
expect(a).toMatchObject({ id: expect.any(String), width: expect.any(Number), height: expect.any(Number), prompt: expect.any(String) });
|
|
expect(Array.isArray(a.usedBy) && Array.isArray(a.checks) && Array.isArray(a.attach)).toBe(true);
|
|
if (a.type === 'spritesheet') {
|
|
expect(a.cells).toHaveLength((a.grid?.cols ?? 0) * (a.grid?.rows ?? 0));
|
|
for (const c of a.cells ?? []) expect(c).toMatchObject({ id: expect.any(String), width: expect.any(Number), height: expect.any(Number), prompt: expect.any(String) });
|
|
}
|
|
}
|
|
expect(data.checklist).toHaveLength(8);
|
|
});
|
|
|
|
it('every kind in the manifest has a group on the board page, or its cards would never show', () => {
|
|
for (const type of new Set(data.assets.map((a) => a.type))) expect(page).toContain(`{ type: '${type}',`);
|
|
});
|
|
|
|
it('the page takes the product name from @rosea/schema, never spells it', () => {
|
|
expect(page).toContain('<title>%PRODUCT_NAME% Art Board</title>');
|
|
expect(page).not.toMatch(/Rosea Domi/);
|
|
});
|
|
|
|
it("shows Claude's review and the move into art/final/ when Claude writes them into a row", () => {
|
|
expect(page).toMatch(/r\.claude \? `Claude's review: \$\{r\.claude\}`/);
|
|
expect(page).toMatch(/r\.final \? `In art\/final\/:/);
|
|
});
|
|
});
|
|
|
|
describe('the stand-ins', () => {
|
|
it('one for every picture and every cell, at its own size', () => {
|
|
const ids = manifest.assets.flatMap((a) => [a.id, ...(a.cells ?? []).map((c) => c.id)]);
|
|
expect([...stand.keys()].sort()).toEqual([...ids].sort());
|
|
for (const a of manifest.assets) expect(stand.get(a.id)).toContain(`viewBox="0 0 ${a.width} ${a.height}"`);
|
|
expect(stand.get('rose-bud')).toContain('viewBox="0 0 384 1024"');
|
|
expect(stand.get('watering-can')).toContain('viewBox="0 0 512 512"');
|
|
});
|
|
|
|
it('load nothing from anywhere', () => {
|
|
for (const svg of stand.values()) {
|
|
expect(svg.replace('xmlns="http://www.w3.org/2000/svg"', '')).not.toMatch(/https?:|href=|<image|<script/);
|
|
}
|
|
});
|
|
|
|
it('art/placeholders/ holds exactly what the generator makes (run pnpm art:board after changing the manifest)', () => {
|
|
const dir = `${root}art/placeholders/`;
|
|
const files = readdirSync(dir).filter((f) => f.endsWith('.svg'));
|
|
expect(files.map((f) => f.slice(0, -4)).sort()).toEqual([...stand.keys()].sort());
|
|
for (const [id, svg] of stand) expect(readFileSync(`${dir}${id}.svg`, 'utf8').replace(/\r\n/g, '\n')).toBe(svg);
|
|
});
|
|
});
|