import fs from 'node:fs'; import path from 'node:path'; import {createRequire} from 'node:module'; import {fileURLToPath} from 'node:url'; import assert from 'node:assert/strict'; import {createHash} from 'node:crypto'; const out=path.dirname(fileURLToPath(import.meta.url)); const qa=path.resolve(out,'../../storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742'); const req=createRequire(path.join(qa,'package.json')),ts=req('typescript'); const source=fs.readFileSync(path.join(qa,'resources/js/lib/portal-navigation.ts'),'utf8'); const js=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022}}).outputText; const module={exports:{}};new Function('exports','module',js)(module.exports,module); const http=JSON.parse(fs.readFileSync(path.join(out,'option-B7-navigation-HTTP.json'),'utf8'));assert.equal(http.result,'passed'); const walk=rows=>rows.flatMap(r=>[r,...walk(r.children??[])]); const cases=http.cases.map(c=>{ const links=walk(module.exports.portalNavigation(c.navigation_input)).filter(x=>x.href==='/management/negocios'); assert.equal(links.length,c.business_review_url?1:0); if(links.length)assert.equal(links[0].label,'Revisão de negócios'); return {actor_id:c.actor_id,authorized_review_links:links.length}; }); assert.equal(walk(module.exports.portalNavigation({authenticated:false,manager:false,businesses:true,businessReviewUrl:null})).filter(x=>x.href==='/management/negocios').length,0); const proof={at:new Date().toISOString(),result:'passed',kind:'actual server props through real navigation function; no DOM or browser',source_sha256:createHash('sha256').update(source).digest('hex'),cases,anonymous_links:0,browser_observed:false,active_changes:0}; const dest=path.join(out,'option-B7-navigation-tree.json');assert(!fs.existsSync(dest));fs.writeFileSync(dest,JSON.stringify(proof,null,2)+'\n');process.stdout.write(JSON.stringify(proof));