const {chromium}=require('C:/Users/PC/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright'); const fs=require('fs'),path=require('path'),assert=require('assert/strict'),{pathToFileURL}=require('url'); const file=path.resolve(__dirname,'../demo.html'),url=pathToFileURL(file).href,screen=path.join(__dirname,'screenshots'); fs.mkdirSync(screen,{recursive:true}); (async()=>{ const browser=await chromium.launch({headless:true,executablePath:'C:/Program Files/Google/Chrome/Application/chrome.exe'}); const observations=[],errors=[],external=[]; const value=async(p,id)=>{const raw=await p.locator('#'+id).getAttribute('data-value');return raw==='null'?null:Number(raw);}; async function check(p,id,expected,label){const actual=await value(p,id);assert.equal(actual,expected,label||id);observations.push({check:label||id,expected,actual});} function watch(p){p.on('pageerror',e=>errors.push(String(e)));p.on('request',r=>{if(!r.url().startsWith('file:'))external.push(r.url());});} async function width(p){assert.equal(await p.evaluate(()=>document.documentElement.scrollWidth>innerWidth+1),false);} try{ const page=await browser.newPage({viewport:{width:1440,height:1024},locale:'ru-RU'});watch(page);await page.goto(url); await check(page,'unit-score',40,'Кг: исходный score');await check(page,'unit-effect',20,'Кг: денежный эффект');await width(page);await page.screenshot({path:path.join(screen,'desktop-units.png'),fullPage:true}); await page.locator('#unit-ton').click();await check(page,'unit-score',40000,'Тонны: исходный score');await check(page,'unit-effect',20,'Тонны: тот же денежный эффект'); await page.locator('#units-delta').fill('');assert.equal(await page.locator('#invalid-units').isVisible(),true);await check(page,'unit-effect',20,'Пустое поле сохраняет прежний расчёт');await page.locator('#restore-units-delta').click();assert.equal(await page.locator('#units-delta').inputValue(),'10'); await page.locator('#units-cost').fill('-1');assert.equal(await page.locator('#units-cost').getAttribute('aria-invalid'),'true');await page.locator('#units-cost').press('Escape');assert.equal(await page.locator('#units-cost').inputValue(),'0'); await page.locator('#units-delta').fill('12,5');await check(page,'unit-effect',25,'Десятичная запятая: 12.5 × 2');await page.locator('[data-reset="units"]').click();await check(page,'unit-score',40,'Сброс возвращает кг и исходные числа'); await page.locator('#tab-salon').click();await check(page,'salon-profit',3000,'Салон: исходная прибыль');await check(page,'salon-served',100,'Салон: ограниченные визиты');await check(page,'salon-unbounded',5400,'Салон: расчёт без ограничения'); await page.locator('#guide-demand').click();await check(page,'salon-profit',3000,'Спрос +20%: прибыль не изменилась');await check(page,'salon-served',100,'Спрос +20%: визитов столько же'); await page.locator('#guide-speed').click();await check(page,'salon-capacity',120,'50 минут: мощность');await check(page,'salon-profit',4200,'50 минут: прибыль');await page.screenshot({path:path.join(screen,'desktop-salon.png'),fullPage:true}); await page.locator('#salon-minutes').fill('0');assert.equal(await page.locator('#salon-minutes').getAttribute('aria-invalid'),'true');await check(page,'salon-profit',4200,'Нулевое время услуги не создаёт бесконечность');await page.locator('#salon-minutes').press('Escape'); await page.locator('#salon-demand').fill('1.5');assert.equal(await page.locator('#salon-demand').getAttribute('aria-invalid'),'true');await page.locator('#salon-demand').press('Escape');await page.locator('#salon-hours').fill('0');await check(page,'salon-profit',-3000,'Нет доступных часов: фиксированные расходы остаются');await check(page,'salon-load',null,'Нет доступных часов: загрузка не определена'); await page.locator('[data-reset="salon"]').click();await page.locator('#salon-demand').fill('80');await check(page,'salon-profit',1800,'Низкий спрос: прибыль определяется 80 визитами');await page.locator('#salon-minutes').fill('50');await check(page,'salon-profit',1800,'Низкий спрос: расширение мощности не помогает'); await page.locator('#tab-product').click();await check(page,'product-double',200000,'Сумма узлов: двойной счёт');await check(page,'product-benefit',100000,'Единый эффект в корне');await check(page,'product-bcr',5,'BCR');await check(page,'product-roi',400,'Чистый ROI, %');await check(page,'product-net',80000,'Чистый денежный эффект'); await page.locator('#probability').evaluate(el=>el.open=true);await check(page,'product-expected',40000,'Вероятность 60% при неизбежных расходах');await page.screenshot({path:path.join(screen,'desktop-product.png'),fullPage:true}); await page.locator('#product-variable').fill('20000');await check(page,'product-benefit',80000,'Дополнительные переменные затраты уменьшают эффект');await check(page,'product-bcr',4,'BCR с переменными затратами');await check(page,'product-roi',300,'Чистый ROI с переменными затратами'); await page.locator('#guide-zero').click();await check(page,'product-bcr',null,'Нулевой знаменатель BCR');await check(page,'product-roi',null,'Нулевой знаменатель ROI');await check(page,'product-net',100000,'Абсолютный эффект при нулевых затратах'); await page.locator('#product-revenue').fill('100000001');assert.equal(await page.locator('#product-revenue').getAttribute('aria-invalid'),'true');await page.locator('#product-revenue').press('Escape');await page.locator('#guide-product').click(); await page.locator('#waterfall').evaluate(el=>el.open=true);await check(page,'shapley-q',100,'Объём первым: вклад Q');await check(page,'shapley-p',220,'Объём первым: вклад P');await page.locator('#method-pq').click();await check(page,'shapley-q',120,'Цена первой: вклад Q');await check(page,'shapley-p',200,'Цена первой: вклад P');await page.locator('#method-shapley').click();await check(page,'shapley-q',110,'Shapley Q');await check(page,'shapley-p',210,'Shapley P');await check(page,'shapley-total',320,'Shapley сумма'); await page.locator('#tab-product').focus();await page.keyboard.press('Home');assert.equal(await page.locator('#tab-units').getAttribute('aria-selected'),'true');await page.keyboard.press('ArrowRight');assert.equal(await page.locator('#panel-salon').isVisible(),true);await width(page); await page.reload();await check(page,'unit-score',40,'Перезагрузка не сохраняет изменения'); const mobile=await browser.newPage({viewport:{width:390,height:844},isMobile:true,hasTouch:true,locale:'ru-RU'});watch(mobile);await mobile.goto(url);await mobile.locator('#unit-ton').tap();await check(mobile,'unit-score',40000,'Мобильный: переключение в тонны');await width(mobile);await mobile.screenshot({path:path.join(screen,'mobile-units.png'),fullPage:true}); await mobile.locator('#tab-salon').tap();await mobile.locator('#guide-speed').tap();await check(mobile,'salon-profit',4200,'Мобильный: 50 минут');await mobile.screenshot({path:path.join(screen,'mobile-salon.png'),fullPage:true}); await mobile.locator('#tab-product').tap();await mobile.locator('#product-development').fill('');assert.equal(await mobile.locator('#invalid-product').isVisible(),true);await mobile.locator('#restore-product-development').tap();await check(mobile,'product-roi',400,'Мобильный: восстановление пустого поля');await width(mobile);await mobile.screenshot({path:path.join(screen,'mobile-product.png'),fullPage:true}); await mobile.setViewportSize({width:320,height:740});for(const tab of ['units','salon','product']){await mobile.locator('#tab-'+tab).tap();await width(mobile);} assert.deepEqual(errors,[]);assert.deepEqual(external,[]); const result={status:'PASS',checked_at:new Date().toISOString(),browser:await browser.version(),sha256:require('crypto').createHash('sha256').update(fs.readFileSync(file)).digest('hex'),observations,page_errors:errors,external_requests:external};fs.writeFileSync(path.join(__dirname,'observations.json'),JSON.stringify(result,null,2));console.log(JSON.stringify({status:'PASS',checks:observations.length,sha256:result.sha256})); }finally{await browser.close();} })().catch(e=>{console.error(e);process.exitCode=1;});