import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import assert from 'node:assert/strict';import {createRequire} from 'node:module';import {pathToFileURL} from 'node:url'; const state=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json','utf8')),tag=process.argv[2];if(state.port!==55439||!/^[a-f0-9]{12}$/.test(tag||''))throw Error('Wrong private source'); const root=path.join(state.root,'private','stock-receipt-'+tag),app=path.join(root,'app'),native=path.resolve('../compras'),privateState=JSON.parse(fs.readFileSync(path.join(root,'state.json'),'utf8'));if(path.resolve(privateState.app)!==path.resolve(app))throw Error('Wrong QA app'); const require=createRequire(path.join(app,'package.json')),React=require('react'),{renderToString}=require('react-dom/server');const {createInertiaApp}=await import(pathToFileURL(path.join(native,'node_modules/@inertiajs/react/dist/index.js')));const {createServer}=await import(pathToFileURL(path.join(native,'node_modules/vite-plus/dist/index.js'))); const server=await createServer({root:app,configFile:false,cacheDir:path.join(root,'return-render-cache'),resolve:{alias:{'@':path.join(app,'resources/js')},dedupe:['react','react-dom','@inertiajs/react']},server:{middlewareMode:true,watch:null},appType:'custom',optimizeDeps:{noDiscovery:true}}); try{ const file=path.join(root,'native-stock-history-page.json'),page=JSON.parse(fs.readFileSync(file,'utf8'));assert.equal(page.component,'stock/operations');assert.equal(page.props.operations.data[0].kind,'workshop_return'); const {default:Operations}=await server.ssrLoadModule('/resources/js/pages/stock/operations.tsx');const result=await createInertiaApp({page,render:renderToString,resolve:()=>Operations,setup:({App,props})=>React.createElement(App,props)}); assert(result.body.includes('Devolução de excedente'));assert(result.body.includes('Registado por'));assert(result.body.includes('Responsável:')); const hash=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');const proof={kind:'server_render_of_actual_native_stock_history_props',page_sha256:hash(file),component_sha256:hash(path.join(app,'resources/js/pages/stock/operations.tsx')),render_passed:true,return_human_label_visible:true,author_and_responsible_rendered:true,actual_http_props_used:true,visual_review:false,browser_interactions_tested:false};fs.writeFileSync('docs/proofs/native-return-history-render-20261102.json',JSON.stringify(proof,null,2)+'\n');console.log(JSON.stringify(proof)); }finally{await server.close();}