// Explicit Development acceptance; requires the dedicated disposable author and its owned scope. const {chromium}=require('playwright'); const fs=require('node:fs'); const assert=require('node:assert/strict'); (async()=>{ const w=JSON.parse(fs.readFileSync(process.env.PD_WRITER_FOUNDATION_IDENTITY)); assert(w.Database==='PlotDirector_Development'&&/^pwa-browser-.*@example\.invalid$/.test(w.Email)); for(const key of ['project','book','chapter','scene','other'])assert(Number.isSafeInteger(w[key])&&w[key]>0); const browser=await chromium.launch(),base='https://dev.plotdirector.com',checks=[]; try {for(const pwa of [false,true]){ const context=await browser.newContext({viewport:{width:1440,height:1000}}); if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true})); const page=await context.newPage(),errors=[];page.setDefaultTimeout(20000);page.on('pageerror',e=>errors.push(e.message)); await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(w.Email);await page.locator('[name=Password]').fill(w.Password); await Promise.all([page.waitForURL('**/Projects'),page.locator('button[type=submit]').click()]); for(const [queue,status]of [['WriteNext','Outlined'],['InProgress','Drafted'],['Revision','Needs Work'],['FinalPass','Revised']]){ await page.goto(`${base}/Writer/Workspaces?bookId=${w.book}&workspace=${queue}`); assert((await page.locator(`[data-writer-queue=${queue}]`).innerText()).includes('Audit '+status)); } checks.push('All four selected-book queues render the correct canonical fixture scene'); await page.goto(`${base}/Writing/Intent?projectId=${w.project}&bookId=${w.book}&sceneId=${w.scene}&pinned=true`); assert.equal(await page.locator('[data-writing-intent]').getAttribute('data-writer-selection-role'),'pinned'); await page.locator('[data-writing-intent-tab=checklist]').click(); const canonical=page.locator('[data-writing-intent-panel=checklist] dt').filter({hasText:'Revision Status'}); assert.equal((await canonical.locator('xpath=following-sibling::dd[1]').innerText()).trim(),'Outlined'); checks.push('Pinned Intent displays canonical Outlined without overwriting legacy draft data'); await page.goto(`${base}/Writer?bookId=${w.other}`);assert.equal(await page.getByRole('heading',{name:'Start Here',exact:true}).isVisible(),true); await page.goto(`${base}/Writer/ScheduleSetup?bookId=${w.book}`); await page.waitForFunction(()=>!!window.jQuery?.fn?.validate);assert.equal(await page.locator('[name=BookID]').inputValue(),String(w.book)); const name='Foundation acceptance '+(pwa?'PWA':'browser');await page.locator('[name=PlanName]').fill(name); await page.getByRole('button',{name:'Review activities',exact:true}).click();await page.waitForURL('**/Writer/PlanActivities?*'); const plan=Number(new URL(page.url()).searchParams.get('writingPlanId')); await page.locator('[name=Confirm][type=checkbox]').check();await page.getByRole('button',{name:'Commit reviewed schedule',exact:true}).click();await page.waitForURL('**/Writer/SchedulePreview?*'); assert((await page.locator('main').innerText()).includes('Reviewed writing activities')); await page.goto(`${base}/Writer/WritingPlans?projectId=${w.project}&bookId=${w.book}`); await page.getByRole('link',{name:'Schedule Preview',exact:true}).click();await page.waitForURL('**/Writer/SchedulePreview?*'); assert.equal(new URL(page.url()).searchParams.get('bookId'),String(w.book)); await page.goto(`${base}/Writer/WritingPlans?projectId=${w.project}&bookId=${w.other}`);await page.getByRole('link',{name:'Schedule Preview',exact:true}).click(); await page.waitForURL('**/Writer/SchedulePreview?*');assert((await page.locator('main').innerText()).includes('No writing plans found.')); assert.equal(await page.locator('select[name=writingPlanId]').count(),0,'Other-book plans do not leak into an empty book preview'); await page.goto(`${base}/Writer/WritingPlans?projectId=${w.project}&bookId=${w.book}`); await page.locator(`tr[data-pd-context-id="${plan}"]`).getByRole('button',{name:'Deactivate Plan',exact:true}).click();await page.waitForLoadState(); assert.equal(new URL(page.url()).searchParams.get('bookId'),String(w.book)); await page.locator(`tr[data-pd-context-id="${plan}"]`).getByRole('button',{name:'Activate Plan',exact:true}).click();await page.waitForLoadState(); assert.equal(new URL(page.url()).searchParams.get('projectId'),String(w.project)); await page.goto(`${base}/Writer/EditWritingPlan?writingPlanId=${plan}`);await page.waitForFunction(()=>!!window.jQuery?.fn?.validate); const help=page.locator('[data-help-key="workspace.writingPlans"]').first(); const heading=await help.getAttribute('data-help-url');assert(heading); assert((await help.locator('[data-help-micro]').getAttribute('data-help-micro')).includes('measured')); if(pwa){ await page.locator('[data-help-open="workspace.writingPlans"]:visible').click(); await page.locator('[data-help-drawer]').waitFor({state:'visible'}); await page.waitForFunction(()=>document.querySelector('[data-help-drawer]')?.innerText.includes('Writing plans')); }else{ await help.locator('button').click();await page.locator('.plotline-help-popover').waitFor(); assert((await page.locator('.plotline-help-popover').innerText()).includes('Reviewed allocations')); } const fullHelp=await page.request.get(base+heading);assert.equal(fullHelp.status(),200);assert((await fullHelp.text()).includes('recorded work')); checks.push('Real setup/confirmation, empty/scoped Preview, activate/deactivate return filters and validation dependencies pass'); const otherPlan=await page.request.get(`${base}/Writer/SchedulePreview?writingPlanId=${plan}&bookId=${w.other}`);assert.equal(otherPlan.status(),404); const invalidNative=await page.request.get(`${base}/Writing/Context?bookId=${w.book}&instanceId=00000000-0000-0000-0000-000000000001`);assert.equal(invalidNative.status(),400); await page.goto(`${base}/manuscript/reader?bookId=${w.other}`);assert((await page.locator('main').innerText()).includes('No accepted manuscript text')); assert.deepEqual(errors,[],'No JavaScript errors, including jQuery validation load order'); checks.push((pwa?'Simulated PWA':'Browser')+': empty Reader, native incomplete-session refusal, out-of-scope plan404 and Help full article pass'); await context.close(); }}finally{await browser.close();} console.log(JSON.stringify({checks,physicalWindows:false,installedPWA:false},null,2)); })().catch(e=>{console.error(e.message);process.exitCode=1;});