
    i6                    `   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
e
j                  j                  dd       ddlZddlmZ ddlmZmZmZ ddlmZmZmZmZ ddlmZ dd	Zej8                  j:                  d
        Zej8                  j:                  d        Zej8                  j:                  d        Z ej8                  j:                  d        Z!ej8                  j:                  d        Z"ej8                  j:                  d        Z#ej8                  j:                  d        Z$d Z%d Z&ej8                  j:                  d        Z'ej8                  j:                  d        Z(ej8                  j:                  d        Z)d Z*d Z+d Z,e-dk(  rddlZd Z. ej^                   e.              yy)u`  
Tests for Story 4.03 (Track B): TierExecutor — Tier-Appropriate Dispatcher

Black Box tests (BB): verify public contract from the outside.
White Box tests (WB): verify internal dispatch paths, registry mechanics,
                      observability events, and enriched payload structure.

Story: 4.03
File under test: core/routing/tier_executor.py
    )annotationsNz/mnt/e/genesis-system)Path)	AsyncMock	MagicMockpatch)TierExecutorT0_HANDLER_REGISTRYregister_t0_handler
EVENTS_DIRRoutingDecisionc                6    dddd}t        | ||    d|        S )z+Build a RoutingDecision for the given tier.python_functiongemini-flashclaude-opus-4-6)T0T1T2ztest decision for )tiermodel	rationaler   )r   	model_maps     6/mnt/e/genesis-system/tests/track_b/test_story_4_03.py_make_decisionr   $   s7      I
 o&tf-     c                   K   t        d      } ddd}t        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}}|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   }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7 w)uN   BB1: T0 task 'health_check' → Python handler called, no LLM, correct result.Ndispatch_fnhealth_checkzbb1-tasktypetask_idr   r   ==z%(py1)s == %(py4)spy1py4assert %(py6)spy6r   r   statusokoutputhealthyTisz%(py1)s is %(py4)sr   r   execute
@pytest_ar_call_reprcompare	_safereprAssertionError_format_explanation	executortask_payloaddecisionresult@py_assert0@py_assert3@py_assert2@py_format5@py_format7s	            r   1test_bb1_t0_task_health_check_uses_python_handlerrC   6   s     -H*zBLd#H##L(;;F&>!T!>T!!!!>T!!!>!!!T!!!!!!!'?///?/////?////?///////////(#t#t####t######t#######(I&.$.&$....&$...&...$....... <s   2H?H<HH?c                   K   d} | t         v}|st        j                  d|fd| t         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dz  }t        j                  d      dz   d	|iz  }t        t        j                  |            d
}g d"fd}t        |      }| dd}t        d      }|j                  ||       d
{   }t              }	d}
|	|
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                  |
      dz  }t        j                  d      dz   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}	}y
7 2w)#uM   BB2: T0 task type with no registered handler → falls back gracefully to T1. __unregistered_t0_type_for_bb2__not inz%(py0)s not in %(py2)sunregistered_typer	   py0py2z<Test prerequisite: unregistered_type must not be in registry
>assert %(py4)sr(   Nc                X   K   j                  |        d| j                  d      ddS w)Nr,   r"   
dispatchedr+   r"   r-   appendgetpayloaddispatch_called_withs    r   capture_dispatchzKtest_bb2_t0_task_without_handler_falls_back_to_t1.<locals>.capture_dispatchO   s+     ##G,7;;y+A\ZZ   '*r   zbb2-taskr    r      r#   z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)slenrV   rK   r'   py3r*   z1dispatch_fn should be called on T0 fallback to T1
>assert %(py8)spy8r   r   r   r%   r&   r)   r*   r   r   rU   dictreturnra   )r	   r4   r5   @py_builtinslocals_should_repr_global_namer6   _format_assertmsgr7   r8   r   r   r3   r[   )rI   @py_assert1@py_format3rA   rW   r:   r;   r<   r=   r@   @py_assert5@py_assert4rB   @py_format9enrichedr>   r?   rV   s                    @r   1test_bb2_t0_task_without_handler_falls_back_to_t1rm   E   s}     ;$77 G5F5FG$7 G G@FG G.F.F  G G=FY  G G@FG G.F.F %8 G G=FY %8 G G5F5FFG G G3F3FG G [ (89H-*ELd#H##L(;;F #$^^$)^^^$^^^^^^3^^^3^^^^^^#^^^#^^^$^^^^^^+^^^^^^^^#A&HF#t#t####t######t#######G................... <s   D0M(3M%4H2M(c                   K   g dfd} t        |       }d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}||k(  }|slt	        j
                  d	|fd||f      t	        j                  |      t	        j                  |      dz  }dd|iz  }t        t	        j                  |            dx}x}}y7 w)u>   BB3: T1 task → dispatch_fn called with model='gemini-flash'.c                X   K   j                  |        d| j                  d      ddS w)Nr,   r"   z	t1-resultrP   rQ   rT   s    r   rW   zNtest_bb3_t1_task_calls_dispatch_fn_with_gemini_flash.<locals>.capture_dispatche   +     ##G,7;;y+A[YYrX   r   email_draftzbb3-taskr    r   NrY   r#   rZ   r[   rV   r\   assert %(py8)sr_   r   r   r   r%   r&   r)   r*   r   r`   r   r   r3   r[   r4   r5   rc   rd   re   r6   r7   r8   rW   r:   r;   r<   r=   r@   ri   rj   rB   rk   rl   r>   r?   rA   rV   s                 @r   4test_bb3_t1_task_calls_dispatch_fn_with_gemini_flashru   `   s     Z (89H)jALd#H##L(;;F#$))$))))$))))))3)))3))))))#)))#)))$))))))))))#A&HG...................F#t#t####t######t####### <   :IIHIc                   K   g dfd} t        |       }d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}||k(  }|slt	        j
                  d	|fd||f      t	        j                  |      t	        j                  |      dz  }dd|iz  }t        t	        j                  |            dx}x}}y7 w)uA   BB4: T2 task → dispatch_fn called with model='claude-opus-4-6'.c                X   K   j                  |        d| j                  d      ddS w)Nr,   r"   z	t2-resultrP   rQ   rT   s    r   rW   zFtest_bb4_t2_task_calls_dispatch_fn_with_opus.<locals>.capture_dispatchz   rp   rX   r   
novel_taskzbb4-taskr    r   NrY   r#   rZ   r[   rV   r\   rr   r_   r   r   r   r%   r&   r)   r*   r   r`   rs   rt   s                 @r   ,test_bb4_t2_task_calls_dispatch_fn_with_opusrz   u   s     Z (89H(Z@Ld#H##L(;;F#$))$))))$))))))3)))3))))))#)))#)))$))))))))))#A&HG1 11 11111 1111111 11111111F#t#t####t######t####### <rv   c                 |  K   t        d      } ddd}t        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}}|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}||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}}y7 w)uT   BB5a: No dispatch_fn provided → T1 returns structured stub result without raising.Nr   rq   z	bb5a-taskr    r   r+   r,   r#   r%   r&   r)   r*   r   r   r   r"   r-   r/   r1   r2   r9   s	            r   'test_bb5_no_dispatch_fn_t1_returns_stubr|      s     -H)kBLd#H##L(;;F(#t#t####t######t#######&>!T!>T!!!!>T!!!>!!!T!!!!!!!'?,n,?n,,,,?n,,,?,,,n,,,,,,,)+++++++++++++++++++(#t#t####t######t####### <   2J<J9JJ<c                 |  K   t        d      } ddd}t        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}}|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}||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}}y7 w)uT   BB5b: No dispatch_fn provided → T2 returns structured stub result without raising.Nr   novel_reasoningz	bb5b-taskr    r   r+   r,   r#   r%   r&   r)   r*   r   r   r   r"   r-   r/   r1   r2   r9   s	            r   'test_bb5_no_dispatch_fn_t2_returns_stubr      s     -H-+FLd#H##L(;;F(#t#t####t######t#######&>!T!>T!!!!>T!!!>!!!T!!!!!!!'?///?/////?////?///////////)+++++++++++++++++++(#t#t####t######t####### <r}   c                   K   g dfd} t        |       }d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(  }|st	        j
                  d	|fd|
|f      t	        j                  |
      t	        j                  |      dz  }t	        j                  d      dz   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7 1w)uT   WB1: T2 path adds tier='T2' to enriched payload — prevents re-classification loop.c                6   K   j                  |        ddiS wNr+   r,   rR   rU   captureds    r   capturez<test_wb1_t2_enriched_payload_has_tier_guard.<locals>.capture         $   r   strategic_analysiswb1r    r   NrY   r#   rZ   r[   r   r\   rr   r_   r   r   r%   r&   zMT2 enriched payload MUST contain tier='T2' guard to prevent re-classification
>assert %(py6)sr*   r   r   r)   r`   r   r   r3   r[   r4   r5   rc   rd   re   r6   r7   r8   rf   r   r:   r;   r<   r@   ri   rj   rB   rk   rl   r>   r?   rA   r   s                @r   +test_wb1_t2_enriched_payload_has_tier_guardr      s     H  0H0UCLd#H


<
222x=A=A=A33xx=A{HF t t#  t         $    	X     G1 11 11111 1111111 11111111 3s   :I1I.H1I1c                    ddl m}  d}t        | |      }|st        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t        j                  |      t        j                  |      dz  }t        t        j                  |            d	x}}| j                  }t        |t              }|sKt        j                  d
t        | j                               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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}}y	)z0WB2: T0_HANDLER_REGISTRY is a module-level dict.r   )tier_executorr	   z.T0_HANDLER_REGISTRY must be a module attributez7
>assert %(py5)s
{%(py5)s = %(py0)s(%(py1)s, %(py3)s)
}hasattrmod)rK   r'   r]   py5Nz(T0_HANDLER_REGISTRY must be a dict, got z`
>assert %(py6)s
{%(py6)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.T0_HANDLER_REGISTRY
}, %(py4)s)
}
isinstancera   )rK   r'   r]   r(   r*   )core.routingr   r   r4   rf   rc   rd   re   r6   r7   r8   r	   r   ra   r!   )r   r@   rj   @py_format6ri   rB   s         r   1test_wb2_t0_handler_registry_is_module_level_dictr      s   1-`73-.`.``0```````7```7``````3```3```-```.``````-- S:-t4 S4 SARAR
248O8O3P2QRS SLRFS S:R:R  S SIR  S SLRFS S:R:R  S SIR  S SIR . S SLRFS S:R:R 04 S SIR 04 S SIR 5 S S S?R?RS Sr   c                    d} t        j                  | d       | t         v}|st        j                  d|fd| t         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dz  }t        j                  d      d	z   d
|iz  }t        t        j                  |            d}t        |       dd       }| t         v }|st        j                  d|fd| t         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dz  }t        j                  d|  d      d	z   d
|iz  }t        t        j                  |            d}t         |    }||u }|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}}t         | = y)zRWB3: @register_t0_handler decorator correctly adds handler to T0_HANDLER_REGISTRY.__wb3_test_type__NrF   rH   unique_typer	   rJ   z!Pre-condition: key must not existrM   r(   c                
    ddiS )Nwb3T )rU   s    r   _my_wb3_handlerzPtest_wb3_register_t0_handler_decorator_adds_to_registry.<locals>._my_wb3_handler   s    t}r   inz%(py0)s in %(py2)s'z1' must be in T0_HANDLER_REGISTRY after decorationr/   )z%(py1)s is %(py3)sr   r'   r]   assert %(py5)sr   r`   )r	   popr4   r5   rc   rd   re   r6   rf   r7   r8   r
   )	r   rg   rh   rA   r   r>   r@   @py_format4r   s	            r   7test_wb3_register_t0_handler_decorator_adds_to_registryr      s   %K K.11VVV;1VVVVVV;VVV;VVVVVV1VVV1VVVV3VVVVVVV% & -- K9J9JK;- K KDJFK K2J2J  K KAJ  K KDJFK K2J2J . K KAJ . K K9J9J!K=IJK K K7J7JK K{+>+>>>>+>>>+>>>>>>>>>>>>>>>> 	K(r   c                d
  K   | dz  }ddl mc m} |j                  |d|       t	        d      }ddd}t        d	      }|j                  ||       d{    |d
z  }|j                  } |       }	|	st        j                  d      dz   dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dz  }
t        t        j                  |
            dx}}	|j!                         j#                         j%                  d      }t'        |      }d}||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                  |      dz  }t        j                  d      dz   d|iz  }t        t        j                  |            dx}x}}t+        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}	||	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$}	||	k(  }|slt        j(                  d|fd||	f      t        j                  |      t        j                  |	      dz  }
dd |
iz  }t        t        j                  |            d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7 حw),zNWB4: Execution event is logged to events.jsonl after a successful T0 dispatch.observabilityr   Nr   r   r   zwb4-taskr    r   zevents.jsonlz.events.jsonl should be created after executionzC
>assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}log_file)rK   rL   r(   
rY   )>=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)sr[   linesr\   z(At least one log entry should be writtenr^   r_   
event_typetier_executionr#   r%   r&   r)   r*   r"   r   r   r   	timestampr   )z%(py1)s in %(py3)seventr   r   r   )core.routing.tier_executorroutingr   setattrr   r   r3   existsr4   rf   rc   rd   re   r6   r7   r8   	read_textstripsplitr[   r5   jsonloads)tmp_pathmonkeypatchlog_dirr   r:   r;   r<   r   rg   r?   rA   r   r@   ri   rj   rB   rk   r   r>   r   r   s                        r   5test_wb4_event_logged_to_events_jsonl_on_t0_executionr      sA     (G -,\73-H*zBLd#H


<
222'H??N?NNNNNNNNNN8NNN8NNN?NNNNNNNNN &&(..t4Eu:FF:?FFF:FFFFFF3FFF3FFFFFFuFFFuFFF:FFFFFFFFFFFFFFJJuRy!E2"22"22222"2222222"22222222)z)z))))z))))))z)))))))= D =D    =D   =   D       >...>.....>....>...........;%;%;%% 3s   AT0T-ST0c                 p  K   g d} t        j                  | d       t        |       dfd       }t        d      }| d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   }
|
| 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   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}}t         | = y7 ϭw)zTWB5: T0 handler is called with the original task_payload dict (not a modified copy).__wb5_handler_test__Nc                4    j                  |        dddi dS Nr,   r   r   )r+   r   r   r-   r   )rU   received_payloadss    r   _wb5_handlerzHtest_wb5_t0_handler_receives_original_task_payload.<locals>._wb5_handler  s"      )7HTVWWr   r   zwb5-taskdata)r!   r"   extrar   rY   r#   rZ   r[   r   r\   rr   r_   r   r!   )z%(py1)s == %(py3)sr   r   r   r   r"   r%   r&   r)   r*   r   r`   )r	   r   r
   r   r   r3   r[   r4   r5   rc   rd   re   r6   r7   r8   )r   r   r:   r;   r<   r@   ri   rj   rB   rk   r>   r   r   r?   rA   r   s                  @r   2test_wb5_t0_handler_receives_original_task_payloadr      s+     (KK.%X &X -H'JPLd#H


<
222 !&Q&!Q&&&&!Q&&&&&&3&&&3&&&&&& &&& &&&!&&&Q&&&&&&&Q'6';6666';666'666666;666;6666666Q	*8j8*j8888*j888*888j8888888Q(2F2(F2222(F222(222F2222222 	K( 3s   A!L6$L3%KL6c                   K   g dfd} t        |       }dd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(  }|st	        j
                  d
|fd|
|f      t	        j                  |
      t	        j                  |      dz  }t	        j                  d      dz   d|iz  }t        t	        j                  |            dx}
x}}|	d   }
d}|
|k(  }|st	        j
                  d
|fd|
|f      t	        j                  |
      t	        j                  |      dz  }t	        j                  d      dz   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}|
|k(  }|slt	        j
                  d
|fd|
|f      t	        j                  |
      t	        j                  |      dz  }dd|iz  }t        t	        j                  |            dx}
x}}y7 Gw)z^WB6: T1 enriched payload forwarded to dispatch_fn contains tier='T1' and model='gemini-flash'.c                6   K   j                  |        ddiS wr   r   r   s    r   r   zEtest_wb6_t1_enriched_payload_contains_tier_and_model.<locals>.capture   r   r   r   rq   zwb6-taskhello)r!   r"   bodyr   NrY   r#   rZ   r[   r   r\   rr   r_   r   r   r%   r&   z*T1 enriched payload must contain tier='T1'r   r*   r   r   z5T1 enriched payload must contain model='gemini-flash'r   r)   r"   r`   r   r   s                @r   4test_wb6_t1_enriched_payload_contains_tier_and_modelr     sE     H  0H)j'RLd#H


<
222x=A=A=A33xx=A{HFQtQt#QQQtQQQQQQtQQQ%QQQQQQQQGgg.gggggggggggg0ggggggggF&w&w&&&&w&&&&&&w&&&&&&&I,*,*,,,,*,,,,,,*,,,,,,, 3s   ;NNMNc                    ddl m}  | t        u }|st        j                  d|fd| t        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dz  }dd	|iz  }t        t        j                  |            d
}y
)z4TierExecutor is exported from core.routing.__init__.r   )r   r/   )z%(py0)s is %(py2)sTEr   rJ   assert %(py4)sr(   N)
r   r   r4   r5   rc   rd   re   r6   r7   r8   )r   rg   rh   rA   s       r   *test_tier_executor_importable_from_packager   7  sm    /222r   c                 P   ddl m}  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)	z;T0_HANDLER_REGISTRY is exported from core.routing.__init__.r   )r	   z5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}r   regra   )rK   r'   rL   r(   N)r   r	   r   ra   rc   rd   r4   re   r6   r7   r8   )r   r?   rA   s      r   0test_t0_handler_registry_importable_from_packager   =  s    7c4        :   :      c   c      4   4          r   c                    ddl m}  t        |       }|sd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                  |      dz  }t        t        j                  |            d}y)z;register_t0_handler is exported from core.routing.__init__.r   )r
   z,assert %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
}callablerth)rK   r'   r]   N)
r   r
   r   rc   rd   r4   re   r6   r7   r8   )r   r@   r   s      r   0test_register_t0_handler_importable_from_packager   C  si    7C==88CC=r   __main__c                 
  K   t        d       t               } | j                  dddt        d             d {   }g }|d   }d}||k(  }|}|r|d   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}	}t        d       | j                  dddt        d             d {   }g }|d   }d}||k(  }|}|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}	}t        d       | j                  dddt        d              d {   }g }|d   }d!}||k(  }|}|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}	}t        d"       d#}t        j                  |d        t        |      d$        }|t        v }|st	        j
                  d%|fd&|t        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(d)z  }d*d+|iz  }t        t	        j                  |            d }t        |= t        d,       t        d-       y 7 '7 7 jw).Nz,Running manual smoke tests for Story 4.03...r   zsmoke-1r    r   r   r-   r.   Tr#   )z%(py3)s == %(py6)s)r]   r*   z%(py8)sr_   r/   )z%(py11)s is %(py14)s)py11py14z%(py16)spy16r   zassert %(py19)spy19u/   [PASS] BB1: T0 health_check → python_functionrq   zsmoke-2r   r   r   u-   [PASS] BB5: No dispatch_fn → T1 stub resultry   zsmoke-3r   r   u-   [PASS] BB5: No dispatch_fn → T2 stub result__smoke_handler__c                    dddi dS r   r   )ps    r   _smoke_handlerz_smoke.<locals>._smoke_handlerp  s    15tN_km&nnr   r   r   	test_typer	   rJ   r   r(   z0[PASS] WB3: register_t0_handler adds to registryu7   
All manual smoke tests passed — Story 4.03 (Track B))printr   r3   r   r4   r5   r6   rR   _format_boolopr7   r8   r	   r   r
   rc   rd   re   )r:   r=   rg   r@   ri   rj   r>   @py_assert10@py_assert13@py_assert12rB   rk   @py_format15@py_format17@py_format18@py_format20r   r   rh   rA   s                       r   _smoker   P  s    <=  >''#	:4 
 
 	Nvf~MM~%M&*:9*EMM*E*MMMM~MMM~MMMMMMMMMM*EMMM*EMMMMMMMMMMMMMMMMM?@  ''"y94 
 
 	NvgM.M.0MVH5EMM5E5MMMM.MMMMMM.MMMMMMM5EMMM5EMMMMMMMMMMMMMMMMM=>  ''!i84 
 
 	QvgP"3P"33Px8HPDP8HD8PPPP"3PPPPPP"3PPPPPPP8HDPPP8HPPPDPPPPPPPPPPPPPP=> (		40	Y	'n 
(n/////y///////y///y//////////////////	*@AHIE


s6   7U)U E"U)U#EU)<U&=I$U)#U)&U))r   strrb   r   )0__doc__
__future__r   builtinsrc   _pytest.assertion.rewrite	assertionrewriter4   r   syspathinsertpytestpathlibr   unittest.mockr   r   r   r   r   r	   r
   r   core.routing.tier_classifierr   r   markasynciorC   rm   ru   rz   r|   r   r   r   r   r   r   r   r   r   r   __name__r   runr   r   r   <module>r     s  	 #    
 * +   5 5  9$ / / / /4 $ $( $ $( $ $ $ $& 2 2,S)(    8 ) )8 - -6! z'JR GKKY r   