
    c:j                       d Z ddlm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mZ  ee      j!                         j"                  d   Z eedz        Zej*                  D  cg c]
  } | ek7  s	|  c} ej*                  dd  ee      ej*                  vr"ej*                  j-                  d ee              eej0                        D cg c]  }|dk(  s|j3                  d      s| c}D ]B  Zej0                  j7                  e      Z eed	d
      xs d
Zdev sed
k(  s6ej0                  e= D ddZ edd        edd      Z  edd      Z!d Z"d Z#d Z$d Z%d Z&d Z'yc c} w c c}w )u]  
test_gate_shadow_runner_2765.py — v2.14 S1/S2 §31 gate shadow report-only wrapper 회귀.

검증: fail-open / no-block / no-secret-log / verdict 기록 / log write 실패 fail-open /
      dispatch behavior unchanged(호출 계약 = 항상 None·raise 0).
회장 승인: ANU_V2_14_PHASE1_GATE_SHADOW_S1_S2_IMPLEMENTATION_APPROVED_ACTIVE_FALSE.
    )annotationsN)Path   testsdispatchz	dispatch.__file__ z/tests/dispatchc                   t         j                  j                  |       }|3t        |dd      r&t	        |j
                        j                  |      r|S t        j                  j                  | t        |z        }g }d }||u}|}|r|j                  }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  }|j%                  |       |rt        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  }|j%                  |       t        j&                  |d      i z  }t        j(                  d|       dz   d|iz  }t+        t        j,                  |            d x}x}x}x}x}x}
}	t        j                  j/                  |      }|t         j                  | <   |j                  j1                  |       |S )Nr   r	   )is not)z%(py2)s is not %(py5)sspec)py2py5z%(py7)spy7)z5%(py11)s
{%(py11)s = %(py9)s.loader
} is not %(py14)s)py9py11py14z%(py16)spy16r   zspec not found: z
>assert %(py19)spy19)sysmodulesgetgetattrstrr   endswith	importlibutilspec_from_file_location_ROOTloader
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprappend_format_boolop_format_assertmsgAssertionError_format_explanationmodule_from_specexec_module)modnamerelpathexistingr   @py_assert1@py_assert4@py_assert3@py_assert0@py_assert10@py_assert13@py_assert12@py_format6@py_format8@py_format15@py_format17@py_format18@py_format20mods                     D/home/jay/workspace/tests/regression/test_gate_shadow_runner_2765.py
_load_realr?      s   {{w'H*b Ac(J[J[F\FeFefmFn>>11'57?KDUtU4tUU4U4 7UUUU4tUUUUUU4UUU4UUUtUUUUUUU4UUUUUUUUUUUUUUU4UUUUUUUUUU;KG99UUUUUUUUU
..
)
)$
/CCKKKKC J    zdispatch/__init__.pyzdispatch.v2_13_gatezdispatch/v2_13_gate.pyzdispatch.gate_shadow_runnerzdispatch/gate_shadow_runner.pyc                   t         j                  }d}d}d}t        |       } |||||      }d }||u }|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                  |      t        j                  |      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                  |      t        j                  |      d

z  }	dd|	iz  }
t        t        j                  |
            d x}x}x}x}x}x}x}}y )Nt1normalcodingtask_idlevel	task_typelog_diris)z%(py14)s
{%(py14)s = %(py2)s
{%(py2)s = %(py0)s.shadow_evaluate
}(task_id=%(py4)s, level=%(py6)s, task_type=%(py8)s, log_dir=%(py12)s
{%(py12)s = %(py9)s(%(py10)s)
})
} is %(py17)sgsrr   tmp_path)
py0r   py4py6py8r   py10py12r   py17zassert %(py19)sr   )rL   shadow_evaluater   r    r!   r"   r#   r$   r%   r)   r*   )rM   r0   r2   @py_assert5@py_assert7@py_assert11r5   @py_assert16@py_assert15r;   r<   s              r>   test_returns_none_no_raiser[   -   s    $08BEh-H- 	 	    	 v     I   I   I  I % I 19 v   CF I CF v   GO I GO I CP I  I       r@   c                   d }|j                  t        d|       t        j                  }d}d}t	        |       } ||||      }d }||u }	|	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	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                  |      t        j                  |      d	z  }
dd|
iz  }t        t        j                  |            d x}x}x}x}x}x}	}y )Nc                     t        d      )Nintentional)RuntimeError)aks     r>   boomz1test_fail_open_when_classify_raises.<locals>.boom6   s    =))r@   classify_gatet2rC   rF   rG   rI   rJ   )z%(py12)s
{%(py12)s = %(py2)s
{%(py2)s = %(py0)s.shadow_evaluate
}(task_id=%(py4)s, level=%(py6)s, log_dir=%(py10)s
{%(py10)s = %(py7)s(%(py8)s)
})
} is %(py15)srL   r   rM   )	rN   r   rO   rP   r   rQ   rR   rS   py15zassert %(py17)srT   )setattr_v213rL   rU   r   r    r!   r"   r#   r$   r%   r)   r*   )rM   monkeypatchrb   r0   r2   rV   @py_assert9rX   @py_assert14r5   @py_format16r;   s               r>   #test_fail_open_when_classify_raisesrm   4   s!   * 5[t[8[S][t8]S[W[[SW[[[[[SW[[[[[[[3[[[3[[[[[[t[[[8[[[[[[S[[[S[[[[[[[[[[[[][[[S[[[W[[[[[[[[[r@   c                ^   t         j                  dddt        |              t        t	        |       j                  d            }|s{t        j                  d      dz   dd	t        j                         v st        j                  |      rt        j                  |      nd	iz  }t        t        j                  |            t        j                  |d
   j!                  d      j#                         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}}|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}||u }|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}}y )!Nt3rC   rD   rE   zgate_shadow_*.jsonlu%   shadow log 파일이 생성돼야 함z
>assert %(py0)srN   filesr   utf-8encodingverdict)in)z%(py1)s in %(py3)srecpy1py3assert %(py5)sr   modereport_only_shadow)==)z%(py1)s == %(py4)s)ry   rO   zassert %(py6)srP   activeFrJ   )z%(py1)s is %(py4)sINVALID_CONTRACT_PROVENANCE)rL   rU   r   listr   globr    r(   r"   r#   r$   r%   r)   r*   jsonloads	read_textstrip
splitlinesr!   )rM   rp   @py_format1rw   r3   @py_assert2@py_format4r7   r2   @py_format5@py_format7s              r>   test_verdict_loggedr   =   s   HRUV^R_`h$$%:;<E9999999995999599999
**U1X'''9??ALLNrR
SC999v;...;.....;....;...........x=!E!=E!!!!=E!!!=!!!E!!!!!!!y>:::>:::::>::::>:::::::::::r@   c           	     	   t         j                  dddddddidt        |       	       t        j                  t        t        t        |       j                  d
            d         j                  d      j                         j                         d         }h d}|j                  } |       }t        |      }||k  }|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$                  |      t        j$                  |      dt        j                          v st        j"                  |      rt        j$                  |      nddz  }t        j&                  dt        |j                               |z
         dz   d|iz  }t)        t        j*                  |            d x}x}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}
}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}
}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t4rC   rD   	RAWPROMPTghp_XKV)prompt
credentialenv)rF   rG   rH   runtime_staterI   z*.jsonlr   rq   rr   rt   >   tsr|   rG   r   reasonsourcegoal_idrF   ru   rH   touched_axesrollback_costcontract_source)<=)za%(py7)s
{%(py7)s = %(py0)s(%(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.keys
}()
})
} <= %(py9)ssetrw   allowed)rN   ry   rz   r   r   r   u#   화이트리스트 외 키 유입: z
>assert %(py11)sr   F)ensure_asciinot inz%(py1)s not in %(py3)sblobrx   r{   r   r   z"env")rL   rU   r   r   r   r   r   r   r   r   r   keysr   r    r!   r"   r#   r$   r%   r(   r)   r*   dumps)rM   rw   r   r   r1   @py_assert6@py_assert8@py_format10@py_format12r   r3   r   r7   s                r>   test_no_sensitive_fields_in_logr   I   s   H!,GSRUJWH  
 **T$tH~229=>qABLLV]L^ddfqqstvw
xCjGxxhxzh3z?h?g%hhh?ghhhhhh3hhh3hhhhhhshhhshhhxhhhzhhh?hhhhhhghhhghhhh)LSQTQYQYQ[__fMfLg'hhhhhhhh::c.D";d"""";d""";""""""d"""d"""""""7$7$7$$#<t####<t###<######t###t#######7$7$7$$r@   c            
     ~   t         j                  } d}d}d} | |||      }d }||u }|st        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                  |      t        j                  |      t        j                  |      t        j                  |      dz  }d	d
|iz  }t        t        j                  |            d x} x}x}x}x}x}}y )Nt5rC   z$/proc/forbidden_nonexistent_xyz_2765re   rJ   )z%(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.shadow_evaluate
}(task_id=%(py4)s, level=%(py6)s, log_dir=%(py8)s)
} is %(py13)srL   )rN   r   rO   rP   rQ   rR   py13zassert %(py15)srf   )
rL   rU   r    r!   r"   r#   r$   r%   r)   r*   )	r0   r2   rV   rW   rj   r6   rX   @py_format14rl   s	            r>    test_log_write_failure_fail_openr   [   sE    $.TH.T 	 	    	 v     I   I   I  I % I /U I  I       r@   c                    dd l } t        | j                  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	}||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   	task_descr   r   paramsrx   r{   r   r   )inspectr   	signaturerL   rU   
parametersr    r!   r%   r"   r#   r$   r)   r*   )r   r   r3   r   r   r7   s         r>   #test_minimal_meta_only_no_task_descr   b   s    ""3#6#67BBCF$;f$$$$;f$$$;$$$$$$f$$$f$$$$$$$!86!!!!86!!!8!!!!!!6!!!6!!!!!!!r@   )r-   r   r.   r   )(__doc__
__future__r   builtinsr"   _pytest.assertion.rewrite	assertionrewriter    importlib.utilr   r   r   pathlibr   r   resolveparentsr   r   
_TESTS_DIRpathinsertr   r   
startswith_mr   _cachedr   _fr?   rh   rL   r[   rm   r   r   r   r   )pra   s   00r>   <module>r      s`   #      
  	X ((+!
((6Qa:oq6u:SXXHHOOAs5z"3;;'
X1
?all;>W1
X Bkkoob!G	*b	)	/RBB"(KKO		 :- .(*BC.0PQ\	;$"a 7 Ys   $
E'/E'E,)E,