this repo has no description
at main 99 lines 3.7 kB view raw
1/** 2 * Test environment isolation in js_top_worker 3 */ 4 5const { chromium } = require('playwright'); 6 7async function testEnvIsolation() { 8 console.log('Launching browser...'); 9 const browser = await chromium.launch({ 10 headless: true, 11 args: ['--no-sandbox', '--disable-setuid-sandbox'] 12 }); 13 14 const page = await browser.newPage(); 15 page.on('console', msg => console.log(`[browser ${msg.type()}] ${msg.text()}`)); 16 17 console.log('Navigating to demo page...'); 18 await page.goto('http://localhost:8000/demo.html', { timeout: 30000 }); 19 20 // Wait for initialization 21 console.log('Waiting for toplevel to initialize...'); 22 await page.waitForFunction( 23 () => document.getElementById('status-indicator')?.classList.contains('ready'), 24 { timeout: 60000 } 25 ); 26 console.log('✓ Toplevel initialized'); 27 28 // Test environment isolation 29 console.log('\n=== Testing Environment Isolation ===\n'); 30 31 // Step 1: Set env_value = 100 in default environment 32 console.log('Step 1: Setting env_value = 100 in default environment...'); 33 await page.fill('#env-input', 'let env_value = 100;;'); 34 await page.click('button:has-text("Execute in Selected Env")'); 35 await page.waitForTimeout(2000); 36 37 let output = await page.$eval('#env-output', el => el.textContent); 38 console.log(` Output: ${output}`); 39 40 // Step 2: Create a new environment 41 console.log('\nStep 2: Creating env1...'); 42 await page.click('button:has-text("+ New Env")'); 43 await page.waitForTimeout(2000); 44 45 // Step 3: Set env_value = 200 in env1 46 console.log('Step 3: Setting env_value = 200 in env1...'); 47 await page.fill('#env-input', 'let env_value = 200;;'); 48 await page.click('button:has-text("Execute in Selected Env")'); 49 await page.waitForTimeout(2000); 50 51 output = await page.$eval('#env-output', el => el.textContent); 52 console.log(` Output: ${output}`); 53 54 // Step 4: Check env_value in env1 (should be 200) 55 console.log('\nStep 4: Checking env_value in env1 (should be 200)...'); 56 await page.fill('#env-input', 'env_value;;'); 57 await page.click('button:has-text("Execute in Selected Env")'); 58 await page.waitForTimeout(2000); 59 60 output = await page.$eval('#env-output', el => el.textContent); 61 console.log(` Output: ${output}`); 62 const env1Value = output.includes('200') ? 200 : (output.includes('100') ? 100 : 'unknown'); 63 console.log(` env_value in env1 = ${env1Value}`); 64 65 // Step 5: Switch back to default environment 66 console.log('\nStep 5: Switching to default environment...'); 67 await page.click('.env-btn[data-env=""]'); 68 await page.waitForTimeout(500); 69 70 // Step 6: Check env_value in default (should be 100) 71 console.log('Step 6: Checking env_value in default (should be 100)...'); 72 await page.fill('#env-input', 'env_value;;'); 73 await page.click('button:has-text("Execute in Selected Env")'); 74 await page.waitForTimeout(2000); 75 76 output = await page.$eval('#env-output', el => el.textContent); 77 console.log(` Output: ${output}`); 78 const defaultValue = output.includes('100') ? 100 : (output.includes('200') ? 200 : 'unknown'); 79 console.log(` env_value in default = ${defaultValue}`); 80 81 // Summary 82 console.log('\n=== RESULTS ==='); 83 console.log(`env1 value: ${env1Value} (expected: 200)`); 84 console.log(`default value: ${defaultValue} (expected: 100)`); 85 86 if (env1Value === 200 && defaultValue === 100) { 87 console.log('\n✓ Environment isolation WORKS correctly'); 88 } else { 89 console.log('\n✗ Environment isolation BROKEN'); 90 console.log(' Both environments share the same state!'); 91 } 92 93 await browser.close(); 94} 95 96testEnvIsolation().catch(e => { 97 console.error('Test error:', e); 98 process.exit(1); 99});