import fs from 'node:fs';import assert from 'node:assert/strict';import crypto from 'node:crypto';import {createRequire} from 'node:module';import {pathToFileURL} from 'node:url';import {transformWithOxc} from 'vite';import {session} from './sgf-single-http.mjs'; const checks=[],ok=(v,n)=>{assert(v,n);checks.push(n);},root=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')).root+'/private/receipt-composition-cc50a276c10c';let r=await fetch('http://127.0.0.1:8085/api/general-ledger/statements',{headers:{Accept:'application/json'},redirect:'manual'});ok(r.status===401,'new endpoint authenticated');const s=await session('sgf:read_only','accounting');r=await s.get('/api/general-ledger/statements/confirm',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({preview:'QA-no-CSRF'})});ok(r.status===419,'new confirmation protected by CSRF');r=await s.get('/api/general-ledger/statements');const data=await r.json();ok(r.status===200&&!data.capabilities.prepare&&!data.capabilities.review&&s.identity.context.internal_statements_enabled===true,'actual consultation profile read-only and feature exposed'); const require=createRequire(import.meta.url);let src=fs.readFileSync('resources/js/WorkspaceNavigation.jsx','utf8').replace("from 'react'",'from '+JSON.stringify(pathToFileURL(require.resolve('react')).href));for(const f of ['billing-menu.js','workshop-menu.js','stock-menu.js','accounting-menu.js'])src=src.replace("from './"+f+"'",'from '+JSON.stringify(pathToFileURL(process.cwd()+'/resources/js/'+f).href));const c=await transformWithOxc(src,'WorkspaceNavigation.jsx',{jsx:{runtime:'classic'}}),{navigationGroups}=await import('data:text/javascript;base64,'+Buffer.from(c.code).toString('base64')),has=groups=>groups.some(g=>g.items.some(i=>i.id==='internal_statements'));ok(!has(navigationGroups(()=>true,2,{})),'function hidden without feature flag');ok(!has(navigationGroups(p=>p!=='general_ledger.view',2,{internalStatements:true})),'function requires original ledger view');ok(has(navigationGroups((p,u)=>s.identity.context.grants.some(g=>g.permission===p&&g.unit_id===(u??null)),2,{internalStatements:true})),'actual authorized reader can navigate statement function'); const manifest=JSON.parse(fs.readFileSync(root+'/app/public/build/manifest.json'));for(const e of Object.values(manifest).filter(v=>v.isEntry||/InternalStatementsWorkspace|FiscalObligationsWorkspace|statement-download/.test(v.file))){r=await fetch('http://127.0.0.1:8085/build/'+e.file);const bytes=Buffer.from(await r.arrayBuffer());ok(r.status===200&&/javascript/.test(r.headers.get('content-type'))&&crypto.createHash('sha256').update(bytes).digest('hex')===crypto.createHash('sha256').update(fs.readFileSync(root+'/app/public/build/'+e.file)).digest('hex'),'final served JS '+e.file);} for(const file of ['resources/js/InternalStatementsWorkspace.jsx','resources/js/FiscalObligationsWorkspace.jsx','resources/js/statement-download.js'])ok(crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex')===crypto.createHash('sha256').update(fs.readFileSync(root+'/app/'+file)).digest('hex'),'installed source exact '+file); const file=root+'/statements-final-http-20261111.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,business_commands:0,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));