Skip to content

feat(web): force auto-arrange before saving or publishing workflows - #1752

Merged
crispinhu27 merged 1 commit into
mainfrom
feat/workflow-save-auto-arrange
Dec 3, 2026
Merged

crispinhu27 merged 1 commit into
mainfrom
feat/workflow-save-auto-arrange

Conversation

@crispinhu27

Copy link
Copy Markdown
Collaborator

What changed

When users drag or edit nodes in the LOOP flowchart designer (web/app/flows.js), manually positioned nodes could remain misaligned or overlapping when saved or published.

  • Extract arrangeWorkflowNodes() / arrangeBeforeCommit() using workflowStages() to lay out nodes by dependency level (x: 80 + col * 320, y: 80 + row * 190) without adding no-op undo entries when already arranged.
  • Force auto-arrange before saveWorkflow() sends PUT /api/workflows and before publishWorkflow() checks whether a save is needed (so even clean unarranged drafts save their arranged positions before publishing).
  • Re-render the canvas and fit the viewport via fitCanvasOrDefer() (deferring the fit cleanly until returning to Canvas when saved from the Configuration check view), while keeping dirty() and undo history intact if a save fails and leaving read-only workflows untouched.
  • Add unit and jsdom regression tests in e2e/unit/flow-designer.test.mjs and webtest/tests/flows-editor.test.mjs.

Scope

  • Platform core / API / runner

Compatibility

Only touches frontend flowchart save/publish handling in web/app/flows.js and corresponding tests; workflow JSON schema and backend APIs remain unchanged.

Validation

  • node --test e2e/unit/*.test.mjs (25/25 passed)
  • node web/workflow_revision_sync_test.js web/orchestrate.js web/app/flows.js web/app/sops.js (passed)
  • npm --prefix webtest run coverage (Node v22.23.2: 610/611 passed, 1 opt-in integration test skipped without LOOPFORGE_ROUTING_TEST_URL, line coverage 86.67%)
  • GOCACHE=/tmp/agentflow-gocache go test ./web -count=1 (passed, with local chatbot build)
  • GOCACHE=/tmp/agentflow-gocache go vet ./... (passed)
  • python3 scripts/check-public.py (passed)
  • bash scripts/scan-secrets.sh (blocked locally on macOS arm64: pinned linux_x64 gitleaks binary cannot execute)
  • Playwright e2e/ui/ suite (not run; will run in CI)

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.

@Robert0622

Copy link
Copy Markdown
Collaborator

CR + 部署实测:#1752 @ b49d0a2(保存/发布前强制自动排版)

结论:可以合入,建议同时处理下面 2 处 P2(不影响本次通过)。

实测环境

私有部署 main+本 PR 构建的 LoopForge(MariaDB 11.8 + native 沙箱,127.0.0.1:18600),未触碰 Tencent/LoopForge 的部署;用真实 Chromium 驱动画布拖拽、保存、发布和配置检查页。

验证结果

场景 结果
拖动节点后点「保存」 PUT 前自动排版为 a:(80,80) b:(400,80) c:(400,270),画布节点 DOM 同步、已保存,服务端位置一致 ✅
未排版的干净草稿点「发布版本」 先保存排版后的位置(rev 1→3)再发布 v1,无冲突 ✅
保存请求失败(模拟 500) 画布保留排版结果、仍为未保存状态、服务端未变;放开后重试保存成功 ✅
配置检查页里 Ctrl+S 保存成功且不跳回画布,检查页不重建;切回画布后画布重新 fit(transform 被更新)✅
已归档 LOOP 发布按钮禁用、保存/整理被拒,位置不变 ✅
单元测试 node --test e2e/unit/flow-designer.test.mjs 14/14、webtest tests/flows-editor.test.mjs 23/23 ✅

拖拽后保存前(上)与保存后(下)
配置检查页保存前/后
未排版干净草稿发布后已排版

建议修改(P2,不阻塞)

  1. 保存后撤销会回滚到未排版快照:arrangeWorkflowNodes() 会 flowHistory.record(),而保存成功后没有 flowHistory.clear()。保存后再点一次「撤销」,节点回到排版前的位置并被标记为已修改——和「已保存」状态矛盾,下次保存还会多一次无意义写入。建议保存成功后清理/重新基线历史,或在 undo 里跳过排版快照。
  2. 画布隐藏时的 fit 没有重试:setFlowView('canvas') 在同一同步调用里先 hidden=false 再 flowViewport.fit({smooth:false})(大约 flows.js:592-593),此时 #canvas 可能还没有布局尺寸;如果 fit 按 0 尺寸计算,就没法自动重试了。建议在 requestAnimationFrame 后再 fit 一次(本次实测浏览器环境下 fit 结果正常,属于潜在问题)。

另外核对了常见的几个疑点,均不成立:dirty() 与 setFlowView('check') 不存在互相递归;发布失败不会出现两条提示(saveWorkflow 抛出后 publishWorkflow 只再弹一次);跨项目面板显示的 LOOP 按钮走同一只读分支;自动选默认预览模型的代码在 arrangeBeforeCommit 之前执行,和本改动无关。

CI:webtest、core、e2e、validate、secrets 均通过(head b49d0a2,GitHub 检查 17/17 绿)。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

部署实测通过(保存/发布前自动排版、保存失败保留画布、配置检查页保存、归档只读均正常),webtest/unit 全过、CI 17/17 绿。两处 P2 建议(保存后撤销回滚到未排版快照、canvas 隐藏时 fit 无重试)已在评论里说明,不阻塞合入。

@crispinhu27
crispinhu27 merged commit bb025bf into main Dec 3, 2026
17 checks passed
@crispinhu27
crispinhu27 deleted the feat/workflow-save-auto-arrange branch December 3, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants