Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

[Loopforge 自动化] fix(web): list acceptance gates in SOP execution order (#499)

fx-kurumi2fac104ba5a1
diff --git a/web/app/issue-drawer.js b/web/app/issue-drawer.js
index a5a759ce..f66cd752 100644
--- a/web/app/issue-drawer.js
+++ b/web/app/issue-drawer.js
@@ -848,6 +848,29 @@ function sopDeliveryPane(issue,data){
const runFacts=`<div class="detail-grid">${drawerFact('Run ID',run?run.id.slice(-14):'—')}${drawerFact('Task ID',data.task?data.task.id.slice(-10):'—')}${drawerFact('触发方式',escapeHTML(taskTriggerInfo(data.task).label))}${drawerFact('状态',run?`<span class="status ${runDisplayStatusClass(run)}">${runDisplayStatus(run)}</span>`:'—')}${drawerFact('执行仓库',escapeHTML(frozen.map(r=>r.name).filter(Boolean).join('、')||'—'))}${drawerFact('冻结目标主分支',escapeHTML(frozenBranches.join('、')||'—'))}${drawerFact('Trace ID',ctx?.traceId?ctx.traceId.slice(-14):'—')}</div>`;
return `<div class="detail-section"><h3>代码仓库与分支${repos.length>1?`<span class="sub">${repos.length} 个仓库</span>`:''}</h3>${repoFacts}</div><div class="detail-section"><h3>交付运行上下文<span class="sub">发起时冻结的仓库与 Trace 关联</span></h3>${run?runFacts+'<div style="margin-top:10px"><button class="button ghost small" data-open-run="'+escapeHTML(run.id)+'">查看运行详情与产物 →</button></div>':'<div class="detail-empty">尚未发起交付运行</div>'}</div>${run?.input?`<div class="detail-section"><h3>任务输入</h3><div class="detail-desc">${escapeHTML(run.input)}</div></div>`:''}`;
}
+// Execution order of a SOP's nodes, same rule as orderNodesByEdges in
+// internal/repo/requirement.go: stable topological sort over the edges, array
+// order breaks ties, cycles fall back to array order. The editor appends a node
+// added in a later SOP version to the end of the array, so without this a gate
+// inserted mid-flow is listed after the last node.
+function nodesInExecutionOrder(wf){
+ const nodes=wf?.nodes||[],edges=wf?.edges||[];
+ if(nodes.length<2||!edges.length||nodes.some(n=>!n?.id))return nodes;
+ const known=new Set(nodes.map(n=>n.id)),indegree=new Map(),children=new Map();
+ for(const e of edges){
+ if(e.source===e.target||!known.has(e.source)||!known.has(e.target))continue;
+ indegree.set(e.target,(indegree.get(e.target)||0)+1);
+ children.set(e.source,[...(children.get(e.source)||[]),e.target]);
+ }
+ const placed=new Set(),out=[];
+ while(out.length<nodes.length){
+ const next=nodes.find(n=>!placed.has(n.id)&&!(indegree.get(n.id)>0));
+ if(!next){for(const n of nodes)if(!placed.has(n.id)){out.push(n);placed.add(n.id)}break}
+ out.push(next);placed.add(next.id);
+ for(const c of children.get(next.id)||[])indegree.set(c,indegree.get(c)-1);
+ }
+ return out;
+}
function acceptancePane(issue,data){
const run=data.run;
if(conversationWorkspaceIssue(issue,run)){
@@ -857,7 +880,7 @@ function acceptancePane(issue,data){
if(!run)return '<div class="detail-empty">尚未执行,暂无验收信息。</div>';
const wf=run.workflowSnapshot||(state.data.workflows||[]).find(w=>w.id===run.workflowId);
const nodes=wf?.nodes||[];
- const gates=nodes.map(n=>{const nr=run.nodes?.[n.id]||{},agent=(state.data.agents||[]).find(a=>a.id===n.agentId),verif=roleGates(agent);const isApproval=n.type==='approval';const manual=verif.some(g=>g.mode==='manual');const commands=verif.filter(g=>g.mode==='command');let verdict='—';
+ const gates=nodesInExecutionOrder(wf).map(n=>{const nr=run.nodes?.[n.id]||{},agent=(state.data.agents||[]).find(a=>a.id===n.agentId),verif=roleGates(agent);const isApproval=n.type==='approval';const manual=verif.some(g=>g.mode==='manual');const commands=verif.filter(g=>g.mode==='command');let verdict='—';
if(nr.status==='succeeded')verdict=isApproval?'已批准':(commands.length||manual)?'门禁通过':'完成';
if(nr.status==='waiting_approval')verdict=turnsExhausted(nr)?'等待确认是否重试':(isApproval?'等待人工判断':'等待人工验收');
if(nr.status==='failed')verdict='门禁失败';
diff --git a/webtest/tests/issue-drawer-actions.test.mjs b/webtest/tests/issue-drawer-actions.test.mjs
index 216f9a46..4ebf5d7b 100644
--- a/webtest/tests/issue-drawer-actions.test.mjs
+++ b/webtest/tests/issue-drawer-actions.test.mjs
@@ -73,6 +73,67 @@ test('drawer clarification, activity, delivery, and operation helpers render mea
assert.equal(result.badTime, '—');
});
+test('acceptance gates follow the SOP edges, so a node inserted by a SOP update shows where it runs', async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ const result = structuredClone(app.evaluate(`(() => {
+ // SOP v2 inserted "preview" between "test" and "accept"; the editor appended
+ // it to the nodes array, and refresh-sop keeps that array order.
+ const wf={id:'flow-1',
+ nodes:[{id:'design',name:'方案设计',type:'agent'},{id:'test',name:'测试验证',type:'agent'},
+ {id:'accept',name:'人工验收',type:'approval'},{id:'summary',name:'交付汇总',type:'agent'},
+ {id:'preview',name:'构建静态站点',type:'agent'}],
+ edges:[{source:'design',target:'test'},{source:'test',target:'preview'},
+ {source:'preview',target:'accept'},{source:'accept',target:'summary'}]};
+ const run={id:'run-v2',status:'waiting',workflowId:'flow-1',workflowSnapshot:wf,
+ nodes:{design:{status:'succeeded'},test:{status:'succeeded'},preview:{status:'succeeded'},
+ accept:{status:'waiting_approval'},summary:{status:'pending'}}};
+ const issue={...state.data.issues[0],source:'manual'};
+ const html=acceptancePane(issue,{issue,run,task:null,requirement:null});
+ const names=html.split('<span class="node-name">').slice(1).map(part=>part.split('<')[0]);
+ const cyclic={...wf,edges:[...wf.edges,{source:'summary',target:'design'}]};
+ return {names,
+ unordered:nodesInExecutionOrder({nodes:wf.nodes}).map(n=>n.id),
+ cyclic:nodesInExecutionOrder(cyclic).map(n=>n.id)};
+ })()`));
+ assert.deepEqual(result.names, ['方案设计','测试验证','构建静态站点','人工验收','交付汇总']);
+ assert.deepEqual(result.unordered, ['design','test','accept','summary','preview']);
+ assert.equal(result.cyclic.length, 5);
+ assert.deepEqual([...result.cyclic].sort(), ['accept','design','preview','summary','test']);
+});
+
+test('acceptance gate ordering ignores self-loops and edges to deleted nodes, and keeps degenerate SOPs as stored', async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ const result = structuredClone(app.evaluate(`(() => {
+ const ids=wf=>nodesInExecutionOrder(wf).map(n=>n.id);
+ const nodes=[{id:'c'},{id:'a'},{id:'b'}];
+ return {
+ // A self-loop and an edge from/to a node removed in a later SOP version
+ // must not block the real order a -> b -> c.
+ dangling:ids({nodes,edges:[{source:'a',target:'b'},{source:'b',target:'c'},
+ {source:'a',target:'a'},{source:'gone',target:'a'},{source:'a',target:'gone'}]}),
+ // Only ignorable edges: stable array order.
+ onlyIgnored:ids({nodes,edges:[{source:'b',target:'b'},{source:'gone',target:'c'}]}),
+ // Diamond: ties are broken by array order.
+ diamond:ids({nodes:[{id:'end'},{id:'right'},{id:'left'},{id:'start'}],
+ edges:[{source:'start',target:'left'},{source:'start',target:'right'},
+ {source:'left',target:'end'},{source:'right',target:'end'}]}),
+ single:ids({nodes:[{id:'only'}],edges:[{source:'x',target:'only'}]}),
+ missingID:ids({nodes:[{id:'b'},{name:'no id'},{id:'a'}],edges:[{source:'a',target:'b'}]}).map(id=>id??null),
+ empty:ids(undefined),
+ noNodes:ids({edges:[{source:'a',target:'b'}]}),
+ };
+ })()`));
+ assert.deepEqual(result.dangling, ['a', 'b', 'c']);
+ assert.deepEqual(result.onlyIgnored, ['c', 'a', 'b']);
+ assert.deepEqual(result.diamond, ['start', 'right', 'left', 'end']);
+ assert.deepEqual(result.single, ['only']);
+ assert.deepEqual(result.missingID, ['b', null, 'a']);
+ assert.deepEqual(result.empty, []);
+ assert.deepEqual(result.noNodes, []);
+});
+
test('drawer actions write back clarification and resync TAPD with API payloads', async (t) => {
const app = await loadApp();
t.after(app.close);