Files
SGF/scripts/stock-read-regression.mjs
2026-11-02 20:29:34 +02:00

18 lines
2.3 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import {spawnSync} from 'node:child_process';
const runtime='C:/laragon/data/sgf-tempo/run';
const state=JSON.parse(fs.readFileSync(path.join(runtime,'modular-regression-current.json'),'utf8'));
if(!/^[a-f0-9]{12}$/.test(state.id)||path.resolve(state.root)!==path.resolve(runtime,'modular-regression-'+state.id)||path.resolve(state.app)!==path.resolve(state.root,'app')||state.port!==55439)throw Error('Unexpected regression host');
const output=path.join(state.root,'stock-read-'+Date.now()+'.json');
if(process.argv[2]&&!['functional','cross','receipt','return'].includes(process.argv[2]))throw Error('Use no argument, functional, cross <private native proof> or receipt <private root>');
const cross=process.argv[2]==='cross';
const receipt=process.argv[2]==='receipt';const returns=process.argv[2]==='return';
if(cross){const file=path.resolve(process.argv[3]||'');if(!file.startsWith(path.resolve(state.root,'private')+path.sep)||!fs.existsSync(file))throw Error('Unexpected native composition proof');}
if(receipt){const root=path.resolve(process.argv[3]||'');if(!root.startsWith(path.resolve(state.root,'private')+path.sep)||!fs.existsSync(path.join(root,'receipt-results.json')))throw Error('Unexpected receipt proof');}
if(returns){const root=path.resolve(process.argv[3]||'');if(!root.startsWith(path.resolve(state.root,'private')+path.sep)||!fs.existsSync(path.join(root,'return-results.json')))throw Error('Unexpected native return proof');}
const filter=returns?['--filter','test_native_return_book']:process.argv[2]==='functional'?['--filter','test_scoped_exact|test_snapshot']:cross?['--filter','test_purchasing_composition']:receipt?['--filter','test_native_receipt_book']:[];
const r=spawnSync('C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',['vendor/phpunit/phpunit/phpunit','tests/Feature/StockReadTest.php',...filter,'--log-junit',output.replace('.json','.xml')],{
cwd:state.app,stdio:'inherit',windowsHide:true,env:{...process.env,SGF_ISOLATED_REGRESSION_RUN:state.id,SGF_STOCK_READ_OUTPUT:output,...(cross?{STOCK_READ_NATIVE_PROOF:path.resolve(process.argv[3])}:{}),...(receipt?{STOCK_RECEIPT_NATIVE_ROOT:path.resolve(process.argv[3])}:{}),...(returns?{STOCK_RETURN_NATIVE_ROOT:path.resolve(process.argv[3])}:{})}});
console.log(JSON.stringify({exit_code:r.status,report:output}));process.exitCode=r.status??1;