diff --git a/chatbot/src/SopDesigner.jsx b/chatbot/src/SopDesigner.jsx index f75671b5..6452bcb7 100644 --- a/chatbot/src/SopDesigner.jsx +++ b/chatbot/src/SopDesigner.jsx @@ -9,7 +9,7 @@ import HarnessIcon from "./HarnessIcon"; import { readThemePreference, resolveTheme } from "./theme.js"; import { conversationEngine, defaultEngine, engineBrand, engineModels, engineOfModel } from "./engines.js"; import { - CONTEXT, DRAFT, END, MODEL_KEY, NEW_CONVERSATION, PLACE, READY, REPLY, RESET, SURFACE, + CONFIGURE_ROLE, CONTEXT, DRAFT, END, MODEL_KEY, NEW_CONVERSATION, PLACE, READY, REPLY, RESET, SURFACE, beginOnCanvas, designerParams, draftSummary, latestSession, postToCanvas, replyDraft, scenarioPage, } from "./sop-designer.js"; import "./sop-designer.css"; @@ -50,7 +50,7 @@ function enginesOf(catalog) { return ids.map((id) => ({ id, name: id === defaultEngine ? "CodeBuddy" : id, configured: true })); } -function DraftNote({ draft, onPlace }) { +function DraftNote({ draft, onPlace, onConfigureRole }) { return (
@@ -62,6 +62,11 @@ function DraftNote({ draft, onPlace }) { {draft.warnings.map((warning) =>
  • {warning}
  • )} ) : null} + {onConfigureRole ? ( + + ) : null} {onPlace ? ( `; + const href='#/agents/'+encodeURIComponent(agent.id)+(validation?'/gov':''); + return `${label}`; +} function nodeGatePane(n){ const agent=workflowAgent(n.agentId); const artifacts=effectiveNodeArtifacts(n,agent); @@ -860,7 +868,7 @@ function nodeGatePane(n){ const gateRows=gates.length?gates.map(g=>{const cmds=(g.commands||[]).filter(Boolean);return `
    ${flowPalette.icon('terminal',13)}${escapeHTML(g.name||g.id||'未命名门禁')}${escapeHTML(cmds.join(' && ')||'人工确认')}${g.executionScope==='repositories'?'每个代码仓库':'Run 工作区'} · 失败后 ${escapeHTML({loop:'本节点自修正',reject:'打回上游',human:'转人工确认',fail:'本节点失败'}[g.onFailure]||'按节点策略')}
    `}).join(''):'
    这个节点没有额外门禁命令。
    '; const terminal=n.type==='agent'?step(1,'先提交结构化终态','平台内建',`
    ${flowPalette.icon('check',13)}pass | rework | fail | humanAgent 完成任务后必须先调用 submit_gate_result 提交终态;缺失时自动恢复同一会话重试。
    `):''; const base=n.type==='agent'?1:0; - return `

    执行时 Agent 节点先提交结构化终态,随后校验产物,最后执行可选门禁命令。

      ${terminal}${step(base+1,'再校验产物',`${artifacts.length} 项`,artifactRows)}${step(base+2,'最后触发额外门禁',`${gates.length} 项`,gateRows)}
    ${agent?'':''}`; + return `

    执行时 Agent 节点先提交结构化终态,随后校验产物,最后执行可选门禁命令。

      ${terminal}${step(base+1,'再校验产物',`${artifacts.length} 项`,artifactRows)}${step(base+2,'最后触发额外门禁',`${gates.length} 项`,gateRows)}
    ${boundRoleLink(agent,true)}`; } function renderAgentAssetsPanel(a){ @@ -970,7 +978,7 @@ function agentBindCard(n){ const duty=String(agent.description||'').trim(),taskHint=duty?(duty.length>48?`${duty.slice(0,48)}…`:duty):'还没写职责,可在角色定义里补'; const model=agent.model||exec?.model||exec?.name||'未选模型'; return `

    ${hint}

    -
    ${escapeHTML(flowPalette.initial(agent.name))}${escapeHTML(agent.name)}${escapeHTML(taskHint)}
    ${escapeHTML(model)}模型
    ${arts.length}产物
    ${gates.length}门禁
    ${agent.loop?.enabled?`${agent.loop.maxIterations||1} 轮`:'单轮'}Loop
    `; +
    ${escapeHTML(flowPalette.initial(agent.name))}${escapeHTML(agent.name)}${escapeHTML(taskHint)}${boundRoleLink(agent)}
    ${escapeHTML(model)}模型
    ${arts.length}产物
    ${gates.length}门禁
    ${agent.loop?.enabled?`${agent.loop.maxIterations||1} 轮`:'单轮'}Loop
    `; } function flowDrawerHead(n,kind,label){ const agent=kind==='agent'?workflowAgent(n.agentId):null; @@ -1063,8 +1071,11 @@ function bindNodeProperties(host,n){ }; host.querySelector('#addSOPHandoff')?.addEventListener('click',()=>{flowHistory.record();n.artifactOutputs=n.artifactOutputs||[];n.artifactOutputs.push({name:'',path:'',mediaType:'text/markdown',required:true});renderProperties();dirty()}); if(n.type==='sop')bindArtifactRows(host,n); - const openBound=$('#openBoundAgent');if(openBound)openBound.onclick=()=>{const agent=workflowAgent(n.agentId);if(!agent)return;if(!catalogGeneric(state.workflow))switchView('agents');openAgentWizard(agent,2)}; - const openBoundValidation=$('#openBoundAgentValidation');if(openBoundValidation)openBoundValidation.onclick=()=>{const agent=workflowAgent(n.agentId);if(!agent)return;if(!catalogGeneric(state.workflow))switchView('agents');openAgentWizard(agent,3)}; + if(catalogGeneric(state.workflow)){ + const agent=workflowAgent(n.agentId); + host.querySelector('#openBoundAgent')?.addEventListener('click',()=>openAgentWizard(agent)); + host.querySelector('#openBoundAgentValidation')?.addEventListener('click',()=>openAgentWizard(agent,3)); + } host.querySelectorAll('[data-fail]').forEach(b=>b.onclick=()=>{ if(b.dataset.fail==='fail'){state.flowWantReject=false;if(!setRejectTo(n.id,'')&&n.onFailure==='reject'){n.onFailure='fail';dirty()}renderProperties();return} state.flowWantReject=true;renderProperties();host.querySelector('#rejectTarget')?.focus(); diff --git a/web/index.html b/web/index.html index b2e7837b..f03a4278 100644 --- a/web/index.html +++ b/web/index.html @@ -1291,7 +1291,7 @@

    确认操作

    - + @@ -1315,6 +1315,6 @@

    确认操作

    - + diff --git a/web/orchestrate.js b/web/orchestrate.js index 13ada967..60488e6f 100644 --- a/web/orchestrate.js +++ b/web/orchestrate.js @@ -16,6 +16,7 @@ const AI_MESSAGES = { reply: 'agentflow-sop-designer-reply', end: 'agentflow-sop-designer-end', place: 'agentflow-sop-designer-place', + role: 'agentflow-sop-designer-role', reset: 'agentflow-sop-designer-reset' }; @@ -238,10 +239,11 @@ function openAIOrchestrator() { function abortAIBuild() { const build = aiBuild; + const restore = isCurrentAIBuild(build); aiBuildToken++; - if (build) restoreAIBuildFailure(build); - finishAIBuildVisuals(); aiBuild = null; + if (restore) restoreAIBuildFailure(build); + finishAIBuildVisuals(); syncCanvasAIEntry(); setAIBuildStatus(''); } @@ -263,6 +265,12 @@ async function beginAIOrchestratorTurn(requestId) { const reply = (payload) => postToAIOrchestrator(AI_MESSAGES.begun, {requestId, ...payload}); if (!state.projectFilter) return reply({ok: false, error: '先在顶栏选择项目'}); if (aiBuild) return reply({ok: false, error: '画布还在生成上一轮的流程,请稍候'}); + const context = aiOrchestratorContext(); + await refreshWorkflowAgents().catch(() => {}); + const current = aiOrchestratorContext(); + if (aiBuild || context.projectId !== current.projectId || context.workflowId !== current.workflowId) { + return reply({ok: false, error: '画布已切换,请重试'}); + } const canvas = state.workflow ? aiClone(state.workflow) : null; const build = await beginAIOrchestration(); if (!build) return reply({ok: false, error: '画布暂时不能编排'}); @@ -290,7 +298,16 @@ async function handleAIOrchestratorMessage(event) { case AI_MESSAGES.draft: return ingestAIDraftBuffer(data.buffer); case AI_MESSAGES.reply: + if (data.draft?.tool === 'agents_save') { + abortAIBuild(); + return; + } return finishAIOrchestration(data.draft?.body || null); + case AI_MESSAGES.role: + if (!aiBuild && data.projectId === state.projectFilter && data.workflowId === state.workflow?.id) { + configureAIRoleDraft(data.role); + } + return; case AI_MESSAGES.end: abortAIBuild(); if (data.error) setAIBuildStatus(data.error); @@ -361,6 +378,11 @@ function placeAIGhost() { host.append(ghost); } +function isCurrentAIBuild(build) { + return !!build && aiBuild === build && build.token === aiBuildToken + && state.projectFilter === build.projectId && state.workflow?.id === build.workflowId; +} + async function startAIBuild(raw, opts = {}) { const occupied = !!state.workflow && ((state.workflow.nodes || []).length > 0 || state.workflowDirty); if (occupied && !opts.confirmed) { @@ -375,8 +397,14 @@ async function startAIBuild(raw, opts = {}) { const token = ++aiBuildToken; finishAIBuildVisuals(); const previous = state.workflow ? aiClone(state.workflow) : null; - aiBuild = {token, buffer: '', thought: '', placed: new Map(), wired: new Set(), pendingEdges: [], queue: [], draining: null, ghostText: opts.ghost || 'AI 正在理解你的需求…', ghostHidden: false, freePositions: true, mode: 'create', previous, spawned: 0}; + const selectedNode = state.selectedNode; state.workflow = shellForAIWorkflow(raw || {}); + aiBuild = { + token, projectId: state.projectFilter, workflowId: state.workflow.id, selectedNode, + buffer: '', thought: '', placed: new Map(), wired: new Set(), pendingEdges: [], queue: [], draining: null, + ghostText: opts.ghost || 'AI 正在理解你的需求…', ghostHidden: false, freePositions: true, + mode: 'create', previous + }; state.selectedNode = null; if ((state.currentView || activeViewName()) !== 'flow') switchView('flow'); renderWorkflowMeta(); @@ -390,7 +418,7 @@ async function startAIBuild(raw, opts = {}) { function ingestStreamingWorkflow(graph) { const build = aiBuild; - if (!build) return; + if (!isCurrentAIBuild(build)) return; if (graph.name && state.workflow && state.workflow.name !== graph.name) { state.workflow.name = graph.name; renderWorkflowMeta(); @@ -417,7 +445,7 @@ function drainAIBuild() { // Yield first so the assignment above lands before the loop can finish and clear it. await Promise.resolve(); try { - while (aiBuild === build && build.token === aiBuildToken) { + while (isCurrentAIBuild(build)) { const ready = build.pendingEdges.findIndex(item => build.placed.has(item.data.source) && build.placed.has(item.data.target)); if (ready >= 0) { const [item] = build.pendingEdges.splice(ready, 1); @@ -439,8 +467,7 @@ async function aiPlaceNode(build, node) { if (!node.position) node.position = aiProvisionalPosition(build.placed.size); state.workflow.nodes.push(node); build.placed.set(node.id, node); - build.spawned = (build.spawned || 0) + 1; - state.selectedNode = node.id; + if ($('#aiOrchestrator')?.hidden === false) state.selectedNode = node.id; renderCanvas(); const el = document.querySelector('.flow-node[data-id="' + (CSS.escape ? CSS.escape(node.id) : node.id) + '"]'); el?.classList.add('ai-just-built'); @@ -511,6 +538,10 @@ async function completeAIBuild(build, finalRaw) { if (build.mode === 'edit') return completeAIEdit(build, finalRaw); if (finalRaw && Array.isArray(finalRaw.nodes)) { ingestStreamingWorkflow({name: finalRaw.name || '', nodes: finalRaw.nodes, edges: finalRaw.edges || []}); + } + await drainAIBuild(); + if (!isCurrentAIBuild(build)) return false; + if (finalRaw && Array.isArray(finalRaw.nodes)) { const finalById = new Map(finalRaw.nodes.filter(n => n.id).map(n => [n.id, n])); state.workflow.nodes.forEach(node => { const fin = finalById.get(node.id); @@ -519,8 +550,7 @@ async function completeAIBuild(build, finalRaw) { if (finalRaw.description) state.workflow.description = finalRaw.description; if (finalRaw.preview) state.workflow.preview = aiClone(finalRaw.preview); } - await drainAIBuild(); - if (aiBuild !== build || build.token !== aiBuildToken) return false; + if (!await validateAIBuildRoles(build)) return false; build.ghostHidden = true; placeAIGhost(); if (!state.workflow.nodes.length) { @@ -531,6 +561,7 @@ async function completeAIBuild(build, finalRaw) { } setAIBuildStatus('整理布局…'); await aiRelayout(build); + if (!isCurrentAIBuild(build)) return false; const canvas = $('#canvas'); finishAIBuildVisuals(); canvas?.classList.add('ai-done'); @@ -541,14 +572,38 @@ async function completeAIBuild(build, finalRaw) { renderCanvas(); renderProperties(); aiOverview(); - setAIBuildStatus(aiUnboundRolesNote() || (state.workflow.edges.length ? '节点和连线都已放好,确认后点保存' : '节点已放好,确认后点保存')); + setAIBuildStatus(state.workflow.edges.length ? '节点和连线都已放好,确认后点保存' : '节点已放好,确认后点保存'); return true; } -function aiUnboundRolesNote() { - const agentIds = new Set((state.data?.agents || []).map(a => a.id)); - const unbound = (state.workflow?.nodes || []).filter(n => n.type === 'agent' && n.id !== 'af-preview-build' && (!n.agentId || !agentIds.has(n.agentId))); - return unbound.length ? unbound.length + ' 个 Agent 节点还没绑定有效角色:' + unbound.map(n => n.name).join('、') + ',保存前在右侧属性里选一下' : ''; +async function validateAIBuildRoles(build) { + const unavailable = () => state.workflow.nodes.filter(node => node.type === 'agent' + && !(isPreviewBuildNode(node.id) && node.agentId === PREVIEW_BUILD_AGENT_ID) + && !workflowAgent(node.agentId)); + if (!isCurrentAIBuild(build)) return false; + if (!unavailable().length) return true; + // A role may have been created or shared while the assistant was working. + await refreshWorkflowAgents().catch(() => {}); + if (!isCurrentAIBuild(build)) return false; + const missing = unavailable(); + if (!missing.length) return true; + const names = missing.map(node => node.name + '(' + (node.agentId || '未绑定') + ')'); + abortAIBuild(); + setAIBuildStatus('草稿引用了当前流程不可用的角色:' + names.join('、') + '。请先创建角色,或选择已有角色。'); + return false; +} + +function configureAIRoleDraft(role) { + if (!role?.name || catalogGeneric(state.workflow)) return; + const {id, name, description, prompt, executorId, model} = role; + if (id && agentIdTaken(id)) return toast('这个角色标识已存在,请使用已保存的角色继续编排'); + openAgentWizard({id: '', name, description, prompt, executorId, model, projectId: state.projectFilter}); + if (id) { + state.agentIdAuto = false; + $('#agentForm').elements.id.value = id; + syncAgentSlug(); + } + setAgentCreateStep(2); } function aiClone(value) { @@ -583,12 +638,13 @@ async function beginAIOrchestration() { const token = ++aiBuildToken; finishAIBuildVisuals(); aiBuild = { - token, buffer: '', thought: '', + token, projectId: state.projectFilter, workflowId: state.workflow.id, selectedNode: state.selectedNode, + buffer: '', thought: '', placed: new Map(state.workflow.nodes.map(node => [node.id, node])), wired: new Set((state.workflow.edges || []).map(edge => edge.source + '→' + edge.target)), pendingEdges: [], queue: [], draining: null, ghostText: '', ghostHidden: true, freePositions: false, - mode: 'edit', base: aiClone(state.workflow), spawned: 0 + mode: 'edit', base: aiClone(state.workflow) }; if ((state.currentView || activeViewName()) !== 'flow') switchView('flow'); openAIOrchestrator(); @@ -615,14 +671,9 @@ async function beginAIOrchestration() { } async function completeAIEdit(build, finalRaw) { + if (!isCurrentAIBuild(build)) return false; if (!finalRaw || !Array.isArray(finalRaw.nodes) || !finalRaw.nodes.length) { - state.workflow = build.base; - finishAIBuildVisuals(); - aiBuild = null; - syncCanvasAIEntry(); - renderWorkflowMeta(); - renderCanvas(); - renderProperties(); + abortAIBuild(); return false; } const merged = mergeAIEdit(build.base, finalRaw); @@ -650,7 +701,7 @@ async function completeAIEdit(build, finalRaw) { ingestStreamingWorkflow({name: merged.name, nodes: newcomers, edges: laterEdges}); await drainAIBuild(); } - if (aiBuild !== build || build.token !== aiBuildToken) return false; + if (!await validateAIBuildRoles(build)) return false; build.ghostHidden = true; placeAIGhost(); finishAIBuildVisuals(); @@ -659,15 +710,14 @@ async function completeAIEdit(build, finalRaw) { renderWorkflowMeta(); renderCanvas(); renderProperties(); - setAIBuildStatus(aiUnboundRolesNote() || '已改在当前流程上,确认后点保存'); + setAIBuildStatus('已改在当前流程上,确认后点保存'); return (state.workflow.nodes || []).length > 0; } function restoreAIBuildFailure(build) { if (!build) return; - const previous = build.mode === 'edit' ? build.base : (build.spawned ? null : build.previous); - if (!previous) return; - state.workflow = previous; + state.workflow = build.mode === 'edit' ? build.base : build.previous; + state.selectedNode = build.selectedNode; renderWorkflowMeta(); renderCanvas(); renderProperties(); @@ -682,8 +732,15 @@ function aiDraftObject(raw) { // id is a new SOP and replaces the canvas only after the user agrees. async function finishAIOrchestration(raw) { const build = aiBuild; - if (!build) return false; + if (!isCurrentAIBuild(build)) { + if (build) abortAIBuild(); + return false; + } const body = aiDraftObject(raw); + if (!body) { + abortAIBuild(); + return false; + } if (build.mode === 'edit' && body?.id && build.base?.id && body.id !== build.base.id && Array.isArray(body.nodes)) { abortAIBuild(); return playWorkflowOnCanvas(body, {confirmed: false}); diff --git a/web/syntax_test.go b/web/syntax_test.go index 8713f3c4..5cea6da1 100644 --- a/web/syntax_test.go +++ b/web/syntax_test.go @@ -1995,9 +1995,9 @@ func TestAgentPageListAndTabbedModal(t *testing.T) { "function setAgentCreateStep(", "function syncTabIndicator(", "function persistAgent(", - "function openAgentWizard(agent=null,initialStep=1)", + "function openAgentWizard(", "state.genericTemplateAgents", - "openAgentWizard(agent,2)", + "function applyAgentRoute(", } { if !strings.Contains(app, want) { t.Fatalf("app bundle is missing agent page wiring %q", want) diff --git a/webtest/tests/flow-designer.test.mjs b/webtest/tests/flow-designer.test.mjs index f52c567b..471fc8e1 100644 --- a/webtest/tests/flow-designer.test.mjs +++ b/webtest/tests/flow-designer.test.mjs @@ -55,8 +55,11 @@ test('flow node metadata, properties, artifact editors, menus, and edge deletion state.selectedNode='agent-node';renderCanvas();renderProperties(); `); const menuButton = app.document.querySelector('[data-id="agent-node"] [data-node-menu]'); + app.evaluate('setAIOrchestratorOpen(true)'); menuButton?.click(); app.document.querySelector('#flowNodeMenu [data-a="edit"]')?.click(); + assert.equal(app.document.querySelector('#aiOrchestrator').hidden, true); + assert.equal(app.document.querySelector('#openBoundAgent').getAttribute('href'), '#/agents/agent-1'); app.evaluate(` nodeMeta(state.workflow.nodes[0]);nodeMeta(state.workflow.nodes[1]);nodeMeta(state.workflow.nodes[2]); artifactRowsHTML(state.workflow.nodes[0]); diff --git a/webtest/tests/orchestrate-ai.test.mjs b/webtest/tests/orchestrate-ai.test.mjs index 3834b2f9..2a0f844e 100644 --- a/webtest/tests/orchestrate-ai.test.mjs +++ b/webtest/tests/orchestrate-ai.test.mjs @@ -43,6 +43,19 @@ function bridge(app) { return { frame, posted, send }; } +test('starting a turn includes canvas edits made while refreshing roles', async (t) => { + const app = await loadApp(); + t.after(app.close); + app.evaluate(`switchView('flow');renderAll();refreshWorkflowAgents=()=>new Promise(resolve=>{window.finishRoleRefresh=resolve})`); + app.document.querySelector('#openAIOrchestrator')?.click(); + const { posted, send } = bridge(app); + const begun = send({ type: 'agentflow-sop-designer-begin', requestId: 'refreshing' }); + app.evaluate(`state.workflow.nodes.push({id:'manual-node',name:'My change',type:'approval',position:{x:100,y:100}});window.finishRoleRefresh()`); + await begun; + assert.equal(posted.at(-1).ok, true); + assert.ok(posted.at(-1).canvas.nodes.some(node => node.id === 'manual-node')); +}); + test('the panel embeds the designer chat and builds the streamed draft on an empty canvas', async (t) => { const app = await loadApp(); t.after(app.close); @@ -126,3 +139,30 @@ test('the chat learns when the canvas switches to another SOP', async (t) => { app.evaluate('renderCanvas()'); assert.equal(posted.length, count, 'an unchanged SOP is not announced again'); }); + +test('orchestration refreshes project roles and restores the canvas for an unavailable role', async (t) => { + const app = await loadApp(); + t.after(app.close); + app.evaluate(` + switchView('flow'); + state.workflow = {...state.workflow, nodes: [], edges: []}; + state.workflowDirty = false; + state.data.agents.push({id:'private', name:'Private role', projectId:'other'}); + renderAll(); + `); + const workflowName = app.evaluate('state.workflow.name'); + app.router.get('/api/agents?projectId=project-1', [{id:'new-role', name:'New role', projectId:'project-1'}]); + app.document.querySelector('#openAIOrchestrator')?.click(); + const { posted, send } = bridge(app); + await send({ type: 'agentflow-sop-designer-begin', requestId: 'roles' }); + assert.equal(posted.at(-1).ok, true); + assert.equal(app.evaluate("!!workflowAgent('new-role')"), true); + assert.equal(app.evaluate("!!workflowAgent('private')"), false); + await send({ type: 'agentflow-sop-designer-reply', draft: { tool: 'workflows_save', body: { + name: 'Unavailable draft', nodes: [{id:'bad', name:'Review', type:'agent', agentId:'private'}], edges: [], + } } }); + assert.equal(app.evaluate('state.workflow.name'), workflowName); + assert.equal(app.evaluate('state.workflow.nodes.length'), 0); + assert.equal(app.evaluate('state.workflowDirty'), false); + assert.match(app.document.querySelector('#aiBuildStatus').textContent, /Review(private)/); +}); diff --git a/webtest/tests/orchestrate-build.test.mjs b/webtest/tests/orchestrate-build.test.mjs index 3db7cd54..b6cc0dc0 100644 --- a/webtest/tests/orchestrate-build.test.mjs +++ b/webtest/tests/orchestrate-build.test.mjs @@ -61,3 +61,45 @@ test('streaming parser handles partial drafts', async (t) => { assert.deepEqual(values.partial.nodes.map((node) => node.id), ['a'], 'an unfinished node waits for its closing brace'); assert.match(values.body, /"name":"X"/); }); + +test('AI edit keeps streamed node positions and applies only the final graph', async (t) => { + const app = await loadApp(); + t.after(app.close); + const result = await app.evaluate(` + (async () => { + const build = await beginAIOrchestration('add two approvals'); + const streamedNode = {id: 'first-approval', name: 'First approval', type: 'approval'}; + ingestStreamingWorkflow({nodes: [streamedNode], edges: []}); + await drainAIBuild(); + const placed = state.workflow.nodes.find(node => node.id === streamedNode.id).position; + + const finalNode = {id: 'final-approval', name: 'Final approval', type: 'approval'}; + const finalEdge = {id: 'to-final', source: streamedNode.id, target: finalNode.id, when: 'success'}; + ingestStreamingWorkflow({ + nodes: [{...finalNode, name: 'Preview label'}, {id: 'extra', name: 'Extra', type: 'approval'}], + edges: [{id: 'to-extra', source: finalNode.id, target: 'extra'}], + }); + const completed = await completeAIEdit(build, { + nodes: [...build.base.nodes, streamedNode, finalNode], + edges: [...build.base.edges, finalEdge], + }); + const {nodes, edges} = state.workflow; + const final = nodes.find(node => node.id === finalNode.id); + const first = nodes.find(node => node.id === streamedNode.id); + return { + completed, + keptPosition: first.position.x === placed.x && first.position.y === placed.y, + finalName: final.name, + finalPositioned: Number.isFinite(final.position.x) && Number.isFinite(final.position.y), + hasFinalEdge: edges.some(edge => edge.id === finalEdge.id), + hasExtra: nodes.some(node => node.id === 'extra') || edges.some(edge => edge.id === 'to-extra'), + }; + })() + `); + assert.equal(result.completed, true); + assert.equal(result.keptPosition, true); + assert.equal(result.finalName, 'Final approval'); + assert.equal(result.finalPositioned, true); + assert.equal(result.hasFinalEdge, true); + assert.equal(result.hasExtra, false); +});