UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

170 lines (145 loc) 5.38 kB
#!/usr/bin/env node /** * Ctrl+Shift+Left VS Code Extension Test Script * * This script tests all VS Code extension commands to ensure they work properly. * It directly runs the individual tool scripts with the same parameters as the extension. */ const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); const { promisify } = require('util'); const exec = promisify(require('child_process').exec); // Target file to test const TARGET_FILE = process.argv[2] || '/Users/johngaspar/CascadeProjects/ctrlshiftleft/demo/src/components/PaymentForm.tsx'; // Tool paths const ROOT_DIR = path.dirname(__dirname); const TOOLS_DIR = path.join(ROOT_DIR, 'vscode-ext-test'); const CLI_PATH = path.join(ROOT_DIR, 'bin', 'ctrlshiftleft'); // Ensure all required directories exist function ensureDirectories() { const dirs = [ path.join(ROOT_DIR, 'tests'), path.join(TOOLS_DIR, 'generated-tests'), path.join(ROOT_DIR, 'reports') ]; for (const dir of dirs) { if (!fs.existsSync(dir)) { console.log(`Creating directory: ${dir}`); fs.mkdirSync(dir, { recursive: true }); } } } // Make the test script and tools executable function ensureExecutablePermissions() { try { // Make the CLI executable if (fs.existsSync(CLI_PATH)) { execSync(`chmod +x "${CLI_PATH}"`); console.log(`Made CLI executable: ${CLI_PATH}`); } // Make tool scripts executable const toolScripts = [ path.join(TOOLS_DIR, 'analyze-security.js'), path.join(TOOLS_DIR, 'generate-tests.js'), path.join(TOOLS_DIR, 'generate-checklist.js') ]; for (const script of toolScripts) { if (fs.existsSync(script)) { execSync(`chmod +x "${script}"`); console.log(`Made script executable: ${script}`); } } } catch (error) { console.error(`Error setting permissions: ${error.message}`); } } // Test a specific command async function testCommand(name, script, targetFile) { console.log(`\nTesting ${name}...`); console.log('='.repeat(40)); try { // First try using the CLI console.log(`Running with CLI: ${name}`); try { await exec(`"${CLI_PATH}" ${script} "${targetFile}"`); console.log(`✅ CLI ${name} succeeded`); } catch (cliError) { console.log(`❌ CLI ${name} failed: ${cliError.message}`); // Fall back to direct script execution console.log(`Running direct script: ${name}`); // Map CLI command names to actual script filenames let scriptFileName; if (script === 'analyze') { scriptFileName = 'analyze-security.js'; } else if (script === 'gen') { scriptFileName = 'generate-tests.js'; } else if (script === 'checklist') { scriptFileName = 'generate-checklist.js'; } else { scriptFileName = `${script}.js`; } const scriptPath = path.join(TOOLS_DIR, scriptFileName); console.log(`Script path: ${scriptPath}`); if (!fs.existsSync(scriptPath)) { console.error(`❌ Script not found: ${scriptPath}`); return false; } try { await exec(`node "${scriptPath}" "${targetFile}"`); console.log(`✅ Direct ${name} succeeded`); } catch (scriptError) { console.error(`❌ Direct ${name} failed: ${scriptError.message}`); return false; } } return true; } catch (error) { console.error(`Error running ${name}: ${error.message}`); return false; } } // Main function async function main() { console.log('Ctrl+Shift+Left VS Code Extension Test'); console.log('====================================='); // Setup ensureDirectories(); ensureExecutablePermissions(); // Verify target file exists if (!fs.existsSync(TARGET_FILE)) { console.error(`Target file not found: ${TARGET_FILE}`); process.exit(1); } console.log(`Target file: ${TARGET_FILE}`); // Test all commands const results = { security: await testCommand('Security Analysis', 'analyze', TARGET_FILE), tests: await testCommand('Test Generation', 'gen', TARGET_FILE), checklist: await testCommand('QA Checklist', 'checklist', TARGET_FILE) }; // Summary console.log('\nTest Results Summary'); console.log('==================='); console.log(`Security Analysis: ${results.security ? '✅ Passed' : '❌ Failed'}`); console.log(`Test Generation: ${results.tests ? '✅ Passed' : '❌ Failed'}`); console.log(`QA Checklist: ${results.checklist ? '✅ Passed' : '❌ Failed'}`); // Provide next steps console.log('\nNext Steps:'); if (Object.values(results).every(r => r)) { console.log('All tests passed! VS Code extension should work correctly.'); console.log('1. Restart VS Code'); console.log('2. Try the commands again from the context menu or command palette'); } else { console.log('Some tests failed. Check the error messages above.'); console.log('1. Fix any path or permission issues mentioned in the errors'); console.log('2. Make sure all required directories exist and are writable'); console.log('3. Run this test script again to verify fixes'); } } // Run the tests main().catch(error => { console.error(`Unhandled error: ${error.message}`); console.error(error.stack); process.exit(1); });