
    jj4!                        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mZ ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ  G d
 d          Zd ZddZddZdS )z,Tests for compiler/stages/capture_import.py.    )annotationsN)Path)import_capture)build_index)retrieve)FakeProvider)load_capturec                      e Zd Zddddd
ZdS )_HashEmbedderF)show_progress_barnormalize_embeddings	sentences	list[str]r   boolr   return
np.ndarrayc                  g }|D ]}t          j        |                                                                          }|dz  d d         }t	          j        |t          j                                      t          j                  dz
  }|r*t          j	        
                    |          }	|	dk    r||	z  }|                    |           t	          j        |          S )N       )dtypeg      `@r   )hashlibsha256encodedigestnp
frombufferuint8astypefloat32linalgnormappendstack)
selfr   r   r   vecsshrawvecr!   s
             K/Users/jameslopez/projects/MentorCore/tests/compiler/test_capture_import.pyr   z_HashEmbedder.encode   s      	 	Aqxxzz**1133Aq5#2#,C-28444;;BJGG%OC#  y~~c**!884KCKKx~~    N)r   r   r   r   r   r   r   r   )__name__
__module____qualname__r    r+   r*   r   r      s:        
 #(%*       r+   r   c                L  !K   | dz  }|dz  }|                     d           |                    dt          |                     t          |           t	          d          }| dz  }|dz  }|dz  }|                     d           |                     d           |d	z                      d
d           |dz                      t          j        ddi          dz   d           t          ddgi|t                      d           | dz  !t          !d           d_!fd}t          j        d          }	t          |||	t                      |           d {V }
|d	z                      d          }|j        }d} ||          }|sd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}}d!}||v }|st%          j        d"|fd#||f          t%          j        |          dt!          j                    v st%          j        |          rt%          j        |          ndd$z  }d%d&|iz  }t+          t%          j        |                    d x}}d'}||v }|st%          j        d"|fd#||f          t%          j        |          dt!          j                    v st%          j        |          rt%          j        |          ndd$z  }d%d&|iz  }t+          t%          j        |                    d x}}|
j        }d}||k    }|st%          j        d(|fd)||f          d*t!          j                    v st%          j        |
          rt%          j        |
          nd*t%          j        |          t%          j        |          d+z  }d,d-|iz  }t+          t%          j        |                    d x}x}}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        |          d0z  }d,d-|iz  }t+          t%          j        |                    d x}x}}|
j        }d1}||k    }|st%          j        d(|fd2||f          d*t!          j                    v st%          j        |
          rt%          j        |
          nd*t%          j        |          t%          j        |          d+z  }d,d-|iz  }t+          t%          j        |                    d x}x}}|
j        }d1}||k    }|st%          j        d(|fd3||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}}d4 |dz                                                                  D             }|d5         d6         }d}||u }|slt%          j        d7|fd8||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}|d5         d         }d<}||k    }|slt%          j        d(|fd=||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}t          j        |d>z                                            }|d?         }d1}||k    }|slt%          j        d(|fd=||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}|d@         }d1}||k    }|slt%          j        d(|fd=||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}dA |dBz                                                                  D             }t;          |          }d1}||k    }|st%          j        d(|fdC||f          dDt!          j                    v st%          j        t:                    rt%          j        t:                    ndDd?t!          j                    v st%          j        |          rt%          j        |          nd?t%          j        |          t%          j        |          dEz  }dFdG|iz  }t+          t%          j        |                    d x}x}}|d5         dH         }|j        }dI} ||          }|ssdJt%          j        |          t%          j        |          t%          j        |          t%          j        |          dKz  }t+          t%          j        |                    d x}x}x}}t=          j        |dLz  dMz                                            }|dN         }dO}||k    }|slt%          j        d(|fd=||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}|dP         }dQ}||k    }|slt%          j        d(|fd=||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}tA          |dR                   }|j!        } |            }|sdSdRt!          j                    v st%          j        |          rt%          j        |          ndRt%          j        |          t%          j        |          dTz  }t+          t%          j        |                    d x}}tE          j#        t          |          dU          5 }|j$        } |            }d5}||k    }|st%          j        dV|fdW||f          dXt!          j                    v st%          j        |          rt%          j        |          ndXt%          j        |          t%          j        |          t%          j        |          dYz  }dZd[|iz  }t+          t%          j        |                    d x}x}x}}d d d            n# 1 swxY w Y   tK          d\|d]t                      ^          } | d5         dH         }|j        }dI} ||          }|ssdJt%          j        |          t%          j        |          t%          j        |          t%          j        |          dKz  }t+          t%          j        |                    d x}x}x}}| d5         d         }d\}||k    }|slt%          j        d(|fd=||f          t%          j        |          t%          j        |          d9z  }d:d;|iz  }t+          t%          j        |                    d x}x}}d S )`Ncapturesfixture-captureT)parentsMENTORCORE_CAPTURES_ROOTbuildstyleindexz
profile.mdz7# Tone
Machine tone.

# Style Summary
Machine summary.
utf-8encodingzexemplars.jsonltextzMachine exemplar.
machinez1An unrelated passage about structure and routine.)embedder	overwritezfixture.wavg       @)seconds	voice_dirr   r   c                    S )Nr/   )	referencerA   fixture_wavs     r*   fake_downloaderzLtest_capture_import_merges_profile_quotes_and_voice.<locals>.fake_downloaderK   s	    r+   z0I hold to this worldview myself, stated plainly.)providerr>   reference_downloaderz# Capture PhilosophyzLassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}profile)py0py2py4py6zFixture worldview.)in)z%(py1)s in %(py3)s)py1py3zassert %(py5)spy5z# Machine Extraction)==)z5%(py2)s
{%(py2)s = %(py0)s.style_summary
} == %(py5)sresult)rI   rJ   rP   zassert %(py7)spy7)not in)z9%(py1)s not in %(py5)s
{%(py5)s = %(py3)s.style_summary
})rN   rO   rP      )z7%(py2)s
{%(py2)s = %(py0)s.verified_quotes
} == %(py5)s)zC%(py2)s
{%(py2)s = %(py0)s.skipped_model_memory_quotes
} == %(py5)sc                ^    g | ]*}|                                 t          j        |          +S r/   stripjsonloads.0lines     r*   
<listcomp>zGtest_capture_import_merges_profile_quotes_and_voice.<locals>.<listcomp>`   s@       ::<<
4  r+   r   	synthetic)is)z%(py1)s is %(py4)s)rN   rK   zassert %(py6)srL   Answer in the capture voice.)z%(py1)s == %(py4)szquote_stats.jsonverified_quotesskipped_model_memory_quotesc                ^    g | ]*}|                                 t          j        |          +S r/   rW   r[   s     r*   r^   zGtest_capture_import_merges_profile_quotes_and_voice.<locals>.<listcomp>l   s@       ::<<
4  r+   zverified_quotes.jsonl)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)slen)rI   rN   rO   rL   zassert %(py8)spy8chunk_idzquote:zLassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.startswith
}(%(py5)s)
})rN   rO   rP   rS   voice
voice.yamlenginef5policycloned-personalreference_audiozAassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
})rI   rJ   rK   rb)>)zH%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.getnframes
}()
} > %(py7)swf)rI   rJ   rK   rS   zassert %(py9)spy9Virtue is the only good.r   )top_kr>   )rA   r   r   r   )&mkdirsetenvstr_write_capture_treer	   
write_textrY   dumpsr   r   
_write_wavr   singler   	read_text
startswith@py_builtinslocals
@pytest_ar_should_repr_global_name	_safereprAssertionError_format_explanation_call_reprcomparestyle_summaryrb   rc   
splitlinesrZ   re   yaml	safe_loadr   existswaveopen
getnframesr   )"tmp_pathmonkeypatchcapture_rootcapture_dircapture	build_dir	style_dir	index_dirrE   rF   rR   rH   @py_assert1@py_assert3@py_assert5@py_format7@py_assert0@py_assert2@py_format4@py_format6@py_assert4@py_format8	exemplars@py_format5quote_statsrb   @py_format9@py_assert6voice_configrn   rq   @py_format10	retrievedrD   s"                                    @r*   3test_capture_import_merges_profile_quotes_and_voicer   )   s2     j(L!22Kd###13|3D3DEEE$$$,--G7"IG#IG#IOODO!!!OODO!!!))F *    ""..
F/011D8 /   
 	HIJ	    ]*K{C((((      "#UVVH!,        F <'22G2DDG545455555555555555575555575555555555455555555555555555555555555*7**********7****************7*****7***************************!,!W,,,,,,,,,,!W,,,,,!,,,,,,,,,,,W,,,,,W,,,,,,,,,,,,,,,,,,,,,,,,,,,U#UU#UUUUUUUUUUU#UUUUUUUUUUUUU6UUUUU6UUUUUUUUUU#UUUUUUUUUUUUUUUUUUUUUUUUUUUU;v';;';;;;;;;;;;;';;;;;;;;;;;;;;;;;v;;;;;v;;;;;;';;;;;;;;;;;;;;;;;;;;;;;;;;;;!&Q&!Q&&&&&&&&&&!Q&&&&&&&&&&&&6&&&&&6&&&&&&!&&&&Q&&&&&&&&&&&&&&&&&&&&&&&&&&&-22-2222222222-2222222222226222226222222-2222222222222222222222222222222 !22==??JJLL  I
 Q<$,,$,,,,,,,,,,$,,,,,$,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Q<A#AA#AAAAAAAAAAA#AAAAAAAAAA#AAAAAAAAAAAAAAAAAAAAAAAAAAAA*i*<<GGIIJJK().Q.)Q..........)Q.....)....Q...........................45::5::::::::::5:::::5::::::::::::::::::::::::::::::: !88CCEEPPRR  O
 $1$1$$$$$$$$$$1$$$$$$$$$$$$3$$$$$3$$$$$$$$$$$$$$$$$$$$$$$$$$$$1$$$$$$$$$$$$$$$$$$$$$$$$$$$1j)>)4>X>44X>>>>>>>>)>>>>4>>>>X>>>>>>>>>>>>>>>>>>>>>>>>>>>>>9w#6#E"P"P"R"RSSL!)T)!T))))))))))!T)))))!))))T)))))))))))))))))))))))))))!6%66!%66666666666!%666666!6666%6666666666666666666666666666<(9:;;O!#!!###############?#####?######!########################	3''	.	. #"}"}}""""""""""""""""""""""""r"""""r""""""}"""""""""""""""""""""""""""""""""""""# # # # # # # # # # # # # # # "	  I Q<
#8#.8x8..x88888888#8888.8888x8888888888888888888888888888Q<=#==#===========#==========#==============================s   $C!wwwr   r   r   Nonec                >   | dz                       dd           | dz                       dd           | dz                       dd           | d	z                       t          j        d
dddd ddddddddd          d           | dz                       d                    t	          j        dddd dgddd d           t	          j        d!d"dd d#gd$d d d           g          dz   d           | d%z                       t	          j        d&d'd(dgd)d*d+          dz   d           | d,z                       t          j        dd-d.d/d0gd1d2gd3d4d d5d6d          d           | d7z                       t	          j        d8d9d:d;d<          dz   d           d S )=Nzphilosophy.mdz]# Identity

Fixture worldview.

## Core worldview

Fixture worldview. Keep the answer short.
r8   r9   zstyle.mdz!# Register

Measured and direct.
z
sources.mdz# Sources

1. Fixture source.
zcapture.yamlrU   r2   zFixture Capturei  rm   zgpt-5-codexz
2026-07-17hybridfixturemediumz!Fixture capture for import tests.)schema_versionslugdisplay_nameborndiedvoice_policycaptured_bycaptured_atcapture_modecapture_focus
confidencenotesF)	sort_keyszquotes.jsonlr<   q001rs   zFixture sourcevirtueverifiedzhttps://example.com/verified)idr;   sourcedatetopics
provenance
verify_urlcontextq002zThe model remembers this line.memoryzmodel-memoryzqa-exemplars.jsonlx001zHow should I respond?ra   Tzcoaching-debrief)r   questionanswerr   r_   registerri   zhttps://example.com/reference	interviewzFixture Referencez00:00-00:01zFixture segment.)urlkindtitleclean_segmentsquality_noteszMeasured and direct.zFixture fallback.)descriptionkokoro_voicepack_hint)rl   
referencespacing_notesstylized_fallbackzeval-questions.jsonle001zWhat matters most?zA fixture answer.zcore-belief)r   r   expectr   )ry   r   	safe_dumpjoinrY   rz   )r   s    r*   rx   rx      s   ?"..:  /    :)). *    <++,OZa+bbb>!--"#) 1 1,+ (!*&<  	
 	
 	
" % .   ( >!--		
$ :"2 $#+*&0&D#'	 	  
$ @"2 $#+*&4&*#'	 	 	
 	
8 9	: = .   @ ''33
38$+!. 		
 		
 
	  4    <+++  ? +!4+8/);  !7#6-1& & " %	
 	
 	
( + ,   . ))55
0-%	 	
 	
 	  6     r+   pathr@   floatc                  d}t          ||z            }t          j        d| dgdg|z  R  }t          j        t          |           d          5 }|                    d           |                    d           |                    |           |	                    |           d d d            d S # 1 swxY w Y   d S )Ni>  <r'   r   wbrU   r   )
intstructpackr   r   rw   setnchannelssetsampwidthsetframeratewriteframes)r   r@   sample_raten_framespcmrq   s         r*   r{   r{      s    K;())H
+o(ooo
9!x
9
9
9C	3t99d	#	# r


$$$
s	                 s   AB33B7:B7)r   r   r   r   )r   r   r@   r   r   r   ) __doc__
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   r   rY   r   r   pathlibr   numpyr   r   compiler.stages.capture_importr   compiler.stages.indexr   runtime.conversation.retrievalr   runtime.providers.faker   shared.capturer	   r   r   rx   r{   r/   r+   r*   <module>r      sN   2 2 " " " " " "                             9 9 9 9 9 9 - - - - - - 3 3 3 3 3 3 / / / / / / ' ' ' ' ' '       *Z> Z> Z>zq q q qh     r+   