Files
SGF/scripts/sgf-stock-inactive-ui.mjs
2026-11-11 09:00:17 +02:00

10 lines
2.9 KiB
JavaScript

// Static rendering and transport lifecycle checks; no browser or business writer.
import fs from 'node:fs';import assert from 'node:assert/strict';import {pathToFileURL} from 'node:url';import {createRequire} from 'node:module';import {transformWithOxc} from 'vite';import React from 'react';import {renderToStaticMarkup} from 'react-dom/server';import {requestStockPeriod} from '../resources/js/stock-period-request.js';
const require=createRequire(import.meta.url),checks=[];const ok=(v,n)=>{assert(v,n);checks.push(n);};
const compile=async(path,replacements={})=>{let code=fs.readFileSync(path,'utf8');for(const [a,b]of Object.entries(replacements))code=code.replace(a,b);code=code.replace(/from ['"]react['"]/g,'from '+JSON.stringify(pathToFileURL(require.resolve('react')).href));const output=await transformWithOxc(code,path,{jsx:{runtime:'classic'}});return 'data:text/javascript;base64,'+Buffer.from(output.code).toString('base64');};
const read=await compile('resources/js/StockReadWorkspace.jsx');const url=await compile('resources/js/StockInactiveReportWorkspace.jsx',{'./StockReadWorkspace.jsx':read,'./stock-period-request.js':pathToFileURL(process.cwd()+'/resources/js/stock-period-request.js').href});const {default:Component}=await import(url);const html=renderToStaticMarkup(React.createElement(Component,{api:()=>{throw Error('SSR must not fetch');},context:{token:'QA'}}));
ok(html.includes('name="as_of"')&&!html.includes('value="2026-'),'cut not automatically chosen');ok(html.includes('name="days"')&&html.includes('value="30"'),'explicit interval input');ok(html.includes('Todos os autorizados')&&html.includes('name="warehouse_id"'),'warehouse selector without first-record default');ok(html.includes('Artigos sem história conhecida ficam fora'),'scope limitation visible');ok(/<option[^>]*>25<\/option>/.test(html)&&/<option[^>]*>100<\/option>/.test(html),'only25/100 page choices');
let release;const old=[];const cancel=requestStockPeriod({query:{view:'inactive',as_of:'2026-11-10',days:30},api:()=>new Promise(r=>release=r),data:v=>old.push(v),error:()=>{},loading:()=>{}});await Promise.resolve();cancel();release({rows:['late']});await new Promise(r=>setTimeout(r,0));ok(old.length===1&&old[0]===null,'late response after context change cannot restore stale report');
let requested='';requestStockPeriod({query:{view:'inactive',as_of:'2026-11-10',days:30,search:'%_!'},api:async p=>{requested=p;return{};},data:()=>{},error:()=>{},loading:()=>{}});await new Promise(r=>setTimeout(r,0));ok(new URL(requested,'http://local').searchParams.get('search')==='%_!','literal filter transported intact');
const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'));const file=run.root+'/private/receipt-composition-cc50a276c10c/stock-inactive-ui-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,browser_visual_review:false,business_commands:0},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));