2026-09-13 12:20:02 +02:00
// 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' ) ;
2026-09-13 14:14:10 +02:00
await navigate ( '/platform/activity' ) ;
await check ( ` !!document.querySelector('input[name="reference"]') && !!document.querySelector('input[name="tenant"]') ` , 'P08 platform investigation filters' ) ;
await evaluate ( ` document.querySelector('input[name="reference"]').value='synthetic-missing';document.querySelector('form[action="/platform/activity"] button').click() ` ) ;
await waitFor ( 'location.search.includes("synthetic-missing") && document.body.innerText.includes("No matching records")' ) ;
await check ( ` document.body.innerText.includes("does not prove that no action occurred") ` , 'P08 missing evidence is explicit' ) ;
await navigate ( '/admin/tenant:trial:demo-company' ) ;
await evaluate ( ` Array.from(document.forms).find(f=>f.action.endsWith("/recover")).querySelector("button").click() ` ) ;
await waitFor ( 'document.body.innerText.includes("Confirm change")' ) ;
await check ( ` document.body.innerText.includes("does not reset a password") && document.body.innerText.includes("cannot bypass") ` , 'P04 restoration explains factor boundary' ) ;
2026-09-13 12:20:02 +02:00
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 ( ) ; }