// Bounded authenticated acceptance using only an explicitly provisioned disposable Development author. const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict'),crypto=require('node:crypto'); const who=JSON.parse(fs.readFileSync(process.env.PD_SQL_IDENTITY)),scope=JSON.parse(fs.readFileSync(process.env.PD_SQL_SCOPE)),base='https://dev.plotdirector.com'; assert(who.Database==='PlotDirector_Development'&&/^pwa-browser-.*@example\.invalid$/.test(who.Email)); (async()=>{const browser=await chromium.launch();const results=[];let accepted; try{for(const pwa of[false,true]){ const context=await browser.newContext({viewport:{width:pwa?1100:1666,height:1050}}); await context.addInitScript(({user,pwa})=>{localStorage.setItem('plotdirector.desktop.v1.'+user,JSON.stringify({dismissedAt:Date.now()}));if(pwa)Object.defineProperty(navigator,'standalone',{value:true});},{user:who.UserID,pwa}); const page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message)); await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(who.Email);await page.locator('[name=Password]').fill(who.Password); await Promise.all([page.waitForURL('**/Projects'),page.locator('button[type=submit]').click()]); const paths={writer:`/Writer?bookId=${scope.book}`,plot:`/PlotLineWorkspace?projectId=${scope.project}`,reader:`/Writer/Review?bookId=${scope.book}&chapterId=${scope.chapter}`,book:`/Books/Details/${scope.book}`,maps:`/Maps?projectId=${scope.project}&bookId=${scope.book}`}; for(const[area,path]of Object.entries(paths)){ const start=performance.now(),response=await page.goto(base+path);assert.equal(response.status(),200,area);assert.equal(new URL(response.url()).pathname,new URL(base+path).pathname); const correlation=response.headers()['x-sql-correlation'];assert(correlation,area+' SQL correlation header');results.push({area,pwa,httpMs:performance.now()-start,correlation,status:200}); if(area==='reader'){ await page.locator('[data-review-panel]').waitFor();assert(await page.locator('#reader-content [data-paragraph-id]').count()>100); const text=await page.locator('#reader-content').textContent(),hash=crypto.createHash('sha256').update(text).digest('hex');accepted??=hash;assert.equal(hash,accepted,'Accepted prose stays identical across browser/PWA');results.push({area,pwa,acceptedTextSha256:hash}); } if(process.env.PD_SQL_SCREENSHOTS){fs.mkdirSync(process.env.PD_SQL_SCREENSHOTS,{recursive:true});await page.screenshot({path:process.env.PD_SQL_SCREENSHOTS+'/'+area+'-'+(pwa?'PWA':'browser')+'.png'});} } const alias=await context.request.get(base+`/manuscript/reader?bookId=${scope.book}&chapterId=${scope.chapter}`);assert.equal(alias.status(),200);assert.equal(new URL(alias.url()).pathname,'/Writer/Review');results.push({area:'legacy-reader',pwa,status:200,correlation:alias.headers()['x-sql-correlation']}); assert.deepEqual(errors,[]);console.log('PASS SQL launch '+(pwa?'1100px simulated PWA':'1666px browser')+': real login, Writer, plot, accepted Reader, book, Maps, private legacy redirect and SQL correlation');await context.close(); } fs.writeFileSync(process.env.PD_SQL_RESULTS,JSON.stringify(results,null,2)); }finally{await browser.close();}})().catch(e=>{console.error(String(e.stack).replaceAll(who.Password,'[redacted]'));process.exitCode=1;});