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): resolve run machine labels without opening settings (refs #198) (#222)

fx-kurumi8d40b94754cf
diff --git a/web/app/runs.js b/web/app/runs.js
index 9b6895e3..f29c0b4f 100644
--- a/web/app/runs.js
+++ b/web/app/runs.js
@@ -272,7 +272,9 @@ function showRunDetail(id){
state.activeRun=summary;
renderRunDetail(summary);
}
- api(`/api/runs/${encodeURIComponent(id)}`,{silent:!!summary}).then(r=>{
+ api(`/api/runs/${encodeURIComponent(id)}`,{silent:!!summary}).then(async r=>{
+ if(state.selectedRun!==id)return;
+ await loadRunMachineMetadata(r);
if(state.selectedRun!==id)return;
state.activeRun=r;
if(shouldPatchRunLive(r))patchRunLive(r);else renderRunDetail(r);
@@ -303,7 +305,9 @@ function selectRun(id,keepPages=false){
renderRunDetail(summary);
if(['queued','running','waiting'].includes(summary.status))startLiveRun(id);else stopLiveRun();
}
- api(`/api/runs/${encodeURIComponent(id)}`,{silent:!!summary}).then(r=>{
+ api(`/api/runs/${encodeURIComponent(id)}`,{silent:!!summary}).then(async r=>{
+ if(state.selectedRun!==id)return;
+ await loadRunMachineMetadata(r);
if(state.selectedRun!==id)return;
state.activeRun=r;
renderRuns();
@@ -1454,6 +1458,14 @@ async function runAction(id,action,body){
toast(action==='cancel'&&run.status==='cancelled'?(run.admissionState==='unstarted'?'已取消排队':'运行已取消'):runControlToast(run,action==='approve'?'已批准,流程继续':action==='reject'?'已打回,开始返工':action==='retry'?'已从中断处继续':'已选择不重试'));
}catch(e){toast(e.message)}
}
+async function loadRunMachineMetadata(r){
+ if(r.executionContext?.executionMode!=='runner')return;
+ // Unlike refreshRunners, this read-only lookup does not create a binding code.
+ try{
+ const runners=await api('/api/runners?mine=1',{silent:true});
+ if(state.selectedRun===r.id)state.runners=runners||[];
+ }catch{} // Machine metadata must not prevent displaying the run.
+}
function runExecutionChipHTML(r){
const ec=r.executionContext||{};
if(ec.executionMode!=='runner')return '';
diff --git a/web/run_queue_test.js b/web/run_queue_test.js
index 7c8401e3..19db5198 100644
--- a/web/run_queue_test.js
+++ b/web/run_queue_test.js
@@ -85,7 +85,7 @@ async function main() {
for (const name of ['showRunDetail','selectRun']) {
const streams=[],context={state:{data:{runs:[]}},$:()=>({hidden:false,classList:{add:()=>{}},dataset:{}}),document:{querySelector:()=>({setAttribute:()=>{}})},stopQueuedRunRefresh:()=>{},stopLiveRun:()=>{},stopPreviewPoll:()=>{},syncRunHash:()=>{},api:async()=>({id:'r',status:'queued'}),shouldPatchRunLive:()=>false,renderRunDetail:()=>{},renderRuns:()=>{},startLiveRun:id=>streams.push(id),toast:()=>{}};
- load(context,[name]);context[name]('r');await flush();assert.deepEqual(streams,['r'],name);
+ load(context,['loadRunMachineMetadata',name]);context[name]('r');await flush();assert.deepEqual(streams,['r'],name);
}
const liveState={selectedRun:'r',data:{runs:[]}},intervals=new Map();let timer=0,status='queued',applied=[];
const polling={state:liveState,api:async()=>({id:'r',status}),setInterval:fn=>{intervals.set(++timer,fn);return timer},clearInterval:id=>intervals.delete(id),patchCachedRun:()=>{},applyRunPayload:r=>applied.push(r.status),refreshRunPagesDelta:async()=>{},renderRuns:()=>{},renderIssueDetailTab:()=>{}};
diff --git a/webtest/tests/run-machine-label-race.test.mjs b/webtest/tests/run-machine-label-race.test.mjs
new file mode 100644
index 00000000..f7467f43
--- /dev/null
+++ b/webtest/tests/run-machine-label-race.test.mjs
@@ -0,0 +1,27 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { loadApp, settle } from '../lib/load-app.mjs';
+
+for (const entry of ['showRunDetail', 'selectRun']) {
+ test(`${entry} ignores machine metadata after switching runs`, async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ const base = app.evaluate('structuredClone(state.data.runs[0])');
+ const first = { ...base, status: 'succeeded', executionContext: { executionMode: 'runner', executionRunnerId: 'runner-first' } };
+ const second = { ...base, id: 'run-2', status: 'succeeded', executionContext: {} };
+ let release;
+ app.router.get('/api/runs/run-1', first);
+ app.router.get('/api/runs/run-2', second);
+ app.router.get('/api/runners?mine=1', () => new Promise((resolve) => { release = resolve; }));
+ app.evaluate(`state.runners=[];state.data.runs=${JSON.stringify([first, second])};${entry}('run-1')`);
+ await settle(4);
+ assert.equal(typeof release, 'function');
+ app.evaluate(`${entry}('run-2')`);
+ await settle(4);
+ release([{ id: 'runner-first', name: 'Stale machine', ownerUserId: 42 }]);
+ await settle(4);
+ assert.equal(app.evaluate('state.activeRun.id'), 'run-2');
+ assert.equal(app.evaluate('state.runners.length'), 0);
+ assert.doesNotMatch(app.document.querySelector('#runsDetailSection').textContent, /Stale machine/);
+ });
+}
diff --git a/webtest/tests/run-machine-label.test.mjs b/webtest/tests/run-machine-label.test.mjs
new file mode 100644
index 00000000..4f5fcfb5
--- /dev/null
+++ b/webtest/tests/run-machine-label.test.mjs
@@ -0,0 +1,41 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { loadApp, settle } from '../lib/load-app.mjs';
+
+for (const entry of ['showRunDetail', 'selectRun']) {
+for (const scenario of [
+ { name: 'personal machine', runners: [{ id: 'runner-personal', name: '<Build machine>', ownerUserId: 42, runLimit: 3 }], expected: /个人机器 &lt;Build machine&gt;.*本机最多 3 条/ },
+ { name: 'unavailable runner endpoint', runners: { status: 403, body: { error: 'Forbidden' } }, expected: /执行机器 personal/ },
+ { name: 'cloud pool', runners: [], pool: 'cloud', expected: /云端执行池/ },
+]) {
+ test(`${entry} resolves ${scenario.name} without visiting the runners page`, async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ const run = {
+ ...app.evaluate('structuredClone(state.data.runs[0])'), status: 'succeeded',
+ workflowSnapshot: app.evaluate('structuredClone(state.data.workflows[0])'),
+ executionContext: { executionMode: 'runner', executionRunnerId: 'runner-personal', executionPool: scenario.pool },
+ };
+ app.router.get('/api/runs/run-1', run);
+ app.router.get('/api/runners?mine=1', scenario.runners);
+ app.evaluate(`state.runners=[];state.data.runs=[${JSON.stringify(run)}];${entry}('run-1')`);
+ await settle(8);
+ assert.ok(app.router.calls.some((call) => call.path === '/api/runners' && call.search === '?mine=1'));
+ assert.match(app.evaluate('runExecutionChipHTML(state.activeRun)'), scenario.expected);
+ assert.match(app.document.querySelector('#runsDetailSection').textContent, /个人机器 <Build machine>|执行机器 personal|云端执行池/);
+ assert.equal(app.router.calls.filter((call) => call.path === '/api/runners/bind-codes').length, 0,
+ 'viewing a run must not create a binding code');
+ });
+}
+}
+
+test('non-runner run detail does not fetch machines', async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ const run = { ...app.evaluate('structuredClone(state.data.runs[0])'), status: 'succeeded', executionContext: {} };
+ app.router.get('/api/runs/run-1', run);
+ const before = app.router.calls.filter((call) => call.path === '/api/runners').length;
+ app.evaluate(`state.data.runs=[${JSON.stringify(run)}];showRunDetail('run-1')`);
+ await settle(8);
+ assert.equal(app.router.calls.filter((call) => call.path === '/api/runners').length, before);
+});