From 8d010a05cdd91ab0b5a4f51b32b4fad67dc71a58 Mon Sep 17 00:00:00 2001 From: abaishu0730 Date: Mon, 26 Oct 2026 09:18:39 +0800 Subject: [PATCH] fix: reconcile failed BPM handshakes and reject revoked session writes --- docs/HANDOFF.md | 9 ++++++ docs/bpm-session-state-machine-2026-10-24.md | 6 ++++ src/modules/bpm/arrival-monitor.cjs | 6 ++-- src/modules/bpm/session-manager.cjs | 31 +++++++++++--------- tests/bpm/arrival-monitor.test.cjs | 12 +++++++- tests/bpm/bpm-session.test.cjs | 7 +++-- tests/bpm/session-machine-manager.test.cjs | 21 +++++++++++++ 7 files changed, 71 insertions(+), 21 deletions(-) diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index 670ea61..9cb5e9d 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -1,5 +1,14 @@ # 开发交接(2026-10-23) +## 2026-10-26 BPM竞态修复 + +- 基于远端42d19c7,修复SignalR握手尚未完成时onClose先于reject的问题:首次关闭在推进轮询状态后立即安排待办/知会只读对账;旧票据使重复关闭和catch不重复推进或入队。既有退避、业务日历、停用及身份隔离继续生效。 +- Cookie持久化的四条调用路径均显式传入principal;异步采集与storageState返回后重新核对授权和票据,在Vault同步提交边界前拦截撤销。权限撤销和普通退出登录统一同步作废对应票据,再等待原连接锁清理;保留已有有效会话,不删除历史凭据。 +- 清理执行前核对仍是原lease,避免误关排队期间其他合法调用者创建的新窗口;不提升整条连接generation,不作废其他调用者/后台托管的票据。 +- 新增14个回归场景均先观察失败,包括握手重复回调、权限撤销/退出登录在save/check/ensure的capture和storage两个阶段,以及新旧窗口清理竞争。测试使用隔离连接/本机浏览器,不访问真实BPM,不发真实邮件。旧测试退出登录后改用新工作台session,避免复用已撤销身份。 +- 部署沿用原本机测试副本,更新前备份,保留账号、模板、业务数据与发送设置,不操作服务机。当前版本与验收回执以code-revision.json及忽略的output/business-flow-test目录为准。 +- 最终关键回归71项全部通过:29项实际manager/本机隔离浏览器、32项接口/账号生命周期/状态及10项监听。独立复核无剩余P1/P2;未跑旧千项全量。已备份更新并重启原测试服务,规则、订单、批次、适配器、原模板、邮箱配置和发信记录哈希一致。实机账号/同步健康,PDF与自动归档仍按原现场验收状态受阻,不因本次修复改为就绪。 + ## 邮件模板编辑与账户签名 - 邮件模板页可新建、编辑待确认/已生效模板,支持纯文本、HTML源码及安全预览。active编辑保留模板ID和分类关联,版本递增并保留修改前历史;历史/忽略模板可复制为新草稿。新建/待确认模板仍需确认生效;已生效模板不能直接改变普通/惠州通知模式。 diff --git a/docs/bpm-session-state-machine-2026-10-24.md b/docs/bpm-session-state-machine-2026-10-24.md index 796770c..92da0f3 100644 --- a/docs/bpm-session-state-machine-2026-10-24.md +++ b/docs/bpm-session-state-machine-2026-10-24.md @@ -43,3 +43,9 @@ Vault 的 SQLite 提交在首次 await 前同步完成;票据在提交前检 现有账号加密、Cookie 复用、验证码、提交目标限制、冷却重启、真实本机浏览器会话、浏览器重建、工作台权限及页面回归一并验证。所有业务端访问使用隔离本机测试环境,不以这些测试代替真实 BPM 订单验收。 2026-10-24 验证结果:后端、状态转换与接口相关测试 77/77;账号、真实本机浏览器会话、运行时、托管器及浏览器重建 30/30;BPM 页面与健康页面 27/27。独立审查发现的临时浏览器阶段并发共享问题已修正并补回归,复审无剩余重要问题。 + +## 2026-10-26 撤销与握手失败边界 + +Cookie采集和storageState均为异步操作,完成后必须重新验证原调用者与票据,再进入同步Vault提交。撤销hash时立即中止对应窗口的手工票据或持久化票据;退出登录复用同一撤销入口。已撤销操作不写Cookie、不提升身份代次、不恢复健康;既有有效Cookie保留。连接串行锁内的后续清理仅关闭当时捕获的原窗口,不能误关其他合法调用者新建的窗口。 + +SignalR握手失败可能同时调用onClose并reject;首次onClose已推进状态机版本,catch会因票据失效退出。因此在未建立订阅的onClose中直接安排一次只读完整对账,重复回调及catch保持无效,不重复推进退避。正常订阅建立后的断线逻辑不变。 diff --git a/src/modules/bpm/arrival-monitor.cjs b/src/modules/bpm/arrival-monitor.cjs index 1c2d2b6..023a49e 100644 --- a/src/modules/bpm/arrival-monitor.cjs +++ b/src/modules/bpm/arrival-monitor.cjs @@ -44,7 +44,7 @@ class BpmArrivalMonitor{ } retry(entry,status='polling',delay){if(!this.active(entry))return;if(entry.connectedAt&&this.clock()-entry.connectedAt>60000)entry.failures=0;if(!entry.lifecycle.transition(({polling:'NETWORK_FAILED',login_required:'AUTH_REQUIRED',busy:'BUSY'})[status]))return;entry.nextRetry=this.clock()+(delay??this.retryMs[Math.min(entry.failures++,this.retryMs.length-1)]);} connect(entry,connection){ - const ticket=entry.lifecycle.begin();if(ticket===null)return;const attempt=++entry.attempt;let closed=false; + const ticket=entry.lifecycle.begin();if(ticket===null)return;const attempt=++entry.attempt;let closed=false,subscribed=false; entry.connecting=(async()=>{ if(this.manager.sessions.has(entry.id))throw Object.assign(new Error('人工登录窗口正在使用。'),{status:409}); const result=await this.manager.ensure(connection,this.principal);if(!this.active(entry)||!entry.lifecycle.current(ticket))return; @@ -52,10 +52,10 @@ class BpmArrivalMonitor{ entry.epoch=this.manager.epoch?.(entry.id)||0;const handle=await this.manager.run(entry.id,async()=>{ this.manager.authorize(connection,this.principal);if(this.manager.sessions.has(entry.id))throw Object.assign(new Error('人工登录窗口正在使用。'),{status:409}); const saved=await this.manager.vault().read(entry.id); - return this.hubClient.connect(saved?.storageState,{signal:entry.controller.signal,onEvent:name=>{if(!this.active(entry)||!entry.lifecycle.current(ticket)||entry.attempt!==attempt||entry.epoch!==(this.manager.epoch?.(entry.id)||0))return;entry.lastSignalAt=new Date(this.clock()).toISOString();this.queue(entry,name==='worklistChanged'?['todo']:name==='informlistChanged'?['inform']:['todo','inform']);},onClose:()=>{closed=true;if(this.active(entry)&&entry.lifecycle.current(ticket)&&entry.attempt===attempt){entry.handle=null;this.retry(entry);}}}); + return this.hubClient.connect(saved?.storageState,{signal:entry.controller.signal,onEvent:name=>{if(!this.active(entry)||!entry.lifecycle.current(ticket)||entry.attempt!==attempt||entry.epoch!==(this.manager.epoch?.(entry.id)||0))return;entry.lastSignalAt=new Date(this.clock()).toISOString();this.queue(entry,name==='worklistChanged'?['todo']:name==='informlistChanged'?['inform']:['todo','inform']);},onClose:()=>{closed=true;if(this.active(entry)&&entry.lifecycle.current(ticket)&&entry.attempt===attempt){entry.handle=null;this.retry(entry);if(!subscribed)this.queue(entry,['todo','inform']);}}}); }); if(!handle)return;if(!this.active(entry)||closed||!entry.lifecycle.transition('CONNECTED',ticket)){await handle.stop();return;} - entry.handle=handle;entry.connectedAt=this.clock();entry.nextRetry=Infinity;entry.lastReconcileAt=this.clock();entry.nextReconcile=this.clock()+this.scanner.store.config().intervalMinutes*60000;this.queue(entry,['todo','inform']); + subscribed=true;entry.handle=handle;entry.connectedAt=this.clock();entry.nextRetry=Infinity;entry.lastReconcileAt=this.clock();entry.nextReconcile=this.clock()+this.scanner.store.config().intervalMinutes*60000;this.queue(entry,['todo','inform']); })().catch(error=>{if(!this.active(entry)||!entry.lifecycle.current(ticket))return;if(error.status===401)this.manager.observe?.(entry.id,'portal',error);this.retry(entry,error.status===409?'busy':error.status===401?'login_required':'polling',error.status===409?5000:error.status===401?5*60000:undefined);if(![401,409].includes(error.status))this.queue(entry,['todo','inform']);}).finally(()=>{entry.connecting=null;}); } dueKinds(entry){return [...entry.dirty].filter(kind=>this.clock()>=this.source(entry,kind).nextAttempt);} diff --git a/src/modules/bpm/session-manager.cjs b/src/modules/bpm/session-manager.cjs index a182ab0..91e0430 100644 --- a/src/modules/bpm/session-manager.cjs +++ b/src/modules/bpm/session-manager.cjs @@ -93,14 +93,16 @@ class BpmSessionManager { return automaticSubmitForm(lease,stored,submit,this.loginForms); } - async persistLease(lease,ticket=lease.stateTicket) { - if(ticket)this.sessionState.assert(ticket); - await this.captureSessions(lease); - const storageState=await lease.context.storageState({indexedDB:true}); - if(ticket)this.sessionState.assert(ticket); - await this.vault().write(lease.id,{storageState,sessionStorage:lease.sessionStorage}); - if(ticket)this.sessionState.assert(ticket); - this.sessionEpochs.set(lease.id,this.epoch(lease.id)+1); + async persistLease(lease,ticket,principal) { + const assertCurrent=()=>{this.authorize(lease.connection,principal);if(lease.sessionId!==principal.sessionId)throw error('此连接正在另一登录窗口中使用。',409);if(ticket)this.sessionState.assert(ticket);}; + lease.persistenceTicket=ticket; + try{ + assertCurrent();await this.captureSessions(lease);assertCurrent(); + const storageState=await lease.context.storageState({indexedDB:true});assertCurrent(); + // Vault commits synchronously before its first await; check ownership at this boundary. + await this.vault().write(lease.id,{storageState,sessionStorage:lease.sessionStorage});assertCurrent(); + this.sessionEpochs.set(lease.id,this.epoch(lease.id)+1); + }finally{delete lease.persistenceTicket;} } canPersistVerified(result) { return result.status==='connected' && result.checks.portal.ok; @@ -160,7 +162,7 @@ class BpmSessionManager { try{ const lease=await this.create(connection,principal);let result=await this.verify(lease); this.authorize(connection,principal);this.sessionState.assert(ticket); - if(this.canPersistVerified(result))await this.persistLease(lease,ticket); + if(this.canPersistVerified(result))await this.persistLease(lease,ticket,principal); this.recordSessionResult(id,result);this.sessionState.finish(ticket,result.status==='connected'?'valid':result.status==='login_required'?'expired':'unavailable'); if(result.status!=='login_required'||result.checks.portal.message!=='请在此入口完成登录。'||lease.blocked)return result; const stored=await this.vault().read('account:'+id);this.authorize(connection,principal);this.assertGeneration(id,generation); @@ -182,7 +184,7 @@ class BpmSessionManager { await this.settleNavigation(lease);result=await this.verify(lease); this.authorize(connection,principal);this.sessionState.assert(ticket); if(this.canPersistVerified(result)){ - await this.persistLease(lease,ticket);delete stored.nextAttemptAt;await this.vault().write('account:'+id,stored); + await this.persistLease(lease,ticket,principal);this.authorize(connection,principal);this.sessionState.assert(ticket);delete stored.nextAttemptAt;await this.vault().write('account:'+id,stored); }else if(!result.checks.portal.ok)result.checks.portal.message='自动登录未完成,请检查托管账号或人工完成验证;稍后重试。'; this.authorize(connection,principal);this.sessionState.assert(ticket);this.recordSessionResult(id,result); this.sessionState.finish(ticket,result.status==='connected'?'valid':result.status==='login_required'?'expired':'unavailable',result.status==='connected'?null:'manual_required'); @@ -473,7 +475,7 @@ class BpmSessionManager { this.authorize(connection,principal); if(lease.stateTicket)this.sessionState.assert(lease.stateTicket); // Failed verification never replaces a previously working credential snapshot. - if (this.canPersistVerified(result)) await this.persistLease(lease); + if (this.canPersistVerified(result)) await this.persistLease(lease,lease.stateTicket,principal); this.authorize(connection,principal);if(lease.stateTicket)this.sessionState.assert(lease.stateTicket);this.recordSessionResult(connection.id,result); return result; }); @@ -487,7 +489,7 @@ class BpmSessionManager { try { const lease=transient?await this.create(connection,principal):await this.getLease(connection.id,principal,true),guard=ticket||lease.stateTicket; const result=await this.verify(lease);this.authorize(connection,principal);if(guard)this.sessionState.assert(guard); - if(this.canPersistVerified(result))await this.persistLease(lease,guard); + if(this.canPersistVerified(result))await this.persistLease(lease,guard,principal); this.authorize(connection,principal);if(guard)this.sessionState.assert(guard);this.recordSessionResult(connection.id,result); if(ticket)this.sessionState.finish(ticket,result.status==='connected'?'valid':result.status==='login_required'?'expired':'unavailable');return result; } finally {this.sessionState.abort(ticket);if(transient)await this.closeLease(connection.id);} @@ -500,11 +502,12 @@ class BpmSessionManager { await lease.context?.close().catch(()=>{}); } async close(id,principal) { return this.run(id,async()=>{ if (!this.sessions.has(id)) return {active:false}; await this.getLease(id,principal,false,true); await this.closeLease(id); return {active:false}; }); } - async releaseSession(sessionId) { await Promise.all([...this.sessions.values()].filter(lease=>lease.sessionId===sessionId).map(lease=>this.run(lease.id,()=>this.closeLease(lease.id)))); } + async releaseSession(sessionId) { await this.releaseSessionHashes([crypto.createHash('sha256').update(sessionId).digest('hex')]); } async releaseSessionHashes(hashes) { const revoked=new Set(hashes); for(const hash of revoked)this.revokedSessionHashes.add(hash); - await Promise.all([...this.sessions.values()].filter(lease=>revoked.has(crypto.createHash('sha256').update(lease.sessionId).digest('hex'))).map(lease=>this.run(lease.id,()=>this.closeLease(lease.id)))); + for(const lease of this.sessions.values())if(revoked.has(crypto.createHash('sha256').update(lease.sessionId).digest('hex'))){this.sessionState.abort(lease.persistenceTicket);this.sessionState.abort(lease.stateTicket);} + await Promise.all([...this.sessions.values()].filter(lease=>revoked.has(crypto.createHash('sha256').update(lease.sessionId).digest('hex'))).map(lease=>this.run(lease.id,()=>this.sessions.get(lease.id)===lease?this.closeLease(lease.id):undefined))); } async suspend(id) { this.disabled.add(id);this.sessionState.lifecycle(id,'pause');this.health.clear(id);await this.sessions.get(id)?.context?.close().catch(()=>{}); await this.run(id,()=>this.closeLease(id)); } async resume(id) { await this.run(id,async()=>{this.disabled.delete(id);this.sessionState.lifecycle(id,'resume');this.health.clear(id);}); } diff --git a/tests/bpm/arrival-monitor.test.cjs b/tests/bpm/arrival-monitor.test.cjs index c01205d..89e0132 100644 --- a/tests/bpm/arrival-monitor.test.cjs +++ b/tests/bpm/arrival-monitor.test.cjs @@ -10,7 +10,7 @@ function fixture(t){assert.equal(typeof Monitor,'function');const dir=fs.mkdtemp const hubClient={connect:async(_,options)=>{connects++;callbacks=options;if(hubFailure)throw Object.assign(Error('hub denied'),{status:hubFailure});return {stop:async()=>{}};}}; const monitor=new Monitor({workspace,manager,scanner,provider,hubClient,settings:()=>({schedule:{weekends:true}}),clock:()=>now,debounceMs:15,pollMs:10,retryMs:[20,40]}); t.after(async()=>{await monitor.stop();await scanner.stop();store.close();workspace.close();fs.rmSync(dir,{recursive:true,force:true});}); - return {workspace,store,monitor,manager,connection,actor,get todoCalls(){return todoCalls;},get connects(){return connects;},hint(name){callbacks.onEvent(name);},disconnect(){callbacks.onClose({reason:'disconnected'});},bumpEpoch:()=>epoch++,setHubFailure:value=>hubFailure=value,setTodo:value=>todo=value,setFailure:value=>failed=value,setHold:value=>hold=value,advance:ms=>now+=ms,until}; + return {workspace,store,monitor,manager,connection,actor,hubClient,get todoCalls(){return todoCalls;},get connects(){return connects;},hint(name){callbacks.onEvent(name);},disconnect(){callbacks.onClose({reason:'disconnected'});},bumpEpoch:()=>epoch++,setHubFailure:value=>hubFailure=value,setTodo:value=>todo=value,setFailure:value=>failed=value,setHold:value=>hold=value,advance:ms=>now+=ms,until}; } test('initial and reconnected subscriptions reconcile real todo and inform sources separately, including equal-count replacement',async t=>{const f=fixture(t);f.monitor.start();await until(()=>f.store.list({kind:'todo'}).total===1&&f.store.list().total===1);assert.equal(f.monitor.snapshot(f.connection.id).status,'listening');f.setTodo([{source:'todo',portalSource:'portal-v4',taskId:'T2',instanceId:'I2',revision:1,processName:'测试订单评审',nodeName:'通知节点',serialNum:'S2',title:'订单号:TEST-2',receivedAt:'2026-10-20T00:10:00Z'}]);f.disconnect();f.advance(100);await until(()=>f.connects>=2&&f.store.list({kind:'todo'}).total===2);assert.equal(f.store.list().total,1);assert.equal(f.store.list({kind:'todo'}).groups[0].items.some(r=>r.taskId==='T2'),true);}); test('hint bursts coalesce and a hint during synchronization schedules exactly one followup',async t=>{const f=fixture(t);f.monitor.start();await until(()=>f.todoCalls===1&&f.monitor.snapshot(f.connection.id).lastSyncAt);let release;f.setHold(new Promise(r=>release=r));for(let i=0;i<20;i++)f.hint('worklistChanged');await until(()=>f.todoCalls===2);for(let i=0;i<20;i++)f.hint('worklistChanged');release();f.setHold(null);await until(()=>f.todoCalls===3);await new Promise(r=>setTimeout(r,60));assert.equal(f.todoCalls,3);}); @@ -22,6 +22,16 @@ test('company calendar pauses automatic synchronization while retaining the list test('identity changes retire old hints and establish a fresh subscription before reconciliation',async t=>{const f=fixture(t);await f.monitor.tick();await until(()=>f.todoCalls===1&&f.monitor.snapshot(f.connection.id).lastSyncAt);f.bumpEpoch();f.hint('worklistChanged');await new Promise(r=>setTimeout(r,45));assert.equal(f.todoCalls,1);await f.monitor.tick();await f.monitor.tick();await until(()=>f.connects===2&&f.todoCalls===2);}); test('a denied push channel falls back immediately to authorized readonly lists',async t=>{const f=fixture(t);f.setHubFailure(403);f.monitor.start();await until(()=>f.store.list({kind:'todo'}).total===1);assert.equal(f.monitor.snapshot(f.connection.id).status,'polling');}); +test('handshake failure plus duplicate close callbacks immediately reconciles lists once and preserves retry backoff',async t=>{ + const f=fixture(t);let close; + f.hubClient.connect=async(_,options)=>{close=options.onClose;close({reason:'handshake_timeout'});close({reason:'handshake_timeout'});throw Object.assign(Error('isolated handshake timeout'),{status:502});}; + await f.monitor.tick();const entry=f.monitor.entries.get(f.connection.id);await entry.connecting; + await until(()=>f.store.list({kind:'todo'}).total===1&&f.store.list().total===1); + assert.equal(entry.status,'polling');assert.equal(entry.failures,1);assert.equal(entry.nextRetry,Date.parse('2026-10-20T01:00:00Z')+20);assert.equal(f.todoCalls,1); + close({reason:'late_close'});await new Promise(r=>setTimeout(r,40));assert.equal(f.todoCalls,1); + await f.monitor.stopConnection(f.connection.id);close({reason:'late_close'});await new Promise(r=>setTimeout(r,25));assert.equal(f.todoCalls,1); +}); + test('verified session recovery releases listener auth backoff without waiting five minutes',async t=>{ const f=fixture(t);f.manager.ensure=async()=>({status:'login_required'}); diff --git a/tests/bpm/bpm-session.test.cjs b/tests/bpm/bpm-session.test.cjs index 33421d6..d6a49cc 100644 --- a/tests/bpm/bpm-session.test.cjs +++ b/tests/bpm/bpm-session.test.cjs @@ -138,13 +138,14 @@ test('concurrent startup never exceeds three contexts and disabling in flight cl assert.equal(browser.contexts().length,3); await manager.releaseSession(principal.sessionId); assert.equal(browser.contexts().length,0); - const opening=manager.open(connection,principal); + const nextPrincipal={...principal,sessionId:'new-dashboard-session-after-logout'}; + const opening=manager.open(connection,nextPrincipal); const disabling=manager.disable('a'); await Promise.allSettled([opening,disabling]); assert.equal(browser.contexts().length,0); - await assert.rejects(manager.open(connection,principal),e=>e.status===409); + await assert.rejects(manager.open(connection,nextPrincipal),e=>e.status===409); await manager.shutdown(); - await assert.rejects(manager.open({...connection,id:'b'},principal),e=>e.status===503); + await assert.rejects(manager.open({...connection,id:'b'},nextPrincipal),e=>e.status===503); }); test('immediate save after remote login Enter waits for pending login navigation and verifies the portal', async t => { diff --git a/tests/bpm/session-machine-manager.test.cjs b/tests/bpm/session-machine-manager.test.cjs index 12b4fb5..4ac18aa 100644 --- a/tests/bpm/session-machine-manager.test.cjs +++ b/tests/bpm/session-machine-manager.test.cjs @@ -47,3 +47,24 @@ test('ensure joins an ongoing recovery after its transient browser lease has bee const b=manager.ensure(c,p);const second=Promise.allSettled([b]);release();await first; const [outcome]=await second;assert.equal(outcome.status,'rejected');assert.equal(outcome.reason.status,503); }); + +for(const revokeKind of ['permissions','logout'])for(const mode of ['save','check','ensure'])for(const stage of ['capture','storage'])test(revokeKind+' revoked '+mode+' during '+stage+' cannot persist cookies or advance identity',async t=>{ + const {manager,writes}=fixture(t,async()=>result('connected'));manager.accessClient=null; + let release,started;const gate=new Promise(r=>release=r),begun=new Promise(r=>started=r),lease={id:c.id,connection:{...c},sessionId:p.sessionId,sessionStorage:{},expiresAt:Date.now()+60000,page:{url:()=>manager.urls.main},context:{storageState:async()=>{if(stage==='storage'){started();await gate;}return {cookies:[],origins:[]};},close:async()=>{}}}; + manager.touch=()=>{};manager.verify=async()=>result('connected');manager.captureSessions=async()=>{if(stage==='capture'){started();await gate;}};manager.create=async()=>{manager.sessions.set(c.id,lease);return lease;}; + if(mode==='save'){lease.stateTicket=manager.sessionState.begin(c.id,'manual');manager.sessions.set(c.id,lease);} + const pending=manager[mode](c,p),rejected=assert.rejects(pending,e=>[401,409].includes(e.status));await begun; + const revoked=revokeKind==='logout'?manager.releaseSession(p.sessionId):manager.releaseSessionHashes([crypto.createHash('sha256').update(p.sessionId).digest('hex')]);release();await Promise.all([revoked,rejected]); + assert.equal(writes.length,0);assert.equal(manager.epoch(c.id),0);assert.equal(manager.health.recent(c.id),false);assert.equal(manager.sessions.size,0); + manager.accessClient={check:async()=>({...result('connected'),storageState:{cookies:[],origins:[]}})}; + const other={...p,sessionId:'unrelated-valid-session'};assert.equal((await manager.check(c,other)).status,'connected');assert.equal(writes.length,1); +}); + +test('queued revocation cleanup does not close a replacement lease owned by another valid caller',async t=>{ + const {manager}=fixture(t,async()=>result('connected'));manager.accessClient=null; + let release,started;const gate=new Promise(r=>release=r),begun=new Promise(r=>started=r);manager.touch=()=>{};manager.verify=async()=>result('connected');manager.captureSessions=async()=>{started();await gate;}; + manager.create=async(connection,principal)=>{const lease={id:connection.id,connection:{...connection},sessionId:principal.sessionId,sessionStorage:{},expiresAt:Date.now()+60000,page:{url:()=>manager.urls.main},context:{storageState:async()=>({cookies:[],origins:[]}),close:async()=>{}}};manager.sessions.set(connection.id,lease);return lease;}; + const old=manager.check(c,p),rejected=assert.rejects(old,e=>[401,409].includes(e.status));await begun; + const other={...p,sessionId:'valid-replacement-caller'},opening=manager.open(c,other),revoked=manager.releaseSession(p.sessionId);release();await Promise.all([rejected,opening,revoked]); + assert.equal(manager.sessions.get(c.id)?.sessionId,other.sessionId);assert.equal(manager.sessionSnapshot(c.id).phase,'manual'); +});