UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

123 lines (122 loc) โ€ข 5.48 kB
#!/usr/bin/env node /** * 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);