24 lines
8.4 KiB
JavaScript
24 lines
8.4 KiB
JavaScript
const {chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict');
|
|
const base=process.env.PD_INV_BASE||'http://127.0.0.1:5238',identity=process.env.PD_INV_IDENTITY?JSON.parse(fs.readFileSync(process.env.PD_INV_IDENTITY)):null,w=identity||{UserID:4,book:12,other:13,project:7};
|
|
const c=JSON.parse(fs.readFileSync('Docs/Writer/Investigations/production-catalogue-v0.1.json')),report=JSON.parse(fs.readFileSync(process.env.PD_INV_TRACE||'/tmp/production-investigation-paths.json'));
|
|
const wanted={A:'disconnected',B:'motivation',C:'slow',D:'conflict',E:'continuity',F:'motivation'};
|
|
(async()=>{const b=await chromium.launch();try{for(const pwa of[false,true]){const context=await b.newContext({viewport:{width:pwa?390:1440,height:pwa?844:1000}});await context.addInitScript(({u,pwa})=>{localStorage.setItem('plotdirector.desktop.v1.'+u,JSON.stringify({dismissedAt:Date.now()}));if(pwa)Object.defineProperty(navigator,'standalone',{value:true});},{u:w.UserID,pwa});const p=await context.newPage(),errors=[],external=[];p.on('pageerror',e=>errors.push(e.message));p.on('request',r=>{if(/openai|anthropic|inference|generativelanguage/i.test(r.url()))external.push(r.url());});
|
|
if(identity){await p.goto(base+'/Account/Login');await p.locator('[name=Email]').fill(w.Email);await p.locator('[name=Password]').fill(w.Password);await Promise.all([p.waitForURL('**/Projects'),p.locator('button[type=submit]').click()]);}
|
|
for(const route of'ABCDEF')for(const pattern of['supported','qualified','uncertain']){
|
|
const paths=report.paths.filter(x=>x.concern===route);const path=pattern==='supported'?paths.find(x=>x.target===wanted[route]&&x.final.Recommendations.length):pattern==='qualified'?(paths.find(x=>x.target==='qualified'&&['tentative','ambiguous'].includes(x.result.Kind))||paths.find(x=>['tentative','ambiguous'].includes(x.result.Kind))):paths.find(x=>x.target==='uncertain');assert(path,'real evaluator witness '+route+'/'+pattern);
|
|
await p.goto(`${base}/Writer/Explore?projectId=${w.project}&bookId=${w.book}`);await p.getByRole('link',{name:'Explore a concern',exact:true}).click();assert.equal((await p.locator('#investigation-question').textContent()).trim(),c.Questions[0].Text);for(const option of c.Questions[0].Options)assert.equal((await p.locator(`label:has([name=concern][value=${option.Id}])`).textContent()).trim(),option.Text);
|
|
await p.locator(`[name=concern][value=${route}]`).check();await p.getByRole('button',{name:'Begin',exact:true}).click();const url=p.url(),id=new URL(url).searchParams.get('id');
|
|
await p.locator('#investigation-explanation').fill('Unfinished editorial acceptance note');await p.getByRole('button',{name:'Save for later',exact:true}).click();await p.reload();assert.equal(await p.locator('#investigation-explanation').inputValue(),'Unfinished editorial acceptance note');
|
|
for(let n=0;n<path.answers.length;n++){const a=path.answers[n],q=c.Questions.find(q=>q.Id===a.Question),form=p.locator('[data-investigation-answer]');assert.equal(await form.locator('[name=question]').inputValue(),q.Id);assert.equal((await p.locator('#investigation-question').textContent()).trim(),q.Text);for(const o of q.Options)assert.equal((await form.locator(`label:has([name=option][value=${o.Id}])`).textContent()).trim(),o.Text);await form.locator(`[name=option][value=${a.Option}]`).check();await form.locator(`button[value=${n===1?'save':'answer'}]`).click();if(n===1){await p.goto(`${base}/Writer/Explore/Investigate?bookId=${w.book}`);await p.locator(`aside a[href*="${id}"]`).click();}}
|
|
assert.equal(await p.locator('[data-investigation-answer]').count(),0);assert.equal(await p.locator('#investigation-question').getAttribute('data-conclusion'),path.result.Kind);assert((await p.locator('[data-writing-action]').first().textContent()).trim().length>20);assert(await p.locator('[data-supporting-observations] li').count()>0);const body=await p.locator('body').textContent();assert(/not an analysis of your manuscript/.test(body));assert(!/synthetic|hypothesis|corroboration|threshold|test catalogue|net evidence|tentative-only/i.test(body));assert.equal(await p.locator('iframe').count(),0);assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));
|
|
if(path.final.Recommendations.length){const forms=p.locator('form[action$="/Open"]');assert(await forms.count()>0);const ids=await forms.locator('[name=capability]').evaluateAll(xs=>[...new Set(xs.map(x=>x.value))]);for(const capability of ids){await p.reload();const f=p.locator('form[action$="/Open"]').filter({has:p.locator(`[name=capability][value="${capability}"]`)}).first(),data=await f.evaluate(f=>Object.fromEntries(new FormData(f)));data.capability=capability;const response=await p.request.post(base+'/Writer/Explore/Investigate/Open',{form:data,maxRedirects:0});assert.equal(response.status(),302);const dest=response.headers().location;assert(!/solver|writing-problems/i.test(dest));assert(dest.includes('projectId='+w.project)&&dest.includes('bookId='+w.book));if(identity)assert.equal((await p.request.get(new URL(dest,base).href)).status(),200);}await p.reload();const hidden=c.Hypotheses.filter(h=>path.final.Recommendations.includes(h.Id)).flatMap(h=>h.Capabilities).filter(id=>!ids.includes(id));for(const capability of hidden){const f=p.locator('form[action$="/Open"]').first(),data=await f.evaluate(f=>Object.fromEntries(new FormData(f)));data.capability=capability;assert.equal((await p.request.post(base+'/Writer/Explore/Investigate/Open',{form:data,maxRedirects:0})).status(),400);}}else assert.equal(await p.locator('form[action$="/Open"]').count(),0);
|
|
if(process.env.PD_INV_SCREENSHOTS&&!pwa){fs.mkdirSync(process.env.PD_INV_SCREENSHOTS,{recursive:true});await p.screenshot({path:process.env.PD_INV_SCREENSHOTS+'/'+route+'-'+pattern+'.png'});}
|
|
assert.equal((await p.request.get(`${base}/Writer/Explore/Investigate?bookId=${w.other}&id=${id}`)).status(),404);
|
|
const revise=path.answers.find(a=>c.Questions.find(q=>q.Id===a.Question).Options.find(o=>o.Id===a.Option).Contributions.some(v=>v.Weight>0))||path.answers[0],q=c.Questions.find(q=>q.Id===revise.Question),next=q.Options.find(o=>o.Id!==revise.Option);await p.goto(url+'&question='+q.Id);await p.locator(`[name=option][value=${next.Id}]`).check();await p.locator('button[value=answer]').click();await p.goto(url+'&question='+q.Id);assert(await p.locator(`[name=option][value=${next.Id}]`).isChecked());await p.reload();assert(await p.locator(`[name=option][value=${next.Id}]`).isChecked());
|
|
if(!identity){const other=await b.newContext();await other.addCookies([{name:'fixture-user',value:'5',url:base}]);assert.equal((await other.request.get(url)).status(),404);await other.close();}
|
|
console.log(`PASS ${identity?'Development':'isolated'} ${pwa?'simulated PWA':'browser'} ${route}/${pattern}: ${path.result.Kind}; exact wording, scoped tool, useful action, observations, save/resume, revision, private book`);
|
|
}
|
|
assert.equal((await p.request.get(`${base}/Writer/Explore/Investigate?bookId=${w.book}&catalogueVersion=synthetic-3d1-v1`)).status(),404);
|
|
if(!identity&&!pwa){assert.equal((await p.request.get(base+'/admin/writer-investigations')).status(),403);await context.addCookies([{name:'solver-reviewer',value:'true',url:base}]);const admin=await p.request.get(base+'/admin/writer-investigations'),token=(await admin.text()).match(/name="__RequestVerificationToken"[^>]*value="([^"]+)"/)[1];const old=fs.readFileSync('Docs/Writer/Investigations/synthetic-catalogue.json','utf8');assert.equal((await p.request.post(base+'/admin/writer-investigations',{form:{json:old,operation:'publish',__RequestVerificationToken:token}})).status(),200);await p.goto(`${base}/Writer/Explore/Investigate?bookId=${w.book}`);assert.equal((await p.locator('#investigation-question').textContent()).trim(),c.Questions[0].Text);await p.goto(`${base}/Writer/Explore/Investigate?bookId=${w.book}&catalogueVersion=synthetic-3d1-v1`);await p.locator('[name=concern][value=story]').check();await p.getByRole('button',{name:'Begin',exact:true}).click();const legacyUrl=p.url();assert((await p.locator('body').textContent()).includes('small test catalogue'));await context.clearCookies({name:'solver-reviewer'});assert.equal((await p.request.get(legacyUrl)).status(),404);console.log('PASS latest synthetic publication cannot replace author catalogue; AdminOnly owner-scoped legacy simulation retained');}
|
|
assert.deepEqual(errors,[]);assert.equal(external.length,0);await context.close();}}finally{await b.close();}})().catch(e=>{console.error(e.stack);process.exitCode=1});
|