
    VUiK                        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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dlmZ  eedz        Z eedz        Z G d d	      Z G d
 d      Z G d d      Z G d d      Z G d d      Zy)u}  
test_qc_integration.py - Phase 1-3 통합 테스트 (아르고스 작성)

테스트 항목:
1. team_prompts normal 레벨: selfcheck + QC-RULES.md 참조 확인
2. team_prompts critical 레벨: 마아트 키워드 + QC-RULES.md 참조
3. team_prompts security 레벨: 마아트 + 로키 키워드 + QC-RULES.md 참조
4. 기존 테스트 회귀: tests/test_team_prompts.py 전체 통과 확인
5. qc_verify.py end-to-end: task-4.4로 실행하여 JSON 출력 확인

Note: 경량화 리팩토링(task-210.1) 이후 _build_verification_section()은
인라인 대신 QC-RULES.md 파일 참조 + 레벨별 요약 1줄만 출력합니다.
    N)PathWORKSPACE_ROOTz/home/jay/workspacezteams/dev1/qc/qc_verify.pyztests/test_team_prompts.pyc                   (    e Zd ZdZd Zd Zd Zd Zy)TestVerificationSectionNormalu-   normal 레벨: selfcheck + QC-RULES.md 참조c                 x   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}}y )	Nnormal	   셀프 QCinz%(py1)s in %(py3)sresultpy1py3assert %(py5)spy5
tp_build_verification_section
@pytest_ar_call_reprcompare	_saferepr@py_builtinslocals_should_repr_global_nameAssertionError_format_explanationselfr   @py_assert0@py_assert2@py_format4@py_format6s         0/home/jay/workspace/tests/test_qc_integration.pytest_normal_contains_selfcheckz<TestVerificationSectionNormal.test_normal_contains_selfcheck*   sk    //9${f$$$${f$$${$$$$$$f$$$f$$$$$$$    c                 x   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}}y )	Nr   QC-RULES.mdr
   r   r   r   r   r   r   r   s         r$   !test_normal_contains_qc_rules_refz?TestVerificationSectionNormal.test_normal_contains_qc_rules_ref.   sk    //9&}&&&&}&&&}&&&&&&&&&&&&&&&&r&   c                 x   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}}y )	Nr   u   자동 검증r
   r   r   r   r   r   r   r   s         r$   (test_normal_contains_auto_verify_keywordzFTestVerificationSectionNormal.test_normal_contains_auto_verify_keyword2   sk    //9(&((((&(((((((((&(((&(((((((r&   c                    t        j                  d      }d|v r|j                  d      d   n|}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}||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 )Nr   u   ## 게이트 지시r   	   마아트not inz%(py1)s not in %(py3)sbase_sectionr   r   r      로키)r   r   splitr   r   r   r   r   r   r   r   )r   r   r1   r    r!   r"   r#   s          r$   test_normal_no_maat_no_lokiz9TestVerificationSectionNormal.test_normal_no_maat_no_loki6   s    //9AVZ`A`v||$9:1=fl.{,....{,...{......,...,.......+x|++++x|+++x++++++|+++|+++++++r&   N)__name__
__module____qualname____doc__r%   r)   r+   r4    r&   r$   r   r   '   s    7%'),r&   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)TestVerificationSectionCriticalu?   critical 레벨: 마아트 + 독립 검증 + QC-RULES.md 참조c                 x   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}}y )	Ncriticalr-   r
   r   r   r   r   r   r   r   s         r$   test_critical_contains_maatz;TestVerificationSectionCritical.test_critical_contains_maatF   k    //
;${f$$$${f$$${$$$$$$f$$$f$$$$$$$r&   c                 x   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}}y )	Nr=   u   독립 검증r
   r   r   r   r   r   r   r   s         r$   /test_critical_contains_independent_verificationzOTestVerificationSectionCritical.test_critical_contains_independent_verificationJ   k    //
;(&((((&(((((((((&(((&(((((((r&   c                 x   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}}y )	Nr=   r(   r
   r   r   r   r   r   r   r   s         r$   #test_critical_contains_qc_rules_refzCTestVerificationSectionCritical.test_critical_contains_qc_rules_refN   k    //
;&}&&&&}&&&}&&&&&&&&&&&&&&&&r&   c                 x   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}}y )	Nr=   r2   r.   r0   r   r   r   r   r   r   s         r$   test_critical_no_lokiz5TestVerificationSectionCritical.test_critical_no_lokiR   sk    //
;%xv%%%%xv%%%x%%%%%%v%%%v%%%%%%%r&   c                 x   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}}y )	Nr=   r	   r
   r   r   r   r   r   r   r   s         r$    test_critical_contains_selfcheckz@TestVerificationSectionCritical.test_critical_contains_selfcheckV   r?   r&   N)	r5   r6   r7   r8   r>   rA   rD   rG   rI   r9   r&   r$   r;   r;   C   s    I%)'&%r&   r;   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)TestVerificationSectionSecurityu8   security 레벨: 마아트 + 로키 + QC-RULES.md 참조c                 x   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}}y )	Nsecurityr-   r
   r   r   r   r   r   r   r   s         r$   test_security_contains_maatz;TestVerificationSectionSecurity.test_security_contains_maatc   r?   r&   c                 x   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}}y )	NrM   r2   r
   r   r   r   r   r   r   r   s         r$   test_security_contains_lokiz;TestVerificationSectionSecurity.test_security_contains_lokig   sk    //
;!x6!!!!x6!!!x!!!!!!6!!!6!!!!!!!r&   c                 x   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}}y )	NrM   u   보안 감사r
   r   r   r   r   r   r   r   s         r$   $test_security_contains_audit_keywordzDTestVerificationSectionSecurity.test_security_contains_audit_keywordk   rB   r&   c                 x   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}}y )	NrM   r(   r
   r   r   r   r   r   r   r   s         r$   #test_security_contains_qc_rules_refzCTestVerificationSectionSecurity.test_security_contains_qc_rules_refo   rE   r&   c                 x   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}}y )	NrM   r	   r
   r   r   r   r   r   r   r   s         r$    test_security_contains_selfcheckz@TestVerificationSectionSecurity.test_security_contains_selfchecks   r?   r&   N)	r5   r6   r7   r8   rN   rP   rR   rT   rV   r9   r&   r$   rK   rK   `   s    B%")'%r&   rK   c                       e Zd ZdZd Zy)TestRegressionTeamPromptsuT   기존 test_team_prompts.py 전체가 여전히 통과하는지 subprocess로 검증c           	         t        j                  dddt        ddgdddt        t                    }|j
                  }d	}||k(  }|st        j                  d
|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }t        j                  d|j                  dd   d|j                  dd         dz   d|iz  }t        t        j                   |            d x}x}}g }d}|j                  }|j"                  }	 |	       }
||
v}|}|s'd}|j                  }|j"                  } |       }||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                  |	      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t        j                        t        j                        t        j                  |      dz  }dd|iz  }|j%                  |       t        j&                  |d       i z  }d!d"|iz  }t        t        j                   |            d x}x}x}x}x}x}	x}
x}x}x}x}}y )#Npython3z-mpytestz-vz
--tb=shortTx   )capture_outputtexttimeoutcwdr   ==z2%(py2)s
{%(py2)s = %(py0)s.returncode
} == %(py5)sprocpy0py2r   u,   기존 test_team_prompts.py 실패!
stdout: iz	
stderr: iz
>assert %(py7)spy7failedz0 failedr.   )zf%(py3)s not in %(py11)s
{%(py11)s = %(py9)s
{%(py9)s = %(py7)s
{%(py7)s = %(py5)s.stdout
}.lower
}()
})r   r   rh   py9py11z%(py13)spy13r
   )zh%(py16)s in %(py24)s
{%(py24)s = %(py22)s
{%(py22)s = %(py20)s
{%(py20)s = %(py18)s.stdout
}.lower
}()
})py16py18py20py22py24z%(py26)spy26   zassert %(py29)spy29)
subprocessrun_TEST_TEAM_PROMPTS_PATHstr
_WORKSPACE
returncoder   r   r   r   r   r   _format_assertmsgstdoutstderrr   r   lowerappend_format_boolop)r   rd   @py_assert1@py_assert4@py_assert3r#   @py_format8r!   @py_assert6@py_assert8@py_assert10r    @py_assert15@py_assert19@py_assert21@py_assert23@py_assert17@py_format12@py_format14@py_format25@py_format27@py_format28@py_format30s                          r$    test_team_prompts_tests_all_passz:TestRegressionTeamPrompts.test_team_prompts_tests_all_pass   sh   ~~h(?|TJ
  	
! 	
!# 	
 	
! 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		 #$ 	
 	
  @EF@S?TTbcgcncnosotcubvw	
 	
 	
 	
 	
 	XxWt{{W{00W02Wx22WjWDKKWKDUDUWDUDWWjDW6WWWWWx2WWWxWWWWWWtWWWtWWW{WWW0WWW2WWWWWWWjDWWWWjWWWWWWDWWWDWWWKWWWDUWWWDWWWWWWWWWWWWWWWWr&   N)r5   r6   r7   r8   r   r9   r&   r$   rX   rX   }   s    ^Xr&   rX   c                   r    e Zd ZdZ ej
                  d      d        Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)TestEndToEndQCVerifyuT   qc_verify.py --task-id task-4.4 --skip api_health,test_runner 실행 및 JSON 검증class)scopec                     t        j                  dt        ddddgddd      }|t        j                  |j
                  j                               fS )	NrZ   z	--task-idtask-4.4z--skipz'api_health,test_runner,full_suite_checkT   )r]   r^   r_   )ru   rv   _QC_VERIFY_PATHjsonloadsr|   strip)r   rd   s     r$   	qc_resultzTestEndToEndQCVerify.qc_result   sU    ~~9  
 TZZ 1 1 3444r&   c                 z   |\  }}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 }y )Nu%   stdout가 유효한 JSON이어야 함z7
>assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}
isinstanceparseddict)rf   r   rg   py4)
r   r   r   r{   r   r   r   r   r   r   )r   r   rd   r   r   @py_format5s         r$   test_e2e_outputs_valid_jsonz0TestEndToEndQCVerify.test_e2e_outputs_valid_json   s     f&$'P'PP)PPPPPPPzPPPzPPPPPP&PPP&PPPPPP$PPP$PPP'PPPPPPr&   c                    |\  }}|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 )Ntask_idr   ra   z%(py1)s == %(py4)sr   r   assert %(py6)spy6r   r   r   r   r   	r   r   _r   r    r   r!   r   @py_format7s	            r$   test_e2e_task_id_correctz-TestEndToEndQCVerify.test_e2e_task_id_correct   s]    	6i .J. J.... J... ...J.......r&   c                    |\  }}|j                  di       }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 )Nchecks)
api_health
file_checkdata_integritytest_runnerr
   )z%(py0)s in %(py2)s
check_name)rf   rg   u   checks에 'u   ' 누락z
>assert %(py4)sr   )
getr   r   r   r   r   r   r{   r   r   )	r   r   r   r   r   r   r   @py_format3r   s	            r$   test_e2e_has_all_check_keysz0TestEndToEndQCVerify.test_e2e_has_all_check_keys   s    	6Hb)W 	LJ'KKK:KKKKKK:KKK:KKKKKKKKKKKKK;zl()KKKKKKK	Lr&   c                 `   |\  }}|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
   d   }d}||v }|st        j                  d|fd||f      t        j                  |      t        j                  |      dz  }t        j
                  d|d
   d          dz   d	|iz  }	t        t        j                  |	            d x}x}}y )Nr   r   statusSKIPra   r   r   r   r   r   )FAILr   r
   )z%(py1)s in %(py4)su[   test_runner는 MANDATORY — skip 차단으로 FAIL 또는 정상 실행 SKIP 기대, got: z
>assert %(py6)s)r   r   r   r   r   r{   )
r   r   r   r   r   r    r   r!   r   r   s
             r$    test_e2e_skipped_checks_are_skipz5TestEndToEndQCVerify.test_e2e_skipped_checks_are_skip   sc   	6!l#H-77-7777-777-7777777777m$X. 	L2B 	L.2BB 	L {L  {L	L.2B 	L 	L CL  CL / 	L 	L CL  CL 3C 	L 	L {L  {Lijpq~j  AI  kJ  jK  L	L 	L 	L yL  yL	L 	L 	Lr&   c                    |\  }}|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}}y
)uG   task-4.4는 completed지만 .done 파일 없음 → data_integrity=FAILr   r   r   r   ra   r   r   r   r   Nr   r   s	            r$   test_e2e_data_integrity_is_failz4TestEndToEndQCVerify.test_e2e_data_integrity_is_fail   sh    	6h 01(;EvE;vEEEE;vEEE;EEEvEEEEEEEr&   c                    |\  }}|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)	u(   FAIL 항목이 있으므로 overall=FAILoverallr   ra   r   r   r   r   Nr   r   s	            r$   test_e2e_overall_is_failz-TestEndToEndQCVerify.test_e2e_overall_is_fail   s]    	6i *F* F**** F*** ***F*******r&   c           	      :   |\  }}d}|j                   }d}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                  |      t        j                  |      t        j                  |      dz  }
dd	|
iz  }t        t        j                  |            d x}x}	x}x}x}}y )
Nr   summary r
   )zT%(py1)s in %(py11)s
{%(py11)s = %(py5)s
{%(py5)s = %(py3)s.get
}(%(py7)s, %(py9)s)
}r   )r   r   r   rh   rj   rk   zassert %(py13)srl   )	r   r   r   r   r   r   r   r   r   )r   r   r   r   r    r   r   r   r   r!   r   r   s               r$   test_e2e_summary_contains_failz3TestEndToEndQCVerify.test_e2e_summary_contains_fail   s    	622I2r2Ir22v22222v2222v222222222222222I222r222222222222r&   c                    |\  }}|d   dk(  r|j                   }d}||k(  }|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}}y y )
Nr   r   rs   ra   rc   rd   re   zassert %(py7)srh   )	rz   r   r   r   r   r   r   r   r   )	r   r   rd   r   r   r   r   r#   r   s	            r$   test_e2e_exit_code_nonzeroz/TestEndToEndQCVerify.test_e2e_exit_code_nonzero   s     f)&??'a'?a''''?a''''''4'''4'''?'''a''''''' 'r&   N)r5   r6   r7   r8   r[   fixturer   r   r   r   r   r   r   r   r   r9   r&   r$   r   r      sN    ^V^^'"5 #5 Q/LLF
+
3(r&   r   )r8   builtinsr   _pytest.assertion.rewrite	assertionrewriter   r   osru   syspathlibr   r[   environr   ry   rx   pathinsertprompts.team_promptsteam_promptsr   r   rw   r   r;   rK   rX   r   r9   r&   r$   <module>r      s      	  
  "**..!13HIJ
z?#(("HHOOAs:' !j#??@j+GGH , ,8% %:% %:X X,;( ;(r&   