const{chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict'); const base=process.env.SOLVER_BASE_URL||'http://127.0.0.1:5238',live=base.includes('dev.plotdirector.com'); const graph=JSON.parse(fs.readFileSync('PlotLine/Content/WritingSolver/Candidates/curated-v2-stage1-repair/writing-solver-curated-v2-stage1-repair.json')); (async()=>{const b=await chromium.launch(),c=await b.newContext();try{await c.addCookies([{name:'solver-anonymous',value:'true',url:base}]);const p=await c.newPage();for(const width of [390,768,1440,1920]){await p.setViewportSize({width,height:1000});for(const path of [live?'/':'/public-fixture/home?anonymous=true',live?'/features':'/public-fixture/tour?anonymous=true',live?'/pricing':'/public-fixture/pricing?anonymous=true','/help','/problem-solver','/problem-solver/'+graph.solutions[0].slug]){await p.goto(base+path);assert.deepEqual(await p.locator('.public-links a').allTextContents(),['Home','Tour','Pricing','Problem Solver','Help']);assert.equal(await p.locator('.public-links a').nth(3).getAttribute('href'),'/problem-solver');assert.equal(await p.locator('a[href*="/writing-problems"]').count(),0);assert(!/Writing Solver|Writing Problem Solver/.test(await p.locator('body').innerText()));assert.equal(await p.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);if(width===390){const toggle=p.getByRole('button',{name:'Open navigation'});await toggle.click();assert(await p.locator('.public-links a').nth(3).isVisible());await toggle.click();}}} for(const suffix of ['',...graph.solutions.map(s=>'/'+s.slug),'/browse','/browse/plots','/workspace/plot']){const old='/writing-problems'+suffix,redirect=await c.request.get(base+old,{maxRedirects:0});assert.equal(redirect.status(),308,old);assert.equal(redirect.headers().location,'/problem-solver'+suffix);} for(const method of ['GET','POST']){const r=await c.request.fetch(base+'/writing-problems/answer?state=opaque%2Btoken%3D&choose=true',{method,maxRedirects:0,data:method==='POST'?'state=opaque&node=welcome':undefined});assert.equal(r.status(),308);assert.equal(r.headers().location,'/problem-solver/answer?state=opaque%2Btoken%3D&choose=true');} // A valid pre-migration state URL survives the single redirect and restores exactly the same question. await p.goto(base+'/problem-solver');await p.locator('input[name=choices][value="story-not-working"]').check();await p.locator('.solver-form button[type=submit]').click();const question=await p.locator('.solver-question').innerText(),query=new URL(p.url()).search;assert(query.includes('state='));await p.goto(base+'/writing-problems'+query);assert.equal(new URL(p.url()).pathname,'/problem-solver');assert.equal(await p.locator('.solver-question').innerText(),question);assert.equal(new URL(p.url()).search,query); await p.locator('.solver-form').evaluate(e=>e.action='/writing-problems/answer');await p.locator('input[name=choices][value=too-many]').check();await p.locator('.solver-form button[type=submit]').click();assert.equal(new URL(p.url()).pathname,'/problem-solver');assert.notEqual(await p.locator('.solver-question').innerText(),question); await p.goto(base+'/problem-solver/'+graph.solutions[0].slug);const trail=p.locator('nav[aria-label=Breadcrumb]');assert.deepEqual(await trail.locator('a').allTextContents(),['Home','Problem Solver']);assert.equal(await trail.locator('[aria-current=page]').innerText(),graph.solutions[0].title); console.log('PASS public navigation/name/internal links at four widths; 52 single-hop legacy 308s, entry/browse/workspace redirects, preserved query/POST method semantics, restored opaque state, permanent breadcrumbs.');}finally{await c.close();await b.close();}})().catch(e=>{console.error(e);process.exit(1)});