@@ -44,7 +44,7 @@ describe("embeddings-ollama", () => {
4444 providers : {
4545 ollama : {
4646 baseUrl : "http://127.0.0.1:11434/v1" ,
47- apiKey : "ollama-local " ,
47+ apiKey : "ollama-\nlocal\r\n " ,
4848 headers : {
4949 "X-Provider-Header" : "provider" ,
5050 } ,
@@ -87,24 +87,43 @@ describe("embeddings-ollama", () => {
8787 ) . rejects . toThrow ( / a g e n t s \. \* \. m e m o r y S e a r c h \. r e m o t e \. a p i K e y : u n r e s o l v e d S e c r e t R e f / i) ;
8888 } ) ;
8989
90- it ( "fails fast when models.providers.ollama.apiKey is an unresolved SecretRef" , async ( ) => {
91- await expect (
92- createOllamaEmbeddingProvider ( {
93- config : {
94- models : {
95- providers : {
96- ollama : {
97- baseUrl : "http://127.0.0.1:11434/v1" ,
98- apiKey : { source : "env" , provider : "default" , id : "OLLAMA_API_KEY" } ,
99- models : [ ] ,
100- } ,
90+ it ( "falls back to env key when models.providers.ollama.apiKey is an unresolved SecretRef" , async ( ) => {
91+ const fetchMock = vi . fn (
92+ async ( ) =>
93+ new Response ( JSON . stringify ( { embedding : [ 1 , 0 ] } ) , {
94+ status : 200 ,
95+ headers : { "content-type" : "application/json" } ,
96+ } ) ,
97+ ) ;
98+ globalThis . fetch = fetchMock as unknown as typeof fetch ;
99+ vi . stubEnv ( "OLLAMA_API_KEY" , "ollama-env" ) ;
100+
101+ const { provider } = await createOllamaEmbeddingProvider ( {
102+ config : {
103+ models : {
104+ providers : {
105+ ollama : {
106+ baseUrl : "http://127.0.0.1:11434/v1" ,
107+ apiKey : { source : "env" , provider : "default" , id : "OLLAMA_API_KEY" } ,
108+ models : [ ] ,
101109 } ,
102110 } ,
103- } as unknown as OpenClawConfig ,
104- provider : "ollama" ,
105- model : "nomic-embed-text" ,
106- fallback : "none" ,
111+ } ,
112+ } as unknown as OpenClawConfig ,
113+ provider : "ollama" ,
114+ model : "nomic-embed-text" ,
115+ fallback : "none" ,
116+ } ) ;
117+
118+ await provider . embedQuery ( "hello" ) ;
119+
120+ expect ( fetchMock ) . toHaveBeenCalledWith (
121+ "http://127.0.0.1:11434/api/embeddings" ,
122+ expect . objectContaining ( {
123+ headers : expect . objectContaining ( {
124+ Authorization : "Bearer ollama-env" ,
125+ } ) ,
107126 } ) ,
108- ) . rejects . toThrow ( / m o d e l s \. p r o v i d e r s \. o l l a m a \. a p i K e y : u n r e s o l v e d S e c r e t R e f / i ) ;
127+ ) ;
109128 } ) ;
110129} ) ;
0 commit comments