Files
SGF/scripts/sgf-document-math-concurrency.mjs
2026-11-11 09:00:17 +02:00

5 lines
1.7 KiB
JavaScript

import fs from 'node:fs';import {spawn,spawnSync} from 'node:child_process';import assert from 'node:assert/strict';
const php='C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',script='scripts/sgf-document-math-concurrency.php',run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),dir=run.root+'/private/receipt-composition-b4093c6f6707/document-math-concurrency';
const call=mode=>{const r=spawnSync(php,[script,mode],{encoding:'utf8',windowsHide:true});assert.equal(r.status,0,r.stdout+r.stderr);assert.match(r.stdout,/"passed":true/);return r.stdout;};if(fs.existsSync(dir+'/result.json')){assert(JSON.parse(fs.readFileSync(dir+'/result.json')).passed);console.log(JSON.stringify({passed:true,reused:true,proof:dir+'/result.json'}));process.exit();}
call('prepare');const first=spawn(php,[script,'first'],{stdio:'pipe',windowsHide:true});let out='';first.stdout.on('data',d=>out+=d);first.stderr.on('data',d=>out+=d);const ended=new Promise(r=>first.once('exit',r));try{const deadline=Date.now()+10000;while(!fs.existsSync(dir+'/locked')&&Date.now()<deadline)await new Promise(r=>setTimeout(r,40));assert(fs.existsSync(dir+'/locked'));const second=spawn(php,[script,'second'],{stdio:'pipe',windowsHide:true});let output='';second.stdout.on('data',d=>output+=d);second.stderr.on('data',d=>output+=d);assert.equal(await new Promise(r=>second.once('exit',r)),0,output);assert.match(output,/"passed":true/);const r=JSON.parse(fs.readFileSync(dir+'/second.json'));assert.equal(r.status,503);assert.equal(r.retry_after,'5');assert(r.elapsed_seconds>=4.5&&r.elapsed_seconds<12);}finally{fs.writeFileSync(dir+'/release','Release existing regression lock only');assert.equal(await ended,0,out);}console.log(call('recover').trim());