| package semanticcache |
|
|
| import ( |
| "context" |
| "strings" |
| "testing" |
| "time" |
|
|
| "github.com/google/uuid" |
| bifrost "github.com/maximhq/bifrost/core" |
| "github.com/maximhq/bifrost/core/schemas" |
| ) |
|
|
| |
| func TestSemanticCacheBasicFlow(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
| |
| |
| request := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Hello, world!"), |
| }, |
| }, |
| }, |
| Params: &schemas.ChatParameters{ |
| Temperature: bifrost.Ptr(0.7), |
| MaxCompletionTokens: bifrost.Ptr(100), |
| }, |
| }, |
| } |
|
|
| t.Log("Testing first request (cache miss)...") |
|
|
| |
| modifiedReq, shortCircuit, err := setup.Plugin.PreLLMHook(ctx, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit != nil { |
| t.Fatal("Expected cache miss, but got cache hit") |
| } |
|
|
| if modifiedReq == nil { |
| t.Fatal("Modified request is nil") |
| } |
|
|
| t.Log("✅ Cache miss handled correctly") |
|
|
| |
| response := &schemas.BifrostResponse{ |
| ChatResponse: &schemas.BifrostChatResponse{ |
| ID: uuid.New().String(), |
| Choices: []schemas.BifrostResponseChoice{ |
| { |
| Index: 0, |
| ChatNonStreamResponseChoice: &schemas.ChatNonStreamResponseChoice{ |
| Message: &schemas.ChatMessage{ |
| Role: schemas.ChatMessageRoleAssistant, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Hello! How can I help you today?"), |
| }}, |
| }, |
| }, |
| }, |
| ExtraFields: schemas.BifrostResponseExtraFields{ |
| Provider: schemas.OpenAI, |
| ModelRequested: "gpt-4o-mini", |
| RequestType: schemas.ChatCompletionRequest, |
| }, |
| }, |
| } |
|
|
| |
| var originalContent string |
| if len(response.ChatResponse.Choices) > 0 && response.ChatResponse.Choices[0].Message.Content.ContentStr != nil { |
| originalContent = *response.ChatResponse.Choices[0].Message.Content.ContentStr |
| } |
| if originalContent == "" { |
| t.Fatal("Original response content is empty") |
| } |
| t.Logf("Original response content: %s", originalContent) |
|
|
| |
| t.Log("Caching response...") |
| _, _, err = setup.Plugin.PostLLMHook(ctx, response, nil) |
| if err != nil { |
| t.Fatalf("PostLLMHook failed: %v", err) |
| } |
|
|
| |
| WaitForCache(setup.Plugin) |
| t.Log("✅ Response cached successfully") |
|
|
| |
| t.Log("Testing second identical request (expecting cache hit)...") |
|
|
| |
| ctx2 := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx2.SetValue(CacheKey, "test-cache-enabled") |
|
|
| modifiedReq2, shortCircuit2, err := setup.Plugin.PreLLMHook(ctx2, request) |
| if err != nil { |
| t.Fatalf("Second PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit2 == nil { |
| t.Fatal("expected cache hit on identical request") |
| return |
| } |
|
|
| if shortCircuit2.Response == nil { |
| t.Fatal("Cache hit but response is nil") |
| } |
|
|
| if modifiedReq2 == nil { |
| t.Fatal("Modified request is nil on cache hit") |
| } |
|
|
| t.Log("✅ Cache hit detected and response returned") |
|
|
| |
| if len(shortCircuit2.Response.ChatResponse.Choices) == 0 { |
| t.Fatal("Cached response has no choices") |
| } |
|
|
| cachedContent := shortCircuit2.Response.ChatResponse.Choices[0].Message.Content.ContentStr |
| if cachedContent == nil || *cachedContent == "" { |
| t.Fatal("Cached response content is empty") |
| } |
|
|
| t.Logf("✅ Cached response content: %s", *cachedContent) |
|
|
| |
| cachedContentStr := *cachedContent |
| |
| originalContentTrimmed := strings.TrimSpace(originalContent) |
| cachedContentTrimmed := strings.TrimSpace(cachedContentStr) |
|
|
| if originalContentTrimmed != cachedContentTrimmed { |
| t.Fatalf("❌ Content mismatch: original='%s', cached='%s'", originalContentTrimmed, cachedContentTrimmed) |
| } |
|
|
| t.Log("✅ Content verification passed - original and cached responses match") |
| t.Log("🎉 Basic semantic cache flow test passed!") |
| } |
|
|
| |
| func TestSemanticCacheStrictFiltering(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
|
|
| |
| baseRequest := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("What is the weather like?"), |
| }, |
| }, |
| }, |
| Params: &schemas.ChatParameters{ |
| Temperature: bifrost.Ptr(0.7), |
| MaxCompletionTokens: bifrost.Ptr(100), |
| }, |
| }, |
| } |
|
|
| t.Log("Testing first request with temperature=0.7...") |
|
|
| |
| _, shortCircuit1, err := setup.Plugin.PreLLMHook(ctx, baseRequest) |
| if err != nil { |
| t.Fatalf("First PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit1 != nil { |
| t.Fatal("Expected cache miss for first request") |
| } |
|
|
| |
| response := &schemas.BifrostResponse{ |
| ChatResponse: &schemas.BifrostChatResponse{ |
| ID: uuid.New().String(), |
| Choices: []schemas.BifrostResponseChoice{ |
| { |
| ChatNonStreamResponseChoice: &schemas.ChatNonStreamResponseChoice{ |
| Message: &schemas.ChatMessage{ |
| Role: schemas.ChatMessageRoleAssistant, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("It's sunny today!"), |
| }}, |
| }, |
| }, |
| }, |
| ExtraFields: schemas.BifrostResponseExtraFields{ |
| Provider: schemas.OpenAI, |
| ModelRequested: "gpt-4o-mini", |
| RequestType: schemas.ChatCompletionRequest, |
| }, |
| }, |
| } |
|
|
| _, _, err = setup.Plugin.PostLLMHook(ctx, response, nil) |
| if err != nil { |
| t.Fatalf("PostLLMHook failed: %v", err) |
| } |
|
|
| WaitForCache(setup.Plugin) |
| t.Log("✅ First response cached") |
|
|
| |
| t.Log("Testing second request with temperature=0.5 (expecting cache miss)...") |
|
|
| ctx2 := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx2.SetValue(CacheKey, "test-cache-enabled") |
|
|
| modifiedRequest := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("What is the weather like?"), |
| }, |
| }, |
| }, |
| Params: &schemas.ChatParameters{ |
| Temperature: bifrost.Ptr(0.5), |
| MaxCompletionTokens: bifrost.Ptr(100), |
| }, |
| }, |
| } |
|
|
| _, shortCircuit2, err := setup.Plugin.PreLLMHook(ctx2, modifiedRequest) |
| if err != nil { |
| t.Fatalf("Second PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit2 != nil { |
| t.Fatal("Expected cache miss due to different temperature, but got cache hit") |
| } |
|
|
| t.Log("✅ Strict filtering working - different parameters result in cache miss") |
|
|
| |
| t.Log("Testing third request with different model (expecting cache miss)...") |
|
|
| ctx3 := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx3.SetValue(CacheKey, "test-cache-enabled") |
|
|
| modifiedRequest2 := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-3.5-turbo", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("What is the weather like?"), |
| }, |
| }, |
| }, |
| Params: &schemas.ChatParameters{ |
| Temperature: bifrost.Ptr(0.7), |
| MaxCompletionTokens: bifrost.Ptr(100), |
| }, |
| }, |
| } |
|
|
| _, shortCircuit3, err := setup.Plugin.PreLLMHook(ctx3, modifiedRequest2) |
| if err != nil { |
| t.Fatalf("Third PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit3 != nil { |
| t.Fatal("Expected cache miss due to different model, but got cache hit") |
| } |
|
|
| t.Log("✅ Strict filtering working - different model results in cache miss") |
| t.Log("🎉 Strict filtering test passed!") |
| } |
|
|
| |
| func TestSemanticCacheStreamingFlow(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
|
|
| request := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionStreamRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Tell me a short story"), |
| }, |
| }, |
| }, |
| Params: &schemas.ChatParameters{ |
| Temperature: bifrost.Ptr(0.8), |
| }, |
| }, |
| } |
|
|
| t.Log("Testing streaming request (cache miss)...") |
|
|
| |
| _, shortCircuit, err := setup.Plugin.PreLLMHook(ctx, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit != nil { |
| t.Fatal("Expected cache miss for streaming request") |
| } |
|
|
| t.Log("✅ Streaming cache miss handled correctly") |
|
|
| |
| t.Log("Caching streaming response chunks...") |
|
|
| chunks := []string{ |
| "Once upon a time,", |
| " there was a brave", |
| " knight who saved the day.", |
| } |
|
|
| for i, chunk := range chunks { |
| var finishReason *string |
| if i == len(chunks)-1 { |
| finishReason = bifrost.Ptr("stop") |
| } |
|
|
| chunkResponse := &schemas.BifrostResponse{ |
| ChatResponse: &schemas.BifrostChatResponse{ |
| ID: uuid.New().String(), |
| Choices: []schemas.BifrostResponseChoice{ |
| { |
| Index: i, |
| FinishReason: finishReason, |
| ChatStreamResponseChoice: &schemas.ChatStreamResponseChoice{ |
| Delta: &schemas.ChatStreamResponseChoiceDelta{ |
| Content: bifrost.Ptr(chunk), |
| }, |
| }, |
| }, |
| }, |
| ExtraFields: schemas.BifrostResponseExtraFields{ |
| Provider: schemas.OpenAI, |
| ModelRequested: "gpt-4o-mini", |
| RequestType: schemas.ChatCompletionStreamRequest, |
| ChunkIndex: i, |
| }, |
| }, |
| } |
|
|
| _, _, err = setup.Plugin.PostLLMHook(ctx, chunkResponse, nil) |
| if err != nil { |
| t.Fatalf("PostLLMHook failed for chunk %d: %v", i, err) |
| } |
| } |
|
|
| WaitForCache(setup.Plugin) |
| t.Log("✅ Streaming response chunks cached") |
|
|
| |
| t.Log("Testing streaming cache retrieval...") |
|
|
| ctx2 := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx2.SetValue(CacheKey, "test-cache-enabled") |
|
|
| _, shortCircuit2, err := setup.Plugin.PreLLMHook(ctx2, request) |
| if err != nil { |
| t.Fatalf("Second PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit2 == nil { |
| t.Log("⚠️ Expected streaming cache hit, but got cache miss - this may be expected with the new unified storage") |
| return |
| } |
|
|
| if shortCircuit2.Stream == nil { |
| t.Fatal("Cache hit but stream is nil") |
| } |
|
|
| t.Log("✅ Streaming cache hit detected") |
|
|
| |
| chunkCount := 0 |
| for chunk := range shortCircuit2.Stream { |
| if chunk.BifrostChatResponse == nil { |
| continue |
| } |
| chunkCount++ |
| t.Logf("Received cached chunk %d", chunkCount) |
| } |
|
|
| if chunkCount == 0 { |
| t.Fatal("No chunks received from cached stream") |
| } |
|
|
| t.Logf("✅ Received %d cached chunks", chunkCount) |
| t.Log("🎉 Streaming cache test passed!") |
| } |
|
|
| |
| func TestSemanticCache_NoCacheWhenKeyMissing(t *testing.T) { |
| t.Log("Testing cache behavior when cache key is missing...") |
|
|
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| |
|
|
| request := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Test message"), |
| }, |
| }, |
| }, |
| }, |
| } |
|
|
| _, shortCircuit, err := setup.Plugin.PreLLMHook(ctx, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit != nil { |
| t.Fatal("Expected no caching when cache key is not set, but got cache hit") |
| } |
|
|
| t.Log("✅ Cache properly disabled when no cache key is set") |
| t.Log("🎉 No cache key test passed!") |
| } |
|
|
| |
| func TestSemanticCache_CustomTTLHandling(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| |
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
| ctx.SetValue(CacheTTLKey, 1*time.Minute) |
|
|
| request := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("TTL test message"), |
| }, |
| }, |
| }, |
| }, |
| } |
|
|
| |
| _, shortCircuit, err := setup.Plugin.PreLLMHook(ctx, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit != nil { |
| t.Fatal("Expected cache miss, but got cache hit") |
| } |
|
|
| |
| response := &schemas.BifrostResponse{ |
| ChatResponse: &schemas.BifrostChatResponse{ |
| ID: "ttl-test-response", |
| Choices: []schemas.BifrostResponseChoice{ |
| { |
| ChatNonStreamResponseChoice: &schemas.ChatNonStreamResponseChoice{ |
| Message: &schemas.ChatMessage{ |
| Role: "assistant", |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("TTL test response"), |
| }, |
| }, |
| }, |
| }, |
| }, |
| ExtraFields: schemas.BifrostResponseExtraFields{ |
| Provider: schemas.OpenAI, |
| ModelRequested: "gpt-4o-mini", |
| RequestType: schemas.ChatCompletionRequest, |
| }, |
| }, |
| } |
|
|
| _, _, err = setup.Plugin.PostLLMHook(ctx, response, nil) |
| if err != nil { |
| t.Fatalf("PostLLMHook failed: %v", err) |
| } |
|
|
| WaitForCache(setup.Plugin) |
|
|
| t.Log("✅ Custom TTL configuration test passed!") |
| } |
|
|
| |
| func TestSemanticCache_CustomThresholdHandling(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| |
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
| ctx.SetValue(CacheThresholdKey, 0.95) |
|
|
| request := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Threshold test message"), |
| }, |
| }, |
| }, |
| }, |
| } |
|
|
| |
| _, shortCircuit, err := setup.Plugin.PreLLMHook(ctx, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit != nil { |
| t.Fatal("Expected cache miss with high threshold, but got cache hit") |
| } |
|
|
| t.Log("✅ Custom threshold configuration test passed!") |
| } |
|
|
| |
| func TestSemanticCache_ProviderModelCachingFlags(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| |
| setup.Config.CacheByProvider = bifrost.Ptr(false) |
| setup.Config.CacheByModel = bifrost.Ptr(false) |
|
|
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
|
|
| request1 := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Provider model flags test"), |
| }, |
| }, |
| }, |
| }, |
| } |
|
|
| |
| _, shortCircuit1, err := setup.Plugin.PreLLMHook(ctx, request1) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed: %v", err) |
| } |
|
|
| if shortCircuit1 != nil { |
| t.Fatal("Expected cache miss, but got cache hit") |
| } |
|
|
| |
| response := &schemas.BifrostResponse{ |
| ChatResponse: &schemas.BifrostChatResponse{ |
| ID: "provider-model-test", |
| Choices: []schemas.BifrostResponseChoice{ |
| { |
| ChatNonStreamResponseChoice: &schemas.ChatNonStreamResponseChoice{ |
| Message: &schemas.ChatMessage{ |
| Role: "assistant", |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Provider model test response"), |
| }, |
| }, |
| }, |
| }, |
| }, |
| ExtraFields: schemas.BifrostResponseExtraFields{ |
| Provider: schemas.OpenAI, |
| ModelRequested: "gpt-4o-mini", |
| RequestType: schemas.ChatCompletionRequest, |
| }, |
| }, |
| } |
|
|
| _, _, err = setup.Plugin.PostLLMHook(ctx, response, nil) |
| if err != nil { |
| t.Fatalf("PostLLMHook failed: %v", err) |
| } |
|
|
| WaitForCache(setup.Plugin) |
|
|
| |
| request2 := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.Anthropic, |
| Model: "claude-3-haiku", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Provider model flags test"), |
| }, |
| }, |
| }, |
| }, |
| } |
|
|
| ctx2 := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx2.SetValue(CacheKey, "test-cache-enabled") |
|
|
| _, shortCircuit2, err := setup.Plugin.PreLLMHook(ctx2, request2) |
| if err != nil { |
| t.Fatalf("Second PreLLMHook failed: %v", err) |
| } |
|
|
| |
| |
| t.Logf("Cache behavior with disabled provider/model flags: hit=%v", shortCircuit2 != nil) |
|
|
| t.Log("✅ Provider/model caching flags test passed!") |
| } |
|
|
| |
| func TestSemanticCache_ConfigurationEdgeCases(t *testing.T) { |
| setup := NewTestSetup(t) |
| defer setup.Cleanup() |
|
|
| |
| ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx.SetValue(CacheKey, "test-cache-enabled") |
| ctx.SetValue(CacheTTLKey, "not-a-duration") |
|
|
| request := &schemas.BifrostRequest{ |
| RequestType: schemas.ChatCompletionRequest, |
| ChatRequest: &schemas.BifrostChatRequest{ |
| Provider: schemas.OpenAI, |
| Model: "gpt-4o-mini", |
| Input: []schemas.ChatMessage{ |
| { |
| Role: schemas.ChatMessageRoleUser, |
| Content: &schemas.ChatMessageContent{ |
| ContentStr: bifrost.Ptr("Edge case test"), |
| }, |
| }, |
| }, |
| }, |
| } |
|
|
| |
| _, shortCircuit, err := setup.Plugin.PreLLMHook(ctx, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed with invalid TTL: %v", err) |
| } |
|
|
| if shortCircuit != nil { |
| t.Fatal("Unexpected cache hit with invalid TTL") |
| } |
|
|
| |
| ctx2 := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline) |
| ctx2.SetValue(CacheKey, "test-cache-enabled") |
| ctx2.SetValue(CacheThresholdKey, "not-a-float") |
|
|
| |
| _, shortCircuit2, err := setup.Plugin.PreLLMHook(ctx2, request) |
| if err != nil { |
| t.Fatalf("PreLLMHook failed with invalid threshold: %v", err) |
| } |
|
|
| if shortCircuit2 != nil { |
| t.Fatal("Unexpected cache hit with invalid threshold") |
| } |
|
|
| t.Log("✅ Configuration edge cases test passed!") |
| } |
|
|