#!/usr/bin/env node /* global console process */ /** * Test script to verify pyvenv.cfg fix works correctly */ import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const projectRoot = path.resolve(__dirname, '..'); function testVenvFix() { console.log('๐Ÿงช Testing pyvenv.cfg fix...\n'); const testCases = [ { name: 'Backend venv', path: path.join( projectRoot, 'resources', 'prebuilt', 'venv', 'pyvenv.cfg' ), }, { name: 'Terminal venv', path: path.join( projectRoot, 'resources', 'prebuilt', 'terminal_venv', 'pyvenv.cfg' ), }, ]; let allPassed = true; for (const testCase of testCases) { console.log(`Testing ${testCase.name}...`); if (!fs.existsSync(testCase.path)) { console.log(` โš ๏ธ File not found: ${testCase.path}`); continue; } const content = fs.readFileSync(testCase.path, 'utf-8'); const homeMatch = content.match(/^home\s*=\s*(.+)$/m); if (!homeMatch) { console.log(` โŒ FAIL: No 'home' line found`); allPassed = false; continue; } const homePath = homeMatch[1].trim(); // Check if placeholder is used if (homePath.includes('{{PREBUILT_PYTHON_DIR}}')) { console.log(` โœ… PASS: Using placeholder correctly`); console.log(` Home: ${homePath}`); // Verify placeholder format (accept both / and \ for cross-platform) const expectedPattern = /^\{\{PREBUILT_PYTHON_DIR\}\}[/\\]cpython-[\w.-]+[/\\](bin|Scripts)$/; if (expectedPattern.test(homePath)) { console.log(` โœ… PASS: Placeholder format is correct`); } else { console.log(` โš ๏ธ WARNING: Placeholder format might be incorrect`); console.log( ` Expected: {{PREBUILT_PYTHON_DIR}}/cpython-X.Y.Z-platform/bin (or \\ on Windows)` ); console.log(` Got: ${homePath}`); } } else { // Check if it's an absolute path (bad) if (path.isAbsolute(homePath)) { console.log(` โŒ FAIL: Still using absolute path`); console.log(` Path: ${homePath}`); console.log(` This path won't work on user machines!`); allPassed = false; } else { console.log(` โš ๏ธ WARNING: Using relative path: ${homePath}`); } } console.log(); } console.log('='.repeat(50)); if (allPassed) { console.log('โœ… All tests passed! Venvs are portable.'); } else { console.log('โŒ Some tests failed. Please run: npm run fix-venv-paths'); process.exit(1); } } testVenvFix();