import fs from 'node:fs'; const f='tests/app.spec.mjs'; let s=fs.readFileSync(f,'utf8'); function replace(a,b,label){if(!s.includes(a))throw new Error(label+' not found');s=s.replace(a,b)} replace("expect(result.version).toBe('17.6.9');","expect(result.version).toBe('17.7.0');",'memory version'); replace("expect(runtimeSource).toContain(\"const VERSION = '17.6.5'\");","expect(runtimeSource).toContain(\"const VERSION = '17.7.0'\");",'runtime version'); replace( ` await page.evaluate(()=>localStorage.setItem('sunOrders',JSON.stringify([{id:77,status:'Новый',total:1000}]))); const result=await page.evaluate(()=>{const before=window.CateriumDataV1770.orders.get(77);window.CateriumDataV1770.orders.update(77,o=>({...o,status:'Тест'}));return {before:before.status,after:window.CateriumDataV1770.orders.get(77).status,version:window.CateriumDataV1770.VERSION}});`, ` const result=await page.evaluate(()=>{window.CateriumDataV1770.orders.replace([{id:77,status:'Новый',total:1000}],{persistLocal:false,reason:'e2e-seed'});const before=window.CateriumDataV1770.orders.get(77);window.CateriumDataV1770.orders.update(77,o=>({...o,status:'Тест'}),{persistLocal:false});return {before:before.status,after:window.CateriumDataV1770.orders.get(77).status,version:window.CateriumDataV1770.VERSION}});`, 'data layer seed'); replace( ` await page.evaluate(()=>{window.__applied=[];window.CateriumDataV1770={isSupportReadOnly:()=>false,diagnostics:{measure:async(_n,fn)=>fn()},orders:{applyServerChanges:(orders)=>window.__applied.push(...orders)}};window.CateriumData=window.CateriumDataV1770;window.SunCloudV2={getSession:()=>({user:{id:'u'}}),getWorkspace:()=>({id:'w'}),getClient:()=>({rpc:async()=>({data:{changed:1,orders:[{id:8,status:'Отдан заказчику'}]},error:null})})};}); const source=fs.readFileSync(path.join(process.cwd(),'public','core','server-automation-v1770.js'),'utf8');await page.addScriptTag({content:source}); await page.waitForFunction(()=>Boolean(window.CateriumServerAutomationV1770));await page.evaluate(()=>window.CateriumServerAutomationV1770.run({force:true}));`, ` await page.evaluate(()=>{window.__applied=[];window.__signed=false;window.CateriumDataV1770={isSupportReadOnly:()=>false,diagnostics:{measure:async(_n,fn)=>fn()},orders:{applyServerChanges:(orders)=>window.__applied.push(...orders)}};window.CateriumData=window.CateriumDataV1770;window.SunCloudV2={getSession:()=>window.__signed?({user:{id:'u'}}):null,getWorkspace:()=>({id:'w'}),getClient:()=>({rpc:async()=>({data:{changed:1,orders:[{id:8,status:'Отдан заказчику'}]},error:null})})};}); const source=fs.readFileSync(path.join(process.cwd(),'public','core','server-automation-v1770.js'),'utf8');await page.addScriptTag({content:source}); await page.waitForFunction(()=>Boolean(window.CateriumServerAutomationV1770));await page.evaluate(async()=>{window.__signed=true;await window.CateriumServerAutomationV1770.run({force:true})});`, 'server automation deterministic start'); fs.writeFileSync(f,s); console.log('v17.7.0 E2E checks stabilized');