6d99d762da
Introduce AI image generation with chat shortcut and agent API, improve MindSpace chat-to-page save resolution, and seed Plaza covers with production deploy scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
buildImageGenerateCurlExample,
|
|
composeDesignerPrompt,
|
|
loadImageGenConfig,
|
|
normalizeImageOutputPath,
|
|
resolveImagesGenerationsUrl,
|
|
} from './image-generation.mjs';
|
|
|
|
test('resolveImagesGenerationsUrl derives from chat completions base', () => {
|
|
assert.equal(
|
|
resolveImagesGenerationsUrl('https://api.openai.com/v1/chat/completions'),
|
|
'https://api.openai.com/v1/images/generations',
|
|
);
|
|
assert.equal(
|
|
resolveImagesGenerationsUrl('https://api.openai.com/v1/images/generations'),
|
|
'https://api.openai.com/v1/images/generations',
|
|
);
|
|
});
|
|
|
|
test('normalizeImageOutputPath defaults to assets slug png', () => {
|
|
assert.equal(
|
|
normalizeImageOutputPath('', '马来西亚旅行海报'),
|
|
'assets/马来西亚旅行海报.png',
|
|
);
|
|
assert.equal(normalizeImageOutputPath('public/hero.webp', 'x'), 'public/hero.webp');
|
|
});
|
|
|
|
test('normalizeImageOutputPath rejects traversal and unsupported extensions', () => {
|
|
assert.throws(
|
|
() => normalizeImageOutputPath('../secret.png', 'x'),
|
|
(error) => error.code === 'invalid_output_path',
|
|
);
|
|
assert.throws(
|
|
() => normalizeImageOutputPath('assets/hero.svg', 'x'),
|
|
(error) => error.code === 'invalid_output_path',
|
|
);
|
|
});
|
|
|
|
test('composeDesignerPrompt merges creative brief and guardrails', () => {
|
|
const prompt = composeDesignerPrompt({
|
|
prompt: 'premium coffee brand poster',
|
|
styleNotes: 'minimal, warm beige palette',
|
|
aspectRatio: '3:4',
|
|
brandColors: '#c8a27d',
|
|
subject: 'latte art',
|
|
});
|
|
assert.match(prompt, /premium coffee brand poster/);
|
|
assert.match(prompt, /minimal, warm beige palette/);
|
|
assert.match(prompt, /Avoid text overlays/);
|
|
});
|
|
|
|
test('buildImageGenerateCurlExample includes agent endpoint', () => {
|
|
const example = buildImageGenerateCurlExample({
|
|
h5ApiBase: 'http://127.0.0.1:8081',
|
|
sessionId: 'sess-1',
|
|
});
|
|
assert.match(example, /\/api\/agent\/generate_image/);
|
|
assert.match(example, /sess-1/);
|
|
});
|
|
|
|
test('loadImageGenConfig defaults', () => {
|
|
const config = loadImageGenConfig({});
|
|
assert.equal(config.enabled, true);
|
|
assert.equal(config.model, 'dall-e-3');
|
|
assert.equal(config.defaultSize, '1024x1024');
|
|
});
|