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.

fix(web): refresh approvals and cover requirement UI journeys (#106)

Xingpeng Zhuc7e2f746ccfc
diff --git a/e2e/README.md b/e2e/README.md
index 9707bb18..625dfc55 100644
--- a/e2e/README.md
+++ b/e2e/README.md
@@ -64,7 +64,7 @@ API Token 和 UI 登录账号应属于同一用户。模型 Key 在平台个人
- `api/68-workspace-edit`:人工接管已停止的运行工作区:运行中不可写、viewer 不可接管、`expectedSha256` 防覆盖与路径校验、其他成员接力编辑、diff 投影、审批点上 `resume` 不能跳过审批。
- `api/69-assistant-sessions`:AI 会话保存(作者不可伪造)、改名、关联需求(乐观并发)、分支与编辑、归档、删除,项目会话的共享与权限。
- `ui/01-views`:真实密码会话下,在体验项目和测试项目逐页巡检;检查页面内容、控制台和失败请求,不模拟登录接口。
-- `ui/02-interactions`:需求创建与真实 AI 分析、页面审批、运行详情页签、设计器编辑保存、可选知识库检索。
+- `ui/02-interactions`:需求创建后列表可见 → 点击打开抽屉 → 启动脚本 SOP;从侧栏进入审批队列、填写上下文并审批;运行详情审批与必需页签断言;设计器编辑保存与可选真实 AI 分析。
- `ui/03-workbench-settings`:AI 工作台会话列表(打开、搜索、改名、归档、删除)、个人凭证向导(格式校验、保存、清除)、Bot 新建与删除、viewer/member 看到的 Bot 页面权限、领域管理编辑与重复标识拦截。
- `public/`:公共登录、语言/主题、真实脚本审批,以及首页草稿和真实模型对话的回归,见[运行说明](public/README.md)。
diff --git a/e2e/public/platform.spec.mjs b/e2e/public/platform.spec.mjs
index 5e90c382..59a6b097 100644
--- a/e2e/public/platform.spec.mjs
+++ b/e2e/public/platform.spec.mjs
@@ -57,7 +57,7 @@ test('Chinese/English and light/dark preferences persist across reloads',async({
expect(errors).toEqual([]);
});
-test('real script artifacts survive a human approval and execution continues',async({page})=>{
+test('real script artifacts survive UI approval and execution continues',async({page})=>{
await signIn(page);
const response=await page.request.post('/api/runs',{data:{workflowId:'welcome-workflow',projectId:'welcome',input:'Browser acceptance: artifacts, approval and continuation'}});
expect(response.ok()).toBe(true);
@@ -72,10 +72,15 @@ test('real script artifacts survive a human approval and execution continues',as
const artifact=detail.artifacts.find(a=>a.name==='welcome');expect(artifact).toBeTruthy();
const content=await page.request.get(`/api/runs/${run.id}/artifacts/${encodeURIComponent(artifact.id)}`);
expect(await content.text()).toContain('LoopForge');
- const approval=await page.request.post(`/api/runs/${run.id}/approve`,{data:{nodeId:'approve',context:'Verified the saved report'}});
- expect(approval.ok()).toBe(true);
+ await page.goto(`/#/runs/${encodeURIComponent(run.id)}`);
+ await page.locator('[data-run-node="approve"]').click();
+ const decision=page.locator('#runDetail .approval-callout.human');
+ await expect(decision).toBeVisible();
+ await decision.locator('[data-human-context]').fill('Verified the saved report');
+ await decision.locator('[data-approve="approve"]').click();
await expect.poll(async()=>(await read()).status,{timeout:30_000}).toBe('succeeded');
detail=await read();expect(detail.nodes.finish.status).toBe('succeeded');
+ expect(detail.humanContext).toBe('Verified the saved report');
expect(detail.artifacts.some(a=>a.name==='completed')).toBe(true);
await openSettingsPage(page,'runs');
await expect(page.locator('#runsView')).toBeVisible();
diff --git a/e2e/ui/02-interactions.spec.mjs b/e2e/ui/02-interactions.spec.mjs
index 23ae0bc5..07f8d6f7 100644
--- a/e2e/ui/02-interactions.spec.mjs
+++ b/e2e/ui/02-interactions.spec.mjs
@@ -1,18 +1,20 @@
-// Key user journeys driven through the real UI: create a requirement, approve
-// a waiting run from its detail page and edit a SOP in the designer. Fixtures are created through the API and cleaned up.
+// Key user journeys driven through the real UI: create and dispatch a requirement,
+// approve waiting runs from the queue and detail page, and edit a SOP in the
+// designer. Fixtures are created through the API and cleaned up.
import { test, expect, watchErrors, openView } from './fixtures.mjs';
-import { get, post, put, del, list, cleanup, track, waitRun } from '../lib/api.mjs';
+import { get, post, put, del, list, cleanup, track, waitFor, waitRun } from '../lib/api.mjs';
import { cfg } from '../lib/env.mjs';
-import { createWorkflow, createAgent, script, approval, agentNode, startRun } from '../lib/fixtures.mjs';
+import { createWorkflow, createAgent, script, approval, agentNode, startRun, trackRun } from '../lib/fixtures.mjs';
test.afterAll(cleanup);
-test('requirement composer: create a platform requirement without analysis', async ({ page }) => {
+test('requirement composer: create, find and dispatch a requirement from its drawer', async ({ page }) => {
const errors = watchErrors(page);
const title = `E2E UI 需求 ${cfg.runTag}-${Date.now() % 100000}`;
// A requirement needs a runnable SOP; a fresh database has none in the e2e project.
- await createWorkflow('ui-requirement', [script('only', 'echo ok')]);
- await openView(page, 'issues');
+ const wf = await createWorkflow('ui-requirement', [script('only', 'echo UI_REQUIREMENT')]);
+ await page.goto('/#/issues');
+ await expect(page.locator('#issuesView')).toBeVisible();
await page.locator('#newIssue').click();
await expect(page.locator('#requirementModal')).toHaveClass(/open/);
await page.locator('#chatInput').fill(`${title}\n\n自动化 UI 测试创建,会被关闭。`);
@@ -20,16 +22,51 @@ test('requirement composer: create a platform requirement without analysis', asy
await expect(page.locator('#reqStepConfirm')).toBeVisible();
await expect(page.locator('#reqCreate')).toBeVisible();
await expect(page.locator('#reqTitle')).toHaveValue(title);
- await page.locator('#reqCreate').click();
- await expect(page.locator('#requirementModal')).not.toHaveClass(/open/, { timeout: 30_000 });
-
- const created = await expect.poll(async () => {
- const items = list(await get(`/api/issues?projectId=${cfg.projectId}&q=${encodeURIComponent(title.slice(0, 20))}`));
- return items.find(i => (i.title + i.description).includes(title))?.id || '';
- }, { timeout: 30_000 }).not.toBe('');
- const issue = list(await get(`/api/issues?projectId=${cfg.projectId}`)).find(i => (i.title + i.description).includes(title));
+ await page.getByRole('button', { name: 'SOP 流程', exact: true }).click();
+ await page.getByRole('listbox', { name: 'SOP 流程', exact: true })
+ .getByRole('option', { name: /E2E ui-requirement/ }).click();
+ await expect(page.locator('#reqWorkflow')).toHaveValue(wf);
+ const [created] = await Promise.all([
+ page.waitForResponse(r => new URL(r.url()).pathname === '/api/issues' && r.request().method() === 'POST'),
+ page.locator('#reqCreate').click(),
+ ]);
+ expect(created.ok()).toBe(true);
+ const issue = await created.json();
track(`issue ${issue.id}`, () => post(`/api/issues/${issue.id}/close`, {}, { expect: [200, 404, 409] }));
expect(issue.source || 'local').toBe('local');
+ expect(issue.workflowId).toBe(wf);
+ await expect(page.locator('#requirementModal')).not.toHaveClass(/open/);
+
+ // Creation opens the drawer automatically. Close it, then exercise the
+ // refreshed list's own click binding without reloading or fetching the row.
+ const drawer = page.locator('#issueDetailDrawer');
+ await expect(drawer).toHaveClass(/open/);
+ await drawer.locator('.drawer-close').click();
+ await expect(drawer).toHaveAttribute('aria-hidden', 'true');
+ const row = page.locator(`#issuesView .issue-table-row[data-id="${issue.id}"]`);
+ await expect(row).toBeVisible();
+ await expect(row).toContainText(title);
+ await row.locator('.issue-title-cell').click();
+ await expect(drawer).toHaveAttribute('aria-hidden', 'false');
+ await expect(drawer.locator('#issueDetailTitle')).toHaveText(title);
+ await drawer.locator('[data-dtab="sop"]').click();
+ await expect(drawer.locator('[data-dtab="sop"]')).toHaveClass(/active/);
+
+ const dispatch = drawer.locator(`[data-dispatch-issue="${issue.id}"][data-workflow="${wf}"]`);
+ await expect(dispatch).toBeVisible();
+ const [dispatched] = await Promise.all([
+ page.waitForResponse(r => new URL(r.url()).pathname === `/api/issues/${issue.id}/dispatch` && r.request().method() === 'POST'),
+ dispatch.click(),
+ ]);
+ expect(dispatched.ok()).toBe(true);
+ const runId = await waitFor('UI-dispatched requirement run', async () => {
+ const runs = list(await get(`/api/issues/${issue.id}/runs`));
+ return runs[0]?.id || runs[0]?.runId;
+ }, { timeoutMs: 30_000 });
+ trackRun(runId);
+ const run = await waitRun(runId, r => r.status === 'succeeded', { label: 'requirement SOP succeeds' });
+ expect(run.workflowId).toBe(wf);
+ expect(run.nodes.only.status).toBe('succeeded');
expect(errors).toEqual([]);
});
@@ -73,8 +110,11 @@ test('run detail: tabs render and a waiting approval is approved from the UI', a
for (const tab of ['trace', 'logs', 'workspace', 'eval', 'overview']) {
await page.locator(`[data-run-tab="${tab}"]`).click();
const pane = page.locator(`[data-run-pane="${tab}"]`);
- if (await pane.count()) await expect(pane).toBeVisible();
- await page.waitForTimeout(800);
+ // These five panes are required by this fixture. Preview is optional
+ // and deliberately not part of this list.
+ await expect(pane).toBeVisible();
+ await expect(page.locator('#runDetail [data-run-tab].active')).toHaveAttribute('data-run-tab', tab);
+ await expect(page.locator('#runDetail [data-run-pane]:not([hidden])')).toHaveCount(1);
}
await page.locator('[data-run-node="prep"]').click();
await expect(page.locator('[data-artifact]').first()).toBeVisible();
@@ -87,6 +127,42 @@ test('run detail: tabs render and a waiting approval is approved from the UI', a
expect(errors).toEqual([]);
});
+test('approvals queue: approve a waiting run with context from the sidebar', async ({ page }) => {
+ const wf = await createWorkflow('ui-approval-queue', [
+ script('prep', 'echo QUEUE_PREP'),
+ approval('gate', 'prep'),
+ script('finish', 'echo QUEUE_FINISH'),
+ ]);
+ const { id } = await startRun(wf, 'e2e queue approval');
+ await waitRun(id, r => r.nodes?.gate?.status === 'waiting_approval', { label: 'queue gate waiting' });
+
+ const errors = watchErrors(page);
+ await page.goto('/#/issues');
+ await expect(page.locator('#issuesView')).toBeVisible();
+ await page.locator('.nav[data-view="approvals"]').click();
+ await expect(page).toHaveURL(/#\/approvals$/);
+ await expect(page.locator('#approvalsView')).toBeVisible();
+ const approve = page.locator(`#approvalList [data-approve="${id}"][data-node="gate"]`);
+ const card = page.locator('#approvalList .ap-card').filter({
+ has: page.locator(`[data-approve="${id}"][data-node="gate"]`),
+ });
+ await expect(card).toBeVisible();
+ await expect(card).toContainText('E2E ui-approval-queue');
+ const context = `Queue approval ${cfg.runTag}`;
+ await card.locator('[data-human-context]').fill(context);
+ const [response] = await Promise.all([
+ page.waitForResponse(r => new URL(r.url()).pathname === `/api/runs/${id}/approve` && r.request().method() === 'POST'),
+ approve.click(),
+ ]);
+ expect(response.ok()).toBe(true);
+ const run = await waitRun(id, r => r.status === 'succeeded', { label: 'succeeded after queue approval' });
+ expect(run.nodes.gate.status).toBe('succeeded');
+ expect(run.nodes.finish.status).toBe('succeeded');
+ expect(run.humanContext).toBe(context);
+ await expect(card).toHaveCount(0);
+ expect(errors).toEqual([]);
+});
+
test('SOP designer: rename a node and save a new revision', async ({ page }) => {
const wf = await createWorkflow('ui-designer', [script('first', 'echo 1'), script('second', 'echo 2')]);
const before = await get(`/api/workflows/${wf}`);
diff --git a/web/app/approvals.js b/web/app/approvals.js
index 02ec04eb..ec655c71 100644
--- a/web/app/approvals.js
+++ b/web/app/approvals.js
@@ -350,7 +350,7 @@ async function cancelRunFlow(runId){
if(!await afConfirm({title:'取消流程确认',message:'确定取消该流程?取消后将不再出现在待我确认列表,对应需求可重新派发。',confirmText:'确认取消',isDanger:true}))return;
try{await api(`/api/runs/${encodeURIComponent(runId)}/cancel`,{method:'POST'});toast('流程已取消','ok');renderApprovals(true)}catch(e){toast(e.message,'err')}
}
-async function approveRun(runId,nodeId,fromEl){if(queuedRunActionBlocked(runId))return;try{await api(`/api/runs/${runId}/approve`,{method:'POST',body:JSON.stringify(withHumanContext({nodeId,context:readHumanContext(fromEl)}))});toast('已批准,流程继续','ok');renderApprovals(true);if(state.drawerOpen&&state.issueDetailData?.issue)openIssueDetail(state.issueDetailData.issue.id,'sop')}catch(e){toast(e.message,'err')}}
+async function approveRun(runId,nodeId,fromEl){if(queuedRunActionBlocked(runId))return;try{await api(`/api/runs/${runId}/approve`,{method:'POST',body:JSON.stringify(withHumanContext({nodeId,context:readHumanContext(fromEl)}))});toast('已批准,流程继续','ok');await renderApprovals();if(state.drawerOpen&&state.issueDetailData?.issue)openIssueDetail(state.issueDetailData.issue.id,'sop')}catch(e){toast(e.message,'err')}}
async function rejectRun(runId,nodeId,fromEl){if(queuedRunActionBlocked(runId))return;const target=String(fromEl?.dataset?.target||'').trim(),targetName=String(fromEl?.dataset?.targetName||target).trim();if(!target)return toast('当前节点没有配置上游返工目标','err');const reason=await afPrompt({title:`退回上游「${targetName}」重做`,message:`将重置「${targetName}」及其全部下游节点。请输入返工原因:`,defaultValue:'验证未通过,请上游修复后重新提交'});if(reason===null||reason===undefined)return;try{await api(`/api/runs/${runId}/reject`,{method:'POST',body:JSON.stringify(withHumanContext({nodeId,targetId:target,reason,context:readHumanContext(fromEl)}))});toast(`已退回「${targetName}」,开始重跑后续流程`,'ok');renderApprovals(true);if(state.drawerOpen&&state.issueDetailData?.issue)openIssueDetail(state.issueDetailData.issue.id,'sop')}catch(e){toast(e.message,'err')}}
function approvalStatusBadgeHTML(paused){
const [tone,icon,label]=paused?['neutral','pause','已暂停']:['warn','pending-review','待确认'];
diff --git a/webtest/tests/approvals.test.mjs b/webtest/tests/approvals.test.mjs
index 014dc164..a8a1aadf 100644
--- a/webtest/tests/approvals.test.mjs
+++ b/webtest/tests/approvals.test.mjs
@@ -49,7 +49,7 @@ test('approval helpers explain gates, failures, pauses, and contextual payloads'
assert.equal(JSON.stringify(result.pausedNodes), JSON.stringify(['review']));
});
-test('approval list renders assigned waiting run and approve sends context', async (t) => {
+test('approval list sends context and removes the approved run after refreshing', async (t) => {
const app = await loadApp();
t.after(app.close);
const run = {
@@ -63,6 +63,9 @@ test('approval list renders assigned waiting run and approve sends context', asy
};
app.router.get('/api/runs/approval-run', run);
app.router.post('/api/runs/approval-run/approve', { ok: true });
+ app.router.get('/api/runs', [{ ...run, status: 'running' }]);
+ app.router.get('/api/tasks', []);
+ app.router.get('/api/issues', []);
app.router.post('/api/runs/approval-run/retry', { ...run, status: 'running' });
app.router.post('/api/runs/approval-run/resume', { ...run, status: 'running' });
app.router.post('/api/runs/approval-run/pause', { ok: true });
@@ -81,6 +84,8 @@ test('approval list renders assigned waiting run and approve sends context', asy
const call = app.router.calls.find(c => c.path === '/api/runs/approval-run/approve');
assert.equal(call.method, 'POST');
assert.equal(call.body.context, '验收通过,保留截图');
+ assert.equal(app.document.querySelector('#approvalList .ap-card'), null);
+ assert.match(app.document.querySelector('#approvalList').textContent, /没有需要你拍板的需求/);
app.evaluate(`
state.data.runs=[${JSON.stringify(run)}];