
    r;iL                        d Z ddlZddlmc mZ ddlZddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZ ddlZ ee
j"                  j%                  dd            Z ee      ej*                  vr"ej*                  j-                  d ee             defdZed	z  d
z  Zd Z e       Zej6                  ZdefdZ G d d      Z G d d      Z G d d      Z G d d      Z  G d d      Z!y)u'  
test_integration.py

모듈 간 연동 통합 테스트 (헤임달 작성)

시나리오:
1. dispatch 전체 흐름: generate_task_id() → build_prompt() → get_dispatch_time()
2. task-timer 전체 라이프사이클: start → list → end → list
3. 로거 + 에러 추적 연동: logger.py → error_tracker.py → get_recent_errors()
4. team_prompts 전팀 프롬프트 생성: dev1/dev2/dev3 모두 검증
5. run_tests.py 실행 검증: subprocess → JSON 파싱 → passed == total

격리 원칙: tmp_path로 파일시스템 완전 격리
    N)datetime)PathWORKSPACE_ROOTz/home/jay/workspacetmp_pathc                    | dz  j                  dd       | dz  dz  j                  dd       ddl}t        t        j                  j                               D ]  }|dk(  s	t        j                  |=  ddl}| |_        |S )u?   dispatch 모듈을 tmp_path를 WORKSPACE로 설정하여 로드memoryTparentsexist_oktasksr   Ndispatch)mkdirprompts.team_promptslistsysmoduleskeysr   	WORKSPACE)r   promptsmod_name	_dispatchs       -/home/jay/workspace/tests/test_integration.py_load_dispatch_isolatedr   $   s    t<7"))$)F   ))+, &z!H%& !"I    r   ztask-timer.pyc                     t         j                  j                  dt              } d}| |u}|st	        j
                  d|fd| |f      dt        j                         v st	        j                  |       rt	        j                  |       ndt	        j                  |      dz  }dd|iz  }t        t	        j                  |            dx}}t         j                  j                  |       }| j                  }d}||u}|st	        j
                  d|fd	||f      dt        j                         v st	        j                  |       rt	        j                  |       ndt	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            dx}x}}| j                  j                  |       |S )u6   하이픈 포함 파일명을 importlib.util로 로드task_timer_integN)is not)z%(py0)s is not %(py3)sspecpy0py3assert %(py5)spy5)z2%(py2)s
{%(py2)s = %(py0)s.loader
} is not %(py5)s)r    py2r#   zassert %(py7)spy7)	importlibutilspec_from_file_location_TIMER_PATH
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationmodule_from_specloaderexec_module)	r   @py_assert2@py_assert1@py_format4@py_format6mod@py_assert4@py_assert3@py_format8s	            r   _load_task_timerr=   >   s
   >>112DkRD4t4t44t
..
)
)$
/C;;"d";d"""";d""""""4"""4""";"""d"""""""KKC Jr   c                 $     ddl m d fd	}|S )uE   tmp_path에 task 파일을 저장하는 격리된 build_prompt 생성r   Nc                    dz  dz  }|j                  dd       || dz  }|j                  |d       j                  j                  |       }	|	st	        d|        |d d	 }
d
| d|  d|
 d}d| }t        dz  dz  | dz        }|	d   dk(  r$j                  |	| |t        |      |||||	      }nj                  |	| |||||||	      }|dk(  r|j                  |      z  }|dk(  rd|z   }|S |dk(  rd|z   }|S )Nr   r   Tr	   z.mdzutf-8)encodingu   알 수 없는 팀 ID:    zpython3 ... start z --team z	 --desc ""zpython3 ... end reportstypedirect)
project_idcodingcriticalum   **[CRITICAL] 이 작업은 중요도 critical입니다. 품질 우선으로 신중하게 작업하세요.**

securityue   **[SECURITY] 이 작업은 보안 중요 작업입니다. 보안 최우선으로 작업하세요.**

)	r   
write_text	TEAM_INFOget
ValueErrorstr_build_direct_prompt_build_glm_prompt_build_verification_section)team_idtask_id	task_desclevelrF   chain_id	task_typetask_dir	task_fileteam
short_desctimer_start	timer_endreport_pathpromptr   tps                  r   _safe_buildz%_make_safe_build.<locals>._safe_buildU   s   h&0td3'#.	Y9||(6wi@AAs^
*7)8G9Ij\YZ[&wi0	(X-	9wisOKL<8#,,I% - 
F ))% * 
F  b44U;;FJ G  JP  PF  j ~  BH  HFr   )normalNNrG   )r   team_prompts)r   ra   r`   s   ` @r   _make_safe_buildrd   Q   s    %0d r   c                   (    e Zd ZdZd Zd Zd Zd Zy)TestIntegrationDispatchFlowuR   generate_task_id() → build_prompt() → get_dispatch_time() 순차 연동 검증c                    t        |      }t        |      }|j                  |d|       |j                         }d}||k(  }|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      dz  }dd|iz  }	t        t	        j                  |	            d	x}}|j                  d
d|      }
t        |
t              }|sddt        j                         v st	        j                  t              rt	        j                  t              nddt        j                         v st	        j                  |
      rt	        j                  |
      nddt        j                         v st	        j                  t              rt	        j                  t              ndt	        j                  |      dz  }t        t	        j                  |            d	}||
v }|st	        j
                  d|fd||
f      dt        j                         v st	        j                  |      rt	        j                  |      nddt        j                         v st	        j                  |
      rt	        j                  |
      nddz  }dd|iz  }t        t	        j                  |            d	}y	)uU   generate_task_id()로 생성한 ID가 build_prompt() 출력에 포함되는지 검증_build_team_promptztask-1==z%(py0)s == %(py3)srS   r   r"   r#   N	dev2-teamu   통합 테스트 작업5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}
isinstancer_   rN   r    py1r$   py4inz%(py0)s in %(py2)sr    r$   assert %(py4)srq   )r   rd   setattrgenerate_task_idr*   r+   r,   r-   r.   r/   r0   r1   build_promptrn   rN   )selfr   monkeypatchdispatch_mod
safe_buildrS   r5   r6   r7   r8   r_   r;   @py_format5@py_format3s                 r   #test_task_id_passed_to_build_promptz?TestIntegrationDispatchFlow.test_task_id_passed_to_build_prompt   s   .x8 &h/
L*>
K //1""w(""""w(""""""w"""w"""(""""""" **;8QSZ[&#&&&&&&&&z&&&z&&&&&&&&&&&&&&&&&#&&&#&&&&&&&&&&&    w&      w   w      &   &       r   c                 $   t        |      }t        |      }|j                  |d|       |j                         }|dz  dz  }|j                  } |       }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }	t        t        j                  |	            dx}}t        j                  |j                               }
|
d   }||v }|st        j                  d	|fd
||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            dx}}|j!                  dd|       t        j                  |j                               }|d   }||v }|st        j                  d	|fd
||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t        t        j                  |            dx}}y)uJ   generate_task_id() 직후 ID가 timer 파일에 기록되어 있어야 함rh   r   ztask-timers.jsonAassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}
timer_filer    r$   rq   Nr   rr   )z%(py0)s in %(py3)srS   r   r"   r#   	dev1-teamu   빌드 프롬프트 테스트)r   rd   rw   rx   existsr,   r-   r*   r.   r/   r0   r1   jsonloads	read_textr+   ry   )rz   r   r{   r|   r}   rS   r   r6   r;   r~   datar5   r7   r8   
data_afters                  r   -test_generate_id_recorded_before_build_promptzITestIntegrationDispatchFlow.test_generate_id_recorded_before_build_prompt   s   .x8%h/
L*>
K//1 (+==
  " """"""""z"""z""" """"""""""zz*..01w-'w-''''w-''''''w'''w'''-''''''' 	!!+/NPWXZZ
 4 4 67
$W--w-----w-------w---w-----------r   c                 .   t        |      }t        j                         }|j                  d      }t        j                  |d      }||kD  }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  |      rt        j                  |      nddz  }dd	|iz  }t        t        j                  |            d
}y
)uU   get_dispatch_time()이 현재 시각보다 미래의 시각을 반환하는지 검증   %Y-%m-%d %H:%M:%S>)z%(py0)s > %(py2)sparsedbeforeru   rv   rq   N)r   r   nowget_dispatch_timestrptimer*   r+   r,   r-   r.   r/   r0   r1   )	rz   r   r|   r   dispatch_timer   r6   r   r~   s	            r   %test_get_dispatch_time_returns_futurezATestIntegrationDispatchFlow.test_get_dispatch_time_returns_future   s    .x8$66r:""=2EFvvvr   c                 <
   t        |      }t        |      }|j                  |d|       |j                         }|j                  }d} ||      }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }	t        t        j                  |	            dx}x}}|j                  dd|      }
||
v }|st        j                  d	|fd
||
f      dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  |
      rt        j                  |
      nddz  }dd|iz  }t        t        j                  |            d}d}||
v }|st        j                  d	|fd||
f      t        j                  |      dt        j                         v st        j                  |
      rt        j                  |
      nddz  }dd|iz  }t        t        j                  |            dx}}|j                  d      }t        j                   |d      }t        j"                  } |       }||kD  }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }	dd|	iz  }t        t        j                  |            dx}x}}g }|}|r|
}|
r|}|sJdddt        j                         v st        j                  |      rt        j                  |      ndiz  }|j%                  |       |rdddt        j                         v st        j                  |
      rt        j                  |
      ndiz  }|j%                  |       |
rXdd d!t        j                         v st        j                  |      rt        j                  |      nd!iz  }	|j%                  |	       t        j&                  |d"      i z  }d#d$|iz  }t        t        j                  |            dx}}y)%uP   세 함수의 순차 호출 결과가 전체적으로 일관성 있는지 검증rh   task-zLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}rS   )r    r$   rq   py6Nrl   u   전체 흐름 검증 작업rr   rt   r_   ru   rv   rq      오딘z%(py1)s in %(py3)srp   r!   r"   r#   
   r   r   )zA%(py0)s > %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s.now
}()
}r   r   assert %(py8)spy8z%(py2)sr$   z%(py4)sz%(py6)sr   dispatch_time_strr   assert %(py9)spy9)r   rd   rw   rx   
startswithr,   r-   r*   r.   r/   r0   r1   ry   r+   r   r   r   r   append_format_boolop)rz   r   r{   r|   r}   rS   r6   r;   @py_assert5@py_format7r_   r   r~   @py_assert0r5   r7   r8   r   r   @py_format9r<   @py_format10s                         r   test_full_flow_sequentialz5TestIntegrationDispatchFlow.test_full_flow_sequential   s   .x8%h/
L*>
K //1!!*'*!'********w***w***!***'********** **;8UW^_&    w&      w   w      &   &       !x6!!!!x6!!!x!!!!!!6!!!6!!!!!!! )::2> ))*;=PQ'||-|~-}~----}~------}---}------x---x---|---~------- 	8w7w676&7777777w777w7777w77777677767777677777&7777&7777777777777r   N)__name__
__module____qualname____doc__r   r   r   r    r   r   rf   rf      s    \!".&8r   rf   c                   J    e Zd ZdZ ej
                         d        Zd Zd Zy)!TestIntegrationTaskTimerLifecycleuV   start → list(running 확인) → end → list(completed 확인) 전체 흐름 검증c                 X    |dz  j                  dd       t        t        |            S )Nr   Tr	   )workspace_path)r   	TaskTimerrN   rz   r   s     r   timerz'TestIntegrationTaskTimerLifecycle.timer   s)    	H	##D4#@H66r   c                    d}|j                  |dd      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d	z  }d
d|iz  }t	        t        j
                  |            dx}x}}|d   }||k(  }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t	        t        j
                  |
            dx}}|j                  d      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d	z  }d
d|iz  }t	        t        j
                  |            dx}x}}|d   d   d   }||k(  }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t	        t        j
                  |
            dx}}|j                  d      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d	z  }d
d|iz  }t	        t        j
                  |            dx}x}}|j                  |      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d	z  }d
d|iz  }t	        t        j
                  |            dx}x}}|d   }||k(  }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t	        t        j
                  |
            dx}}d}||v }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t	        t        j
                  |
            dx}}|j                  d      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d	z  }d
d|iz  }t	        t        j
                  |            dx}x}}|d   d   d   }||k(  }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t	        t        j
                  |
            dx}}|j                  d      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d	z  }d
d|iz  }t	        t        j
                  |            dx}x}}y)uA   start → list(running) → end → list(completed) 전체 흐름z
task-999.2rl   u#   라이프사이클 통합 테스트)rR   descriptionstatusstartedri   z%(py1)s == %(py4)srp   rq   assert %(py6)sr   NrS   )z%(py1)s == %(py3)sr   r"   r#   runningr   total   r   r   	completedduration_secondsrr   r   
end_result)
start_taskr*   r+   r/   r0   r1   r,   r-   r.   
list_tasksend_task)rz   r   rS   start_resultr   r;   r5   r~   r   r7   r8   running_listcompleted_beforer   completed_listrunning_afters                   r   test_full_lifecyclez5TestIntegrationTaskTimerLifecycle.test_full_lifecycle   sf    ''Rw'xH%22%2222%222%2222222222I&1&'1111&'111&111111'111'1111111 ''y'9G$))$))))$)))$))))))))))G$Q'	2=2g====2g===2======g===g======= !++;+?(-A-(A----(A---(---A------- ^^G,
(#2{2#{2222#{222#222{2222222)$/$////$///$////////////////!/!Z////!Z///!//////Z///Z/////// )))=g&+!+&!++++&!+++&+++!+++++++g&q))4?4????4???4???????????????? ((	(:W%**%****%***%**********r   c                 z   |j                  dd       |j                  dd       |j                  dd       |j                  d	      d
   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  d       |j                  d	      d
   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  d	      d
   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  d       |j                  d	      d
   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  d	      d
   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                         }|d
   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y)uT   여러 작업 동시 진행 시 상태 구분이 올바르게 동작하는지 검증z
task-100.1u   작업 A)r   z
task-200.1u   작업 Bz
task-300.1u   작업 Cr   r   r      ri   r   r   r   r   N   r   r   )r   r   r*   r+   r/   r0   r1   r   )rz   r   r   r;   r5   r~   r   	all_taskss           r   test_multiple_tasks_lifecyclez?TestIntegrationTaskTimerLifecycle.test_multiple_tasks_lifecycle  s   :>:>:> y1':?a?:a????:a???:???a??????? 	|$y1':?a?:a????:a???:???a???????{3G<AA<AAAA<AAA<AAAAAAAAAA 	|$y1':?a?:a????:a???:???a???????{3G<AA<AAAA<AAA<AAAAAAAAAA $$&	!&Q&!Q&&&&!Q&&&!&&&Q&&&&&&&r   N)	r   r   r   r   pytestfixturer   r   r   r   r   r   r   r      s+    `V^^7 7+B'r   r   c                   "    e Zd ZdZd Zd Zd Zy)!TestIntegrationLoggerErrorTrackeru`   logger.py 로그 기록 → error_tracker.py 에러 기록 → get_recent_errors() 조회 검증c                 \	   ddl m} ddlm} |dz  }|j	                  dd       |dz  }|dz  }|j                  |d|       |j                  |d	|       d
|j                   }|j                  |      }	|	j                  d       |j                  }
 |
       }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      t        j                  |      dz  }t        t        j                   |            dx}
}	 t#        d      # t"        $ r}|j%                  d|d       Y d}~nd}~ww xY w|j                  }
 |
       }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      t        j                  |      dz  }t        t        j                   |            dx}
}|j'                  d      }t)        |      }d}||k\  }|st        j*                  d|fd||f      dt        j                         v st        j                  t(              rt        j                  t(              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                   |            dx}x}}|d   }|d   }d}||k(  }|slt        j*                  d|fd ||f      t        j                  |      t        j                  |      d!z  }d"d#|iz  }t        t        j                   |            dx}x}}|d$   }d%}||k(  }|slt        j*                  d|fd ||f      t        j                  |      t        j                  |      d!z  }d"d#|iz  }t        t        j                   |            dx}x}}d}|d&   }||v }|slt        j*                  d'|fd(||f      t        j                  |      t        j                  |      d!z  }d"d#|iz  }t        t        j                   |            dx}x}}y))uA   로그 파일 생성 + 에러 JSONL 기록 + 조회 연동 검증r   NlogsTr	   zapp.logerrors.jsonlLOG_FILEERRORS_FILEinteg_test_u!   통합 테스트 로그 메시지r   fake_log_filer   u   통합 테스트용 에러 XYZtest_integrationzfake tracebacktb_strfake_errors_filer   r   )>=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)slenerrorsr    rp   r!   r   r   r   moduleri   r   r   r   r   
error_typerM   messagerr   )z%(py1)s in %(py4)s)utils.error_trackererror_trackerutils.loggerloggerr   rw   name
get_loggerinfor   r,   r-   r*   r.   r/   r0   r1   rM   track_errorget_recent_errorsr   r+   )rz   r   r{   et_mod
logger_modlog_dirr   r   unique_logger_namer   r6   r;   r~   er   r5   r   r:   r   r   
last_errorr   s                         r   1test_logger_writes_file_and_error_tracker_recordszSTestIntegrationLoggerErrorTracker.test_logger_writes_file_and_error_tracker_records&  s3   ,) V#dT2)+"^3J
MBFM3CD  +8==/:&&'9:78 ##%#%%%%%%%%}%%%}%%%#%%%%%%%%%%	O=>> 	O11=MNN	O  &&(&((((((((((((((&(((((((((( ))"-6{a{a{ass66{aBZ
(#9'99#'99999#'9999#999'99999999,'7<7'<7777'<777'777<7777777/H:i3HH/3HHHHH/3HHHH/HHH3HHHHHHHHs   -D8 8	EEEc                 2   ddl m} |dz  }|j                  |d|       t        d      D ]  }	 t	        d|        |j                  d
      }t        |      }d}	||	k(  }
|
st        j                  d|
fd||	f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dz  }dd|iz  }t        t        j                  |            dx}x}
}	|d   d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|d   d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|d   d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y# t        $ r%}|j                  d| |d| 	       Y d}~d}~ww xY w)uE   여러 에러를 기록했을 때 순서대로 조회되는지 검증r   Nr   r   r   u   에러 번호 module_tb_r   r   ri   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr   r   r   r   r   r   module_0r   r   r   r   r   module_1r   module_2)r   r   rw   rangeRuntimeErrorr   r   r   r*   r+   r,   r-   r.   r/   r0   r1   )rz   r   r{   r   r   ir   r   r5   r   r:   r   r   r   r;   r~   s                   r   )test_multiple_errors_retrievable_in_orderzKTestIntegrationLoggerErrorTracker.test_multiple_errors_retrievable_in_orderN  s,   ,#n4FM3CD q 	GAG"^A3#788	G ))"-6{a{a{ass66{a ay"0j0"j0000"j000"000j0000000ay"0j0"j0000"j000"000j0000000ay"0j0"j0000"j000"000j0000000   G""WQC=!c!I"FFGs   K((	L1LLc                    ddl m} |dz  }|j                  |d|       |j                  d      }g }||k(  }|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      d	z  }d
d|iz  }	t        t	        j                  |	            dx}}y)uZ   에러 파일이 없을 때 get_recent_errors()가 빈 리스트를 반환하는지 검증r   Nznonexistent_errors.jsonlr   r   ri   rk   r   r   r"   r#   )r   r   rw   r   r*   r+   r,   r-   r.   r/   r0   r1   )
rz   r   r{   r   nonexistent_filer   r5   r6   r7   r8   s
             r   1test_get_recent_errors_returns_empty_when_no_filezSTestIntegrationLoggerErrorTracker.test_get_recent_errors_returns_empty_when_no_filed  s    ,#&@@FM3CD))"-v|vvvr   N)r   r   r   r   r   r  r	  r   r   r   r   r   #  s    j&IP1,r   r   c                   V    e Zd ZdZ ej
                         d        Zd Zd Zd Z	d Z
y)TestIntegrationTeamPromptsuK   dev1/dev2/dev3 모든 팀에 대해 build_prompt() 호출 및 내용 검증c                     t        |      S )N)rd   r   s     r   r}   z%TestIntegrationTeamPrompts.safe_buildw  s    ))r   c                    g d}|D ]`  \  }} |||| d      }t        |t              }|s$t        j                  | d      dz   dt	        j
                         v st        j                  t               rt        j                  t               nddt	        j
                         v st        j                  |      rt        j                  |      nddt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      dz  }t        t        j                  |            d	}t        |      }d
}	||	kD  }
|
st        j                  d|
fd||	f      dt	        j
                         v st        j                  t              rt        j                  t              nddt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dz  }t        j                  | d      dz   d|iz  }t        t        j                  |            d	x}x}
}	||v }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      nddt	        j
                         v st        j                  |      rt        j                  |      nddz  }t        j                  | d| d      dz   d|iz  }t        t        j                  |            d	}c y	)u7   3개 팀 모두 프롬프트 생성 가능한지 검증))r   task-1.1)rl   task-2.1)	dev3-teamztask-3.1u    통합 테스트 작업u$    프롬프트가 문자열이 아님z7
>assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}rn   r_   rN   ro   Nr   r   )z/%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py6)sr   r   u    프롬프트가 비어 있음z
>assert %(py8)sr   rr   rt   rS   ru       프롬프트에     누락
>assert %(py4)srq   )rn   rN   r*   _format_assertmsgr,   r-   r.   r/   r0   r1   r   r+   )rz   r}   teamsrR   rS   r_   r;   r~   r5   r   r:   r   r   r6   r   s                  r   -test_all_teams_prompts_generated_successfullyzHTestIntegrationTeamPrompts.test_all_teams_prompts_generated_successfully{  s   

 !& 	TGWWI=U2VWFfc*\*\\wi7[,\\\\\\\:\\\:\\\\\\f\\\f\\\\\\c\\\c\\\*\\\\\\v;NN;?NNN;NNNNNN3NNN3NNNNNNvNNNvNNN;NNNNNNwi/M$NNNNNNNNf$SSS7fSSSSSS7SSS7SSSSSSfSSSfSSSS	1B7)7&SSSSSSS		Tr   c                 |    |ddd      }d}||v }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j
                  |      rt        j                  |      nddz  }d	d
|iz  }t        t        j                  |            dx}}dD ]  }||v }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      nddt        j                         v st        j
                  |      rt        j                  |      nddz  }	t        j                  d| d      dz   d|	iz  }
t        t        j                  |
            d}  |ddd      }d}||v }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j
                  |      rt        j                  |      nddz  }d	d
|iz  }t        t        j                  |            dx}}dD ]  }||v }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      nddt        j                         v st        j
                  |      rt        j                  |      nddz  }	t        j                  d| d      dz   d|	iz  }
t        t        j                  |
            d} y)uQ   direct 타입(dev1, dev2)은 팀원 이름이 프롬프트에 포함되어야 함r   r  u   dev1 통합 테스트u   헤르메스rr   r   prompt1r   r"   r#   N)u   불칸u	   이리스u	   아테나u   아르고스rt   memberru   u   dev1-team 프롬프트에 'u   ' 누락r  rq   rl   r  u   dev2 통합 테스트r   prompt2)u   토르u   프레이야u	   미미르u	   헤임달u   dev2-team 프롬프트에 ')	r*   r+   r/   r,   r-   r.   r0   r1   r  )rz   r}   r  r   r5   r7   r8   r  r6   r   r~   r  s               r   &test_direct_teams_contain_member_nameszATestIntegrationTeamPrompts.test_direct_teams_contain_member_names  s    [*6MN(~((((~(((~((((((((((((((((J 	UFW$TTT6WTTTTTT6TTT6TTTTTTWTTTWTTTT(CF88&TTTTTTT	U [*6MN"x7""""x7"""x""""""7"""7"""""""J 	UFW$TTT6WTTTTTT6TTT6TTTTTTWTTTWTTTT(CF88&TTTTTTT	Ur   c                     |ddd      }g }d}|j                   } |       }||v }|}|sd}	|	|v }
|
}|st        j                  d|fd||f      t        j                  |      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      d	z  }d
d|iz  }|j                  |       |st        j                  d
fd	|f      t        j                  |	      dt	        j
                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }|j                  |       t        j                  |d      i z  }t        j                  d      dz   d|iz  }t        t        j                  |            dx}x}x}x}x}x}x}	}
d}||v }|st        j                  d|fd||f      t        j                  |      dt	        j
                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }t        t        j                  |            dx}}y)uM   glm 타입(dev8)은 openclaw 키워드가 프롬프트에 포함되어야 함z	dev8-teamztask-8.1u   dev8 GLM 통합 테스트openclawGLMrr   )zD%(py3)s in %(py9)s
{%(py9)s = %(py7)s
{%(py7)s = %(py5)s.lower
}()
}r_   )r!   r#   r%   r   z%(py11)spy11)z%(py14)s in %(py16)s)py14py16z%(py18)spy18r   u7   dev8-team 프롬프트에 openclaw/GLM 키워드 누락z
>assert %(py21)spy21Nr   r   r"   r#   )lowerr*   r+   r/   r,   r-   r.   r   r   r  r0   r1   )rz   r}   r_   r6   r5   @py_assert6@py_assert8r:   r   @py_assert13@py_assert15r   @py_format12@py_format17@py_format19@py_format20@py_format22r7   r8   s                      r   'test_glm_team_contains_openclaw_keywordzBTestIntegrationTeamPrompts.test_glm_team_contains_openclaw_keyword  sc   K5PQyzyV\\y\^yz^+yuyuyyyyz^yyyzyyyyyyVyyyVyyy\yyy^yyyyyyyuyyyuyyyyyyyyyyyyyyyyyyy@yyyyyyyyy${f$$$${f$$${$$$$$$f$$$f$$$$$$$r   c                 (   t        g dd      D ]   \  }}d| d} |||d      }||v }|st        j                  d|fd||f      dt        j                         v st        j
                  |      rt        j                  |      ndd	t        j                         v st        j
                  |      rt        j                  |      nd	d
z  }t        j                  | d| d      dz   d|iz  }t        t        j                  |            d} y)uJ   생성된 모든 팀 프롬프트에 해당 task_id가 포함되어야 함)r   rl   r  r   r   z.1u   task_id 포함 검증rr   rt   rS   r_   ru   r  r  r  rq   N)
	enumerater*   r+   r,   r-   r.   r/   r  r0   r1   )	rz   r}   r  rR   rS   r_   r6   r   r~   s	            r    test_all_prompts_contain_task_idz;TestIntegrationTeamPrompts.test_all_prompts_contain_task_id  s    #$KQO 	TJAwaSmG2IJFf$SSS7fSSSSSS7SSS7SSSSSSfSSSfSSSS	1B7)7&SSSSSSS	Tr   N)r   r   r   r   r   r   r}   r  r  r.  r1  r   r   r   r  r  t  s7    UV^^* *TU%Tr   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)TestIntegrationRunTestsuC   subprocess로 run_tests.py 실행 후 JSON 파싱 및 결과 검증c                 <   t         dz  dz  }t        j                  t        j                  t        |      gddd      }|j                  }|st        j                  d      dz   dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      d	z  }t        t        j                  |            d
}t        j                   |j                        }t#        |t$              }|sddt        j                         v st        j                  t"              rt        j                  t"              nddt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  t$              rt        j                  t$              ndt        j                  |      dz  }t        t        j                  |            d
}y
)uO   run_tests.py가 실행되고 유효한 JSON을 stdout에 출력하는지 확인testsrun_tests.pyT<   capture_outputtexttimeoutuC   run_tests.py가 stdout에 아무것도 출력하지 않았습니다z,
>assert %(py2)s
{%(py2)s = %(py0)s.stdout
}procru   Nrm   rn   resultdictro   )r   
subprocessrunr   
executablerN   stdoutr*   r  r,   r-   r.   r/   r0   r1   r   r   rn   r>  )rz   run_tests_pathr<  r6   r   r=  r;   r~   s           r   "test_run_tests_produces_valid_jsonz:TestIntegrationRunTests.test_run_tests_produces_valid_json  s&   "W,~=~~^^S01	
 {{a{aaaaaaaaataaataaa{aaaaaaDKK(&$''''''''z'''z''''''&'''&''''''$'''$''''''''''r   c                     t         dz  dz  }t        j                  t        j                  t        |      gddd      }t        j                  |j                        }d}||v }|st        j                  d|fd||f      t        j                  |      d	t        j                         v st        j                  |      rt        j                  |      nd	d
z  }t        j                  d      dz   d|iz  }t!        t        j"                  |            dx}}d}||v }|st        j                  d|fd||f      t        j                  |      d	t        j                         v st        j                  |      rt        j                  |      nd	d
z  }t        j                  d      dz   d|iz  }t!        t        j"                  |            dx}}d}||v }|st        j                  d|fd||f      t        j                  |      d	t        j                         v st        j                  |      rt        j                  |      nd	d
z  }t        j                  d      dz   d|iz  }t!        t        j"                  |            dx}}y)uB   JSON 출력에 total, passed, failed 키가 존재하는지 확인r5  r6  Tr7  r8  r   rr   r   r=  r   u   JSON에 'total' 키 누락z
>assert %(py5)sr#   Npassedu   JSON에 'passed' 키 누락failedu   JSON에 'failed' 키 누락)r   r?  r@  r   rA  rN   r   r   rB  r*   r+   r/   r,   r-   r.   r  r0   r1   )rz   rC  r<  r=  r   r5   r7   r8   s           r   'test_run_tests_output_has_required_keysz?TestIntegrationRunTests.test_run_tests_output_has_required_keys  s|   "W,~=~~^^S01	
 DKK(>w& >>>w&>>>w>>>>>>&>>>&>>>>">>>>>>>@x6!@@@x6@@@x@@@@@@6@@@6@@@@#@@@@@@@@x6!@@@x6@@@x@@@@@@6@@@6@@@@#@@@@@@@r   c                 :   t         dz  dz  }t        j                  t        j                  t        |      gddd      }t        j                  |j                        }|d   }|d   }||k(  }|st        j                  d|fd	||f      t        j                  |      t        j                  |      d
z  }t        j                  d|d    d|d    d|d    d|j                  dg              dz   d|iz  }t        t        j                  |            dx}x}}y)zpassed == total (0 failures)r5  r6  Tr7  r8  rF  r   ri   r   r   u   일부 run_tests 실패: total=z	, passed=z	, failed=rG  z
, details=resultsz
>assert %(py6)sr   N)r   r?  r@  r   rA  rN   r   r   rB  r*   r+   r/   r  rL   r0   r1   )	rz   rC  r<  r=  r   r;   r5   r~   r   s	            r   test_run_tests_all_passedz1TestIntegrationRunTests.test_run_tests_all_passed  s"   "W,~=~~^^S01	
 DKK(h 	
6'? 	
?2 	
 		
? 	
 	
 
		   	
 	
 
		 $3 	
 	
  .fWo-> ?X&'y1A0B Czz)R013	
 	
 	
 		
 	
 	
r   c                    t         dz  dz  }t        j                  t        j                  t        |      gddd      }t        j                  |j                        }d}||v }|st        j                  d|fd||f      t        j                  |      d	t        j                         v st        j                  |      rt        j                  |      nd	d
z  }dd|iz  }t        t        j                   |            dx}}|d   }t#        |t$              }	|	sddt        j                         v st        j                  t"              rt        j                  t"              ndt        j                  |      dt        j                         v st        j                  t$              rt        j                  t$              ndt        j                  |	      dz  }t        t        j                   |            dx}}	|d   }t'        |      }
|d   }|
|k(  }|st        j                  d|fd|
|f      dt        j                         v st        j                  t&              rt        j                  t&              ndt        j                  |      t        j                  |
      t        j                  |      dz  }dd|iz  }t        t        j                   |            dx}x}
x}}y)uW   JSON 출력에 results 배열이 존재하고 total과 개수가 일치하는지 확인r5  r6  Tr7  r8  rJ  rr   r   r=  r   r"   r#   Nz5assert %(py5)s
{%(py5)s = %(py0)s(%(py2)s, %(py3)s)
}rn   r   )r    r$   r!   r#   r   ri   )z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)sr   )r    r$   rq   r%   r   r   )r   r?  r@  r   rA  rN   r   r   rB  r*   r+   r/   r,   r-   r.   r0   r1   rn   r   r   )rz   rC  r<  r=  r   r5   r7   r8   r6   r:   r;   r%  r   r<   r   s                  r   "test_run_tests_results_list_existsz:TestIntegrationRunTests.test_run_tests_results_list_exists  s   "W,~=~~^^S01	
 DKK("yF""""yF"""y""""""F"""F""""""" +2z+T22222222z222z222+222222T222T2222222222)$8s$%88%8888%888888s888s888$888%8888888888r   N)r   r   r   r   rD  rH  rK  rM  r   r   r   r3  r3    s    M(A
 9r   r3  )"r   builtinsr,   _pytest.assertion.rewrite	assertionrewriter*   importlib.utilr&   r   osr?  r   r   pathlibr   r   environrL   r   rN   pathinsertr   r)   r=   _task_timer_modr   rd   rf   r   r   r  r3  r   r   r   <module>rY     s        	  
    02GHI	y>!HHOOAs9~&d . ("_4 #$%%	6t 6|F8 F8\>' >'LI Ib-T -Tj:9 :9r   