briefcase-wasm 2.0.8

WebAssembly bindings for Briefcase AI
Documentation
// Node.js test script for Briefcase AI WASM
const fs = require('fs');
const path = require('path');

// Import the WASM module (requires the bundler target for Node.js)
// For now, let's just verify the files exist and check basic structure

function testWasmPackage() {
    console.log('๐Ÿงช Testing Briefcase AI WASM Package\n');

    const pkgDir = path.join(__dirname, 'pkg');

    // Check if all expected files exist
    const expectedFiles = [
        'briefcase_wasm.js',
        'briefcase_wasm.d.ts',
        'briefcase_wasm_bg.wasm',
        'package.json'
    ];

    let allFilesExist = true;
    expectedFiles.forEach(file => {
        const filepath = path.join(pkgDir, file);
        if (fs.existsSync(filepath)) {
            console.log(`โœ… ${file} exists`);
        } else {
            console.log(`โŒ ${file} missing`);
            allFilesExist = false;
        }
    });

    if (!allFilesExist) {
        console.log('โŒ WASM package incomplete');
        return;
    }

    // Check package.json content
    try {
        const packageJson = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'));
        console.log(`โœ… Package name: ${packageJson.name}`);
        console.log(`โœ… Package version: ${packageJson.version}`);
        console.log(`โœ… Package type: ${packageJson.type || 'commonjs'}`);
    } catch (error) {
        console.log(`โŒ Error reading package.json: ${error.message}`);
        return;
    }

    // Check TypeScript definitions
    try {
        const tsDefContent = fs.readFileSync(path.join(pkgDir, 'briefcase_wasm.d.ts'), 'utf8');
        const hasDecisionSnapshot = tsDefContent.includes('JsDecisionSnapshot');
        const hasMemoryStorage = tsDefContent.includes('JsMemoryStorage');
        const hasVersionFunction = tsDefContent.includes('version()');
        const hasTestFunction = tsDefContent.includes('test_functionality');

        if (hasDecisionSnapshot) console.log('โœ… JsDecisionSnapshot type definitions found');
        if (hasMemoryStorage) console.log('โœ… JsMemoryStorage type definitions found');
        if (hasVersionFunction) console.log('โœ… version() function definition found');
        if (hasTestFunction) console.log('โœ… test_functionality() function definition found');

        if (hasDecisionSnapshot && hasMemoryStorage && hasVersionFunction && hasTestFunction) {
            console.log('โœ… All expected TypeScript definitions present');
        }
    } catch (error) {
        console.log(`โŒ Error checking TypeScript definitions: ${error.message}`);
        return;
    }

    // Check WASM binary size
    try {
        const wasmStats = fs.statSync(path.join(pkgDir, 'briefcase_wasm_bg.wasm'));
        const wasmSizeKB = Math.round(wasmStats.size / 1024);
        console.log(`โœ… WASM binary size: ${wasmSizeKB} KB`);

        if (wasmSizeKB > 10 && wasmSizeKB < 1000) {
            console.log('โœ… WASM binary size looks reasonable');
        } else {
            console.log(`โš ๏ธ  WASM binary size unusual: ${wasmSizeKB} KB`);
        }
    } catch (error) {
        console.log(`โŒ Error checking WASM binary: ${error.message}`);
        return;
    }

    console.log('\n๐ŸŽ‰ WASM package validation completed successfully!');
    console.log('\n๐Ÿ“‹ Summary:');
    console.log('  โœ… All required files present');
    console.log('  โœ… Package.json valid');
    console.log('  โœ… TypeScript definitions complete');
    console.log('  โœ… WASM binary properly generated');
    console.log('\n๐Ÿ’ก To test in browser: serve test.html via HTTP');
    console.log('๐Ÿ’ก To test in Node.js: build with --target nodejs');
}

testWasmPackage();