// Isolated, loopback-only MVC host. Never target the deployed public site with this suite. const { chromium } = require('playwright'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const candidate = path.resolve('PlotLine/Content/WritingSolver/Candidates/curated-v2'); const graph = JSON.parse(fs.readFileSync(path.join(candidate,'writing-solver-curated-v2.json'),'utf8')); const cases = JSON.parse(fs.readFileSync(path.join(candidate,'acceptance-paths.json'),'utf8')).cases; const base = process.env.SOLVER_BASE_URL || 'http://127.0.0.1:5238'; assert(['127.0.0.1:5238','127.0.0.1:5050','dev.plotdirector.com'].includes(new URL(base).host),'Test only local or Development.'); (async () => { const browser = await chromium.launch(); try { const context=await browser.newContext({javaScriptEnabled:false,viewport:{width:1440,height:1000}}); const page=await context.newPage(); for (const [kind,pages] of [['problem-solver',graph.solutions],['features',graph.features]]) { for(const record of pages) { const response=await page.goto(`${base}/${kind}/${record.slug}`); assert.equal(response.status(),200,record.id); assert.equal(await page.locator('h1').innerText(),record.title,record.id); assert.equal(await page.locator('link[rel=canonical]').getAttribute('href'),`https://plotdirector.com/${kind}/${record.slug}`,record.id); assert.equal(await page.locator('meta[name=description]').getAttribute('content'),record.description,record.id); assert.equal(await page.locator('meta[property="og:description"]').getAttribute('content'),record.description,record.id); assert.equal(await page.locator('meta[name=robots]').getAttribute('content'),'noindex, follow',record.id); assert(await page.locator('script[type="application/ld+json"]').count(),record.id); assert((await page.locator('body').innerText()).includes(record.summary),record.id); assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false,record.id); assert(!((await page.locator('main').innerText()).includes('\uFFFD')),`Replacement character in ${record.id}`); for(const script of await page.locator('script[type="application/ld+json"]').allTextContents()) JSON.parse(script); if(kind==='problem-solver') { for(const link of record.features) { const feature=graph.features.find(f=>f.id===link.feature); assert(await page.locator(`a[href="/features/${feature.slug}"]`).count(),`${record.id}/${feature.id}`); } } } } await page.goto(base+'/problem-solver'); for(const choice of ['unsure','reread-cant-see','using-tool-concern','draft-done','too-much-written']) { await page.locator(`input[name=choices][value="${choice}"]`).check(); await page.locator('.solver-form button[type=submit]').click(); } assert.match(await page.locator('.solver-neutral h1').innerText(),/don't need to start again/); assert.equal(await page.locator('.solver-library').count(),0); assert(await page.locator('a[href="/features/manuscript-import"]').count()); await context.close(); for(const width of [390,1440]) { const context=await browser.newContext({viewport:{width,height:1000}}); await context.addInitScript(()=>{ localStorage.setItem('plotdirector.applicationTheme','rose-pink'); window.__shifts=[]; new PerformanceObserver(list=>list.getEntries().forEach(e=>{if(!e.hadRecentInput)window.__shifts.push(e.value);})).observe({type:'layout-shift',buffered:true}); }); const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message)); for(const id of [13,20,23,50,55,56,58,60]) { await page.goto(base+'/problem-solver'); const test=cases.find(c=>c.id===id); for(let i=0;idocument.documentElement.scrollWidth>innerWidth),false,`case ${id} width ${width}`); } assert.equal(await page.locator('html').getAttribute('data-site-theme'),'public'); assert.equal(await page.locator('html').getAttribute('data-app-theme'),null); assert((await page.evaluate(()=>window.__shifts.reduce((a,b)=>a+b,0)))<.1,`layout shift in case ${id}`); } // Browser history returns to the actual prior question; revise to neutral knowledge-state advice. await page.goto(base+'/problem-solver'); for(const answer of cases.find(c=>c.id===20).answers) { for(const choice of answer.choices) await page.locator(`input[name=choices][value="${choice}"]`).check(); await page.locator('.solver-form button[type=submit]').click(); } await page.goBack(); assert.equal(await page.locator('input[name=node]').getAttribute('value'),'track-knowledge'); await page.goForward();assert(await page.locator('.solver-result h1').innerText().then(s=>s===graph.solutions.find(s=>s.id==='d22').title)); await page.goBack();await page.locator('input[value="who-knows-fact"]').check();await page.locator('.solver-form button[type=submit]').click(); assert.equal(await page.locator('.solver-result').count(),0); assert(await page.locator('main').innerText().then(t=>t.includes('isn’t enough evidence'))); // All adoption concerns use their authored content, with at most one relevant capability. const endpoint=graph.nodes.find(n=>n.neutralEndpoint); for(const concern of endpoint.choices.filter(c=>c.active)) { await page.goto(base+'/problem-solver'); for(const [node,choice] of [['entry','unsure'],['rescue-happening','reread-cant-see'],['rescue-confidence','using-tool-concern'],['existing-stage','draft-done'],[endpoint.id,concern.id]]) { assert.equal(await page.locator('input[name=node]').getAttribute('value'),node); await page.locator(`input[name=choices][value="${choice}"]`).check(); await page.locator('.solver-form button[type=submit]').click(); } const expected=concern.reassurance || endpoint.reassurance; assert.equal(await page.locator('.solver-neutral h1').innerText(),expected.title); assert.equal(await page.locator('.solver-neutral .solver-intro').innerText(),expected.summary); assert.equal(await page.locator('.solver-result').count(),0); assert.equal(await page.locator('.solver-library').count(),0); assert(!(await page.locator('main').innerText()).includes('isn’t enough evidence')); assert.equal(await page.locator('.solver-neutral a[href^="/features/"]').count(),expected.feature ? 1 : 0); if(expected.feature) assert(await page.locator(`.solver-neutral a[href="/features/${graph.features.find(f=>f.id===expected.feature).slug}"]`).count()); assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false); } await page.goBack();await page.goForward();assert.equal(await page.locator('.solver-neutral').count(),1); await page.goBack();await page.goBack();await page.goBack(); assert.equal(await page.locator('input[name=node]').getAttribute('value'),'rescue-confidence'); await page.locator('input[value="story-moving"]').check();await page.locator('.solver-form button[type=submit]').click(); assert.equal(await page.locator('.solver-neutral').count(),0); assert.equal(await page.locator('input[name=node]').getAttribute('value'),'flow-target'); assert.equal(errors.length,0,errors.join('\n')); await context.close(); } // Existing renderer lists every public solution under a neutral result. Record its size // as a UX finding rather than silently treating a blank recommendation as a diagnosis. console.log('PASS curated V2 rendering: all 67 no-JS pages; desktop/mobile neutral, nonlinear, absence, multi-select, revision and Back/Forward journeys; all adoption concerns and no-JS reassurance; no overflow/CLS; noindex.'); } finally {await browser.close();} })().catch(error=>{console.error(error);process.exit(1);});