Skip to content

fix(bpm-core): keep the top-level manager fallback when custom fields are empty - #3

Merged
fantasywind merged 1 commit into
Rytass:mainfrom
coollugi:fix/dry-run-manager-snapshot
Aug 3, 2026
Merged

fix(bpm-core): keep the top-level manager fallback when custom fields are empty#3
fantasywind merged 1 commit into
Rytass:mainfrom
coollugi:fix/dry-run-manager-snapshot

Conversation

@coollugi

@coollugi coollugi commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

問題

只要範本裡含有「發起人主管」關卡(approverResolver.type === 'ORG_MANAGER'),從設計器按試跑一定失敗:

workflow.nodes.<id>.data.approverResolver did not resolve to a member id

範本本身沒問題 —— 發布後實際送出案件,主管會正常透過 manager_resolutions 解析出來
壞掉的只有預覽這條路,所以設計器的試跑按鈕對最常用的那個簽核來源等於不能用

根因

readManagerMemberIdFromInitiatorSnapshot 依序找四個來源:managerChainmanagerMemberIdscustomFields.managerMemberId,最後才是頂層的 managerMemberId

第三步只要 customFields任何物件就直接回傳:

if (isRecord(customFields)) {
  return customFields.managerMemberId;   // customFields 是 {} 時回 undefined
}

return initiatorMetadataSnapshot.managerMemberId;   // 永遠走不到

{} 也是物件,所以空的 customFields 會短路成 undefined,第四步永遠不會執行

而設計器預覽組出來的 snapshot 正好就是這個形狀 —— { customFields: {}, managerMemberId: 'member-002', memberId: 'member-001', ... } —— 它刻意帶進來的頂層 id 反而永遠讀不到

修法

只有在 custom fields 真的帶了 manager id 時才走那一條分支

測試

libs/bpm-core/src/lib/workflow-engine/workflow-engine.service.spec.ts 新增兩個案例:

  • 空的 customFields 會往下落到頂層的 managerMemberId
  • 有值的 customFields.managerMemberId 仍然優先於頂層的

驗證過第一個是真的迴歸防護:只還原 source 的改動,它會紅

nx test bpm-core(21 suites/162 tests)/nx lint bpm-corenx typecheck bpm-core 全部通過

備註

bpm-core-react 那側的 snapshot 建構函式其實也可以改成把 managerMemberId 放進 customFields
但修讀取端是比較保險的選擇,任何送出這個形狀的呼叫端都能得到合理結果

🤖 Generated with Claude Code

https://claude.ai/code/session_01BVBYyU83KfmAeJGj6gGsVm

… are empty

readManagerMemberIdFromInitiatorSnapshot returned as soon as customFields was
any record, so a snapshot shaped { customFields: {}, managerMemberId: '...' }
resolved to undefined and every ORG_MANAGER node reported "did not resolve to
a member id". That is exactly the shape the template designer preview sends,
so dry running any template with a "manager of the initiator" step always
failed.

Only take the custom-fields branch when it actually carries a manager id.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVBYyU83KfmAeJGj6gGsVm
@coollugi
coollugi force-pushed the fix/dry-run-manager-snapshot branch from abd6bdd to e8a0b96 Compare August 3, 2026 12:23
@coollugi
coollugi changed the base branch from main to staging August 3, 2026 12:23
@coollugi

coollugi commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

base 已經從 main 改成 staging,原因寫在 #2

@coollugi
coollugi changed the base branch from staging to main August 3, 2026 13:03
@fantasywind
fantasywind merged commit 588abca into Rytass:main Aug 3, 2026
1 check failed
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