test-jit-fixes.js•3.42 kB
#!/usr/bin/env node
/**
* Test script to verify JIT workflow fixes
* Tests both UID format compatibility and auto-fix validation
*/
import { CompositionEditorOpener } from './src/tools/open-composition-editor.js';
import { LessonDataValidator } from './src/tools/validate-lesson-data.js';
console.log('🧪 Testing JIT Workflow Fixes');
console.log('==============================');
// Test 1: UID Format Compatibility
console.log('\n📝 Test 1: UID Format Compatibility');
const editorOpener = new CompositionEditorOpener();
// Test various UID formats
const testUIDs = [
// Standard UUID format
'2ff37486-aa42-45aa-9403-6c8ff50be686',
// Base64 encoded format (from actual test)
'H4sIAAAAAAAAAwBiAZ3-AwAAAUEQAAAAADE0MGUwYzE1IpaoH3ndz-MxVeOzi93yJsbABDZmdWLUXb1t34bSxP9KlBRqLNuFe7rZxxkuW4d3qYyA3fRhS5-GRTu_HbLK0rof1DUcIp_zOjkIDe7Q5_qbkdeV4HEpiJTCIOCyvsT8TNQiknMahk2wM7zYjkZJx54mZ9qbnPDIctO0_xNfiUFmYFKo0ZHHqMe__s1GK9lnUQZDcNRF6j5FqeWp3ODwH7QUuK2XInsvEeLvVsJcV0uzzQbwVIgKpLeblTIg__oAN8V-IUAtwLsA2ZWaViebN3Dl2UmgwBnV5WH4POvu1hz6PkplCBseX7WjcSiceywWVuNR2aB-0HE75yXHngArvWZKLZ2sfIk2t90oyQzd25-htuPYvNqw9pL6QP1vHRIjGTSXdm8L6-5KEx57svOEaNGi9U-EBIgRGP8gIyoIpwnRATjgq_J3pQWKyn399kl3AAAA__8',
// Short UID
'abc123def456',
// Invalid UID (should fail)
'invalid@uid#format'
];
testUIDs.forEach((uid, index) => {
const isValid = editorOpener.isValidCompositionUID(uid);
const expectedResult = index < 3 ? '✅ VALID' : '❌ INVALID';
console.log(` UID ${index + 1}: ${isValid ? '✅' : '❌'} (expected: ${expectedResult})`);
console.log(` Format: ${uid.substring(0, 50)}${uid.length > 50 ? '...' : ''}`);
});
// Test 2: Auto-Fix Validation
console.log('\n📝 Test 2: Auto-Fix Validation');
const validator = new LessonDataValidator();
// Test data with missing topic field (should trigger auto-fix)
const testLessonData = {
metadata: {
// topic is missing - should be auto-fixed
duration: 50,
subject: 'matemática'
},
widgets: [
{
type: 'head-1',
content: {
category: 'MATEMÁTICA',
author_name: 'Professor(a) Virtual'
}
},
{
type: 'text-1',
content: {
title: 'Introdução',
text: '<p>Conteúdo educacional aqui.</p>'
}
}
]
};
console.log(' Original data: topic =', testLessonData.metadata.topic || 'undefined');
// Test the validation with auto-fix
validator.validateLessonData(testLessonData)
.then(result => {
if (result.success) {
const fixedTopic = result.data.validatedLessonData.metadata.topic;
console.log(' ✅ Auto-fix successful!');
console.log(' Fixed topic =', fixedTopic);
console.log(' Validation summary:', result.data.validationSummary);
} else {
console.log(' ❌ Auto-fix failed:', result.error.message);
}
})
.catch(error => {
console.log(' ❌ Test error:', error.message);
});
console.log('\n🎯 Testing Complete');
console.log('Both fixes address the core issues from the January 12 test transcript:');
console.log('1. UID format compatibility prevents NAVIGATION_ERROR');
console.log('2. Auto-fix validation prevents VALIDATION_ERROR workflow abandonment');
console.log('\nThis should resolve the recurring 500 error issue by ensuring:');
console.log('- Compositions save with valid UIDs that can be navigated to');
console.log('- Validation errors are auto-fixed instead of causing failures');