24 lines
2.3 KiB
JavaScript
24 lines
2.3 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import crypto from 'node:crypto';
|
|
import {spawnSync} from 'node:child_process';
|
|
|
|
// No provisioning, server launch, database migration, real credentials or grants.
|
|
const repo=process.cwd(),run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'));
|
|
if(run.id!=='2576427d1939'||run.port!==55439||path.resolve(run.root)!==path.resolve('C:/laragon/data/sgf-tempo/run/modular-regression-'+run.id))throw Error('Known existing QA cluster only');
|
|
const pointer=path.join(run.root,'private/sgc-invoice-current.json');
|
|
if(process.argv.includes('--new')){
|
|
const root=path.join(run.root,'private','sgc-invoice-proof-'+crypto.randomBytes(6).toString('hex'));
|
|
fs.mkdirSync(root);fs.writeFileSync(path.join(root,'client.json'),JSON.stringify({token:crypto.randomBytes(32).toString('hex'),context:crypto.randomBytes(32).toString('hex')}));
|
|
fs.writeFileSync(pointer,JSON.stringify({root}));
|
|
for(const [script,result]of [['sgc-invoice-proof.php','result.json'],['sgc-invoice-security-proof.php','security-result.json'],['sgc-invoice-context-proof.php','context-result.json'],['sgc-invoice-authority-proof.php','authority-result.json']]){
|
|
const r=spawnSync('C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',['scripts/'+script],{cwd:repo,env:{...process.env,SGC_INVOICE_PROOF_ROOT:root},windowsHide:true,encoding:'utf8',timeout:180000});
|
|
fs.writeFileSync(path.join(root,script+'.log'),(r.stdout??'')+(r.stderr??''));
|
|
if(r.status!==0||!fs.existsSync(path.join(root,result))||JSON.parse(fs.readFileSync(path.join(root,result))).passed!==true)throw Error('Proof incomplete; inspect private log, preserve accepted steps before retrying');
|
|
}
|
|
}
|
|
const {root}=JSON.parse(fs.readFileSync(pointer));if(path.dirname(path.resolve(root))!==path.resolve(run.root,'private')||!/^sgc-invoice-proof-[a-f0-9]{12}$/.test(path.basename(root)))throw Error('Private proof root invalid');
|
|
const results=['result.json','security-result.json','context-result.json','authority-result.json'].map(file=>JSON.parse(fs.readFileSync(path.join(root,file))));
|
|
if(results.some(x=>x.passed!==true))throw Error('Incomplete proof');
|
|
console.log(JSON.stringify({passed:true,checks:results.reduce((n,x)=>n+x.checks.length,0),existing_regression_book:'da77bb730751',new_demo:false,new_server:false,endpoint_enabled_in_source:false,credentials_printed:false}));
|