@@ -111,6 +111,42 @@ test('检测 condition 字段里的未定义变量', () => {
111111 ) ;
112112} ) ;
113113
114+ test ( 'output 重名例外:any_completed 分支收敛模式合法' , ( ) => {
115+ // 多个并行 step 产出同名 output,下游用 any_completed 引用——是有意的"分支收敛"设计
116+ const wf = parseWorkflow ( workflowPath ) ;
117+ if ( wf . steps . length < 4 ) throw new Error ( 'fixture 至少需要 4 个 step' ) ;
118+ // 让两个并行 step 都 output 同名
119+ wf . steps [ 1 ] . output = 'analysis_result' ;
120+ wf . steps [ 2 ] . output = 'analysis_result' ;
121+ // 下游 step(已存在的)改成 any_completed
122+ wf . steps [ 3 ] . depends_on = [ wf . steps [ 1 ] . id , wf . steps [ 2 ] . id ] ;
123+ wf . steps [ 3 ] . depends_on_mode = 'any_completed' ;
124+ const errors = validateWorkflow ( wf ) ;
125+ // 不应报 output 重名错误
126+ assert (
127+ ! errors . some ( e => e . includes ( 'analysis_result' ) && e . includes ( '多个 step 同时产出' ) ) ,
128+ `any_completed 模式下 output 重名应被允许,实际错误: ${ errors . join ( '; ' ) } `
129+ ) ;
130+ } ) ;
131+
132+ test ( 'output 重名例外:loop 迭代覆盖模式合法' , ( ) => {
133+ // write 产生种子 + revise 用 loop 反复覆盖同名 output,是合法的"原地修改"迭代
134+ const wf = parseWorkflow ( workflowPath ) ;
135+ if ( wf . steps . length < 3 ) throw new Error ( 'fixture 至少需要 3 个 step' ) ;
136+ wf . steps [ 0 ] . output = 'doc' ;
137+ wf . steps [ 1 ] . output = 'doc' ;
138+ wf . steps [ 1 ] . loop = {
139+ back_to : wf . steps [ 0 ] . id ,
140+ max_iterations : 3 ,
141+ exit_condition : '{{doc}} contains 通过' ,
142+ } ;
143+ const errors = validateWorkflow ( wf ) ;
144+ assert (
145+ ! errors . some ( e => e . includes ( '"doc"' ) && e . includes ( '多个 step 同时产出' ) ) ,
146+ `loop 迭代覆盖应被允许,实际错误: ${ errors . join ( '; ' ) } `
147+ ) ;
148+ } ) ;
149+
114150test ( '检测 output 重名:两个 step 产出同一个变量' , ( ) => {
115151 const wf = parseWorkflow ( workflowPath ) ;
116152 // 强制把第二个 step 的 output 改成和第一个相同
0 commit comments