contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
123 lines (122 loc) โข 5.48 kB
JavaScript
/**
* Test script for transparent background functionality in TextToImageTool
*
* This script tests:
* 1. Transparent PNG generation
* 2. Solid background PNG generation
* 3. Agent-compatible parameter formats
* 4. HTML template generation with correct background handling
*/
import { TextToImageTool } from '../services/tools/TextToImageTool.js';
import path from 'path';
import fs from 'fs/promises';
const baseDir = process.cwd();
const tool = new TextToImageTool(baseDir);
async function runTests() {
console.log('๐งช Testing Transparent Background Functionality\n');
// Test 1: Transparent background
console.log('๐ Test 1: Transparent Background');
const transparentResult = await tool.execute({
text: 'LOGO TEXT',
output_path: 'demo/test_transparent.png',
design_prompt: 'Modern logo style with bold typography',
width: 300,
height: 100,
transparent: true
});
if (transparentResult.success) {
console.log('โ
Transparent PNG generated successfully');
console.log(` Output: ${transparentResult.data?.output_file_path}`);
console.log(` Size: ${transparentResult.data?.file_size} bytes`);
// Check HTML has no background
const htmlPath = path.join(baseDir, 'demo/test_transparent.html');
const htmlContent = await fs.readFile(htmlPath, 'utf-8');
const hasBackground = htmlContent.includes('bg-') && !htmlContent.includes('bg-transparent');
console.log(` HTML Background: ${hasBackground ? 'โ Found background classes' : 'โ
No background classes'}`);
}
else {
console.log('โ Transparent test failed:', transparentResult.error);
}
console.log('');
// Test 2: Solid background
console.log('๐ Test 2: Solid Background');
const solidResult = await tool.execute({
text: 'BANNER TEXT',
output_path: 'demo/test_solid.png',
design_prompt: 'Vibrant banner with gradient background',
width: 300,
height: 100,
transparent: false
});
if (solidResult.success) {
console.log('โ
Solid PNG generated successfully');
console.log(` Output: ${solidResult.data?.output_file_path}`);
console.log(` Size: ${solidResult.data?.file_size} bytes`);
// Check HTML has background
const htmlPath = path.join(baseDir, 'demo/test_solid.html');
const htmlContent = await fs.readFile(htmlPath, 'utf-8');
const hasBackground = htmlContent.includes('bg-') && !htmlContent.includes('bg-transparent');
console.log(` HTML Background: ${hasBackground ? 'โ
Found background classes' : 'โ No background classes'}`);
}
else {
console.log('โ Solid test failed:', solidResult.error);
}
console.log('');
// Test 3: HTML-only mode with transparency
console.log('๐ Test 3: HTML-only Mode with Transparency');
const htmlOnlyResult = await tool.execute({
html_file_path: 'demo/test_transparent.html',
output_path: 'demo/test_html_only_transparent.png',
html_only: true,
width: 300,
height: 100,
transparent: true
});
if (htmlOnlyResult.success) {
console.log('โ
HTML-only transparent rendering successful');
console.log(` Output: ${htmlOnlyResult.data?.output_file_path}`);
console.log(` Size: ${htmlOnlyResult.data?.file_size} bytes`);
}
else {
console.log('โ HTML-only transparent test failed:', htmlOnlyResult.error);
}
console.log('');
// Test 4: Agent-style parameter format
console.log('๐ Test 4: Agent-Compatible Parameters');
const agentResult = await tool.execute({
text: 'AGENT TEST',
output_path: 'demo/test_agent_transparent.png',
design_prompt: 'Clean minimal design for overlay use',
width: 200,
height: 80,
transparent: true // Agent passes boolean directly
});
if (agentResult.success) {
console.log('โ
Agent-compatible parameters work');
console.log(` Output: ${agentResult.data?.output_file_path}`);
}
else {
console.log('โ Agent parameter test failed:', agentResult.error);
}
console.log('');
// Summary
console.log('๐ฏ Test Summary:');
console.log(` Transparent PNG: ${transparentResult.success ? 'โ
' : 'โ'}`);
console.log(` Solid PNG: ${solidResult.success ? 'โ
' : 'โ'}`);
console.log(` HTML-only Transparent: ${htmlOnlyResult.success ? 'โ
' : 'โ'}`);
console.log(` Agent Parameters: ${agentResult.success ? 'โ
' : 'โ'}`);
const allPassed = transparentResult.success && solidResult.success &&
htmlOnlyResult.success && agentResult.success;
console.log(`\n๐ Overall Result: ${allPassed ? 'โ
ALL TESTS PASSED' : 'โ SOME TESTS FAILED'}`);
if (allPassed) {
console.log('\n๐ Transparent background functionality is working perfectly!');
console.log(' Agents can now generate:');
console.log(' โข PNG images with transparent backgrounds for overlays');
console.log(' โข PNG images with solid backgrounds for standalone graphics');
console.log(' โข Both modes work with AI generation and HTML-only rendering');
console.log(' โข Parameter format is agent-friendly (boolean transparent flag)');
}
}
// Run the tests
runTests().catch(console.error);