user-engine/scripts/browser_journeys.mjs
tegwick 1127f852dd
Some checks failed
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Container Image / build-and-push (push) Successful in 20s
Account journey acceptance / journeys (push) Failing after 0s
Implement role-based account journeys with database and browser acceptance suites
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a092fe-13b1-7f12-ac74-7d258af4d79c
2026-09-13 12:20:02 +02:00

51 lines
4.7 KiB
JavaScript

// No production accounts, network providers or header overrides are used.
const [debug, base] = process.argv.slice(2);
const version=await (await fetch(debug+'/json/version')).json();
const ws=new WebSocket(version.webSocketDebuggerUrl);
await new Promise(resolve=>ws.addEventListener('open',resolve,{once:true}));
let next=0;const pending=new Map();
ws.addEventListener('message',event=>{const m=JSON.parse(event.data);if(pending.has(m.id)){const p=pending.get(m.id);pending.delete(m.id);m.error?p.reject(Error(m.error.message)):p.resolve(m.result);}});
const call=(method,params={},sessionId)=>new Promise((resolve,reject)=>{const id=++next;pending.set(id,{resolve,reject});ws.send(JSON.stringify({id,method,params,...(sessionId?{sessionId}:{})}));});
const {targetId}=await call('Target.createTarget',{url:'about:blank'});
const {sessionId}=await call('Target.attachToTarget',{targetId,flatten:true});
const cmd=(method,params)=>call(method,params,sessionId);
await cmd('Page.enable');await cmd('Network.enable');
const evaluate=async expression=>{const r=await cmd('Runtime.evaluate',{expression,returnByValue:true});if(r.exceptionDetails)throw Error('Browser evaluation failed');return r.result.value;};
async function waitFor(expression){for(let n=0;n<70;n++){if(await evaluate(expression))return;await new Promise(r=>setTimeout(r,100));}throw Error('Browser condition not met: '+expression);}
async function navigate(path){await cmd('Page.navigate',{url:base+path});await waitFor('location.href === '+JSON.stringify(base+path)+' && document.readyState === "complete"');}
async function identity(who){await cmd('Network.clearBrowserCookies');if(who)await cmd('Network.setCookie',{name:'ue_session',value:who,url:base,path:'/',httpOnly:true,sameSite:'Lax'});}
let checks=0;async function check(expression,name){if(!await evaluate(expression))throw Error(name);console.log('PASS '+name);checks++;}
try{
await navigate('/');
await check(`!!document.querySelector('a[href="/login"]') && !document.querySelector('a[href="/logout"]')`,'U01 anonymous session controls');
await identity('member');await navigate('/onboarding');
await check(`!!document.querySelector('a[href="/logout"]') && !document.querySelector('a[href="/login"]')`,'U01 authenticated session controls');
await navigate('/platform');
await check(`document.body.innerText.includes("Access is not available") && !!document.querySelector('a[href="/access-recovery"]')`,'T01 member denial has recovery');
await navigate('/security');
await check(`document.body.innerText.includes("Authenticator setup is temporarily unavailable")`,'U06 unavailable OTP is explicit');
await identity('admin');await navigate('/admin/tenant:trial:demo-company');
await check(`document.body.innerText.includes("Login name: actual.login")`,'T03 actual login name shown');
await check(`document.body.innerText.includes("Onboarding follow-up")`,'T07 onboarding state visible');
await evaluate(`Array.from(document.forms).find(f=>f.action.endsWith("/status")).querySelector("button").click()`);
await waitFor('document.body.innerText.includes("Confirm change")');
await check(`document.body.innerText.includes("Other tenant access and the shared login are retained")`,'T06 scope confirmation');
await evaluate(`Array.from(document.links).find(a=>a.textContent==="Cancel without changes").click()`);
await waitFor('location.pathname === "/"');
await navigate('/admin/tenant:trial:demo-company');
await check(`document.body.innerText.includes("active for this tenant")`,'T06 cancel preserves active account');
await cmd('Emulation.setDeviceMetricsOverride',{width:390,height:844,deviceScaleFactor:1,mobile:true});
await navigate('/security');
await check(`document.documentElement.scrollWidth <= innerWidth`,'U12 security recovery fits mobile');
await cmd('Emulation.clearDeviceMetricsOverride');
await identity('operator');await navigate('/platform');
await check(`!!document.querySelector('a[href="/platform/operations"]')`,'P01 platform recovery navigation');
await navigate('/platform/operations');
await check(`document.body.innerText.includes("Live sign-in, email receipt and authenticator health are not verified here")`,'P05 unknown provider health remains explicit');
await navigate('/logout');
await check(`document.body.innerText.includes("Log out of this portal?")`,'U11 logout requires confirmation');
await evaluate(`document.querySelector('form[action="/logout"] button').click()`);
await waitFor('location.pathname === "/logged-out"');
await check(`!!document.querySelector('a[href="/login"]') && !document.querySelector('a[href="/logout"]')`,'U11 logout updates controls');
console.log(JSON.stringify({checks,result:'passed',scope:'isolated browser and synthetic providers; live OTP/email not inferred'}));
}finally{await call('Target.closeTarget',{targetId});ws.close();}