Files
SGF/scripts/invoice-progress-read-overlay.mjs
T
2026-11-04 09:37:20 +02:00

9 lines
3.0 KiB
JavaScript

import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import {spawnSync} from 'node:child_process';
const variant=process.argv[2];const cases={available:{tag:'ce4c9bef1a51',proof:'receipt-ui-http.json'},partial:{tag:'da77bb730751',proof:'invoice-result.json'}};if(!cases[variant])throw Error('Explicit completed invoice progress book required');const selected=cases[variant];const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),tag=crypto.randomBytes(6).toString('hex'),sourceRoot=path.join(run.root,'private/receipt-composition-'+selected.tag),source=JSON.parse(fs.readFileSync(path.join(sourceRoot,'state.json'))),root=path.join(run.root,'private/invoice-progress-read-'+tag),app=path.join(root,'app');
if(!JSON.parse(fs.readFileSync(path.join(sourceRoot,selected.proof))).passed||source.env.DB_DATABASE!=='budget_core_sgf_'+selected.tag||source.env.DB_PORT!=='55439'||source.env.SGF_ISOLATED_REGRESSION_RUN!==run.id)throw Error('Owned completed regression book required');
fs.mkdirSync(root);for(const dir of ['app','bootstrap','config','routes','resources','database','public'])fs.cpSync(dir,path.join(app,dir),{recursive:true,filter:p=>!p.replaceAll('\\','/').includes('bootstrap/cache')});for(const pkg of ['budget-control','payables','general-ledger','module-updates','purchasing'])fs.cpSync(path.join('packages',pkg),path.join(app,'packages',pkg),{recursive:true});fs.symlinkSync(path.resolve('vendor'),path.join(app,'vendor'),'junction');fs.copyFileSync('composer.json',path.join(app,'composer.json'));for(const dir of ['bootstrap/cache','storage/logs','storage/framework/cache/data','storage/framework/views','storage/framework/sessions'])fs.mkdirSync(path.join(app,dir),{recursive:true});
// Existing bindings, native manifests and business facts remain in place; only application/session files are new.
for(const file of ['fixture.json','native-fixture.json'])fs.copyFileSync(path.join(sourceRoot,file),path.join(root,file));
const env={...source.env,APP_BASE_PATH:app,SGF_DOSSIERS_QA_ENABLED:'true',SGF_PURCHASING_FOCUS_QA_ENABLED:'true',SGF_PURCHASING_CONTINUITY_QA_ENABLED:'true',SGF_INVOICE_PROGRESS_QA_ENABLED:'true',SESSION_COOKIE:'sgf_dossier_read_'+tag,RECEIPT_COMPOSITION_STATE:path.join(root,'state.json')};const state={...source,root,app,env,invoiceProgress:true,progress_variant:variant,focus:true,dossiers:true,read_overlay:true,original_root:sourceRoot};fs.writeFileSync(path.join(root,'state.json'),JSON.stringify(state,null,2));
const result=spawnSync('C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',[path.resolve('scripts/invoice-progress-read-proof.php')],{cwd:app,env,encoding:'utf8',windowsHide:true,timeout:180000});fs.writeFileSync(path.join(root,'read-proof.log'),result.stdout+'\n'+result.stderr);if(result.status!==0||!fs.existsSync(path.join(root,'invoice-progress-read-result.json')))throw Error('Dossier read proof incomplete; private diagnostics retained '+tag);console.log(JSON.stringify({tag,root,result:result.stdout.trim()}));