( ref: string, activePorts: string[] | undefined, readyQueue: ReadyItem[], pending: Set<string>, nodeStates: Map<string, NodeState>, successEdges: Map<string, WorkflowEdge[]>, onNodeSkipped?: (ref: string) => Promise<void>, )
| 214 | } |
| 215 | |
| 216 | async function handleSuccess( |
| 217 | ref: string, |
| 218 | activePorts: string[] | undefined, |
| 219 | readyQueue: ReadyItem[], |
| 220 | pending: Set<string>, |
| 221 | nodeStates: Map<string, NodeState>, |
| 222 | successEdges: Map<string, WorkflowEdge[]>, |
| 223 | onNodeSkipped?: (ref: string) => Promise<void>, |
| 224 | ) { |
| 225 | const edges = successEdges.get(ref) ?? []; |
| 226 | |
| 227 | const triggeredChildren = new Set<string>(); |
| 228 | const skippedChildren = new Set<string>(); |
| 229 | |
| 230 | for (const edge of edges) { |
| 231 | let isActive = true; |
| 232 | if (activePorts) { |
| 233 | const port = edge.sourceHandle ?? 'default'; |
| 234 | isActive = activePorts.includes(port); |
| 235 | } |
| 236 | |
| 237 | if (isActive) { |
| 238 | triggeredChildren.add(edge.targetRef); |
| 239 | } else { |
| 240 | skippedChildren.add(edge.targetRef); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // Refine sets: if ANY edge to a child is active, the child is triggered. |
| 245 | // Only if ALL edges to the child are inactive (from this parent) do we consider it skipped from this parent's perspective. |
| 246 | // Actually, we process edges. If Ref A -> Ref B via "Default" (active) AND via "Error" (inactive), |
| 247 | // Ref B is triggered. |
| 248 | |
| 249 | const finalTriggered = new Set(triggeredChildren); |
| 250 | const finalSkipped = new Set<string>(); |
| 251 | |
| 252 | for (const child of skippedChildren) { |
| 253 | if (!finalTriggered.has(child)) { |
| 254 | finalSkipped.add(child); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | for (const child of finalTriggered) { |
| 259 | await processChild( |
| 260 | child, |
| 261 | ref, |
| 262 | 'fulfilled', |
| 263 | readyQueue, |
| 264 | pending, |
| 265 | nodeStates, |
| 266 | successEdges, |
| 267 | onNodeSkipped, |
| 268 | ); |
| 269 | } |
| 270 | |
| 271 | for (const child of finalSkipped) { |
| 272 | await processChild( |
| 273 | child, |
no test coverage detected