Skip to main content
Glama
test-jit-widget-specs.jsโ€ข12.1 kB
#!/usr/bin/env node /** * Test JIT Widget Specification Provider v1.0.0 * Validates Just-In-Time widget specification loading and token efficiency * Tests token savings and specification completeness */ import { JITWidgetSpecProvider } from '../../src/tools/jit-widget-specs.js'; async function testJITWidgetSpecs() { console.log('๐Ÿงช Testing JIT Widget Specification Provider v1.0.0'); console.log('๐Ÿ’พ Validates token-efficient specification delivery'); console.log(''); const provider = new JITWidgetSpecProvider(); let testsPassed = 0; let totalTests = 0; // Test 1: Basic JIT Delivery console.log('๐Ÿ“ฆ Test 1: Basic JIT Delivery'); totalTests++; try { const selectedWidgets = ['head-1', 'text-1', 'quiz-1', 'flashcards-1']; const result = provider.getSpecificationsForWidgets(selectedWidgets); const deliveredCount = Object.keys(result.specifications).length; const tokenSaved = result.summary.tokenSavings.saved; const savingsPercentage = result.summary.tokenSavings.savingsPercentage; console.log(` Widgets requested: ${selectedWidgets.length}`); console.log(` Widgets delivered: ${deliveredCount}`); console.log(` Token cost: ${result.summary.tokenCost}`); console.log(` Token saved: ${tokenSaved}`); console.log(` Savings percentage: ${savingsPercentage}%`); if (deliveredCount === selectedWidgets.length && savingsPercentage > 60) { console.log(' โœ… Basic JIT delivery successful with >60% token savings'); testsPassed++; } else { console.log(' โŒ JIT delivery failed or insufficient token savings'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 2: Widget Specification Completeness console.log('๐Ÿ” Test 2: Widget Specification Completeness'); totalTests++; try { const testWidget = 'quiz-1'; const result = provider.getSpecificationsForWidgets([testWidget]); const spec = result.specifications[testWidget]; const hasRequiredFields = spec.requiredFields && spec.requiredFields.includes('questions'); const hasJsonSchema = spec.jsonSchema && spec.jsonSchema.questions; const hasFieldTransformations = spec.fieldTransformations && spec.fieldTransformations.options === 'answers'; const hasTokenCost = spec.tokenCost > 0; console.log(` Widget type: ${testWidget}`); console.log(` Has required fields: ${hasRequiredFields ? 'โœ…' : 'โŒ'}`); console.log(` Has JSON schema: ${hasJsonSchema ? 'โœ…' : 'โŒ'}`); console.log(` Has field transformations: ${hasFieldTransformations ? 'โœ…' : 'โŒ'}`); console.log(` Has token cost: ${hasTokenCost ? 'โœ…' : 'โŒ'}`); if (hasRequiredFields && hasJsonSchema && hasFieldTransformations && hasTokenCost) { console.log(' โœ… Widget specification is complete'); testsPassed++; } else { console.log(' โŒ Widget specification is incomplete'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 3: Simplified Requirements console.log('๐Ÿ“‹ Test 3: Simplified Requirements'); totalTests++; try { const widgets = ['text-1', 'flashcards-1', 'list-1']; const requirements = {}; widgets.forEach(widget => { requirements[widget] = provider.getSimplifiedRequirements(widget); }); let allValid = true; widgets.forEach(widget => { const req = requirements[widget]; console.log(` ${widget}:`); console.log(` Required fields: ${req.required.join(', ')}`); console.log(` Validation rules: ${req.validation.length} rules`); console.log(` Has example: ${Object.keys(req.example).length > 0 ? 'โœ…' : 'โŒ'}`); if (!req.required || !req.example) { allValid = false; } }); if (allValid) { console.log(' โœ… Simplified requirements are complete and valid'); testsPassed++; } else { console.log(' โŒ Simplified requirements are incomplete'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 4: Widget Categories console.log('๐Ÿ“‚ Test 4: Widget Categories'); totalTests++; try { const testWidgets = { 'head-1': 'header', 'text-1': 'content', 'quiz-1': 'assessment', 'flashcards-1': 'vocabulary', 'image-1': 'visual', 'list-1': 'organization', 'accordion': 'interaction', 'video-1': 'multimedia', 'table-1': 'data' }; let categoriesCorrect = 0; Object.entries(testWidgets).forEach(([widget, expectedCategory]) => { const categoryInfo = provider.getWidgetCategory(widget); if (categoryInfo.category === expectedCategory) { categoriesCorrect++; } }); console.log(` Categories tested: ${Object.keys(testWidgets).length}`); console.log(` Categories correct: ${categoriesCorrect}`); console.log(` Accuracy: ${Math.round(categoriesCorrect / Object.keys(testWidgets).length * 100)}%`); if (categoriesCorrect === Object.keys(testWidgets).length) { console.log(' โœ… All widget categories are correct'); testsPassed++; } else { console.log(' โŒ Some widget categories are incorrect'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 5: Token Efficiency Target console.log('๐Ÿ’ฐ Test 5: Token Efficiency Target'); totalTests++; try { // Test with typical lesson widget selection const typicalLesson = [ 'head-1', 'text-1', 'text-1', 'image-1', 'flashcards-1', 'quiz-1', 'list-1' ]; const result = provider.getSpecificationsForWidgets(typicalLesson); const savings = result.summary.tokenSavings; console.log(` Typical lesson widgets: ${typicalLesson.length}`); console.log(` Total token cost (all widgets): ${savings.initial}`); console.log(` Delivered token cost: ${savings.delivered}`); console.log(` Token saved: ${savings.saved}`); console.log(` Savings percentage: ${savings.savingsPercentage}%`); if (savings.savingsPercentage >= 60) { console.log(' โœ… Achieved target 60%+ token savings'); testsPassed++; } else { console.log(' โŒ Failed to achieve 60% token savings target'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 6: JIT Package Integration console.log('๐ŸŽ Test 6: JIT Package Integration'); totalTests++; try { const selectedWidgets = ['head-1', 'text-1', 'quiz-1']; const specPackage = provider.getJITSpecificationPackage(selectedWidgets); const hasSpecifications = Object.keys(specPackage.specifications).length === selectedWidgets.length; const hasExamples = Object.keys(specPackage.examples).length === selectedWidgets.length; const hasValidationRules = Object.keys(specPackage.validationRules).length === selectedWidgets.length; const hasTokenEfficiency = specPackage.tokenEfficiency && specPackage.tokenEfficiency.savingsPercentage > 0; console.log(` Specifications: ${Object.keys(specPackage.specifications).length}/${selectedWidgets.length}`); console.log(` Examples: ${Object.keys(specPackage.examples).length}/${selectedWidgets.length}`); console.log(` Validation rules: ${Object.keys(specPackage.validationRules).length}/${selectedWidgets.length}`); console.log(` Token efficiency data: ${hasTokenEfficiency ? 'โœ…' : 'โŒ'}`); if (hasSpecifications && hasExamples && hasValidationRules && hasTokenEfficiency) { console.log(' โœ… JIT package is complete and ready for integration'); testsPassed++; } else { console.log(' โŒ JIT package is incomplete'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 7: Input Format Flexibility console.log('๐Ÿ”„ Test 7: Input Format Flexibility'); totalTests++; try { const inputFormats = [ // Array of strings ['head-1', 'text-1'], // Object with selectedWidgetTypes { selectedWidgetTypes: ['quiz-1', 'flashcards-1'] }, // Object with widgets array { widgets: [{ type: 'image-1' }, { type: 'list-1' }] }, // Single string 'table-1' ]; let formatSuccess = 0; inputFormats.forEach((input, index) => { const normalized = provider.normalizeWidgetTypes(input); if (normalized.length > 0) { formatSuccess++; } console.log(` Format ${index + 1}: ${normalized.length} widgets normalized`); }); console.log(` Formats successful: ${formatSuccess}/${inputFormats.length}`); if (formatSuccess === inputFormats.length) { console.log(' โœ… All input formats handled correctly'); testsPassed++; } else { console.log(' โŒ Some input formats failed'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Test 8: Unknown Widget Handling console.log('โš ๏ธ Test 8: Unknown Widget Handling'); totalTests++; try { const widgetsWithUnknown = ['head-1', 'unknown-widget', 'text-1']; const result = provider.getSpecificationsForWidgets(widgetsWithUnknown); const deliveredCount = Object.keys(result.specifications).length; const expectedCount = 2; // Only head-1 and text-1 should be delivered console.log(` Widgets requested: ${widgetsWithUnknown.length} (including unknown)`); console.log(` Widgets delivered: ${deliveredCount}`); console.log(` Unknown widget handled gracefully: ${deliveredCount === expectedCount ? 'โœ…' : 'โŒ'}`); if (deliveredCount === expectedCount) { console.log(' โœ… Unknown widgets handled gracefully'); testsPassed++; } else { console.log(' โŒ Unknown widget handling failed'); } } catch (error) { console.log(` โŒ Error: ${error.message}`); } console.log(''); // Final Results console.log('๐Ÿ“Š Final Test Results'); console.log(` Tests passed: ${testsPassed}/${totalTests} (${Math.round(testsPassed/totalTests * 100)}%)`); console.log(''); // Token Efficiency Summary const allWidgets = Object.keys(provider.widgetSpecs); const fullResult = provider.getSpecificationsForWidgets(allWidgets); const typicalResult = provider.getSpecificationsForWidgets(['head-1', 'text-1', 'quiz-1', 'flashcards-1', 'image-1']); console.log('๐Ÿ’พ Token Efficiency Summary:'); console.log(` Total widgets available: ${allWidgets.length}`); console.log(` Full specification token cost: ${fullResult.summary.tokenCost}`); console.log(` Typical lesson (5 widgets) token cost: ${typicalResult.summary.tokenCost}`); console.log(` Typical lesson token savings: ${typicalResult.summary.tokenSavings.savingsPercentage}%`); console.log(''); if (testsPassed >= totalTests * 0.85) { console.log('๐ŸŽ‰ SUCCESS: JIT Widget Specification Provider is excellent!'); console.log(' โœ… JIT delivery works perfectly with 60%+ token savings'); console.log(' โœ… Widget specifications are complete and accurate'); console.log(' โœ… Simplified requirements provide optimal information'); console.log(' โœ… Widget categorization is correct'); console.log(' โœ… Token efficiency target achieved'); console.log(' โœ… Integration package is comprehensive'); console.log(' โœ… Input format handling is flexible'); console.log(' โœ… Error handling is robust'); } else { console.log('โš ๏ธ PARTIAL SUCCESS: Some improvements needed'); console.log(` ${testsPassed} tests passed, ${totalTests - testsPassed} tests failed`); } return { testsPassed, totalTests, success: testsPassed >= totalTests * 0.85 }; } // Run the test testJITWidgetSpecs().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