33 lines
3.4 KiB
JavaScript
33 lines
3.4 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import crypto from 'node:crypto';
|
|
import {spawnSync} from 'node:child_process';
|
|
const read=p=>JSON.parse(fs.readFileSync(p,'utf8'));
|
|
const state=read('C:/laragon/data/sgf-tempo/run/modular-regression-current.json');
|
|
if(state.port!==55439||!/^[a-f0-9]{12}$/.test(state.id))throw Error('Isolated QA host required');
|
|
const resume=process.argv[2];if(resume&&!/^[a-f0-9]{12}$/.test(resume))throw Error('Invalid owned tag');
|
|
const tag=resume??crypto.randomBytes(6).toString('hex'),root=path.join(state.root,'private/settlement-page-'+tag),settings=path.join(root,'settings.json');
|
|
if(!resume){
|
|
const prior=path.join(state.root,'private/payable-history-03e16d9fb37d/source.json'),bundle=read(prior);
|
|
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('Isolated provisioning failed');return r.stdout.trim();};
|
|
if(pg("SELECT current_setting('cluster_name')")!=='sgf_modular_regression_'+state.id)throw Error('Wrong effective cluster');
|
|
const role='payable_history_sgf_'+tag,database='payable_sgf_'+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 dir of ['framework/cache/data','framework/views','framework/sessions','logs','cache'])fs.mkdirSync(path.join(storage,dir),{recursive:true});
|
|
fs.copyFileSync(prior,path.join(root,'source.json'));
|
|
fs.writeFileSync(settings,JSON.stringify({tag,root,cluster:'sgf_modular_regression_'+state.id,source_instance:bundle.source.instance,app_key:'base64:'+crypto.randomBytes(32).toString('base64'),source_bundle_sha256:crypto.createHash('sha256').update(fs.readFileSync(prior)).digest('hex'),sgf:{root:process.cwd(),database,role,password,storage}},null,2));
|
|
}
|
|
const owned=read(settings);if(owned.tag!==tag||owned.cluster!=='sgf_modular_regression_'+state.id)throw Error('Owned context mismatch');
|
|
const phases=process.argv[3]?.split(',')??(resume?[]:['sgf','settlement-page-setup']);
|
|
for(const phase of phases){
|
|
const name={sgf:'fixture.json','settlement-page-setup':'settlement-fixture.json','settlement-page-cases':'settlement-cases.json','settlement-page-seed':'settlement-volume.json','settlement-page-post':'settlement-post.json'}[phase];if(!name)throw Error('Unknown phase');
|
|
if(fs.existsSync(path.join(root,name)))throw Error('Completed phase preserved; do not overwrite');
|
|
const at=Date.now(),r=spawnSync('C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',['-d','memory_limit=512M','scripts/payable-history-sgf-proof.php',settings,phase],{encoding:'utf8',windowsHide:true,maxBuffer:1024*1024});
|
|
fs.writeFileSync(path.join(root,phase+'-'+at+'.log'),(r.stdout??'')+(r.stderr??''));
|
|
if(r.status!==0||!fs.existsSync(path.join(root,name)))throw Error('Private QA phase failed: '+root);
|
|
process.stdout.write(r.stdout);
|
|
}
|
|
fs.writeFileSync(path.join(state.root,'settlement-page-latest.json'),JSON.stringify({tag,root}));
|
|
console.log(JSON.stringify({tag,root,owned_synthetic_database_only:true}));
|