
    4js                    Z   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mZ ddlZ ee      j!                         j"                  d   Z ee      ej(                  vr"ej(                  j+                  d ee              ej,                  d      d        Zd	 Zd
 Zd Zd Zd Zd Zy)u;  regression — task-2553+57 Track B NEXT_RUNTIME_STRUCTURE_PILOT_PLAN.

스키마/조건 검증 + mock-only FAIL 음성 케이스. 실 policy_profile_engine
read-only resolve 실 entrypoint 가 호출됨을 *증명* 한다 (문서-only/날조
완료 금지). 본 테스트는 read-only — write 0, 실 dispatch 0.
    )annotationsN)Path   module)scopec                 
   t         j                  j                  dt        dz        } g }| }| r| j                  }|}|sdddt        j                         v st        j                  |       rt        j                  |       ndiz  }|j                  |       | rlddt        j                         v st        j                  |       rt        j                  |       ndt        j                        dz  }|j                  |       t        j                  |d      i z  }d	d
|iz  }t        t        j                  |            d x}x}}t         j                  j                  |       }| j                  j                  |       |S )N_p57_builder+scripts/build_next_pilot_plan_2553plus57.pyz%(py2)spy2specz#%(py6)s
{%(py6)s = %(py4)s.loader
})py4py6r   zassert %(py9)spy9)	importlibutilspec_from_file_locationROOTloader@py_builtinslocals
@pytest_ar_should_repr_global_name	_safereprappend_format_boolopAssertionError_format_explanationmodule_from_specexec_module)	r   @py_assert1@py_assert0@py_assert5@py_format3@py_format7@py_format8@py_format10mods	            G/home/jay/workspace/tests/regression/test_next_pilot_plan_2553plus57.pybuilderr)      s     >>11LLD  44DKKK444DDK
..
)
)$
/CKKC J    c                @   | 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}}| j                  D ]  }| j                   }||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t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}} d}	| j                  }|	|v}
|
st        j                  d|
fd|	|f      t        j                  |	      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}	x}
}d}	| j                  }|	|v}
|
st        j                  d|
fd|	|f      t        j                  |	      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}	x}
}d}	| j                  }|	|v}
|
st        j                  d|
fd|	|f      t        j                  |	      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}	x}
}y)uK   §3 expected_files allowlist = 정확히 9종, Track A/C/D disjoint 의도.)	memory/events/pilot_goal.json*memory/events/selected_policy_profile.json'memory/events/pilot_execution_plan.json#memory/events/success_criteria.jsonr
   3tests/regression/test_next_pilot_plan_2553plus57.py(memory/events/task-2553+57.decision.json&memory/events/task-2553+57.result.jsonmemory/reports/task-2553+57.md==)z6%(py2)s
{%(py2)s = %(py0)s.EXPECTED_FILES
} == %(py5)sr)   py0r   py5assert %(py7)spy7Nin)z6%(py0)s in %(py4)s
{%(py4)s = %(py2)s.EXPECTED_FILES
}rel)r7   r   r   assert %(py6)sr   r
   )not in)z6%(py1)s not in %(py5)s
{%(py5)s = %(py3)s.EMIT_FILES
}py1py3r8   r0   r3   )
EXPECTED_FILESr   _call_reprcomparer   r   r   r   r   r   
EMIT_FILES)r)   r    @py_assert4@py_assert3@py_format6r%   r=   @py_format5r$   r!   @py_assert2s              r(   #test_expected_files_allowlist_exactrK   !   s   !! 
 
& 
! 
& 
 
 
! 
& 
 
 
 
   
 
   
 
  " 
 
 
& 
 
 
 
 
 
 !! -,,,s,,,,,s,,,,,,,s,,,s,,,,,,g,,,g,,,,,,,,,,,-8R@R@RR8@RRRRR8@RRRR8RRRRRRRRRRRR@RRRRRRRR@ZHZHZZ@HZZZZZ@HZZZZ@ZZZZZZZZZZZZHZZZZZZZZ+E73E3EE+3EEEEE+3EEEE+EEEEEE7EEE7EEE3EEEEEEEEr*   c                J   | 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}}| 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}}| j                   }| j                  }||k7  }|st        j                  d|fd||f      dt        j                         v st        j
                  |       rt        j                  |       ndt        j                  |      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}x}}y)uN   callback owner = 독립 ANU key; executor self key 절대 금지 (+49 정본).c119085addb0f8b7r4   )z8%(py2)s
{%(py2)s = %(py0)s.ANU_CALLBACK_KEY
} == %(py5)sr)   r6   r9   r:   N1e41a2324a3ccdd0)z9%(py2)s
{%(py2)s = %(py0)s.EXECUTOR_SELF_KEY
} == %(py5)s!=)z_%(py2)s
{%(py2)s = %(py0)s.ANU_CALLBACK_KEY
} != %(py6)s
{%(py6)s = %(py4)s.EXECUTOR_SELF_KEY
})r7   r   r   r   zassert %(py8)spy8)
ANU_CALLBACK_KEYr   rD   r   r   r   r   r   r   EXECUTOR_SELF_KEY)	r)   r    rF   rG   rH   r%   r"   r$   @py_format9s	            r(   *test_callback_owner_is_independent_anu_keyrU   6   s   ##9'99#'99999#'999999979997999#999'99999999$$:(::$(:::::$(:::::::7:::7:::$:::(::::::::##@w'@'@@#'@@@@@#'@@@@@@@7@@@7@@@#@@@@@@w@@@w@@@'@@@@@@@@r*   c                    t        j                  | j                        5  | j                  d       ddd       y# 1 sw Y   yxY w)uO   mock-only 검증 경로는 FAIL — 문서-only/날조 완료 금지 (§3/§5).T
allow_mockN)pytestraisesMockOnlyError_call_real_entrypoints)r)   s    r(   test_mock_only_path_failsr]   =   s:    	w,,	- 8&&$&78 8 8s	   <Ac                6	   | j                  d      }|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}||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   }||v }|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}||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}}|d   d   }d}||k7  }|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}||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}||u }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d	x}x}}y	)u   실 policy_profile_engine read-only resolve 실 entrypoint 가
    runtime_structure_smoke_pilot 을 RESOLVED 로 산출 (mock 아님).FrW   	mock_onlyisz%(py1)s is %(py4)srA   r   r>   r   Nreal_entrypointTpolicy_profile_engineengine_consumed_read_onlyr;   z%(py1)s in %(py4)sresolvedstatusRESOLVEDr4   z%(py1)s == %(py4)sprofile_boundresolved_profile_nameruntime_structure_smoke_pilotunknown_goal_type_resolutionrO   )z%(py1)s != %(py4)sowner_key_consistencymandated_is_anu_keyexecutor_self_is_anu_key)r\   r   rD   r   r   r   )	r)   realr!   rG   rJ   rI   r$   resokcs	            r(   &test_real_entrypoint_resolves_readonlyrv   C   s    ))U);D%%%%%%%%%%%%%%%%%%%!"*d*"d****"d***"***d*******"Gd+F&GG"&GGGGG"&GGGG"GGG&GGGGGGGG
z
Cx=&J&=J&&&&=J&&&=&&&J&&&&&&&'4'4''''4''''''4'''''''&'J+JJ'+JJJJJ'+JJJJ'JJJ+JJJJJJJJ./9GZG9ZGGGG9ZGGG9GGGZGGGGGGG
&
'C$%--%----%---%----------)*3e3*e3333*e333*333e3333333r*   c                &   | j                         }|j                  }d} ||      }d}||u }|st        j                  d|fd||f      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}}|d
   }	|	d   }
|
j                  }d} ||      }|stdt        j                  |
      t        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            d	x}
x}x}}g }|	d   }d}||u }|}
|r|	d   }d}||u }|}
|
st        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }|j                  |       |r_t        j                  dfdf      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}}|	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(   }
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}|
|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.   }
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   }
d}|
|u }|slt        j                  d|fd,|
|f      t        j                  |
      t        j                  |      d#z  }d$d%|iz  }t        t        j                  |            d	x}
x}}|d0   d1   }
d}|
|u }|slt        j                  d|fd,|
|f      t        j                  |
      t        j                  |      d#z  }d$d%|iz  }t        t        j                  |            d	x}
x}}|d2   d3   }
| j                  }|
|k(  }|st        j                  d!|fd4|
|f      t        j                  |
      d5t	        j
                         v st        j                  |       rt        j                  |       nd5t        j                  |      d6z  }d7d8|iz  }t        t        j                  |            d	x}
x}}|d9   }|d:   D ch c]  }|d;   	 }}h d<}
|
|k  }|st        j                  d=|fd>|
|f      t        j                  |
      d?t	        j
                         v st        j                  |      rt        j                  |      nd?d@z  }dAdB|iz  }t        t        j                  |            d	x}
}|dC   } dD}
| dE   }|
|v }|slt        j                  dF|fdG|
|f      t        j                  |
      t        j                  |      d#z  }d$d%|iz  }t        t        j                  |            d	x}
x}}dHj                  | dI         }!g }dJ}||!v }|}
|sdK}"|"|!v }#|#}
|
sXt        j                  dF|fdL||!f      t        j                  |      dMt	        j
                         v st        j                  |!      rt        j                  |!      ndMdNz  }dOd8|iz  }|j                  |       |st        j                  dF#fdP"|!f      t        j                  |"      dMt	        j
                         v st        j                  |!      rt        j                  |!      ndMdQz  }$dRdS|$iz  }|j                  |       t        j                  |dT      i z  }%dUdV|%iz  }t        t        j                  |            d	x}
x}x}x}x}"}#dW}
|
|!v }|st        j                  dF|fdX|
|!f      t        j                  |
      dMt	        j
                         v st        j                  |!      rt        j                  |!      ndMd@z  }dAdB|iz  }t        t        j                  |            d	x}
}dY}
|
|!v }|st        j                  dF|fdX|
|!f      t        j                  |
      dMt	        j
                         v st        j                  |!      rt        j                  |!      ndMd@z  }dAdB|iz  }t        t        j                  |            d	x}
}|dZ   }&g }|&d   }d}||u }|}
|r|&d[   }d}||u }|}
|
st        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }|j                  |       |r_t        j                  d|fd||f      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}}|d\   }'g }|'d]   }d}||u }|}
|r|'d^   }d}||u }|}
|
st        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }|j                  |       |r_t        j                  d|fd||f      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}}|'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}|
|u }|slt        j                  d|fd,|
|f      t        j                  |
      t        j                  |      d#z  }d$d%|iz  }t        t        j                  |            d	x}
x}}| j                  }|'d`   }||v }|st        j                  dF|fda||f      d5t	        j
                         v st        j                  |       rt        j                  |       nd5t        j                  |      t        j                  |      dbz  }d7d8|iz  }t        t        j                  |            d	x}x}}y	c c}w )cuK   4종 plan + decision/result 스키마/조건 검증, actual_dispatch=False.__checks_passed__Tr`   )zI%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.pop
}(%(py4)s)
} is %(py9)sbuilt)r7   r   r   r   r   zassert %(py11)spy11Nr,   schemazpilot_goal.v1zJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
})rA   rB   r8   r:   actual_dispatchFdesign_only)z%(py3)s is %(py6)s)rB   r   z%(py8)srQ   )z%(py11)s is %(py14)s)rz   py14z%(py16)spy16r   zassert %(py19)spy19
pilot_goalgoal_request	goal_typern   r4   rk   rc   r>   r   r-   selected_profileri   rj   engine_mapping_statusprofile_engine_resolvedrb   fail_closed_negative_checkexpected_not_resolvedr.   conditions_2no_branch_commit_push&would_be_dispatch_contract_DESIGN_ONLY$normal_completion_callback_owner_key)z8%(py1)s == %(py5)s
{%(py5)s = %(py3)s.ANU_CALLBACK_KEY
}r)   r@   r9   r:   r/   pilot_success_criteriaid>   SC1_real_entrypointSC8_no_actual_dispatchSC5_callback_owner_anu_key)<=)z%(py1)s <= %(py3)sids)rA   rB   zassert %(py5)sr8   %track_c_fallback_acceptance_criterionztask-2553+58sourcer;   rg    	criterionu   fallback ≠ progressu.   진행/수락 트리거로 사용해서는 안)z%(py3)s in %(py5)sjoined)rB   r8   z%(py7)s)z%(py10)s in %(py12)s)py10py12z%(py14)sr~      zassert %(py17)spy17DUPLICATE_CALLBACK_IGNORED)z%(py1)s in %(py3)sz%normal-callback durable-success eventr1   hold_for_chairr2   r_   real_entrypoint_calledself_chain_authoritativenext_action)z8%(py2)s
{%(py2)s = %(py0)s.ANU_CALLBACK_KEY
} in %(py5)sr6   )	build_allpopr   rD   r   r   r   r   r   r   endswithr   r   rR   join)(r)   ry   r    rG   r"   @py_assert8@py_assert7r&   @py_format12pgr!   rJ   rF   @py_assert6r%   @py_assert10@py_assert13@py_assert12r$   rT   @py_format15@py_format17@py_format18@py_format20rI   sppeprH   sccr   @py_format4tcfacr   @py_assert9@py_assert11@py_format13@py_format16decrslts(                                           r(   test_build_all_artifacts_schemar   V   s	   E991(19()1T1)T1111)T111111511151119111(111)111T1111111	.	/Bh<1<  11 11111<111 1111111111111G2 GEG E)Gb.?G4G.?4.GGGG EGGG GGGEGGGGGGG.?4GGG.?GGG4GGGGGGGGGGGGGGlN+K8[<[[8<[[[[[8<[[[[8[[[<[[[[[[[[	;	<B !(+9z9+z9999+z999+999z9999999%&'@AITIATIIIIATIIIAIIITIIIIIII*+,CDLLDLLLLDLLLDLLLLLLLLLL
9
:C !*U*!U****!U***!***U*******~67?4?74????74???7???4???????452	
 ##		
 $	$
 	
 $	 
 		
 
  
  	 
  	 
  $	   
   
4	5B78
9q1T7
9C
9ZaZ^aaaaaZ^aaaaZaaaaaa^aaaa^aaaaaaaa67E,U8_,>_,,,,>_,,,>,,,_,,,,,,,XXeK()Fj"j"f,j0`j0`dj0jjjjj"fjjj"jjjjjjfjjjfjjjjjjj0`djjjj0`jjjjjjdjjjjdjjjjjjjjjjjjjjj'1'61111'6111'1111116111611111112<2f<<<<2f<<<2<<<<<<f<<<f<<<<<<<
:
;CM3 !MUM!U*Ms3C/DMM/D/MMMM!UMMM!MMMUMMMMMMM/DMMM/DMMMMMMMMMMMMMMMMM9:DP4PP%P$/G*HPDP*HD*PPPPPPPPPPPPPPPPP*HDPPP*HPPPDPPPPPPPPPPPPPP*+4u4+u4444+u444+444u4444444!"+e+"e++++"e+++"+++e+++++++##:tM'::#':::::#':::::::7:::7:::#:::'::::::::! :s   |c                D   | j                         }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}}|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}}| j                         }d}|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)u7   self-* 0 · 실 dispatch 0 명시 (회장 §2/§4/§5).zself-collectorself_star_zeror;   rg   rc   r>   r   Nr|   Fr`   rb   zself-dispatchr   no_self_star)build_decisionr   rD   r   r   r   build_pilot_execution_plan)r)   r   r!   rG   rJ   rI   r$   r   s           r(   (test_no_self_star_and_no_actual_dispatchr      s   

 
 
"C4s#34444444444444444444444 !*U*!U****!U***!***U*******

,
,
.C[c"JKN[[?[[[[[?[[[[?[[[[[[[[[[[r*   )__doc__
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   importlib.utilr   syspathlibr   rY   __file__resolveparentsr   strpathinsertfixturer)   rK   rU   r]   rv   r   r    r*   r(   <module>r      s    #     
  H~''*t9CHHHHOOAs4y! h  F*A84&);X\r*   