From 6cd6520baeee215c6b1e0ed3128f2098c7d56950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Mon, 16 Nov 2026 11:00:46 +0800 Subject: [PATCH] fix: wait for native workspace projection before opening a conversation --- .gitea/workflows/ci.yml | 1 + integration/dsh/task-plugin/client.js | 7 ++++--- tools/verify_dsh_dock_startup.mjs | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index d2e9fda..e5a9280 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -154,5 +154,6 @@ jobs: - name: Intervention panel and bounded model views (no model or network) run: | node tools/verify_dsh_incident_panel.mjs + node tools/verify_dsh_dock_startup.mjs node tools/verify_dsh_model_results.mjs node tools/verify_dsh_diagnosis_cancel.mjs diff --git a/integration/dsh/task-plugin/client.js b/integration/dsh/task-plugin/client.js index c03a7d7..ee06c4b 100644 --- a/integration/dsh/task-plugin/client.js +++ b/integration/dsh/task-plugin/client.js @@ -295,7 +295,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{ tab==='tickets'?h(TicketsPanel,{operations,perform,pending:pending||operations.busy}):h(UsagePanel,{runtime,control,pending})), tab!=='overview'&&h('p',{'data-testid':'dx-operations-notice',role:'status',style:{fontSize:12,color:secondary,lineHeight:1.8,whiteSpace:'pre-wrap'}},operations.activity?.message||notice||'')); } - return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession','uiWorkspace'],apply(ctx){ + return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession','uiWorkspace','workspaces'],apply(ctx){ ctx.effect(()=>{ let live=true,opened=''; const check=()=>fetch('/dx/context').then(r=>r.json()).then(data=>{ @@ -318,10 +318,11 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{ if(sessionId){ if(openedSession===sessionId)return; try{ctx.sidebarRight.openTab('dx-task');if(ctx.sidebarRight.isExpanded()){openedSession=sessionId;return;}}catch{} - }else if(!connecting&&!adopted){ + }else if(!connecting&&!adopted&&ctx.workspaces.list.getSnapshot().phase==='ready'){ connecting=true; fetch('/dx/workspace').then(r=>{if(!r.ok&&r.ok!==undefined)throw Error();return r.json();}).then(value=>{ - if(live&&!current.getSnapshot()&&typeof value.workspace_id==='string'){ + if(live&&!current.getSnapshot()&&typeof value.workspace_id==='string'&& + ctx.workspaces.list.getSnapshot().items.some(row=>row.workspaceId===value.workspace_id)){ adopted=true;return ctx.uiWorkspace.openWorkspace(value.workspace_id); } }).catch(()=>{adopted=false;}).finally(()=>{connecting=false;if(live)queue();}); diff --git a/tools/verify_dsh_dock_startup.mjs b/tools/verify_dsh_dock_startup.mjs index 381c476..206d779 100644 --- a/tools/verify_dsh_dock_startup.mjs +++ b/tools/verify_dsh_dock_startup.mjs @@ -4,6 +4,7 @@ import {readFile} from 'node:fs/promises'; import vm from 'node:vm'; let plugin,session,subscriber,expanded=false,openedWorkspace=0,openedTabs=0; +let workspaceSnapshot={phase:'pending',items:[]}; const effects=[]; const sandbox={window:{__ModuleLoader__:{load:value=>{plugin=value;}}}, setTimeout,clearTimeout,setInterval,clearInterval, @@ -12,6 +13,7 @@ const sandbox={window:{__ModuleLoader__:{load:value=>{plugin=value;}}}, vm.runInNewContext(await readFile(new URL('../integration/dsh/task-plugin/client.js',import.meta.url),'utf8'),sandbox); const exported=plugin.factory(name=>name==='react'?{createElement:()=>null}:{}); const ctx={slots:{inject:(_name,fn)=>fn(),register:()=>()=>{}}, + workspaces:{list:{getSnapshot:()=>workspaceSnapshot}}, effect:(fn)=>{effects.push(fn());},sidebarRightTabs:{register:()=>{}}, sidebarRight:{mounted:{getSnapshot:()=>session,subscribe:fn=>{subscriber=fn;return()=>{};}}, openTab:()=>{if(!session)throw Error('Session seat absent');openedTabs++;expanded=true;},isExpanded:()=>expanded}, @@ -22,6 +24,12 @@ const ctx={slots:{inject:(_name,fn)=>fn(),register:()=>()=>{}}, try{ exported.apply(ctx); await new Promise(r=>setTimeout(r,150)); + assert.equal(openedWorkspace,0,'native workspace adoption must wait for the official client workspace snapshot'); + workspaceSnapshot={phase:'ready',items:[]}; + await new Promise(r=>setTimeout(r,150)); + assert.equal(openedWorkspace,0,'a ready snapshot must actually contain the native workspace before opening'); + workspaceSnapshot={phase:'ready',items:[{workspaceId:'owned-workspace'}]}; + await new Promise(r=>setTimeout(r,150)); assert.equal(openedWorkspace,1,'fresh page must adopt the owned native workspace once'); assert.equal(expanded,true,'right dock must open after delayed Session adoption'); const previous=openedTabs;