
    +i֡                    H   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ZddlZddlmZmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlZdZeej6                  vrej6                  j9                  de       dd	lmZmZ dd
l m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl m4Z4 ddl5m6Z6 ddl7m8Z8 dddZ9dddZ:dddZ;ddZ<ddZ=dddZ>ddZ?ddd Z@	 d	 	 	 dd!ZAdd"ZBddd#ZCdd$ZDdddd%	 	 	 	 	 	 	 	 	 dd&ZEd' ZF G d( d)      ZG G d* d+      ZH G d, d-      ZI G d. d/      ZJ G d0 d1      ZK G d2 d3      ZL G d4 d5      ZM G d6 d7      ZNdd8ZOd9 ZPd: ZQdd;ZRdd<ZSdd=ZTdd>ZUdd?ZVdd@ZWeXdAk(  r\ddlYZYddlZddBZZg dCdD fdEdF fdGdH fdIdJ fdKdL fdMdN fdOdP fdQdR fdSdT fdUdV fdWdX fdYdZ fd[d\ fd]d^ fd_d` fdadb fdcdd fdedf fdgdh fdidj fdkdl fdmdn fdodp fdqdr fdsdt fdudv fdwdx fdydz fd{d| fd} eM       j                  fd~d fdd fdd fdd fdd fdd fdd fdd fdePfdeQfdd fdd fdd fdd fdd fdd fZ\dZ] e^e\      Z_e\D ]  \  Z`Za	  ea         ebde`        e]dz  Z]  ebde] de_ d       e]e_k(  r	 ebd       y ej                  d       yy# ec$ r)Zd ebde` ded         eYj                          Y dZd[dzdZd[dww xY w)u  
tests/track_b/test_story_9_02.py

Story 9.02: EpochRunner — Full Epoch Orchestrator

Black Box Tests (BB):
    BB1  Successful epoch with ontological proposal + arena pass
         → all phases (including 'pr_create') in phases_completed, pr_url set
    BB2  Successful epoch with epistemic scope
         → phases do NOT include 'code_propose'/'shadow_arena'/'pr_create';
           tier1_update IS present; pr_url=None
    BB3  run_epoch_safe() with lock already held → returns None immediately
    BB4  Epoch log entry written with correct epoch_id and status

White Box Tests (WB):
    WB1  Phase execution is sequential (mock call order verification)
    WB2  Lock acquired before run_epoch, released in finally
    WB3  asyncio.wait_for with 7200s timeout used
    WB4  Phase failure mid-run → partial phases_completed, success not blocking remaining phases

ALL external I/O is mocked — zero live Redis/Postgres/Gemini/Qdrant.
    )annotationsN)datetimetimezone)Path)Optional)	AsyncMock	MagicMockcallpatchz/mnt/e/genesis-systemEpochRunnerEPOCH_LOG_PATH)EpochResult)AxiomDistillationResultWriteResultTier1EpochResult)ArchitectureAnalysis
BottleneckCodeProposalArenaResultPRResult)Tier1ResultEpochReport
ScarReport)WeeklyConversationSummary   c           	     :    t        d| dd|  ddd| dg      S )Nepoch_2026_02_25_03dzAxiom content 
operationsg333333?saga_)idcontentcategory
confidencesource_saga_ids)r   )idxs    6/mnt/e/genesis-system/tests/track_b/test_story_9_02.py_make_axiomr1   E   s:    s3i( & S	*+     c                X    t        d| dz         D cg c]  }t        |       c}S c c}w )Nr$   )ranger1   )nis     r0   _make_axiomsr7   O   s$    $)!QUO4qKN444s   'c                .    t        t        |       d      S )Nz1Genesis ran 12 sessions. Three failures resolved.axiomsweek_summary)r   r7   n_axiomss    r0   _make_distillation_resultr>   S   s    H%H r2   c                 n    t        j                  t        j                        } t	        dddddg| |       S )N
   2      event1event2)total_sessionstotal_tasksfailed_tasksconversation_snippetsperiod_start
period_end)r   nowr   utcr#   )rK   s    r0   _make_weekly_summaryrM   Z   s8    
,,x||
$C$'2 r2   c                     t        dg d      S )N      )total_scarsclustersnew_since_last_epochr!    r2   r0   _make_scar_reportrU   f   s    !bqIIr2   	epistemicc                R    g }| dk(  rt        ddddgdg      g}t        |g |       S )	Nontologicalzfunction missing in router.pyrB   s1s2scar_001)description	frequencyaffected_saga_idsscar_ids)bottlenecksrecommended_fixesscope)r   r   )rb   r`   s     r0   _make_analysisrc   j   sH    K;#',$	
   r2   c                 "    t        ddddi       S )Nzcore/interceptors/fix_router.pyz&class FixRouter(BaseInterceptor): passz%tests/interceptors/test_fix_router.pyzdef test_fix(): assert True)	file_pathcode_contenttest_file_pathtest_contentconfig_changesr   rT   r2   r0   _make_proposalrj   |   s    3=>2 r2   Tc                $    t        |g ddi|       S )Ndeltag?)	pass_rateaxiom_violationsimproved_metricsready_for_prr   passedrm   s     r0   _make_arena_resultrs      s    !3	 r2   c                    t        | dd      S )Nz&genesis-auto-refactor-epoch_2026_02_25*   )pr_urlbranch_name	pr_numberr   )rv   s    r0   _make_pr_resultry      s     < r2   c                      t        dddd      S )NrB   r$   kg_axioms_writtenqdrant_scars_updatedprompt_templates_updatedrules_appendedr   rT   r2   r0   _make_tier1_epoch_resultr      s    !"	 r2   c                &    t        dd|  d|       S )Nz# Genesis Nightly Epochz/tmp/epoch_z.md)markdown_contentre   epoch_idr   )r   s    r0   _make_epoch_reportr      s!    2z- r2   c                     t        ddd      S )NzN/mnt/e/genesis-system/KNOWLEDGE_GRAPH/axioms/genesis_evolution_learnings.jsonlrB   )kg_file_pathqdrant_upsertsjsonl_entriesr   rT   r2   r0   _make_write_resultr      s    e r2   )rb   arena_passedlock_acquiredc                   i }t               }||j                  _        d|j                  _        ||d<   t               }t	               |j
                  _        ||d<   t               }t               |j
                  _        ||d<   t               }t        d      |j                  _        ||d<   t               }	t               |	j                  _        |	|d<   t               }
t        |	      |
j                  _        |
|d
<   t               }t               |j                  _        ||d<   t               }t        ||rdnd      |j                   _        ||d<   t               }t#               |j$                  _        ||d<   t               }t'               |j(                  _        ||d<   t               }t+               |j,                  _        ||d<   t/        | dz        }t1        |||||	|
||||||      }||fS )zu
    Build an EpochRunner with all mocked dependencies.

    Returns (runner, mocks_dict) for call verification.
    Nlock
aggregatorscar_aggregatorrB   r<   	distillerknowledge_writer)rb   meta_architectcode_proposer?g      ?rq   shadow_arena
pr_creatortier1_triggerreport_generatorepoch_log.jsonl)r   r   r   r   r   r   r   r   r   r   r   epoch_log_path)r	   acquirereturn_valuereleaserM   	aggregaterU   r>   distillr   writerc   analyzerj   proposers   evaluate_proposalry   	create_prr   applyr   generatestrr   )tmp_pathrb   r   r   mocksr   r   r   r   r   r   r   r   r   r   r   r   runners                     r0   _build_runnerr      s    E ;D -DLL $DLLE&M J(<(>J%$E,  kO->-@O*.E
 I%>%JI""E+ !{*<*>' 0E
 [N*8u*EN',E
 KM)7)9M&*E/ ;L2D%#33L""/ )E. J(7(9J%$E, KM'?'AM$*E/ !{-?-A* 0E
$556N')%#!#)%F 5=r2   c                H    t        j                         j                  |       S )z8Helper to run an async coroutine synchronously in tests.)asyncioget_event_looprun_until_complete)coros    r0   _runr     s    !!#66t<<r2   c                  @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
TestBB1_OntologicalEpochWithPRuJ   BB1: ontological scope + arena passes → pr_create in phases, pr_url set.c                   t        |dd      \  }}t        |j                  d            }|j                  }d }||u}|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }t	        j                  d	      d
z   d|iz  }	t        t	        j                  |	            d x}x}}g }d}
|j                  }|
|v }|}|s$|j                  }|j                  }d} ||      }|}|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  }|j                  |       |sddt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                        t	        j                        t	        j                        t	        j                        dz  }|j                  |       t	        j                  |d      i z  }t	        j                  d|j                        dz   d|iz  }t        t	        j                  |            d x}x}x}
x}x}x}x}x}}y )NrX   Tr   rb   r   epoch_2026_02_25is not)z2%(py2)s
{%(py2)s = %(py0)s.pr_url
} is not %(py5)sresultpy0py2py5z&pr_url should be set when arena passes
>assert %(py7)spy7z
github.comzhttps://in)z.%(py3)s in %(py7)s
{%(py7)s = %(py5)s.pr_url
})py3r   r   z%(py9)spy9zi%(py19)s
{%(py19)s = %(py15)s
{%(py15)s = %(py13)s
{%(py13)s = %(py11)s.pr_url
}.startswith
}(%(py17)s)
})py11py13py15py17py19r$   zpr_url looks invalid: z
>assert %(py22)spy22)r   r   	run_epochrv   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_saferepr_format_assertmsgAssertionError_format_explanation
startswithappend_format_boolop)selfr   r   r   r   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert2@py_assert6@py_assert0@py_assert12@py_assert14@py_assert16@py_assert18@py_format10@py_format20@py_format21@py_format23s                        r0   test_pr_url_is_setz1TestBB1_OntologicalEpochWithPR.test_pr_url_is_set!  sw   %x}[_`f&&'9:;}}RDR}D(RRR}DRRRRRRvRRRvRRR}RRRDRRR*RRRRRRRR	
| 	
v}} 	
|}, 	
 	
0H0H 	
 	
0H0T 	
0T 	
 	
 	
|} 	
 	
 		  	
 	
	6	
 	
   & 	
 	
 		  & 	
 	
 		  - 	
 	
 	
	6	
		
 	
	6	
 	
  17 	
 	
 		 17 	
 	
 		 1> 	
 	
 		 1I 	
 	
 		 JT 	
 	
 		 1U 	
 	
	6	
		
 	
 	
  %V]]$56	
 	
 	
 	
 	
 	
 	
r2   c                .   t        |dd      \  }}t        |j                  d            }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  }t	        j                  d
|j                         dz   d|iz  }	t        t	        j                  |	            d x}x}}y )NrX   Tr   r   	pr_creater   z8%(py1)s in %(py5)s
{%(py5)s = %(py3)s.phases_completed
}r   py1r   r   z+'pr_create' should be in phases_completed: r   r   r   r   r   phases_completedr   r   r   r   r   r   r   r   r   
r   r   r   r   r   r   r   r   r   r   s
             r0   "test_pr_create_in_phases_completedzATestBB1_OntologicalEpochWithPR.test_pr_create_in_phases_completed*  s    %x}[_`f&&'9:; 	
f55 	
{55 	
 	
{5 	
 	
 		  	
 	
	6	
 	
  % 	
 	
 		 % 	
 	
 		 6 	
 	
  :&:Q:Q9RS	
 	
 	
 	
 	
 	
r2   c                .   t        |dd      \  }}t        |j                  d            }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  }t	        j                  d
|j                         dz   d|iz  }	t        t	        j                  |	            d x}x}}y )NrX   Tr   r   code_proposer   r   r   r   z4'code_propose' should be in phases for ontological: r   r   r   r   s
             r0   %test_code_propose_in_phases_completedzDTestBB1_OntologicalEpochWithPR.test_code_propose_in_phases_completed2      %x}[_`f&&'9:; 	
!8!8 	
~!88 	
 	
~!8 	
 	
 		  	
 	
	6	
 	
  "( 	
 	
 		 "( 	
 	
 		 "9 	
 	
  C6CZCZB[\	
 	
 	
 	
 	
 	
r2   c                .   t        |dd      \  }}t        |j                  d            }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  }t	        j                  d
|j                         dz   d|iz  }	t        t	        j                  |	            d x}x}}y )NrX   Tr   r   r   r   r   r   r   z4'shadow_arena' should be in phases for ontological: r   r   r   r   s
             r0   %test_shadow_arena_in_phases_completedzDTestBB1_OntologicalEpochWithPR.test_shadow_arena_in_phases_completed:  r   r2   c                   t        |dd      \  }}t        |j                  d            }dD ]  }|j                  }||v }|s t	        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  }t	        j                  d| d|j                         dz   d|iz  }	t        t	        j                  |	            dx}} y)z2Phases 1-5 are always present regardless of scope.rX   Tr   r   )conversation_aggregatescar_aggregateaxiom_distillknowledge_writer   r   z8%(py0)s in %(py4)s
{%(py4)s = %(py2)s.phases_completed
}phaser   r   r   py4zCore phase 'z' missing from 
>assert %(py6)spy6Nr   r   r   r   r   r   r   r   r   r   r   r   r   
r   r   r   r   r   r   r   r   @py_format5@py_format7s
             r0   test_core_phases_all_presentz;TestBB1_OntologicalEpochWithPR.test_core_phases_all_presentB  s0   %x}[_`f&&'9:;
 		E #33 533   53  v     I   v   #  I #  I 4    ug_V5L5L4MN    		r2   c                   t        |dd      \  }}t        |j                  d            }|j                  }d }||u}|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }t	        j                  d	      d
z   d|iz  }	t        t	        j                  |	            d x}x}}d}
|j                  }|
|k  }d}||k  }|r|st	        j
                  d||fd|
||f      t	        j                  |
      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }dd|iz  }t        t	        j                  |            d x}
x}x}x}}y )NrX   Tr   r   r   )z<%(py2)s
{%(py2)s = %(py0)s.shadow_pass_rate
} is not %(py5)sr   r   z.shadow_pass_rate should be set for ontologicalr   r           g      ?)<=r
  )z8%(py1)s <= %(py6)s
{%(py6)s = %(py4)s.shadow_pass_rate
}z8%(py6)s
{%(py6)s = %(py4)s.shadow_pass_rate
} <= %(py8)s)r   r   r  py8zassert %(py10)spy10)r   r   r   shadow_pass_rater   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   @py_assert5r   @py_assert7@py_format9@py_format11s                   r0   test_shadow_pass_rate_setz8TestBB1_OntologicalEpochWithPR.test_shadow_pass_rate_setR  s>   %x}[_`f&&'9:;&&ddd&d2ddd&dddddddvdddvddd&ddddddd4dddddddd4f--4s-444-44444s-444s444444f444f444-44444444444r2   Nr   r   )
__name__
__module____qualname____doc__r   r   r   r   r  r  rT   r2   r0   r   r     s#    T



 5r2   r   c                  X    e Zd ZdZddZddZddZddZddZddZ	ddZ
dd	Zdd
Zy)$TestBB2_EpistemicEpochNoCodeProposaluV   BB2: epistemic scope → no code_propose/shadow_arena/pr_create; tier1_update present.c                ,   t        |d      \  }}t        |j                  d            }|j                  }d }||u }|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }t	        j                  d|j                        d	z   d
|iz  }	t        t	        j                  |	            d x}x}}y )NrV   r   rb   r   isz.%(py2)s
{%(py2)s = %(py0)s.pr_url
} is %(py5)sr   r   z0pr_url should be None for epistemic scope, got: r   r   )r   r   r   rv   r   r   r   r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   s
             r0   test_pr_url_is_nonez8TestBB2_EpistemicEpochNoCodeProposal.test_pr_url_is_none]  s    %x{Kf&&'9:;}} 	
 	
}$ 	
 	
} 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		 !% 	
 	
  ?v}}>OP	
 	
 	
 	
 	
 	
r2   c                ,   t        |d      \  }}t        |j                  d            }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  }t	        j                  d	|j                         d
z   d|iz  }	t        t	        j                  |	            d x}x}}y )NrV   r  r   r   not inz<%(py1)s not in %(py5)s
{%(py5)s = %(py3)s.phases_completed
}r   r   z4'code_propose' should NOT be present for epistemic: r   r   r   r   s
             r0   test_no_code_propose_in_phaseszCTestBB2_EpistemicEpochNoCodeProposal.test_no_code_propose_in_phasese      %x{Kf&&'9:; 	
V%<%< 	
~%<< 	
 	
~%< 	
 	
 		  	
 	
	6	
 	
  &, 	
 	
 		 &, 	
 	
 		 &= 	
 	
  C6CZCZB[\	
 	
 	
 	
 	
 	
r2   c                ,   t        |d      \  }}t        |j                  d            }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  }t	        j                  d	|j                         d
z   d|iz  }	t        t	        j                  |	            d x}x}}y )NrV   r  r   r   r!  r#  r   r   z4'shadow_arena' should NOT be present for epistemic: r   r   r   r   s
             r0   test_no_shadow_arena_in_phaseszCTestBB2_EpistemicEpochNoCodeProposal.test_no_shadow_arena_in_phasesm  r%  r2   c                ,   t        |d      \  }}t        |j                  d            }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  }t	        j                  d	|j                         d
z   d|iz  }	t        t	        j                  |	            d x}x}}y )NrV   r  r   r   r!  r#  r   r   z1'pr_create' should NOT be present for epistemic: r   r   r   r   s
             r0   test_no_pr_create_in_phasesz@TestBB2_EpistemicEpochNoCodeProposal.test_no_pr_create_in_phasesu  s    %x{Kf&&'9:; 	
&"9"9 	
{"99 	
 	
{"9 	
 	
 		  	
 	
	6	
 	
  #) 	
 	
 		 #) 	
 	
 		 #: 	
 	
  @@W@W?XY	
 	
 	
 	
 	
 	
r2   c                ,   t        |d      \  }}t        |j                  d            }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  }t	        j                  d	|j                         d
z   d|iz  }	t        t	        j                  |	            d x}x}}y )NrV   r  r   tier1_updater   r   r   r   z$'tier1_update' should be in phases: r   r   r   r   s
             r0   test_tier1_update_in_phasesz@TestBB2_EpistemicEpochNoCodeProposal.test_tier1_update_in_phases}  s    %x{Kf&&'9:; 	
!8!8 	
~!88 	
 	
~!8 	
 	
 		  	
 	
	6	
 	
  "( 	
 	
 		 "( 	
 	
 		 "9 	
 	
  363J3J2KL	
 	
 	
 	
 	
 	
r2   c                   t        |d      \  }}t        |j                  d            }dD ]  }|j                  }||v }|s t	        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  }t	        j                  d
| d|j                         dz   d|iz  }	t        t	        j                  |	            d x}} y )NrV   r  r   )r   r   r   r   r   r+  r   r   r   r   r   zPhase 'z' missing from epistemic run: r  r  r  r  s
             r0   test_core_phases_presentz=TestBB2_EpistemicEpochNoCodeProposal.test_core_phases_present  s.   %x{Kf&&'9:;
 
	E #33 533   53  v     I   v   #  I #  I 4    % >v?V?V>WX    
	r2   c                    t        |d      \  }}t        |j                  d             |d   j                  j	                          y )NrV   r  r   r   )r   r   r   r   assert_not_calledr   r   r   r   s       r0   test_code_proposer_not_calledzBTestBB2_EpistemicEpochNoCodeProposal.test_code_proposer_not_called  s=    %x{KV012o&&88:r2   c                    t        |d      \  }}t        |j                  d             |d   j                  j	                          y )NrV   r  r   r   )r   r   r   r   r0  r1  s       r0   test_shadow_arena_not_calledzATestBB2_EpistemicEpochNoCodeProposal.test_shadow_arena_not_called  s=    %x{KV012n//AACr2   c                    t        |d      \  }}t        |j                  d             |d   j                  j	                          y )NrV   r  r   r   )r   r   r   r   r0  r1  s       r0   test_pr_creator_not_calledz?TestBB2_EpistemicEpochNoCodeProposal.test_pr_creator_not_called  s=    %x{KV012l%%779r2   Nr  )r  r  r  r  r  r$  r'  r)  r,  r.  r2  r4  r6  rT   r2   r0   r  r  Z  s3    `




 ;D:r2   r  c                  8    e Zd ZdZddZddZddZddZddZy)	TestBB3_RunEpochSafeLockHelduB   BB3: run_epoch_safe() with lock held → returns None immediately.c                   t        |d      \  }}t        |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  }t        j                  d|      dz   d	|iz  }t        t        j                  |            d x}}y )
NFr   r   r  z%(py0)s is %(py3)sr   r   r   z&Expected None when lock is held, got: 
>assert %(py5)sr   )r   r   run_epoch_safer   r   r   r   r   r   r   r   r   	r   r   r   r   r   r   r   @py_format4r   s	            r0    test_returns_none_when_lock_heldz=TestBB3_RunEpochSafeLockHeld.test_returns_none_when_lock_held  s    %xuMf++-.Rv~RRRvRRRRRRvRRRvRRRRRR!GzRRRRRRRr2   c                    t        |d      \  }}t        |j                                |d   j                  j	                          |d   j
                  j	                          y )NFr:  r   r   )r   r   r>  r   r0  r   r1  s       r0   !test_no_epoch_runs_when_lock_heldz>TestBB3_RunEpochSafeLockHeld.test_no_epoch_runs_when_lock_held  sS    %xuMV""$% 	l%%779k""446r2   c                R   t        |dd      \  }}t        |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  }t        j                  d      d	z   d
|iz  }t        t        j                  |            d x}}t        |t              }	|	s-t        j                  dt        |             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 )NTrV   r   r   rb   r   z%(py0)s is not %(py3)sr   r<  z-Expected an EpochResult when lock is acquiredr=  r   zExpected EpochResult, got 7
>assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}
isinstancer   r   r   r   r   )r   r   r>  r   r   r   r   r   r   r   r   r   rH  r   type)r   r   r   r   r   r   r   r@  r   r   r  s              r0   &test_returns_result_when_lock_acquiredzCTestBB3_RunEpochSafeLockHeld.test_returns_result_when_lock_acquired  s*   %xtS^_f++-.!RvT!RRRvTRRRRRRvRRRvRRRTRRR#RRRRRRR&+.[.[[2LTRX\N0[[[[[[[z[[[z[[[[[[&[[[&[[[[[[+[[[+[[[.[[[[[[r2   c                    t        |dd      \  }}t        |j                                |d   j                  j	                          y NTrV   rE  r   r   r   r>  r   assert_called_oncer1  s       r0   'test_lock_released_after_successful_runzDTestBB3_RunEpochSafeLockHeld.test_lock_released_after_successful_run  <    %xtS^_V""$%f002r2   c                    t        |dd      \  }}t        d      |d   j                  _        t	        |j                               }|d   j                  j                          y )NTrV   rE  z
DB crashedr   r   )r   RuntimeErrorr   side_effectr   r>  r   rO  r   r   r   r   r   s        r0    test_lock_released_even_on_errorz=TestBB3_RunEpochSafeLockHeld.test_lock_released_even_on_error  sZ    %xtS^_4@4Nl%%1 f++-. 	f002r2   Nr  )	r  r  r  r  rA  rC  rK  rP  rV  rT   r2   r0   r8  r8    s     LS7\3	3r2   r8  c                  @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
TestBB4_EpochLogWrittenzEBB4: Epoch log entry written to EPOCH_LOG_PATH with correct epoch_id.c                    t        |d      \  }}t        |j                  d             t        |j                        }|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}}y )NrV   r  r   zEpoch log not found at zC
>assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}log_filer   )r   r   r   r   r   existsr   r   r   r   r   r   r   r   )r   r   r   r   rZ  r   r   r  s           r0   test_log_file_createdz-TestBB4_EpochLogWritten.test_log_file_created  s    %x{KV012--.F F FF$;H:"FFFFFFFxFFFxFFFFFF FFFFFFr2   c                   t        |d      \  }}t        |j                  d             t        |j                        }|j                         j                         D cg c]#  }|j                         s|j                         % }}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         }|j(                  }d} ||      }d}||k(  }|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  }t        j                  d|j)                  d            dz   d|iz  }t!        t        j"                  |            d x}x}x}x}}y c c}w )NrV   r  r   r$   >=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)slenlinesr   r   r   r  zNo epoch log entries written
>assert %(py8)sr  r   r   ==zI%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get
}(%(py4)s)
} == %(py9)sentryr   r   r   r  r   epoch_id mismatch: 
>assert %(py11)sr   )r   r   r   r   r   	read_text
splitlinesstripr`  r   r   r   r   r   r   r   r   r   jsonloadsget)r   r   r   r   rZ  lnra  r   r  r   r  r  rg  r   r   @py_assert8r  r   @py_format12s                      r0   #test_log_entry_has_correct_epoch_idz;TestBB4_EpochLogWritten.test_log_entry_has_correct_epoch_id  s(   %x{KV012--.&.&8&8&:&E&E&GV288:VV5z>Q>zQ>>>zQ>>>>>>s>>>s>>>>>>5>>>5>>>z>>>Q>>> >>>>>>>>

58$yy 	
 	
y$ 	
(: 	
$(:: 	
 	
$(: 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		 $ 	
 	
 		 % 	
 	
 		 ); 	
 	
  "%))J"7!:;	
 	
 	
 	
 	
 	
	 Ws    K06K0c                B   t        |d      \  }}t        |j                  d             t        |j                        }t        j                  |j                         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   }
t%        |
t&              }|sddt        j                         v st        j                  t$              rt        j                  t$              ndt        j                  |
      dt        j                         v st        j                  t&              rt        j                  t&              ndt        j                  |      dz  }	t!        t        j"                  |	            d x}
}y )NrV   r  r   r   r   z%(py1)s in %(py3)srg  r   r   assert %(py5)sr   z5assert %(py5)s
{%(py5)s = %(py0)s(%(py2)s, %(py3)s)
}rH  list)r   r   r   r   )r   r   r   r   r   rn  ro  rk  rm  rl  r   r   r   r   r   r   r   r   rH  rz  )r   r   r   r   rZ  rg  r   r   r@  r   r   r   s               r0   #test_log_entry_has_phases_completedz;TestBB4_EpochLogWritten.test_log_entry_has_phases_completed  sA   %x{KV012--.

8--/557BBDRHI!*!U****!U***!******U***U******* 23:z3T::::::::z:::z:::3::::::T:::T::::::::::r2   c                   t        |d      \  }}t        |j                  d             t        |j                        }t        j                  |j                         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   }
t$        t&        f}t)        |
|      }|sddt        j                         v st        j                  t(              rt        j                  t(              ndt        j                  |
      t        j                  |      t        j                  |      d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 )NrV   r  r   rv  duration_secondsr   rw  rg  rx  ry  r   z5assert %(py6)s
{%(py6)s = %(py0)s(%(py2)s, %(py4)s)
}rH  r   r   r   r  r	  r^  )z%(py1)s >= %(py4)s)r   r   zassert %(py6)sr  )r   r   r   r   r   rn  ro  rk  rm  rl  r   r   r   r   r   r   r   r   intfloatrH  )r   r   r   r   rZ  rg  r   r   r@  r   r   r   r  r  r  s                  r0   test_log_entry_has_durationz3TestBB4_EpochLogWritten.test_log_entry_has_duration  s   %x{KV012--.

8--/557BBDRHI!*!U****!U***!******U***U******* 23Bc5\Bz3\BBBBBBBBzBBBzBBB3BBB\BBBBBBBBBB'(/C/(C////(C///(///C///////r2   c                (   t        |d      \  }}t        |j                  d             t        |j                        }t        j                  |j                         j                         j                         d         }|j                  d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(                  |j+                  dd            }|j,                  }	d }
|	|
u}|st        j.                  d|fd|	|
f      dt        j                         v st        j                  |      rt        j                   |      ndt        j                   |	      t        j                   |
      dz  }t        j                  d      dz   d|iz  }t#        t        j$                  |            d x}	x}}
y )NrV   r  r   rv  	timestamp z!timestamp field must not be emptyz
>assert %(py0)sr   tsZz+00:00r   )z2%(py2)s
{%(py2)s = %(py0)s.tzinfo
} is not %(py5)sdtr   z$timestamp must include timezone infor   r   )r   r   r   r   r   rn  ro  rk  rm  rl  rp  r   r   r   r   r   r   r   r   r   fromisoformatreplacetzinfor   )r   r   r   r   rZ  rg  r  @py_format1r  r   r   r   r   r   s                 r0   test_log_entry_has_timestampz4TestBB4_EpochLogWritten.test_log_entry_has_timestamp  sB   %x{KV012--.

8--/557BBDRHIYY{B'666666666r666r66666##BJJsH$=>yyLLy$LLLyLLLLLLrLLLrLLLyLLLLLL&LLLLLLLLr2   c                R   t        |d      \  }}t        |j                  d             t        |j                        }t        j                  |j                         j                         j                         d         }|j                  }d} ||      }d}	||	k(  }
|
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  }t        j"                  d|j                  d            dz   d|iz  }t%        t        j&                  |            d x}x}x}x}
}	y )NrV   r  r   rv  axioms_countrB   rd  rf  rg  rh  zExpected axioms_count=3, got rj  r   )r   r   r   r   r   rn  ro  rk  rm  rl  rp  r   r   r   r   r   r   r   r   r   )r   r   r   r   rZ  rg  r   r   r  rr  r  r   rs  s                r0   test_log_entry_axioms_countz3TestBB4_EpochLogWritten.test_log_entry_axioms_count
  ss   %x{KV012--.

8--/557BBDRHI yy 	
 	
y( 	
A 	
(A- 	
 	
(A 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		 ( 	
 	
 		 ) 	
 	
 		 -. 	
 	
  ,EIIn,E+HI	
 	
 	
 	
 	
 	
r2   Nr  )
r  r  r  r  r\  rt  r{  r  r  r  rT   r2   r0   rX  rX    s%    OG
;	0
M

r2   rX  c                  0    e Zd ZdZddZddZddZddZy)TestWB1_SequentialExecutionzBWB1: Phase execution is sequential (mock call order verification).c                   t        |d      \  }}g fd|d   j                  _        fd|d   j                  _        t	        |j                  d             j                  }d} ||      }j                  }d} ||      }	||	k  }
|
sWt        j                  d|
fd	||	f      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
t        j                  |      t        j                  |      t        j                  |	      dz  }t        j                  d       dz   d|iz  }t        t        j                  |            d x}x}x}x}
x}x}}	y )NrV   r  c                 >    j                  d      xs
 t               S Nr   r   rM   kw
call_orders    r0   <lambda>zUTestWB1_SequentialExecution.test_aggregator_called_before_distiller.<locals>.<lambda>$      **<8R<P<R r2   r   c                 >    j                  d      xs
 t               S Nr   r   r>   ar  r  s     r0   r  zUTestWB1_SequentialExecution.test_aggregator_called_before_distiller.<locals>.<lambda>'      Z..{;Z?X?Z r2   r   r   <z%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.index
}(%(py4)s)
} < %(py14)s
{%(py14)s = %(py10)s
{%(py10)s = %(py8)s.index
}(%(py12)s)
}r  r   r   r   r  r  r  py12py14z3aggregator must be called before distiller; order: 
>assert %(py16)spy16)r   r   rT  r   r   r   indexr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  @py_assert9@py_assert11@py_assert13r  @py_format15@py_format17r  s                @r0   'test_aggregator_called_before_distillerzCTestWB1_SequentialExecution.test_aggregator_called_before_distiller  s   %x{K "
R 	l%%1 [ 	k"". 	V012 	
 	
- 	

0@0@ 	
 	
0@0M 	
-0MM 	
 	
 	
-0M 	
 	
	6	
 	
   	
 	
 		  	
 	
 		   	
 	
 		 !- 	
 	
 		 . 	
 	
	6	
 	
  1; 	
 	
 		 1; 	
 	
 		 1A 	
 	
 		 BM 	
 	
 		 1N 	
 	
  B*N	
 	
 	
 	
 	
 	
 	
r2   c                   t        |d      \  }}g fd|d   j                  _        fd|d   j                  _        t	        |j                  d             j                  }d} ||      }j                  }d} ||      }	||	k  }
|
sWt        j                  d|
fd	||	f      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
t        j                  |      t        j                  |      t        j                  |	      dz  }t        j                  d       dz   d|iz  }t        t        j                  |            d x}x}x}x}
x}x}}	y )NrV   r  c                 >    j                  d      xs
 t               S r  r  r  s     r0   r  z[TestWB1_SequentialExecution.test_distiller_called_before_knowledge_writer.<locals>.<lambda>5  r  r2   r   c                 >    j                  d      xs
 t               S Nr   r   r   r  s     r0   r  z[TestWB1_SequentialExecution.test_distiller_called_before_knowledge_writer.<locals>.<lambda>8      Z../ABZFXFZ r2   r   r   r  r  r  r  z0distiller must precede knowledge_writer; order: r  r  )r   r   rT  r   r   r   r  r   r   r   r   r   r   r   r   r   r  s                @r0   -test_distiller_called_before_knowledge_writerzITestWB1_SequentialExecution.test_distiller_called_before_knowledge_writer0  s   %x{K "
Z 	k"". [ 	 !''3 	V012 	
 	
, 	
z/?/? 	
@R 	
/?@R/S 	
,/SS 	
 	
 	
,/S 	
 	
	6	
 	
   	
 	
 		  	
 	
 		   	
 	
 		 !, 	
 	
 		 - 	
 	
	6	
 	
  0: 	
 	
 		 0: 	
 	
 		 0@ 	
 	
 		 AS 	
 	
 		 0T 	
 	
  ?zlK	
 	
 	
 	
 	
 	
 	
r2   c                   t        |d      \  }}g fd|d   j                  _        fd|d   j                  _        t	        |j                  d             j                  }d} ||      }j                  }d} ||      }	||	k  }
|
sWt        j                  d|
fd	||	f      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
t        j                  |      t        j                  |      t        j                  |	      dz  }t        j                  d       dz   d|iz  }t        t        j                  |            d x}x}x}x}
x}x}}	y )NrV   r  c                 >    j                  d      xs
 t               S r  r  r  s     r0   r  z_TestWB1_SequentialExecution.test_meta_architect_called_after_knowledge_writer.<locals>.<lambda>F  r  r2   r   c                 >    j                  d      xs
 t               S Nr   r   rc   r  s    r0   r  z_TestWB1_SequentialExecution.test_meta_architect_called_after_knowledge_writer.<locals>.<lambda>I      **+;<P@P r2   r   r   r  r  r  r  z5knowledge_writer must precede meta_architect; order: r  r  )r   r   rT  r   r   r   r  r   r   r   r   r   r   r   r   r   r  s                @r0   1test_meta_architect_called_after_knowledge_writerzMTestWB1_SequentialExecution.test_meta_architect_called_after_knowledge_writerA  s   %x{K "
Z 	 !''3 Q 	''3 	V012 	
 2 	
 23 	
j6F6F 	
GW 	
6FGW6X 	
36XX 	
 	
 	
36X 	
 	
	6	
 	
   	
 	
 		  	
 	
 		   	
 	
 		 !3 	
 	
 		 4 	
 	
	6	
 	
  7A 	
 	
 		 7A 	
 	
 		 7G 	
 	
 		 HX 	
 	
 		 7Y 	
 	
  DJ<P	
 	
 	
 	
 	
 	
 	
r2   c                   t        |d      \  }}g fd|d   j                  _        fd|d   j                  _        t	        |j                  d             j                  }d} ||      }j                  }d} ||      }	||	k  }
|
sWt        j                  d|
fd	||	f      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
t        j                  |      t        j                  |      t        j                  |	      dz  }t        j                  d       dz   d|iz  }t        t        j                  |            d x}x}x}x}
x}x}}	y )NrV   r  c                 >    j                  d      xs
 t               S r  r  r  s    r0   r  z\TestWB1_SequentialExecution.test_tier1_trigger_called_after_meta_architect.<locals>.<lambda>W  r  r2   r   c                 >    j                  d      xs
 t               S )Nr   )r   r   r  s     r0   r  z\TestWB1_SequentialExecution.test_tier1_trigger_called_after_meta_architect.<locals>.<lambda>Z  s    Z..?]C[C] r2   r   r   r  r  r  r  z2meta_architect must precede tier1_trigger; order: r  r  )r   r   rT  r   r   r   r  r   r   r   r   r   r   r   r   r   r  s                @r0   .test_tier1_trigger_called_after_meta_architectzJTestWB1_SequentialExecution.test_tier1_trigger_called_after_meta_architectR  s   %x{K "
P 	''3 ^ 	o$$0 	V012 	
 0 	
 01 	
J4D4D 	
_ 	
4D_4U 	
14UU 	
 	
 	
14U 	
 	
	6	
 	
   	
 	
 		  	
 	
 		   	
 	
 		 !1 	
 	
 		 2 	
 	
	6	
 	
  5? 	
 	
 		 5? 	
 	
 		 5E 	
 	
 		 FU 	
 	
 		 5V 	
 	
  AM	
 	
 	
 	
 	
 	
 	
r2   Nr  )r  r  r  r  r  r  r  r  rT   r2   r0   r  r    s    L
"
"
"
r2   r  c                  (    e Zd ZdZddZddZddZy)TestWB2_LockAcquireAndReleasez?WB2: Lock acquired before run_epoch; released in finally block.c                   t        |dd      \  }}g fd|d   j                  _        fd|d   j                  _        t	        |j                                j                  }d} ||      }j                  }d} ||      }	||	k  }
|
sWt        j                  d	|
fd
||	f      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t        j                  |      t        j                  |      t        j                  |	      dz  }t        j                  d       dz   d|iz  }t        t        j                  |            d x}x}x}x}
x}x}}	y )NTrV   rE  c                .    j                  d      xs dS )Nlock.acquireT)r   )r   r  s    r0   r  zTTestWB2_LockAcquireAndRelease.test_lock_acquired_before_aggregator.<locals>.<lambda>l  s    Z..~>F$ r2   r   c                 >    j                  d      xs
 t               S r  r  r  s    r0   r  zTTestWB2_LockAcquireAndRelease.test_lock_acquired_before_aggregator.<locals>.<lambda>o  r  r2   r   r  r  r  r  r  z-lock.acquire must precede aggregator; order: r  r  )r   r   rT  r   r   r>  r  r   r   r   r   r   r   r   r   r   r  s                @r0   $test_lock_acquired_before_aggregatorzBTestWB2_LockAcquireAndRelease.test_lock_acquired_before_aggregatorg  s   %xtS^_ "
F 	f) S 	l%%1 	V""$% 	
 	
/ 	
*2B2B 	
< 	
2B<2P 	
/2PP 	
 	
 	
/2P 	
 	
	6	
 	
   	
 	
 		  	
 	
 		   	
 	
 		 !/ 	
 	
 		 0 	
 	
	6	
 	
  3= 	
 	
 		 3= 	
 	
 		 3C 	
 	
 		 DP 	
 	
 		 3Q 	
 	
  <J<H	
 	
 	
 	
 	
 	
 	
r2   c                    t        |dd      \  }}t        |j                                |d   j                  j	                          y rM  rN  r1  s       r0   test_lock_released_after_epochz<TestWB2_LockAcquireAndRelease.test_lock_released_after_epochx  rQ  r2   c                    t        |dd      \  }}t        d      |d   j                  _        t	        |j                               }|d   j                  j                          y)zCLock must be released even if a phase raises an uncaught exception.TrV   rE  OOMr   r   N)r   MemoryErrorr   rT  r   r>  r   rO  rU  s        r0   %test_lock_released_on_phase_exceptionzCTestWB2_LockAcquireAndRelease.test_lock_released_on_phase_exception~  sZ    %xtS^_1<U1Ck"". f++-. 	f002r2   Nr  )r  r  r  r  r  r  r  rT   r2   r0   r  r  d  s    I
"3
3r2   r  c                  .    e Zd ZdZd ZddZddZddZy)TestWB3_AsyncTimeoutUsedzCWB3: asyncio.wait_for with 7200s timeout is used in run_epoch_safe.c                   ddl m} d}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        j                  d|       d	z   d
|iz  }t        t        j                  |            d x}}y )Nr   )_EPOCH_TIMEOUT_SECONDS   rd  z%(py0)s == %(py3)sr  r<  zExpected 7200s timeout, got r=  r   )core.epoch.epoch_runnerr  r   r   r   r   r   r   r   r   r   )r   r  r   r   r@  r   s         r0   test_timeout_constant_is_7200z6TestWB3_AsyncTimeoutUsed.test_timeout_constant_is_7200  s    B)- 	
%- 	
 	
% 	
 	
	6	
 	
  & 	
 	
 		 & 	
 	
 		 *. 	
 	
  ++A*BC	
 	
 	
 	
 	
r2   c                   t        |dd      \  }}t        dt        j                        5 }t	        |j                                ddd       j                          |j                  }|j                  }|j                  }d|v r|d   }nt        |      dk\  r|d	   }nd}d
}	||	k(  }
|
st        j                  d|
fd||	f      dt        j                         v st        j                  |      rt        j                   |      ndt        j                   |	      dz  }t        j"                  d|d|      dz   d|iz  }t%        t        j&                  |            dx}
}	y# 1 sw Y   !xY w)zGPatch asyncio.wait_for to verify it is called with the correct timeout.TrV   rE  (core.epoch.epoch_runner.asyncio.wait_for)wrapsNtimeoutrP   r$   r  rd  r  timeout_valr<  z9asyncio.wait_for should be called with timeout=7200, got z. call_args=r=  r   )r   r   r   wait_forr   r>  rO  	call_argsargskwargsr`  r   r   r   r   r   r   r   r   r   )r   r   r   r   mock_wait_forr  
positionalkeywordr  r   r   r@  r   s                r0   test_timeout_appliedz-TestWB3_AsyncTimeoutUsed.test_timeout_applied  s`   %xtS^_=WEUEUV 	*Zg&&()	* 	((*!++	^^
"" !),K_!$Q-KK" 	
{d" 	
 	
{d 	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
	 # 	
 	
  H W"'	
 	
 	
 	
 	
!	* 	*s   E&&E0c                <   t        |dd      \  }}t        dt        j                               5  t	        |j                               }ddd       d}|u }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      d
z  }t        j                  d|      dz   d|iz  }t        t        j                  |            dx}}y# 1 sw Y   xY w)z;Simulate asyncio.TimeoutError: run_epoch_safe returns None.TrV   rE  r  rT  Nr  r;  r   r<  zExpected None on timeout, got r=  r   )r   r   r   TimeoutErrorr   r>  r   r   r   r   r   r   r   r   r   r?  s	            r0   +test_run_epoch_safe_returns_none_on_timeoutzDTestWB3_AsyncTimeoutUsed.test_run_epoch_safe_returns_none_on_timeout  s    %xtS^_=7K_K_Kab 	3&//12F	3 Jv~JJJvJJJJJJvJJJvJJJJJJ!?zJJJJJJJ	3 	3s   DDc                    t        |dd      \  }}t        dt        j                               5  t	        |j                                ddd       |d   j                  j                          y# 1 sw Y   'xY w)z6Lock is released even when asyncio.TimeoutError fires.TrV   rE  r  r  Nr   )r   r   r   r  r   r>  r   rO  r1  s       r0   test_lock_released_on_timeoutz6TestWB3_AsyncTimeoutUsed.test_lock_released_on_timeout  sg    %xtS^_=7K_K_Kab 	*&&()	* 	f002	* 	*s   A11A:Nr  )r  r  r  r  r  r  r  r  rT   r2   r0   r  r    s    M

2K3r2   r  c                  0    e Zd ZdZddZddZddZddZy)!TestWB4_PhaseFailurePartialResultuG   WB4: Phase failure mid-run → success=False, partial phases_completed.c                `   t        |d      \  }}t        d      |d   j                  _        t	        |j                  d            }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}}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 )NrV   r  zDB downr   r   r   r!  r#  r   r   assert %(py7)sr   5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}rH  r   rI  )r   rS  r   rT  r   r   r   r   r   r   r   r   r   r   r   rH  r   )r   r   r   r   r   r   r   r   r   r   r   r  s               r0   7test_conversation_aggregate_failure_does_not_block_restzYTestWB4_PhaseFailurePartialResult.test_conversation_aggregate_failure_does_not_block_rest  sA   %x{K4@4Kl%%1f&&'9:; (Fv/F/FF'/FFFFF'/FFFF'FFFFFFvFFFvFFF/FFFFFFFF &+........z...z......&...&......+...+..........r2   c                   t        |d      \  }}t        d      |d   j                  _        t	        |j                  d            }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}}|j                  }
g }|
|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z   d|iz  }	t        t        j                  |	            d x}
x}}y )NrV   r  zLLM unavailabler   r   r   r!  r#  r   r   r  r   rd  )z.%(py2)s
{%(py2)s = %(py0)s.axioms
} == %(py5)sr   z0Expected empty axioms on distiller failure, got r   )r   rS  r   rT  r   r   r   r   r   r   r   r   r   r   r   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   s               r0   *test_distiller_failure_leaves_empty_axiomszLTestWB4_PhaseFailurePartialResult.test_distiller_failure_leaves_empty_axioms  s;   %x{K1=>O1Pk"".f&&'9:;=f&=&==&=====&==========f===f===&========}}ff}"fff}ffffffvfffvfff}ffffff&VW]WdWdVe$ffffffffr2   c                >   t        |dd      \  }}t        d      |d   j                  _        t	        |j                  d            }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 )NrX   Tr   zAnalysis failedr   r   r!  r#  r   r   r  r   r   r   )r   rS  r   rT  r   r   r   r   r   r   r   r   r   r   r   r   s
             r0   4test_meta_architect_failure_skips_ontological_phaseszVTestWB4_PhaseFailurePartialResult.test_meta_architect_failure_skips_ontological_phases  s   %x}[_`6BCT6U''3f&&'9:;  >v'>'>>'>>>>>'>>>>>>>>>>v>>>v>>>'>>>>>>>><V%<%<<~%<<<<<~%<<<<~<<<<<<V<<<V<<<%<<<<<<<<9&"9"99{"99999{"9999{999999&999&999"99999999r2   c                v   t        |dd      \  }}t        |j                  d            }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  }t	        j                  d
      dz   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  }t	        j                  d|j                         dz   d|iz  }	t        t	        j                  |	            dx}x}}|j                  }
d}|
|u }|st	        j
                  d|fd|
|f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |
      t	        j                  |      dz  }dd|iz  }	t        t	        j                  |	            dx}
x}}y)uA   Arena not passing → no PR created, but tier1_update still runs.rX   Fr   r   r   r!  r#  r   r   z(No PR should be created when arena failsr   r   Nr+  r   r   z0tier1_update should still run when arena fails: r  r  r   r  )r   r   r   r   r   r   r   r   r   r   r   r   r   rv   r  s               r0   ,test_arena_fail_prevents_pr_but_allows_tier1zNTestWB4_PhaseFailurePartialResult.test_arena_fail_prevents_pr_but_allows_tier1  s&   %x}[`af&&'9:; 	
&"9"9 	
{"99 	
 	
{"9 	
 	
 		  	
 	
	6	
 	
  #) 	
 	
 		 #) 	
 	
 		 #: 	
 	
  7	
 	
 	
 	
 	
  	
!8!8 	
~!88 	
 	
~!8 	
 	
 		  	
 	
	6	
 	
  "( 	
 	
 		 "( 	
 	
 		 "9 	
 	
  ?v?V?V>WX	
 	
 	
 	
 	
 }}$$}$$$$}$$$$$$v$$$v$$$}$$$$$$$$$$r2   Nr  )r  r  r  r  r  r  r  r  rT   r2   r0   r  r    s    Q/g	:%r2   r  c                .   t        | d      \  }}t        |j                  d            }|j                  }d}||k(  }|st	        j
                  d|fd||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }t	        j                  d|j                        d	z   d
|iz  }t        t	        j                  |            dx}x}}y)z>EpochResult.epoch_id matches the epoch_id passed to run_epoch.rV   r  epoch_2026_03_01rd  )z0%(py2)s
{%(py2)s = %(py0)s.epoch_id
} == %(py5)sr   r   ri  r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   	r   r   r   r   r   r   r   r   r   s	            r0   $test_epoch_result_epoch_id_preservedr    s    !8;GMFE&""#567F?? 0 ?00  ?0                  1    foo01     r2   c                    t         j                  } d} | |      }|st        j                  dt               dz   dt	        j
                         v st        j                  t               rt        j                  t               ndt        j                  |       t        j                  |      t        j                  |      dz  }t        t        j                  |            dx} x}}t         j                  } d} | |      }|st        j                  dt               d	z   dt	        j
                         v st        j                  t               rt        j                  t               ndt        j                  |       t        j                  |      t        j                  |      dz  }t        t        j                  |            dx} x}}y)
z'EPOCH_LOG_PATH constant is on E: drive.z/mnt/e/z)EPOCH_LOG_PATH must be on E: drive, got: zN
>assert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r   r~  Nr   5EPOCH_LOG_PATH should end with epoch_log.jsonl, got: L
>assert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
})r   r   r   r   r   r   r   r   r   r   endswith)r   r   r  r  s       r0   test_epoch_log_path_constantr     s   $$ Y $Y/ /   4N3EF             %    &/    0      "" #4 "#45 5   @?QR             #    $5    6      r2   c                    ddl m} 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  }t        j                  d      d	z   d
|iz  }t        t        j                  |            d}t        |t              }|s!t        j                  d      dz   dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      dz  }t        t        j                  |            d}|j                  }d} ||      }|st        j                  d|      dz   dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}}y)z;core.epoch __init__ exports EpochRunner and EPOCH_LOG_PATH.r   r   r  )z%(py0)s is %(py2)sERr   )r   r   z+EpochRunner not re-exported from core.epochz
>assert %(py4)sr   Nz!EPOCH_LOG_PATH should be a stringrG  rH  ELPr   rI  r   r  r  r~  )
core.epochr   r   r   r   r   r   r   r   r   r   r   rH  r   r  )r  r  r   @py_format3r  r   r  r  s           r0   test_package_init_exportsr    s   CKKK2KKKKKK2KKK2KKKKKKKKKKKKKKKKKKKKc3DDD!DDDDDDD:DDD:DDDDDDcDDDcDDDDDD3DDD3DDDDDDDDD<< ) <)* *   @wG                 *    +      r2   c                ~   t        | d      \  }}t        t        d      d      |d   j                  _        t        |j                  d            }|j                  }d}||k(  }|st        j                  d|fd	||f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      t        j                  |      dz  }t        j                  d|j                        dz   d|iz  }t        t        j                   |            dx}x}}y)z<EpochResult.week_summary comes from the distillation result.rV   r  rP   z&Special week: 42 sessions, 0 failures.r9   r   r   rd  )z4%(py2)s
{%(py2)s = %(py0)s.week_summary
} == %(py5)sr   r   zweek_summary not propagated: r   r   N)r   r   r7   r   r   r   r   r;   r   r   r   r   r   r   r   r   r   r  s	            r0   &test_week_summary_propagated_to_resultr    s   !8;GMFE.@A=/E++
 &""#567F "J "JJ  "J                  #K    ((;(;'>?     r2   c                   t        | d      \  }}t        dddd      |d   j                  _        t	        |j                  d	            }d
}|j                  }||k(  }|s t        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dz  }t        j                  d| d|j                         dz   d|iz  }t        t        j                  |            dx}}y)zCtier1_updates in EpochResult reflects counts from Tier1EpochResult.rV   r  rO   rB   rP   r$   r{   r   r      rd  )z5%(py2)s
{%(py2)s = %(py0)s.tier1_updates
} == %(py4)sr   expectedr   zExpected tier1_updates=, got r  r  N)r   r   r   r   r   r   tier1_updatesr   r   r   r   r   r   r   r   r   )	r   r   r   r   r  r   r   r  r  s	            r0   !test_tier1_update_count_in_resultr  &  sB   !8;GMFE0@!"	1E/  - &""#567F H 8+   8                     $,    $,    "(6&2F2F1GH    r2   c                    t        | d      \  }}t        |j                  d             |d   j                  j	                          y)z=report_generator.generate() is called exactly once per epoch.rV   r  r   r   N)r   r   r   r   rO  )r   r   r   s      r0   test_report_generator_calledr  9  s>    !8;GMFE		,	-.	
&&99;r2   c                ^   t        | d      \  }}t        |j                  d             t        |j                  d             t        |j                        }|j                         j                         D cg c]#  }|j                         s|j                         % }}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t        |             dz   d|	iz  }
t!        t        j"                  |
            dx}x}}|D cg c]  }t%        j&                  |      d    }}ddg}||k(  }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }t!        t        j"                  |            dx}}yc c}w c c}w )z:Multiple run_epoch calls each append a separate log entry.rV   r  r   epoch_2026_02_26rP   rd  )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr`  ra  rb  zExpected 2 log entries, got rc  r  Nr   r  idsr<  ry  r   )r   r   r   r   r   rk  rl  rm  r`  r   r   r   r   r   r   r   r   r   rn  ro  )r   r   r   rZ  rq  ra  r   r  r   r  r  r  r   r@  r   s                  r0   "test_multiple_log_entries_appendedr  A  s   !8;GMFE		,	-.		,	-.F))*H"*"4"4"6"A"A"CRBrxxzRXXZRERu:GG:?GGG:GGGGGG3GGG3GGGGGGuGGGuGGG:GGGGGG:3u:,GGGGGGGG05
6"4::b>*%
6C
6%'9::3:::::3:::::::3:::3:::::::::::	 S 7s   :J%J%J*c                @   t        | dd      \  }}t        |j                               }t        j                  t
        j                        j                  d      }d| }d}||u}|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      d
z  }dd|iz  }	t        t        j                  |	            dx}}|j                   }||k(  }
|
s t        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dz  }t        j"                  d|d|j                         dz   d|iz  }t        t        j                  |            dx}}
y)z8run_epoch_safe() generates epoch_id as epoch_YYYY_MM_DD.TrV   rE  z%Y_%m_%depoch_Nr   rF  r   r<  ry  r   rd  )z0%(py2)s
{%(py2)s = %(py0)s.epoch_id
} == %(py4)sexpected_epoch_idr   zExpected epoch_id=r  r  r  )r   r   r>  r   rK   r   rL   strftimer   r   r   r   r   r   r   r   r   r   )r   r   r   r   todayr  r   r   r@  r   r   r  r  s                r0   0test_run_epoch_safe_generates_epoch_id_from_dater  P  s   !84{[MFE&'')*FLL&//
;E (6666?? ?//   ?/                    0    0    .17JK    r2   c                   t        | d      \  }}d|_        t        dt        d            5  t	        |j                  d            }ddd       t        t              }|sd	d
t        j                         v st        j                  t              rt        j                  t              nd
dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      dz  }t        t        j                  |            d}y# 1 sw Y   +xY w)z<OSError during epoch log write must not propagate to caller.rV   r  z3/mnt/e/this/does/not/exist/readonly/epoch_log.jsonlzos.makedirszPermission deniedr  r   Nr  rH  r   r   rI  )r   r   r   OSErrorr   r   rH  r   r   r   r   r   r   r   r   )r   r   r   r   r   r  s         r0   ,test_oserror_on_log_write_does_not_propagater  ^  s    !8;GMFE RF	}'2E*F	G <f&&'9:;< fk********:***:******f***f******k***k**********	< <s   E22E<__main__c                 <    t        t        j                               S N)r   tempfilemkdtemprT   r2   r0   _tmpr#  t  s    H$$&''r2   z*BB1: pr_url set for ontological+arena_passc                 D    t               j                  t                     S r   )r   r   r#  rT   r2   r0   r  r  y  s    ?]?_?r?rswsy?z r2   zBB1: pr_create in phasesc                 D    t               j                  t                     S r   )r   r   r#  rT   r2   r0   r  r  z  s    -K-M-p-pquqw-x r2   zBB1: code_propose in phasesc                 D    t               j                  t                     S r   )r   r   r#  rT   r2   r0   r  r  {      0N0P0v0vw{w}0~ r2   zBB1: shadow_arena in phasesc                 D    t               j                  t                     S r   )r   r   r#  rT   r2   r0   r  r  |  r'  r2   zBB1: core phases presentc                 D    t               j                  t                     S r   )r   r  r#  rT   r2   r0   r  r  }  s    -K-M-j-jkokq-r r2   zBB1: shadow_pass_rate setc                 D    t               j                  t                     S r   )r   r  r#  rT   r2   r0   r  r  ~  s    .L.N.h.himio.p r2   z!BB2: pr_url is None for epistemicc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s    6Z6\6p6pquqw6x r2   z"BB2: no code_propose for epistemicc                 D    t               j                  t                     S r   )r  r$  r#  rT   r2   r0   r  r    $    7[7]7|7|  ~B  ~D  8E r2   z"BB2: no shadow_arena for epistemicc                 D    t               j                  t                     S r   )r  r'  r#  rT   r2   r0   r  r    r-  r2   zBB2: no pr_create for epistemicc                 D    t               j                  t                     S r   )r  r)  r#  rT   r2   r0   r  r    s    4X4Z4v4vw{w}4~ r2   zBB2: tier1_update in phasesc                 D    t               j                  t                     S r   )r  r,  r#  rT   r2   r0   r  r    s    0T0V0r0rswsy0z r2   z BB3: returns None when lock heldc                 D    t               j                  t                     S r   )r8  rA  r#  rT   r2   r0   r  r    s    5Q5S5t5tuyu{5| r2   z!BB3: no epoch runs when lock heldc                 D    t               j                  t                     S r   )r8  rC  r#  rT   r2   r0   r  r    s    6R6T6v6vw{w}6~ r2   z&BB3: returns result when lock acquiredc                 D    t               j                  t                     S r   )r8  rK  r#  rT   r2   r0   r  r    s*    ;W;Y  <A  <A  BF  BH  <I r2   zBB3: lock released after runc                 D    t               j                  t                     S r   )r8  rP  r#  rT   r2   r0   r  r    s    1M1O1w1wx|x~1 r2   zBB3: lock released on errorc                 D    t               j                  t                     S r   )r8  rV  r#  rT   r2   r0   r  r    s    0L0N0o0optpv0w r2   zBB4: log file createdc                 D    t               j                  t                     S r   )rX  r\  r#  rT   r2   r0   r  r    s    *A*C*Y*YZ^Z`*a r2   zBB4: log epoch_id correctc                 D    t               j                  t                     S r   )rX  rt  r#  rT   r2   r0   r  r    s    .E.G.k.klplr.s r2   zBB4: log has phases_completedc                 D    t               j                  t                     S r   )rX  r{  r#  rT   r2   r0   r  r    s    2I2K2o2optpv2w r2   zBB4: log has durationc                 D    t               j                  t                     S r   )rX  r  r#  rT   r2   r0   r  r    s    *A*C*_*_`d`f*g r2   zBB4: log has timestampc                 D    t               j                  t                     S r   )rX  r  r#  rT   r2   r0   r  r    s    +B+D+a+abfbh+i r2   zBB4: log axioms_count=3c                 D    t               j                  t                     S r   )rX  r  r#  rT   r2   r0   r  r    s    ,C,E,a,abfbh,i r2   z WB1: aggregator before distillerc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s     5P5R5z5z{  |B  6C r2   z&WB1: distiller before knowledge_writerc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s*    ;V;X  <G  <G  HL  HN  <O r2   z+WB1: knowledge_writer before meta_architectc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s-    @[@]  AP  AP  QU  QW  AX r2   z WB1: meta_architect before tier1c                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s*    5P5R  6B  6B  CG  CI  6J r2   z$WB2: lock acquired before aggregatorc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s$    9V9X9}9}  C  E  :F r2   zWB2: lock released after epochc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s    3P3R3q3qrvrx3y r2   zWB2: lock released on exceptionc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s     4Q4S4y4yz~  {A  5B r2   zWB3: timeout constant is 7200zWB3: timeout appliedc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s    )A)C)X)XY]Y_)` r2   zWB3: None on timeoutc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s    )A)C)o)optpv)w r2   zWB3: lock released on timeoutc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s    2J2L2j2jkokq2r r2   z&WB4: phase failure does not block restc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s*    ;\;^  <W  <W  X\  X^  <_ r2   z#WB4: distiller failure empty axiomsc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s*    8Y8[  9G  9G  HL  HN  9O r2   z-WB4: meta_architect failure skips ontologicalc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s-    BcBe  C[  C[  \`  \b  Cc r2   u(   WB4: arena fail → no PR but tier1 runsc                 D    t               j                  t                     S r   )r  r  r#  rT   r2   r0   r  r    s*    =^=`  >N  >N  OS  OU  >V r2   zEDGE: epoch_id preservedc                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    -QRVRX-Y r2   z EDGE: EPOCH_LOG_PATH on E: drivezEDGE: package exportszEDGE: week_summary propagatedc                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    2XY]Y_2` r2   zEDGE: tier1_updates sum correctc                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    4UVZV\4] r2   z"EDGE: report_generator called oncec                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    7STXTZ7[ r2   zEDGE: multiple log entriesc                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    /QRVRX/Y r2   z'EDGE: run_epoch_safe epoch_id from datec                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    <lmqms<t r2   z-EDGE: OSError on log write does not propagatec                 (    t        t                     S r   )r  r#  rT   r2   r0   r  r    s    BnosouBv r2   z	  [PASS] z	  [FAIL] z: 
/z tests passedz(ALL TESTS PASSED -- Story 9.02 (Track B))r$   )r/   r  returnr   )rB   )r5   r  rS  zlist[Axiom])r=   r  rS  r   )rS  r#   )rS  r"   )rV   )rb   r   rS  r   )rS  r   )Tr   )rr   boolrm   r  rS  r   )z'https://github.com/genesis/repo/pull/42)rv   r   rS  r   )rS  r   )r   )r   r   rS  r    )rS  r   )
r   r   rb   r   r   rT  r   rT  rS  ztuple[EpochRunner, dict]r  )rS  r   )gr  
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   r   rn  ossysr!  r   r   pathlibr   typingr   unittest.mockr   r	   r
   r   pytestGENESIS_ROOTpathinsertr  r   r   !core.epoch.epoch_report_generatorr   core.epoch.axiom_distillerr   r   !core.epoch.epoch_knowledge_writerr   core.epoch.epoch_tier1_triggerr   core.evolution.meta_architectr   r   core.evolution.code_proposerr   core.evolution.shadow_arenar    core.evolution.gitops_pr_creatorr   'core.evolution.tier1_autonomous_updaterr   r    core.evolution.scar_aggregatorr"   "core.epoch.conversation_aggregatorr#   r1   r7   r>   rM   rU   rc   rj   rs   ry   r   r   r   r   r   r   r  r8  rX  r  r  r  r  r  r   r  r  r  r  r  r  r  r  	tracebackr#  r  test_fnsrr   r`  totalnamefnprint	Exceptionexc	print_excexitrT   r2   r0   <module>rx     s  . #     	 
  '   ; ;  'sxxHHOOA|$ @ 9 @ 9 ; J 5 3 5 ? 9 5 H5	J$ <  ZZ Z 	Z
 Z Zz=95 95xK: K:\'3 '3TB
 B
TE
 E
P$3 $3N23 23j0% 0%p&<;+$ z(8	57z{8 
$%xy8 
'(~	8
 
'(~8 
$%rs8 
%&pq8 
-.xy8 
.  0E  	F8 
.  0E  	F8 
+,~8 
'(z{8 
,-|}8  
-.~!8" 
2  4I  	J#8$ 
()  	A%8& 
'(wx'8* 
!"ab+8, 
%&st-8. 
)*wx/80 
!"gh182 
"#ij384 
#$ij588 
,  .C  	D98: 
2  4O  	P;8< 
7  9X  	Y=8> 
,  .J  	K?8B 
0  2F  	GC8D 
*+yzE8F 
+  -B  	CG8J 
)*B*D*b*bcK8L 
 !`aM8N 
 !wxO8P 
)*rsQ8T 
2  4_  	`U8V 
/  1O  	PW8X 
9  ;c  	dY8Z 
4  6V  	W[8^ 
$%YZ_8` 
,-IJa8b 
!";<c8d 
)*`ae8f 
+,]^g8h 
./[\i8j 
&'YZk8l 
34tum8n 
9:vwo8Ht FME "b	"DIdV$%aKF	" 
Bvhawm
,-89a P  	"IdV2cU+,I!!	"s   )K33L!8LL!