fix: separate BPM reads from durable execution delivery
This commit is contained in:
1 parent
3ff69c6832
commit
10eac70745
8 files changed
+120
-27
No files matched your search
@@ -23,3 +23,10 @@ test('health reports process event loop observations without exposing host data'
|
||||
const observed=health.snapshot({role:'admin'}).runtime.eventLoop;
|
||||
assert.ok(observed,'process event loop observations must be available');assert.equal(observed.observed,true);assert.ok(Number.isFinite(observed.maxMs));assert.ok(observed.maxMs>=0);
|
||||
});
|
||||
test('paused connections retain their source and listener failure evidence',t=>{
|
||||
const stateDir=fs.mkdtempSync(path.join(os.tmpdir(),'health-paused-')),at=new Date().toISOString(),connection={id:'c',owner:'worker',status:'connected'};
|
||||
const health=new RuntimeHealth({stateDir,workspace:{snapshot:()=>({connections:[connection]})},scanner:{store:{status:()=>({config:{enabled:true},runs:[{connectionId:'c',kind:'inform',status:'error',finishedAt:at,message:'合成失败'}]})}},monitor:{snapshot:()=>({status:'error',lastFailureAt:at,sources:{}})}});
|
||||
t.after(()=>{health.close();fs.rmSync(stateDir,{recursive:true,force:true});});health.snapshot({role:'admin'});connection.status='disabled';const data=health.snapshot({role:'admin'}),scan=data.groups.find(group=>group.key==='scan');
|
||||
assert.equal(scan.items.length,2);assert.equal(scan.items.find(item=>item.kind==='inform').status,'paused');assert.equal(scan.items.find(item=>item.kind==='inform').lastFailureAt,at);
|
||||
const listener=data.groups.find(group=>group.key==='listener').items[0];assert.equal(listener.status,'paused');assert.equal(listener.lastFailureAt,at);
|
||||
});
|
||||
@@ -9,15 +9,15 @@ function fixture(t,{interval=1440,onTodoReconciled}={}){
|
||||
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'arrival-recovery-')),workspace=new WorkspaceStore(path.join(dir,'workspace')),scanStore=new BpmScanStore(path.join(dir,'scan'));
|
||||
let scanner,monitor;t.after(async()=>{await monitor?.stop();await scanner?.stop();scanStore.close();workspace.close();fs.rmSync(dir,{recursive:true,force:true});});
|
||||
const admin={username:'admin',role:'admin'},connection=workspace.createConnection({name:'合成连接',owner:'admin'},admin,[admin]);
|
||||
let now=Date.parse('2026-10-21T01:00:00Z'),todoCalls=0,failed=false,callbacks,hold;
|
||||
let now=Date.parse('2026-10-21T01:00:00Z'),todoCalls=0,informCalls=0,failed=false,callbacks,hold,informHold;
|
||||
workspace.updateConnectionSession(connection.id,{status:'connected',identity:'synthetic',checkedAt:new Date(now).toISOString(),checks:{portal:{ok:true,message:'synthetic'}}},admin);
|
||||
scanStore.saveConfig({enabled:true,intervalMinutes:interval});
|
||||
const row={source:'todo',portalSource:'portal-v4',taskId:'T',instanceId:'I',revision:1,processName:'合成订单',nodeName:'通知',processVersion:'1',serialNum:'S',title:'订单号:TEST',receivedAt:'2026-10-21T00:30:00Z'};
|
||||
const manager={sessions:new Map(),epoch:()=>0,ensure:async()=>({status:'connected'}),run:async(_,fn)=>fn(),authorize(){},vault:()=>({read:async()=>({storageState:{cookies:[],origins:[]}})}),scanArrivals:async()=>[]};
|
||||
const manager={sessions:new Map(),epoch:()=>0,ensure:async()=>({status:'connected'}),run:async(_,fn)=>fn(),authorize(){},vault:()=>({read:async()=>({storageState:{cookies:[],origins:[]}})}),scanArrivals:async()=>{informCalls++;if(informHold)await informHold;return [];}};
|
||||
const provider={scan:async()=>{todoCalls++;if(hold)await hold;if(failed)throw Object.assign(Error('synthetic network failure'),{code:'ETIMEDOUT'});return [structuredClone(row)];}};
|
||||
scanner=new BpmScanner({workspace,store:scanStore,manager,settings:()=>({schedule:{weekends:true}})});
|
||||
monitor=new BpmArrivalMonitor({workspace,manager,scanner,provider,onTodoReconciled,clock:()=>now,settings:()=>({schedule:{weekends:true}}),hubClient:{connect:async(_,options)=>{callbacks=options;return {stop:async()=>{}};}},debounceMs:1,sourceRetryMs:[100,200,1000]});
|
||||
return {workspace,scanStore,connection,admin,monitor,row,get now(){return now;},get calls(){return todoCalls;},advance:ms=>now+=ms,fail:value=>failed=value,hint:()=>callbacks.onEvent('worklistChanged'),hold:value=>hold=value};
|
||||
return {workspace,scanStore,connection,admin,monitor,row,get now(){return now;},get calls(){return todoCalls;},get informCalls(){return informCalls;},advance:ms=>now+=ms,fail:value=>failed=value,hint:()=>callbacks.onEvent('worklistChanged'),hintInform:()=>callbacks.onEvent('informlistChanged'),hold:value=>hold=value,holdInform:value=>informHold=value};
|
||||
}
|
||||
test('reducing a live reconciliation interval applies from the last completed reconciliation',async t=>{
|
||||
const f=fixture(t);await f.monitor.tick();await until(()=>f.monitor.snapshot(f.connection.id).lastSyncAt);
|
||||
@@ -37,3 +37,20 @@ test('only fully committed authorized todo reads publish trusted execution hints
|
||||
let release;f.hold(new Promise(resolve=>release=resolve));f.hint();await until(()=>f.calls===2);f.workspace.disableConnection(f.connection.id,f.admin);
|
||||
const stopping=f.monitor.stopConnection(f.connection.id);release();await stopping;assert.equal(hints.length,1);
|
||||
});
|
||||
test('global automatic pause revokes the in-flight todo ticket without blocking later manual sync',async t=>{
|
||||
const hints=[],f=fixture(t,{onTodoReconciled:payload=>hints.push(payload)});await f.monitor.tick();await until(()=>f.monitor.snapshot(f.connection.id).lastSyncAt);
|
||||
let release;f.hold(new Promise(resolve=>release=resolve));f.hint();await until(()=>f.calls===2);f.scanStore.saveConfig({enabled:false,intervalMinutes:1440});const stopping=f.monitor.reconfigure();release();await stopping;
|
||||
assert.equal(hints.length,1);assert.equal(f.scanStore.status().runs.filter(run=>run.kind==='todo'&&run.status==='success').length,1);
|
||||
f.hold(null);await f.monitor.startTodoScan(f.connection.id,{user:f.admin,sessionId:'manual'}).promise;assert.equal(hints.length,2);
|
||||
});
|
||||
test('retiring the listener revokes an in-flight inform commit ticket',async t=>{
|
||||
const f=fixture(t);await f.monitor.tick();await until(()=>f.monitor.snapshot(f.connection.id).lastSyncAt);
|
||||
let release;f.holdInform(new Promise(resolve=>release=resolve));f.hintInform();await until(()=>f.informCalls===2);const stopping=f.monitor.stopConnection(f.connection.id);release();await stopping;
|
||||
assert.equal(f.scanStore.status().runs.filter(run=>run.kind==='inform'&&run.status==='success').length,1);
|
||||
});
|
||||
test('local hint delivery retries its encrypted committed payload without re-reading BPM or changing read success',async t=>{
|
||||
let attempts=0;const f=fixture(t,{onTodoReconciled:()=>{attempts++;if(attempts===1)throw Error('synthetic queue failure');}});await f.monitor.tick();await until(()=>attempts===1&&!f.monitor.entries.get(f.connection.id).sync);
|
||||
const run=f.scanStore.status().runs.find(item=>item.kind==='todo');assert.equal(run.status,'success');assert.equal(f.monitor.snapshot(f.connection.id).delivery.status,'error');
|
||||
const stored=f.scanStore.db.prepare('SELECT payload FROM execution_deliveries WHERE run_id=?').get(run.id);assert.ok(stored);assert.equal(Buffer.from(stored.payload).includes(Buffer.from(f.row.title)),false);
|
||||
f.advance(101);await f.monitor.tick();await until(()=>attempts===2&&f.monitor.snapshot(f.connection.id).delivery.pending===0);assert.equal(f.calls,1);assert.equal(f.scanStore.status().runs.find(item=>item.id===run.id).status,'success');
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
||||
const {BpmScanStore}=require('../../src/modules/bpm/scan-store.cjs');
|
||||
test('committed delivery survives restart encrypted and acknowledgement releases only transport payload',t=>{
|
||||
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'scan-delivery-'));let store=new BpmScanStore(dir);t.after(()=>{store.close();fs.rmSync(dir,{recursive:true,force:true});});
|
||||
const runId=store.begin('c','synthetic','todo'),payload={runId,connectionId:'c',rows:[{title:'synthetic-private-title'}],startedAt:'2026-10-21T01:00:00Z',finishedAt:'2026-10-21T01:00:01Z'};
|
||||
store.complete(runId,'c',[{arrivalDay:'2026-10-21',taskId:'t',source:'todo:fixture'}],{id:'c',owner:'synthetic'},{delivery:payload});
|
||||
const bytes=store.db.prepare('SELECT payload FROM execution_deliveries WHERE run_id=?').get(runId).payload;assert.equal(Buffer.from(bytes).includes(Buffer.from('synthetic-private-title')),false);
|
||||
store.close();store=new BpmScanStore(dir);assert.deepEqual(store.deliveries.pending('c',Date.now())[0].payload,payload);store.deliveries.acknowledge(runId);assert.equal(store.deliveries.summary('c').pending,0);
|
||||
assert.equal(store.db.prepare('SELECT payload FROM execution_deliveries WHERE run_id=?').get(runId).payload,null);assert.equal(store.status().runs.find(run=>run.id===runId).status,'success');assert.equal(store.list({kind:'todo'}).total,1);
|
||||
});
|
||||
test('a damaged transport payload remains visible as delivery failure without falsifying its successful read',t=>{
|
||||
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'scan-delivery-damaged-')),store=new BpmScanStore(dir);t.after(()=>{store.close();fs.rmSync(dir,{recursive:true,force:true});});
|
||||
const id=store.begin('c','synthetic','todo');store.complete(id,'c',[],{id:'c'},{delivery:{runId:id,connectionId:'c',rows:[],startedAt:'2026-10-21T01:00:00Z',finishedAt:'2026-10-21T01:00:01Z'}});
|
||||
store.db.prepare('UPDATE execution_deliveries SET payload=? WHERE run_id=?').run(Buffer.from('damaged'),id);assert.deepEqual(store.deliveries.pending('c',Date.now()),[]);assert.equal(store.deliveries.summary('c').status,'error');assert.equal(store.deliveries.summary('c').pending,1);assert.equal(store.status().runs.find(run=>run.id===id).status,'success');
|
||||
});
|
||||
Reference in new issue
Block a user