Skip to main content
Glama
minimal-json-structure-test.jsβ€’6.19 kB
#!/usr/bin/env node /** * Minimal JSON Structure Test * Tests the core JSON structure fix with minimal payload to isolate the issue */ import { createComposerFormatter } from '../src/tools/format-for-composer.js'; import { createCompositionAPISaver } from '../src/tools/save-composition-api.js'; import { chromium } from 'playwright'; // Minimal test data - just the essential components that caused the 500 error const minimalTestData = { metadata: { topic: "Teste JSON Structure", subject: "CiΓͺncias", gradeLevel: "8ΒΊ ano", duration: 15, learningObjectives: ["Testar estrutura JSON"] }, widgets: [ { type: "head-1", content: { category: "TESTE - ESTRUTURA JSON", author_name: "Professor Teste", author_office: "Especialista em Testes" } }, { type: "text-1", content: { text: "<h2>Teste de Estrutura JSON</h2><p>Este Γ© um teste mΓ­nimo para validar a estrutura JSON.</p>" } }, { type: "quiz-1", content: { questions: [ { question: "Este Γ© um teste de estrutura JSON?", options: ["Sim", "NΓ£o"], correct_option: 0 } ], max_attempts: 1 } } ] }; async function runMinimalTest() { console.error('πŸ§ͺ Minimal JSON Structure Test - Isolating Core Fix\n'); // Step 1: Format the minimal composition console.error('πŸ“‹ Step 1: Formatting minimal composition'); const formatter = createComposerFormatter(); const formatResult = await formatter.formatForComposer(minimalTestData); if (!formatResult.success) { console.error('❌ Format failed:', formatResult.error); return; } const composerJSON = formatResult.data.composerJSON; console.error('βœ… Formatting successful'); // Step 2: Validate JSON structure matches reference console.error('\nπŸ“‹ Step 2: Validating JSON structure'); // Check metadata const metadata = composerJSON.metadata; console.error('βœ… Metadata category:', metadata.category); console.error('βœ… Metadata duration:', metadata.duration); // Check header widget const headerWidget = composerJSON.structure.find(w => w.type === 'head-1'); console.error('βœ… Header category HTML:', headerWidget.category); console.error('βœ… Header author HTML:', headerWidget.author_name); console.error('βœ… Header office HTML:', headerWidget.author_office); // Check quiz widget const quizWidget = composerJSON.structure.find(w => w.type === 'quiz-1'); const firstQuestion = quizWidget.questions[0]; console.error('βœ… Quiz question HTML:', firstQuestion.question); console.error('βœ… Quiz uses choices field:', !!firstQuestion.choices); console.error('βœ… Quiz choice HTML:', firstQuestion.choices[0].text); // Step 3: Size check const jsonSize = JSON.stringify(composerJSON).length; console.error('\nπŸ“‹ Step 3: Size analysis'); console.error('βœ… Composition size:', jsonSize, 'bytes'); console.error('βœ… Size is minimal:', jsonSize < 5000); // Step 4: Attempt API save (the real test) console.error('\nπŸ“‹ Step 4: Testing API save with minimal payload'); let browser; try { // Launch browser browser = await chromium.launch({ headless: false, slowMo: 100 }); const context = await browser.newContext({ viewport: { width: 1920, height: 1080 } }); const page = await context.newPage(); // Set up console logging page.on('console', msg => { console.error(`[BROWSER] ${msg.text()}`); }); console.error('πŸ” Authenticating via JWT redirect...'); // Authenticate via JWT redirect await page.goto('http://localhost:8080', { waitUntil: 'networkidle', timeout: 30000 }); await page.waitForURL('**/composer.euconquisto.com/**', { timeout: 15000 }); await page.waitForLoadState('networkidle'); await page.waitForTimeout(2000); console.error('βœ… Authentication successful'); // Test API save console.error('πŸ’Ύ Testing API save...'); const apiSaver = createCompositionAPISaver(); const saveResult = await apiSaver.saveCompositionAPI(composerJSON, page); if (saveResult.success) { console.error('βœ… API SAVE SUCCESSFUL!'); console.error(' Composition UID:', saveResult.data.compositionUid); console.error(' File size:', saveResult.data.uploadDetails.fileSize, 'bytes'); if (saveResult.optimizationApplied) { console.error(' Optimization applied:', saveResult.optimizationDetails.reductionPercent + '%'); } else { console.error(' No optimization needed'); } console.error('\n🎯 MINIMAL TEST RESULTS:'); console.error(' βœ… JSON structure fix is working'); console.error(' βœ… HTTP 500 errors resolved'); console.error(' βœ… Minimal payload saves successfully'); console.error(' βœ… Ready for full workflow testing'); } else { console.error('❌ API SAVE FAILED'); console.error(' Error:', saveResult.error); // Analyze the failure if (saveResult.error.details?.httpStatus === 500) { console.error('\nπŸ” ANALYSIS:'); console.error(' ❌ HTTP 500 still occurring'); console.error(' ❌ JSON structure fix incomplete'); console.error(' πŸ”§ Need to investigate further'); } else { console.error('\nπŸ” ANALYSIS:'); console.error(' ℹ️ Different error type - not JSON structure'); console.error(' πŸ”§ May need different approach'); } } } catch (error) { console.error('❌ Test failed:', error.message); console.error('\nπŸ” ANALYSIS:'); console.error(' ❌ System error occurred'); console.error(' πŸ”§ Check authentication or browser setup'); } finally { if (browser) { await browser.close(); } } } async function main() { try { await runMinimalTest(); } catch (error) { console.error('πŸ’₯ Test execution failed:', error); } } main().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rkm097git/euconquisto-composer-mcp-poc'

If you have feedback or need assistance with the MCP directory API, please join our Discord server