17 lines
3.3 KiB
JavaScript
17 lines
3.3 KiB
JavaScript
import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import {spawnSync} from 'node:child_process';
|
|
const state=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),php='C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe';
|
|
if(state.port!==55439||!/^[a-f0-9]{12}$/.test(state.id)||path.resolve(state.root)!==path.resolve('C:/laragon/data/sgf-tempo/run/modular-regression-'+state.id))throw Error('Owned QA cluster only');
|
|
const resume=process.argv[2]&&process.argv[2]!=='new'?process.argv[2]:null;if(resume&&!/^[a-f0-9]{12}$/.test(resume))throw Error('Bad identifier');
|
|
const tag=resume??crypto.randomBytes(6).toString('hex'),root=path.join(state.root,'private/stock-ledger-'+tag),settings=path.join(root,'settings.json');
|
|
if(!resume){
|
|
fs.mkdirSync(root);const admin=fs.readFileSync(path.join(state.root,'private/admin-password.txt'),'utf8').trim();
|
|
const pg=input=>{const r=spawnSync('C:/Program Files/PostgreSQL/17/bin/psql.exe',['-h','127.0.0.1','-p','55439','-U','sgf_regression_owner','-d','postgres','-Atq','-v','ON_ERROR_STOP=1'],{input,encoding:'utf8',windowsHide:true,env:{...process.env,PGPASSWORD:admin}});if(r.status!==0)throw Error('QA provisioning failed; preserve private diagnostics without resetting');return r.stdout.trim();};
|
|
if(pg("SELECT current_setting('cluster_name')")!=='sgf_modular_regression_'+state.id)throw Error('Wrong physical cluster');
|
|
const database='compras_receipts_test_'+tag,role='payable_history_native_'+tag,password=crypto.randomBytes(32).toString('hex');pg(`CREATE ROLE ${role} LOGIN PASSWORD '${password}' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS; CREATE DATABASE ${database} OWNER ${role}; REVOKE ALL ON DATABASE ${database} FROM PUBLIC;`);
|
|
const storage=path.join(root,'storage');for(const d of ['framework/cache/data','framework/views','framework/sessions','logs','cache'])fs.mkdirSync(path.join(storage,d),{recursive:true});
|
|
fs.writeFileSync(settings,JSON.stringify({tag,root,database,role,password,storage,native:path.resolve('../compras'),ledger:path.resolve('packages/general-ledger'),cluster:'sgf_modular_regression_'+state.id,run:state.id,app_key:'base64:'+crypto.randomBytes(32).toString('base64')},null,2));
|
|
const fixture=fs.readFileSync('../compras/tests/Support/ReceiptFixture.php','utf8').replace('function receiptFixture(','function stockValuationFixture(').replace('function receiptPayload(','function stockValuationPayload(').replaceAll("'cx'","'UN'");
|
|
fs.writeFileSync(path.join(root,'StockReceiptFixture.php'),fixture);
|
|
}
|
|
const phases=process.argv[3]?.split(',')??['setup'];for(const phase of phases){if(!['setup','access','contract','cases','order-guard','extra','workflow','race','worker','http-proof','demo-baseline','demo-preservation'].includes(phase))throw Error('Unknown stock phase');if(fs.existsSync(path.join(root,phase+'.json')))throw Error('Completed proof preserved');const r=spawnSync(php,[path.resolve('scripts/stock-ledger-entry.php'),settings,phase],{encoding:'utf8',windowsHide:true,timeout:120000,maxBuffer:1024*1024});fs.writeFileSync(path.join(root,phase+'-'+Date.now()+'.log'),r.stdout+'\n'+r.stderr);console.log(JSON.stringify({tag,phase,exit_code:r.status,proof_present:fs.existsSync(path.join(root,phase+'.json'))}));if(r.status!==0||!fs.existsSync(path.join(root,phase+'.json'))){process.exitCode=1;break;}}
|