fix: close merge-review mail policy and repair validation gaps

This commit is contained in:
abaishu0730 committed 2026-10-27 14:38:36 +08:00
1 parent dcea4a063f
commit d744c36365
16 files changed
+168 -31

No files matched your search

@@ -0,0 +1,14 @@
'use strict';
// Keep the real server entrypoint and OS lifecycle, replacing business startup
// so this crash test cannot access company systems or production state.
const fs=require('node:fs'),http=require('node:http'),path=require('node:path');
const {respondToPing}=require('../../../src/platform/service/ping.cjs');
const application=require.resolve('../../../src/app/application.cjs');
require.cache[application]={id:application,filename:application,loaded:true,exports:{async main(){
const dir=process.env.ORDER_CRASH_TEST_DIR,port=Number(process.env.ORDER_CRASH_TEST_PORT);let ticks=0;
const server=http.createServer((req,res)=>respondToPing(req,res,{token:process.env.ORDER_SUPERVISOR_TOKEN,instanceId:process.env.ORDER_SUPERVISOR_INSTANCE,startedAt:new Date().toISOString()}));
await new Promise(resolve=>server.listen(port,'127.0.0.1',resolve));
fs.writeFileSync(path.join(dir,'child.pid'),String(process.pid));
const timer=setInterval(()=>fs.writeFileSync(path.join(dir,'ticks'),String(++ticks)),40);
return {async stop(){clearInterval(timer);await new Promise(resolve=>server.close(resolve));}};
}}};
@@ -0,0 +1,4 @@
'use strict';
const path=require('node:path');
const {ServiceSupervisor}=require('../../../src/platform/service/supervisor.cjs');
new ServiceSupervisor({stateDir:process.env.ORDER_CRASH_TEST_DIR,ports:[Number(process.env.ORDER_CRASH_TEST_PORT)],env:{NODE_OPTIONS:'--require "'+path.join(__dirname,'crash-service-preload.cjs').replaceAll('\\','/')+'"'},timing:{intervalMs:50,pingTimeoutMs:100,startupGraceMs:3000}}).start().catch(error=>{console.error(error);process.exit(1);});
+20
View File
@@ -0,0 +1,20 @@
'use strict';
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path'),net=require('node:net'),{spawn}=require('node:child_process');
const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
const crash=guard=>process.platform==='win32'?require('node:child_process').execFileSync('powershell.exe',['-NoProfile','-NonInteractive','-Command','Stop-Process -Id '+guard.pid+' -Force'],{windowsHide:true}):guard.kill('SIGKILL');
const alive=pid=>{try{process.kill(pid,0);return true;}catch{return false;}};
async function until(predicate,timeout=5000){const end=Date.now()+timeout;while(Date.now()<end){if(await predicate())return true;await pause(40);}return false;}
async function freePort(){const socket=net.createServer();await new Promise(resolve=>socket.listen(0,'127.0.0.1',resolve));const port=socket.address().port;await new Promise(resolve=>socket.close(resolve));return port;}
async function fixture(t){
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'order-guard-crash-')),port=await freePort();let childPid;
const guard=spawn(process.execPath,[path.resolve('tests/service/fixtures/crash-supervisor.cjs')],{cwd:process.cwd(),windowsHide:true,detached:true,stdio:'ignore',env:{...process.env,ORDER_CRASH_TEST_DIR:dir,ORDER_CRASH_TEST_PORT:String(port)}});
t.after(async()=>{if(alive(guard.pid))guard.kill('SIGKILL');if(childPid&&alive(childPid))process.kill(childPid,'SIGKILL');await until(()=>!alive(guard.pid)&&(!childPid||!alive(childPid)));await fs.rm(dir,{recursive:true,force:true});});
assert.equal(await until(async()=>{try{childPid=Number(await fs.readFile(path.join(dir,'child.pid'),'utf8'));return Number(await fs.readFile(path.join(dir,'ticks'),'utf8'))>1;}catch{return false;}}),true,'isolated child must start');
return {dir,port,guard,childPid};
}
test('Windows abrupt supervisor death stops its business child and releases its listening port',{timeout:15000,skip:process.platform!=='win32'},async t=>{
const {dir,port,guard,childPid}=await fixture(t);crash(guard);
assert.equal(await until(()=>!alive(childPid)),true,'orphan business child must exit after supervisor death');
const ticks=await fs.readFile(path.join(dir,'ticks'),'utf8');await pause(150);assert.equal(await fs.readFile(path.join(dir,'ticks'),'utf8'),ticks,'scheduled work must cease');
const socket=net.createServer();await new Promise((resolve,reject)=>{socket.once('error',reject);socket.listen(port,'127.0.0.1',resolve);});await new Promise(resolve=>socket.close(resolve));
});