// Run the public interfaces in throwaway projects. A rejected call must identify the problem // and its recovery route on the documented stream, and preserve every existing file and directory. import assert from 'node:assert/strict'; import { runCLI as run, rejectedPreview, mcpRequest } from './check-cli.mjs'; import { createHash } from 'node:crypto'; import { chmod, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, writeFile } from 'node:fs/promises'; import os from 'node:os'; import { createBundle } from '../src/export.js'; import { encodePNG } from '../src/png.js'; import path from 'node:path'; const root = await mkdtemp(path.join(await realpath(os.tmpdir()), 'pixelbolt-failures-')); const failures = []; let cases = 0; async function snapshot(dir, prefix = '') { const result = []; const entries = await readdir(path.join(dir, prefix), { withFileTypes: true }); for (const entry of entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) { const relative = prefix ? prefix + '/' + entry.name : entry.name, file = path.join(dir, relative); if (entry.isDirectory()) { result.push([relative, 'directory'], ...await snapshot(dir, relative)); } else if (entry.isSymbolicLink()) { result.push([relative, 'link', await readlink(file)]); } else { result.push([relative, 'file', createHash('sha256').update(await readFile(file)).digest('hex')]); } } return result; } async function check(label, attempt, prepare) { const cwd = await mkdtemp(path.join(root, 'project-')); await mkdir(path.join(cwd, 'assets', 'empty'), { recursive: true }); await writeFile(path.join(cwd, 'assets', 'original.bin'), Buffer.from([0, 255, 13, 10, 0])); if (prepare) await prepare(cwd); const before = await snapshot(cwd), delivered = new Set(); cases++; try { try { await attempt(cwd, delivered); } finally { // Only explicitly verified new files from a documented partial success may differ. const after = await snapshot(cwd); for (const file of delivered) assert.ok(after.some(([name]) => name === file), file + ' was not delivered'); assert.deepEqual(after.filter(([name]) => !delivered.has(name)), before, label + ' changed the project'); } } catch (error) { failures.push(label + '\n' + error.message); } } // An elevated account can write a POSIX file marked 0444. It still exercises a refused destination. async function withReadOnly(file, denied, elevated) { await chmod(file, 0o444); try { try { await (await open(file, 'r+')).close(); } catch (error) { if (!['EACCES', 'EPERM', 'EROFS'].includes(error.code)) throw error; return await denied(); } return await elevated(); } finally { await chmod(file, 0o644); } } async function preparePatch(cwd) { const sprite = { version: 1, name: 'dot', width: 2, height: 2, palette: { a: '#abcdef' }, frames: [{ name: 'on', ops: [{ op: 'fill', color: 'a' }] }] }; await writeFile(path.join(cwd, 'sprite.json'), JSON.stringify(sprite)); await writeFile(path.join(cwd, 'edits.json'), JSON.stringify([{ paint: 'frames[on]', value: [{ x: 0, y: 0, color: 'transparent' }] }])); await writeFile(path.join(cwd, 'diff.png'), 'previous diff'); await mkdir(path.join(cwd, 'diff-folder.png')); } async function cliFailure(args, cwd, ...details) { const { status, stdout, stderr } = args[0] === 'preview' ? await rejectedPreview(args, cwd) : run(args, cwd); assert.equal(status, 1, args.join(' ') + ' should fail'); assert.equal(stdout, '', 'failure belongs on stderr'); const reply = JSON.parse(stderr); assert.equal(reply.ok, false); for (const pattern of details) assert.match(reply.error, pattern); return reply; } function toolFailure(name, args, cwd, ...details) { const reply = mcpRequest('tools/call', { name, arguments: args }, cwd); assert.equal(reply.error, undefined, JSON.stringify(reply.error)); assert.equal(reply.result?.isError, true, name + ' should return a tool error'); const content = reply.result.content; assert.equal(content.length, 1); assert.equal(content[0].type, 'text'); const problem = JSON.parse(content[0].text); for (const pattern of details) assert.match(problem.error, pattern); return problem; } try { const help = run(['help'], root); assert.equal(help.status, 0, help.stderr); const commands = new Set([...help.stdout.matchAll(/^ pixelbolt ([a-z][a-z-]*)\b/gm)].map(match => match[1])); assert.ok(commands.has('help') && commands.has('render') && commands.has('mcp')); for (const command of commands) { await check('unknown option on ' + command, async cwd => { const reply = await cliFailure([command, '--unknown-option'], cwd, /--unknown-option/); if (command === 'help') assert.match(reply.error, /topics:/); else assert.ok(reply.error.includes('pixelbolt ' + command + ' --help'), reply.error); }); } await check('missing value for --out', cwd => cliFailure(['render', 'input.json', '--out'], cwd, /--out requires a value/, /pixelbolt render --help/)); await check('unquoted input name', cwd => cliFailure(['render', 'my', 'art.json', '--out', 'sprites'], cwd, /art\.json/, /quote/i, /pixelbolt render --help/)); const missingInputs = [ ['validate', 'absent.json'], ['inspect', 'absent.json', '--out', 'sheet.png'], ['render', 'absent.json', '--out', 'sprites'], ['patch', 'absent.json', '--changes', 'changes.json', '--out', 'next.json'], ['overlay', 'absent.json', '--changes', 'changes.json', '--out', 'overlay.json'], ['compile', 'absent.json', '--out', 'next.json'], ['autotile', 'absent.json', '--out', 'tiles.json'], ['gif', 'absent.json', '--out', 'preview.gif'], ['sequence', 'absent.json', '--fps', '12', '--out', 'frames'], ['share', 'absent.json'], ['preview', 'absent.json'], ['import', 'absent.png', '--out', 'sprite.json'], ['import', 'absent.png', '--embedded', '--out', 'sprite.json'], ['scene', 'absent.json', '--image', 'view.png'], ['scene', 'absent.json', '--out', 'room'] ]; for (const args of missingInputs) { await check('missing input for ' + args.join(' '), async cwd => { const reply = await cliFailure(args, cwd, /absent\.(json|png)/, /existing file/i, /working directory/i); assert.equal(reply.path, path.join(cwd, args[1])); }, cwd => writeFile(path.join(cwd, 'changes.json'), '[]')); } for (const args of missingInputs.filter(args => args[1].endsWith('.json'))) { await check('malformed primary JSON for ' + args.join(' '), cwd => { return cliFailure(args, cwd, /absent\.json/, /not JSON/, /recipe or source file/); }, cwd => writeFile(path.join(cwd, args[1]), '{invalid')); } for (const command of ['patch', 'overlay']) { await check('malformed --changes for ' + command, async cwd => { const reply = await cliFailure([command, 'sprite.json', '--changes', 'edits.json', '--out', 'new.json'], cwd, /--changes/, /edits\.json/, /JSON list of edits/); if (command === 'patch') assert.match(reply.error, /correction overlay/); }, async cwd => { await writeFile(path.join(cwd, 'sprite.json'), await readFile(new URL('../examples/coin.json', import.meta.url))); await writeFile(path.join(cwd, 'edits.json'), '[?]'); }); } await check('failed forced in-place patch', cwd => { const longImage = path.join('new', 'diffs', 'x'.repeat(280) + '.png'); return cliFailure(['patch', 'sprite.json', '--changes', 'edits.json', '--out', 'sprite.json', '--image', longImage, '--force'], cwd, /--image/, /too long/, /shorter|choose/i); }, preparePatch); await check('read-only image for a forced in-place patch', async cwd => { const image = path.join(cwd, 'diff.png'); const args = ['patch', 'sprite.json', '--changes', 'edits.json', '--out', 'sprite.json', '--force', '--image']; await withReadOnly(image, () => cliFailure([...args, 'diff.png'], cwd, /--image/, /diff\.png/, /permission|read-only/, /writable|choose/i), () => cliFailure([...args, 'diff-folder.png'], cwd, /--image/, /folder/)); }, preparePatch); for (const target of ['readonly', 'directory']) { await check('failed replacement of sequence manifest (' + target + ')', async cwd => { const manifest = path.join(cwd, 'frames', 'sequence.json'); const args = ['sequence', 'sprite.json', '--fps', '10', '--out', 'frames', '--force']; if (target === 'directory') { return cliFailure(args, cwd, /sequence\.json/, /folder/, /choose|writable/i); } await withReadOnly(manifest, () => cliFailure(args, cwd, /sequence\.json/, /permission|read-only/i, /choose|writable/i), () => cliFailure([...args.slice(0, -2), 'assets/original.bin/frames', '--force'], cwd, /original\.bin/, /choose|folder/i)); }, async cwd => { await preparePatch(cwd); const initial = run(['sequence', 'sprite.json', '--fps', '10', '--out', 'frames'], cwd); assert.equal(initial.status, 0, initial.stderr); const source = path.join(cwd, 'sprite.json'), recipe = JSON.parse(await readFile(source, 'utf8')); recipe.frames.push({ name: 'off', duration: 100 }); await writeFile(source, JSON.stringify(recipe)); if (target === 'directory') { const manifest = path.join(cwd, 'frames', 'sequence.json'); await rm(manifest); await mkdir(manifest); } }); } const project = JSON.parse(await readFile(new URL('../examples/coin.json', import.meta.url), 'utf8')); const png = encodePNG(new Uint8Array([16, 32, 64, 255]), 1, 1); const scene = { format: 'pixelforge-scene', version: 1, name: 'room', width: 16, height: 16, assets: { coin: project }, instances: [{ asset: 'coin', at: [0, 0] }] }; const storageCalls = { pixel_validate: { project }, pixel_inspect: { project }, pixel_render: { project }, pixel_patch: { project, changes: [{ set: 'frames[turn-0].duration', value: 200 }] }, pixel_compile: { preset: 'coin' }, pixel_scene: { scene, export: true }, pixel_import: { data: Buffer.from(png).toString('base64') } }; for (const [name, args] of Object.entries(storageCalls)) { await check('MCP output storage for ' + name, cwd => { const problem = toolFailure(name, args, cwd, /--out/, /writable (?:output )?(?:folder|directory)/i); assert.ok(problem.error.includes(path.join(cwd, 'output')), problem.error); }, cwd => writeFile(path.join(cwd, 'output'), 'an existing file')); } await check('build can only deliver groups if it can record them', async cwd => { const record = path.join(cwd, 'pixelbolt.build.lock.json'); await withReadOnly(record, async () => { const error = await cliFailure(['build', '--keep', 'kept'], cwd, /pixelbolt\.build\.lock\.json/, /writable|write permission/i); assert.equal(error.path, 'pixelbolt.build.lock.json'); }, () => { // Elevated accounts can still check the same manifest read-only and report its stale outputs. const reply = run(['build', '--check'], cwd); assert.equal(reply.status, 1); assert.equal(reply.stdout, ''); assert.equal(JSON.parse(reply.stderr).ok, false); }); }, async cwd => { await preparePatch(cwd); const manifest = path.join(cwd, 'pixelbolt.build.json'), source = path.join(cwd, 'sprite.json'); const config = { entries: [{ name: 'dot', file: 'sprite.json', outputs: [{ sheet: 'art' }] }] }; await writeFile(manifest, JSON.stringify(config)); const first = run(['build'], cwd); assert.equal(first.status, 0, first.stderr); const recipe = JSON.parse(await readFile(source, 'utf8')); recipe.palette.a = '#ee1212'; await writeFile(source, JSON.stringify(recipe)); config.entries[0].outputs.push({ still: 'new/ui/dot.png' }); await writeFile(manifest, JSON.stringify(config)); }); await check('mixed build records exactly the independent files it delivered', async (cwd, delivered) => { const child = run(['build'], cwd); assert.equal(child.status, 1); assert.equal(child.stdout, ''); const report = JSON.parse(child.stderr); assert.equal(report.ok, false); assert.deepEqual(report.written, ['dot.png']); assert.deepEqual(report.refused.map(item => item.file), ['art/dot.atlas.json']); assert.match(report.refused[0].message, /move.*--force/i); const bytes = await readFile(path.join(cwd, 'dot.png')); const expected = encodePNG(Uint8Array.from(Array.from({ length: 4 }, () => [171, 205, 239, 255]).flat()), 2, 2); assert.deepEqual(bytes, Buffer.from(expected)); const record = JSON.parse(await readFile(path.join(cwd, 'pixelbolt.build.lock.json'), 'utf8')); assert.deepEqual(Object.keys(record.entries.dot.outputs), ['still dot.png']); assert.deepEqual(record.entries.dot.outputs['still dot.png'].files, { 'dot.png': 'sha256:' + createHash('sha256').update(bytes).digest('hex') }); delivered.add('dot.png'); delivered.add('pixelbolt.build.lock.json'); }, async cwd => { await preparePatch(cwd); await mkdir(path.join(cwd, 'art')); await writeFile(path.join(cwd, 'art', 'dot.atlas.json'), 'user-authored atlas'); await writeFile(path.join(cwd, 'pixelbolt.build.json'), JSON.stringify({ entries: [{ name: 'dot', file: 'sprite.json', outputs: [{ sheet: 'art' }, { still: 'dot.png' }] }] })); }); const writeCalls = [ [['init'], 'example.json'], [['presets', 'coin', '--out'], 'preset.json'], [['inspect', 'sprite.json', '--out'], 'sheet.png'], [['patch', 'sprite.json', '--changes', 'edits.json', '--out'], 'fixed.json'], [['overlay', 'sprite.json', '--changes', 'edits.json', '--out'], 'overlay.json'], [['compile', 'pose.json', '--out'], 'compiled.json'], [['autotile', 'tiles.json', '--out'], 'tileset.json'], [['gif', 'sprite.json', '--out'], 'animation.gif'], [['gif-frames', 'pictures', '--fps', '10', '--out'], 'movie.gif'], [['import', 'pictures/one_0001.png', '--out'], 'imported.json'], [['scene', 'room.json', '--image'], 'view.png'], [['render', 'sprite.json', '--out'], 'bundle', 'dot.png'], [['sequence', 'sprite.json', '--fps', '10', '--out'], 'frames', 'sequence.json'], [['scene', 'room.json', '--out'], 'room', 'scene.png'] ]; async function prepareOutputs(cwd) { await preparePatch(cwd); await writeFile(path.join(cwd, 'pose.json'), await readFile(new URL('../examples/slime-idle.poses.json', import.meta.url))); await writeFile(path.join(cwd, 'tiles.json'), await readFile(new URL('../examples/ground.autotile.json', import.meta.url))); await writeFile(path.join(cwd, 'room.json'), JSON.stringify(scene)); await mkdir(path.join(cwd, 'pictures')); await writeFile(path.join(cwd, 'pictures', 'one_0001.png'), png); } const blocked = 'assets/original.bin/'; for (const [args, output, member] of writeCalls) { const label = args.join(' '), target = member ? path.join(output, member) : output; const existing = async cwd => { await prepareOutputs(cwd); await mkdir(path.dirname(path.join(cwd, target)), { recursive: true }); await writeFile(path.join(cwd, target), 'bytes from before'); }; await check('unwritable parent for ' + label, cwd => cliFailure([...args, blocked + output], cwd, /original\.bin/, /choose|writable/i), prepareOutputs); await check('refused overwrite for ' + label, async cwd => { const reply = await cliFailure([...args, output], cwd, /already exists/i, /new (?:file|folder)|--force/i); assert.ok(reply.error.includes(path.basename(target)), reply.error); }, existing); await check('unwritable forced output for ' + label, cwd => withReadOnly(path.join(cwd, target), () => cliFailure([...args, output, '--force'], cwd, /permission|read-only/i, /choose|writable/i), () => cliFailure([...args, blocked + output, '--force'], cwd, /original\.bin/, /choose|writable/i)), existing); } await check('unwritable skill installation directory', cwd => cliFailure(['skill', 'install', '--dir', blocked + 'skills'], cwd, /original\.bin/, /--dir/, /writable/i)); await check('a refused skill install preserves an existing skill', cwd => cliFailure(['skill', 'install', '--dir', 'skills'], cwd, /already holds files/, /--force/, /--dir/), async cwd => { const skill = path.join(cwd, 'skills', 'pixelbolt-pixel-art'); await mkdir(skill, { recursive: true }); await writeFile(path.join(skill, 'SKILL.md'), 'personal instructions'); }); await check('a failed forced skill update preserves the whole installation', cwd => cliFailure(['skill', 'install', '--dir', 'skills', '--force'], cwd, /\.pixelbolt-skill\.json/, /folder|directory/, /--dir/), async cwd => { const installed = run(['skill', 'install', '--dir', 'skills'], cwd); assert.equal(installed.status, 0, installed.stderr); const skill = path.join(cwd, 'skills', 'pixelbolt-pixel-art'), manifest = path.join(skill, '.pixelbolt-skill.json'); await writeFile(path.join(skill, 'SKILL.md'), 'personal instructions'); await rm(manifest); await mkdir(manifest); }); await check('MCP refuses an existing saveAs destination before exporting', cwd => toolFailure('pixel_render', { project, saveAs: { sheet: 'art.png' } }, cwd, /saveAs\.sheet/, /already exists/, /overwrite/), cwd => writeFile(path.join(cwd, 'art.png'), 'existing sheet')); // Windows refuses the long component when placing a copy. Ordinary POSIX users can instead deny directory writes. if (process.platform === 'win32' || process.getuid() !== 0) { await check('failed optional MCP copies retain the verified export and revision', async (cwd, delivered) => { const target = process.platform === 'win32' ? 'closed/' + 'x'.repeat(300) + '.png' : 'closed/frame.png'; const problem = toolFailure('pixel_render', { project, overwrite: true, saveAs: { sheet: 'new/sprites/coin.png', atlas: 'atlas.json', 'frames/turn-0.png': target } }, cwd, /saveAs\.frames\/turn-0\.png/, /use its files/, /revision/); assert.equal(problem.path, 'saveAs.frames/turn-0.png'); assert.match(problem.revision, /^[0-9a-f]{12}$/); assert.equal(path.dirname(problem.directory), path.join(cwd, 'output')); const expected = await createBundle(project), prefix = 'output/' + path.basename(problem.directory); delivered.add(prefix); for (const [file, bytes] of expected.files) { assert.deepEqual(await readFile(path.join(problem.directory, file)), Buffer.from(bytes), file); for (let part = file; part !== '.'; part = path.posix.dirname(part)) delivered.add(prefix + '/' + part); } const filename = 'output/.revisions/' + problem.revision + '.json'; assert.deepEqual(JSON.parse(await readFile(path.join(cwd, filename), 'utf8')), project); const again = mcpRequest('tools/call', { name: 'pixel_validate', arguments: { revision: problem.revision } }, cwd); assert.equal(JSON.parse(again.result.content[0].text).revision, problem.revision); delivered.add(filename); }, async cwd => { await writeFile(path.join(cwd, 'atlas.json'), JSON.stringify({ frames: [], meta: { image: 'previous.png' } })); await mkdir(path.join(cwd, 'output', '.revisions'), { recursive: true }); await mkdir(path.join(cwd, 'closed'), { mode: 0o555 }); }); } for (const args of [['init', 'portrait.png'], ['presets', 'coin', '--out', 'art.PNG']]) { await check('recipe text sent to an image filename by ' + args[0], cwd => cliFailure(args, cwd, /\.png/i, /\.json/i, /pixelbolt render/i)); } for (const flag of [[], ['--help'], ['-h']]) { await check('unknown CLI command ' + ['vaildate', ...flag].join(' '), cwd => cliFailure(['vaildate', ...flag], cwd, /Unknown command: vaildate/, /pixelbolt (?:validate --)?help/)); } await check('missing numbered frame folder', cwd => cliFailure(['gif-frames', 'absent', '--fps', '12', '--out', 'movie.gif'], cwd, /absent/, /numbered PNG/)); await check('missing MCP import path', cwd => toolFailure('pixel_import', { path: 'absent.png' }, cwd, /absent\.png/, /server root|--root/i, /existing PNG/i)); const linked = { ...project, palette: { $ref: 'absent.palette.json' } }; await check('missing CLI palette reference', cwd => cliFailure(['validate', 'sprite.json'], cwd, /absent\.palette\.json/, /existing JSON file/i), cwd => writeFile(path.join(cwd, 'sprite.json'), JSON.stringify(linked))); await check('missing MCP palette reference', cwd => toolFailure('pixel_validate', { project: linked }, cwd, /absent\.palette\.json/, /existing JSON file/i)); for (const invalid of ['null', 'false', '0', '""']) { await check('preview rejects the explicit JSON value ' + invalid, cwd => cliFailure(['preview', 'invalid.json', '--port', '0'], cwd, /project/, /object/), cwd => writeFile(path.join(cwd, 'invalid.json'), invalid)); } await check('build refuses a file where its output folder should go', cwd => cliFailure(['build'], cwd, /original\.bin/, /folder is required/), async cwd => { await preparePatch(cwd); await writeFile(path.join(cwd, 'pixelbolt.build.json'), JSON.stringify({ entries: [{ name: 'dot', file: 'sprite.json', outputs: [{ sheet: 'assets/original.bin/sprites' }] }] })); }); await check('build --init preserves a pre-existing manifest', cwd => cliFailure(['build', '--init', '--force'], cwd, /already exists/, /first manifest/), cwd => writeFile(path.join(cwd, 'pixelbolt.build.json'), 'original manifest')); await check('a forced build reports its unwritable group member', async cwd => { await withReadOnly(path.join(cwd, 'art', 'dot.png'), () => { const child = run(['build', '--force'], cwd); assert.equal(child.status, 1); assert.equal(child.stdout, ''); const report = JSON.parse(child.stderr); assert.equal(report.ok, false); assert.equal(report.failed.length, 1); assert.match(report.failed[0].error, /dot\.png/); assert.match(report.failed[0].error, /writable.*(?:path|folder)|write permission/i); }, () => cliFailure(['build', '--check', '--force'], cwd, /--check/, /--force/)); }, async cwd => { await preparePatch(cwd); await writeFile(path.join(cwd, 'pixelbolt.build.json'), JSON.stringify({ entries: [{ name: 'dot', file: 'sprite.json', outputs: [{ sheet: 'art' }] }] })); const first = run(['build'], cwd); assert.equal(first.status, 0, first.stderr); const source = path.join(cwd, 'sprite.json'), recipe = JSON.parse(await readFile(source, 'utf8')); recipe.palette.a = '#0d0c0b'; await writeFile(source, JSON.stringify(recipe)); }); for (const args of missingInputs.filter(args => args[0] !== 'preview')) { const [command, , ...options] = args; await check('missing primary operand for ' + args.join(' '), cwd => cliFailure([command, ...options], cwd, command === 'import' ? /requires a PNG filename/ : /provide a project JSON filename or - for stdin/i)); } const poses = JSON.parse(await readFile(new URL('../examples/slime-idle.poses.json', import.meta.url), 'utf8')); const tiles = JSON.parse(await readFile(new URL('../examples/ground.autotile.json', import.meta.url), 'utf8')); for (const args of missingInputs) { const command = args[0]; let input = { ...project, width: 0 }, details = [/width/, /integer from 1/]; if (command === 'compile') { input = { ...poses, width: 0 }; details = [/width/, /integer from 1/]; } if (command === 'autotile') { input = { ...tiles, tile: 0 }; details = [/autotile\.tile/, /even tile size from 2/]; } if (command === 'share') { input = null; details = [/recipe/, /JSON object/i]; } if (command === 'scene') input = { ...scene, width: 0 }; if (command === 'import') { input = 'plain text'; details = [/PNG/i]; } await check('invalid primary input for ' + args.join(' '), cwd => cliFailure(args, cwd, ...details), async cwd => { await writeFile(path.join(cwd, args[1]), command === 'import' ? input : JSON.stringify(input)); await writeFile(path.join(cwd, 'changes.json'), JSON.stringify([{ set: 'frames[turn-0].duration', value: 200 }])); }); } const cliMistakes = [ [['help', 'missing-topic'], /missing-topic/, /topics:/i], [['presets', 'absentxxx'], /absentxxx/, /presets/i], [['schema', 'extra.json'], /schema/, /does not accept a filename/], [['mcp', '--time-limit', '0'], /--time-limit/, /1 to 3600/], [['preview', '--port', '70000'], /port/i, /0 to 65535/], [['skill', 'wrong'], /skill install/, /--dir/], [['build'], /pixelbolt\.build\.json/, /build --init/], [['gif-frames'], /requires a folder/, /numbered PNG/], [['gif-frames', 'assets/empty', '--fps', '10', '--out', 'movie.gif'], /numbered PNG/, /frame_0001\.png/] ]; for (const [args, ...details] of cliMistakes) await check('usage for ' + args.join(' '), cwd => cliFailure(args, cwd, ...details)); const unexpected = { ...project, width: 0 }; const toolMistakes = [ ['pixel_help', { name: 'unused', topic: 'example' }, /name/, /goes with topic/], ['pixel_help', { topic: 'absent' }, /topic/, /expected one of/], ['pixel_validate', {}, /arguments/, /project or revision/], ['pixel_inspect', {}, /arguments/, /project or revision/], ['pixel_render', {}, /arguments/, /project or revision/], ['pixel_patch', {}, /arguments/, /changes or overlay/], ['pixel_compile', {}, /arguments/, /source or preset/], ['pixel_scene', {}, /scene/, /expected an object/], ['pixel_import', {}, /arguments/, /data.*or path/], ...['pixel_validate', 'pixel_inspect', 'pixel_render', 'pixel_patch'].map(name => [name, { project: unexpected, ...(name === 'pixel_patch' && { changes: [{ set: 'frames[turn-0].duration', value: 200 }] }) }, /project\.width/, /integer from 1/]), ['pixel_compile', { source: { format: 'unknown' } }, /source\.format/, /expected pixelforge-poses/], ['pixel_scene', { scene: { ...scene, width: 0 } }, /scene\.width/, /integer from 1/], ['pixel_import', { data: Buffer.from('a text file').toString('base64') }, /import/, /expected a PNG/], ...['pixel_validate', 'pixel_inspect', 'pixel_render'].map(name => [name, { revision: '000000000000' }, /unknown revision 000000000000/, /send the saved project/]) ]; for (const [name, args, ...details] of toolMistakes) { await check('invalid input to ' + name + ' (' + Object.keys(args).join(', ') + ')', cwd => toolFailure(name, args, cwd, ...details)); } const tools = mcpRequest('tools/list', {}, root).result.tools; // Commands that only print, validate, serve or share have no destination to overwrite. Build and skill have their // own publication rules. All other commands with public outputs are represented in writeCalls above. const covered = new Set([...writeCalls.map(([args]) => args[0]), 'build', 'skill', 'help', 'schema', 'validate', 'share', 'preview', 'mcp']); if (commands.has('version')) { await check('version takes no file', cwd => cliFailure(['version', 'extra.json'], cwd, /version/, /does not accept a filename/)); covered.add('version'); } assert.deepEqual([...commands].sort(), [...covered].sort(), 'give each new CLI command its applicable failure cases'); // All tools except the textual help route can publish revisions or exports. Help's optional preset cache is disposable. assert.deepEqual(tools.map(tool => tool.name).sort(), [...Object.keys(storageCalls), 'pixel_help'].sort()); assert.ok(tools.some(tool => tool.name === 'pixel_render')); for (const { name } of tools) { await check('unknown argument on ' + name, cwd => { const { error } = mcpRequest('tools/call', { name, arguments: { unwantedField: true } }, cwd); assert.equal(error?.code, -32602); assert.ok(error.message.includes(name), error.message); assert.match(error.message, /unwantedField/); assert.match(error.message, /its options are/); }); } if (failures.length) throw new Error(failures.length + ' of ' + cases + ' failure checks failed:\n' + failures.join('\n\n')); console.log('Passed ' + cases + ' failure checks across ' + commands.size + ' CLI commands and ' + tools.length + ' MCP tools.'); } finally { await rm(root, { recursive: true, force: true }); }