@@ -2367,12 +2367,20 @@ describe('FlowSchema — top-level node ids are unique', () => {
23672367 } ) ;
23682368
23692369 it ( 'accepts the same flow once the ids are unique, keeping the nodes in authored order' , ( ) => {
2370- const unique = flowWith ( [
2371- { id : 'start' , type : 'start' , label : 'Start' } ,
2372- { id : 'n' , type : 'assignment' , label : 'Assign A' } ,
2373- { id : 'n2' , type : 'assignment' , label : 'Assign B' } ,
2374- { id : 'end' , type : 'end' , label : 'End' } ,
2375- ] ) ;
2370+ // `n2` is wired in: a node no edge reaches is refused at parse.
2371+ const unique = {
2372+ ...flowWith ( [
2373+ { id : 'start' , type : 'start' , label : 'Start' } ,
2374+ { id : 'n' , type : 'assignment' , label : 'Assign A' } ,
2375+ { id : 'n2' , type : 'assignment' , label : 'Assign B' } ,
2376+ { id : 'end' , type : 'end' , label : 'End' } ,
2377+ ] ) ,
2378+ edges : [
2379+ { id : 'e1' , source : 'start' , target : 'n' } ,
2380+ { id : 'e2' , source : 'n' , target : 'n2' } ,
2381+ { id : 'e3' , source : 'n2' , target : 'end' } ,
2382+ ] ,
2383+ } ;
23762384 const result = FlowSchema . safeParse ( unique ) ;
23772385 expect ( result . success ) . toBe ( true ) ;
23782386 if ( ! result . success ) return ;
@@ -2645,15 +2653,23 @@ describe('FlowSchema — one node-id space across the top-level nodes[] and ever
26452653 } ) ;
26462654
26472655 it ( 'accepts a flow whose ids are unique across the whole flow, keeping every region node in authored order' , ( ) => {
2648- const unique = flowWith ( [
2649- { id : 'start' , type : 'start' , label : 'Start' } ,
2650- loopOver ( [ step ( 'sweep_first' ) , step ( 'sweep_second' ) ] , [ { id : 'b1' , source : 'sweep_first' , target : 'sweep_second' } ] ) ,
2651- {
2652- id : 'p' , type : 'parallel' , label : 'Fan out' ,
2653- config : { branches : [ { nodes : [ step ( 'left' ) ] } , { nodes : [ step ( 'right' ) ] } ] } ,
2654- } ,
2655- { id : 'end' , type : 'end' , label : 'End' } ,
2656- ] ) ;
2656+ // `p` is wired in: a node no edge reaches is refused at parse.
2657+ const unique = {
2658+ ...flowWith ( [
2659+ { id : 'start' , type : 'start' , label : 'Start' } ,
2660+ loopOver ( [ step ( 'sweep_first' ) , step ( 'sweep_second' ) ] , [ { id : 'b1' , source : 'sweep_first' , target : 'sweep_second' } ] ) ,
2661+ {
2662+ id : 'p' , type : 'parallel' , label : 'Fan out' ,
2663+ config : { branches : [ { nodes : [ step ( 'left' ) ] } , { nodes : [ step ( 'right' ) ] } ] } ,
2664+ } ,
2665+ { id : 'end' , type : 'end' , label : 'End' } ,
2666+ ] ) ,
2667+ edges : [
2668+ { id : 'e1' , source : 'start' , target : 'n' } ,
2669+ { id : 'e2' , source : 'n' , target : 'p' } ,
2670+ { id : 'e3' , source : 'p' , target : 'end' } ,
2671+ ] ,
2672+ } ;
26572673 const result = FlowSchema . safeParse ( unique ) ;
26582674 expect ( result . success ) . toBe ( true ) ;
26592675 if ( ! result . success ) return ;
@@ -2852,3 +2868,88 @@ describe('FlowSchema — an edge resolves in its own graph, and is followed once
28522868 expect ( defineFlow ( flow ) . edges . map ( ( e ) => e . id ) ) . toEqual ( [ 'e1' , 'e2' , 'e3' ] ) ;
28532869 } ) ;
28542870} ) ;
2871+
2872+ describe ( 'FlowSchema — every top-level node is reachable from the start node' , ( ) => {
2873+ // A run starts at the `start` node and follows edges; nothing else schedules
2874+ // a top-level node. A node no edge path reaches parsed, published and never
2875+ // ran. Refused at `nodes[i]`, for each such node.
2876+ const start : FlowNode = { id : 'start' , type : 'start' , label : 'Start' } ;
2877+ const end : FlowNode = { id : 'end' , type : 'end' , label : 'End' } ;
2878+ const step = ( id : string ) : FlowNode => ( { id, type : 'assignment' , label : id } ) ;
2879+ const flowOf = ( nodes : FlowNode [ ] , edges : FlowEdge [ ] ) : Flow => ( {
2880+ name : 'reach_flow' ,
2881+ label : 'Reach flow' ,
2882+ type : 'autolaunched' ,
2883+ nodes,
2884+ edges,
2885+ } ) ;
2886+
2887+ it ( 'refuses an action node with no in-edge, anchored at the node, naming it and the start node' , ( ) => {
2888+ const result = FlowSchema . safeParse ( flowOf ( [ start , step ( 'orphan' ) , end ] , [
2889+ { id : 'e1' , source : 'start' , target : 'end' } ,
2890+ ] ) ) ;
2891+ expect ( result . success ) . toBe ( false ) ;
2892+ if ( result . success ) return ;
2893+ expect ( result . error . issues . map ( ( i ) => [ i . code , i . path ] ) ) . toEqual ( [ [ 'custom' , [ 'nodes' , 1 ] ] ] ) ;
2894+ const [ issue ] = result . error . issues ;
2895+ expect ( issue . message ) . toContain ( 'Node `orphan` (`assignment`, `nodes[1]`) is not reachable' ) ;
2896+ expect ( issue . message ) . toContain ( 'from the start node `start`' ) ;
2897+ } ) ;
2898+
2899+ it ( 'refuses every node of a disconnected chain — an in-edge from an unreachable node is no path' , ( ) => {
2900+ const result = FlowSchema . safeParse ( flowOf ( [ start , step ( 'a' ) , step ( 'b' ) , end ] , [
2901+ { id : 'e1' , source : 'start' , target : 'end' } ,
2902+ { id : 'e2' , source : 'a' , target : 'b' } ,
2903+ { id : 'e3' , source : 'b' , target : 'end' } ,
2904+ ] ) ) ;
2905+ expect ( result . success ) . toBe ( false ) ;
2906+ if ( result . success ) return ;
2907+ expect ( result . error . issues . map ( ( i ) => i . path ) ) . toEqual ( [ [ 'nodes' , 1 ] , [ 'nodes' , 2 ] ] ) ;
2908+ } ) ;
2909+
2910+ it ( 'refuses through every door that parses a flow — defineFlow throws' , ( ) => {
2911+ expect ( ( ) => defineFlow ( flowOf ( [ start , step ( 'orphan' ) , end ] , [
2912+ { id : 'e1' , source : 'start' , target : 'end' } ,
2913+ ] ) ) ) . toThrow ( / N o d e ` o r p h a n ` / ) ;
2914+ } ) ;
2915+
2916+ it ( 'CONTROL — a node reached only by a `fault` edge or a conditional edge is reachable' , ( ) => {
2917+ const result = FlowSchema . safeParse ( flowOf ( [ start , step ( 'work' ) , step ( 'recover' ) , step ( 'big' ) , end ] , [
2918+ { id : 'e1' , source : 'start' , target : 'work' } ,
2919+ { id : 'e2' , source : 'work' , target : 'end' } ,
2920+ { id : 'e3' , source : 'work' , target : 'recover' , type : 'fault' } ,
2921+ { id : 'e4' , source : 'recover' , target : 'end' } ,
2922+ { id : 'e5' , source : 'start' , target : 'big' , condition : 'record.amount > 1' } ,
2923+ { id : 'e6' , source : 'big' , target : 'end' } ,
2924+ ] ) ) ;
2925+ expect ( result . success ) . toBe ( true ) ;
2926+ } ) ;
2927+
2928+ it ( 'CONTROL — a `boundary_event`, and a node reached only through one, are not judged' , ( ) => {
2929+ const result = FlowSchema . safeParse ( flowOf ( [
2930+ start ,
2931+ step ( 'work' ) ,
2932+ {
2933+ id : 'on_error' , type : 'boundary_event' , label : 'On error' ,
2934+ boundaryConfig : { attachedToNodeId : 'work' , eventType : 'error' } ,
2935+ } ,
2936+ step ( 'recover' ) ,
2937+ end ,
2938+ ] , [
2939+ { id : 'e1' , source : 'start' , target : 'work' } ,
2940+ { id : 'e2' , source : 'work' , target : 'end' } ,
2941+ { id : 'e3' , source : 'on_error' , target : 'recover' } ,
2942+ { id : 'e4' , source : 'recover' , target : 'end' } ,
2943+ ] ) ) ;
2944+ expect ( result . success ) . toBe ( true ) ;
2945+ } ) ;
2946+
2947+ it ( 'CONTROL — a flow with no start node, and a graph with a dangling edge, are left to their own refusals' , ( ) => {
2948+ expect ( FlowSchema . safeParse ( flowOf ( [ step ( 'a' ) , end ] , [ { id : 'e1' , source : 'a' , target : 'end' } ] ) ) . success )
2949+ . toBe ( true ) ;
2950+ const dangling = FlowSchema . safeParse ( flowOf ( [ start , end ] , [ { id : 'e1' , source : 'start' , target : 'node_1' } ] ) ) ;
2951+ expect ( dangling . success ) . toBe ( false ) ;
2952+ if ( dangling . success ) return ;
2953+ expect ( dangling . error . issues . map ( ( i ) => i . path ) ) . toEqual ( [ [ 'edges' , 0 , 'target' ] ] ) ;
2954+ } ) ;
2955+ } ) ;
0 commit comments