@@ -3,15 +3,15 @@ import {
33 PromptTemplate ,
44 MessagesPlaceholder ,
55} from "@langchain/core/prompts" ;
6- import { describe , it , expect , beforeEach , vi } from "vitest" ;
7-
8- import { LangfuseClient } from "@langfuse/client" ;
96import {
7+ LangfuseClient ,
108 ChatPromptClient ,
119 TextPromptClient ,
1210 ChatMessageType ,
1311} from "@langfuse/client" ;
1412import type { ChatMessage , ChatMessageWithPlaceholders } from "@langfuse/core" ;
13+ import { nanoid } from "nanoid" ;
14+ import { describe , it , expect , beforeEach , vi } from "vitest" ;
1515
1616describe ( "Langfuse Prompts E2E" , ( ) => {
1717 let langfuse : LangfuseClient ;
@@ -209,6 +209,39 @@ describe("Langfuse Prompts E2E", () => {
209209 expect ( result . config ) . toEqual ( { temperature : 0.7 } ) ;
210210 } ) ;
211211
212+ it ( "should fetch and cache a prompt with correct version when not in cache" , async ( ) => {
213+ const promptName = "test-cache-prompt-versioned-" + nanoid ( ) ;
214+
215+ // Create two prompts first
216+ await langfuse . prompt . create ( {
217+ name : promptName ,
218+ prompt : "This is a cached prompt with {{variable}}" ,
219+ config : { temperature : 0.7 } ,
220+ labels : [ "production" ] ,
221+ } ) ;
222+
223+ await langfuse . prompt . create ( {
224+ name : promptName ,
225+ prompt : "This is a cached prompt with {{variable}}" ,
226+ config : { temperature : 0.7 } ,
227+ } ) ;
228+
229+ // Get it (should fetch and cache)
230+ const result = await langfuse . prompt . get ( promptName ) ;
231+
232+ expect ( result ) . toBeInstanceOf ( TextPromptClient ) ;
233+ expect ( result . name ) . toBe ( promptName ) ;
234+ expect ( result . version ) . toBe ( 1 ) ;
235+
236+ const result2 = await langfuse . prompt . get ( promptName , {
237+ version : 2 ,
238+ } ) ;
239+
240+ expect ( result2 ) . toBeInstanceOf ( TextPromptClient ) ;
241+ expect ( result2 . name ) . toBe ( promptName ) ;
242+ expect ( result2 . version ) . toBe ( 2 ) ;
243+ } ) ;
244+
212245 it ( "should throw an error if prompt not found" , async ( ) => {
213246 await expect (
214247 langfuse . prompt . get ( "non-existent-prompt" ) ,
0 commit comments