@@ -21,6 +21,7 @@ import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-tr
2121vi . mock ( '@/lib/core/rate-limiter/provider-admission' , ( ) => ( {
2222 PROVIDER_QUOTA_COOLDOWN_MS : 300_000 ,
2323 ProviderQuotaExhaustedError : class ProviderQuotaExhaustedError extends Error { } ,
24+ ProviderAdmissionTimeoutError : class ProviderAdmissionTimeoutError extends Error { } ,
2425 isProviderQuotaExhausted : vi . fn ( ) . mockResolvedValue ( false ) ,
2526 recordProviderCooldown : vi . fn ( ) . mockResolvedValue ( undefined ) ,
2627 waitForProviderAdmission : vi . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -105,18 +106,23 @@ function makeResult(id: string, distance = 0.1): SearchResult {
105106 }
106107}
107108
108- const TEST_EMBEDDING = [ 0.1 , 0.2 , 0.3 , ...Array . from ( { length : 1533 } , ( ) => 0 ) ]
109+ const TEST_EMBEDDING = [ 0.1 , 0.2 , 0.3 , ...Array . from ( { length : 1533 } , ( ) => 0 ) ] . map ( Math . fround )
109110
110111function mockNextEmbeddingResponse ( ) : void {
111- vi . mocked ( fetch ) . mockResolvedValueOnce (
112- new Response (
112+ vi . mocked ( fetch ) . mockImplementationOnce ( async ( _url , init ) => {
113+ const request = JSON . parse ( String ( init ?. body ) )
114+ const embedding =
115+ request . encoding_format === 'base64'
116+ ? Buffer . from ( new Float32Array ( TEST_EMBEDDING ) . buffer ) . toString ( 'base64' )
117+ : TEST_EMBEDDING
118+ return new Response (
113119 JSON . stringify ( {
114- data : [ { embedding : TEST_EMBEDDING , index : 0 } ] ,
120+ data : [ { embedding, index : 0 } ] ,
115121 usage : { prompt_tokens : 1 , total_tokens : 1 } ,
116122 } ) ,
117123 { status : 200 , headers : { 'Content-Type' : 'application/json' } }
118124 )
119- )
125+ } )
120126}
121127
122128describe ( 'Knowledge Search Utils' , ( ) => {
@@ -220,7 +226,8 @@ describe('Knowledge Search Utils', () => {
220226 } )
221227
222228 expect ( results . map ( ( row ) => row . id ) ) . toEqual ( [ 'first' , 'second' ] )
223- expect ( dbChainMockFns . select ) . toHaveBeenCalledTimes ( 1 )
229+ expect ( dbChainMockFns . select ) . toHaveBeenCalledTimes ( 2 )
230+ expect ( dbChainMockFns . as ) . toHaveBeenCalledWith ( 'ranked_embeddings' )
224231 expect ( dbChainMockFns . select . mock . calls [ 0 ] [ 0 ] ) . toHaveProperty ( 'distance' )
225232 expect ( dbChainMockFns . limit ) . toHaveBeenCalledWith ( 2 )
226233 } )
@@ -541,7 +548,8 @@ describe('Knowledge Search Utils', () => {
541548 } )
542549
543550 expect ( results . map ( ( r ) => r . id ) ) . toEqual ( [ 'vector-hit' ] )
544- expect ( dbChainMockFns . select ) . toHaveBeenCalledTimes ( 1 )
551+ expect ( dbChainMockFns . select ) . toHaveBeenCalledTimes ( 2 )
552+ expect ( dbChainMockFns . as ) . toHaveBeenCalledWith ( 'ranked_embeddings' )
545553 } )
546554
547555 it ( 'runs both legs and fuses them in hybrid mode' , async ( ) => {
@@ -565,7 +573,7 @@ describe('Knowledge Search Utils', () => {
565573 } )
566574
567575 expect ( results . map ( ( r ) => r . id ) . sort ( ) ) . toEqual ( [ 'keyword-hit' , 'vector-hit' ] )
568- expect ( dbChainMockFns . select ) . toHaveBeenCalledTimes ( 3 )
576+ expect ( dbChainMockFns . select ) . toHaveBeenCalledTimes ( 4 )
569577 } )
570578
571579 it ( 'falls back to vector results when the keyword leg fails' , async ( ) => {
@@ -830,7 +838,7 @@ describe('Knowledge Search Utils', () => {
830838 body : JSON . stringify ( {
831839 input : [ 'test query' ] ,
832840 model : 'text-embedding-3-small' ,
833- encoding_format : 'float ' ,
841+ encoding_format : 'base64 ' ,
834842 dimensions : 1536 ,
835843 } ) ,
836844 } )
@@ -860,7 +868,7 @@ describe('Knowledge Search Utils', () => {
860868 body : JSON . stringify ( {
861869 input : [ 'prefix {{TOKEN}} suffix' ] ,
862870 model : 'text-embedding-3-small' ,
863- encoding_format : 'float ' ,
871+ encoding_format : 'base64 ' ,
864872 dimensions : 1536 ,
865873 } ) ,
866874 } )
0 commit comments