mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
chore(translator): update cache functions to include model name parameter in tests
This commit is contained in:
70
internal/cache/signature_cache_test.go
vendored
70
internal/cache/signature_cache_test.go
vendored
@@ -13,10 +13,10 @@ func TestCacheSignature_BasicStorageAndRetrieval(t *testing.T) {
|
|||||||
signature := "abc123validSignature1234567890123456789012345678901234567890"
|
signature := "abc123validSignature1234567890123456789012345678901234567890"
|
||||||
|
|
||||||
// Store signature
|
// Store signature
|
||||||
CacheSignature(sessionID, text, signature)
|
CacheSignature("test-model", sessionID, text, signature)
|
||||||
|
|
||||||
// Retrieve signature
|
// Retrieve signature
|
||||||
retrieved := GetCachedSignature(sessionID, text)
|
retrieved := GetCachedSignature("test-model", sessionID, text)
|
||||||
if retrieved != signature {
|
if retrieved != signature {
|
||||||
t.Errorf("Expected signature '%s', got '%s'", signature, retrieved)
|
t.Errorf("Expected signature '%s', got '%s'", signature, retrieved)
|
||||||
}
|
}
|
||||||
@@ -29,13 +29,13 @@ func TestCacheSignature_DifferentSessions(t *testing.T) {
|
|||||||
sig1 := "signature1_1234567890123456789012345678901234567890123456"
|
sig1 := "signature1_1234567890123456789012345678901234567890123456"
|
||||||
sig2 := "signature2_1234567890123456789012345678901234567890123456"
|
sig2 := "signature2_1234567890123456789012345678901234567890123456"
|
||||||
|
|
||||||
CacheSignature("session-a", text, sig1)
|
CacheSignature("test-model", "session-a", text, sig1)
|
||||||
CacheSignature("session-b", text, sig2)
|
CacheSignature("test-model", "session-b", text, sig2)
|
||||||
|
|
||||||
if GetCachedSignature("session-a", text) != sig1 {
|
if GetCachedSignature("test-model", "session-a", text) != sig1 {
|
||||||
t.Error("Session-a signature mismatch")
|
t.Error("Session-a signature mismatch")
|
||||||
}
|
}
|
||||||
if GetCachedSignature("session-b", text) != sig2 {
|
if GetCachedSignature("test-model", "session-b", text) != sig2 {
|
||||||
t.Error("Session-b signature mismatch")
|
t.Error("Session-b signature mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,13 +44,13 @@ func TestCacheSignature_NotFound(t *testing.T) {
|
|||||||
ClearSignatureCache("")
|
ClearSignatureCache("")
|
||||||
|
|
||||||
// Non-existent session
|
// Non-existent session
|
||||||
if got := GetCachedSignature("nonexistent", "some text"); got != "" {
|
if got := GetCachedSignature("test-model", "nonexistent", "some text"); got != "" {
|
||||||
t.Errorf("Expected empty string for nonexistent session, got '%s'", got)
|
t.Errorf("Expected empty string for nonexistent session, got '%s'", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Existing session but different text
|
// Existing session but different text
|
||||||
CacheSignature("session-x", "text-a", "sigA12345678901234567890123456789012345678901234567890")
|
CacheSignature("test-model", "session-x", "text-a", "sigA12345678901234567890123456789012345678901234567890")
|
||||||
if got := GetCachedSignature("session-x", "text-b"); got != "" {
|
if got := GetCachedSignature("test-model", "session-x", "text-b"); got != "" {
|
||||||
t.Errorf("Expected empty string for different text, got '%s'", got)
|
t.Errorf("Expected empty string for different text, got '%s'", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,12 +59,12 @@ func TestCacheSignature_EmptyInputs(t *testing.T) {
|
|||||||
ClearSignatureCache("")
|
ClearSignatureCache("")
|
||||||
|
|
||||||
// All empty/invalid inputs should be no-ops
|
// All empty/invalid inputs should be no-ops
|
||||||
CacheSignature("", "text", "sig12345678901234567890123456789012345678901234567890")
|
CacheSignature("test-model", "", "text", "sig12345678901234567890123456789012345678901234567890")
|
||||||
CacheSignature("session", "", "sig12345678901234567890123456789012345678901234567890")
|
CacheSignature("test-model", "session", "", "sig12345678901234567890123456789012345678901234567890")
|
||||||
CacheSignature("session", "text", "")
|
CacheSignature("test-model", "session", "text", "")
|
||||||
CacheSignature("session", "text", "short") // Too short
|
CacheSignature("test-model", "session", "text", "short") // Too short
|
||||||
|
|
||||||
if got := GetCachedSignature("session", "text"); got != "" {
|
if got := GetCachedSignature("test-model", "session", "text"); got != "" {
|
||||||
t.Errorf("Expected empty after invalid cache attempts, got '%s'", got)
|
t.Errorf("Expected empty after invalid cache attempts, got '%s'", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,9 +76,9 @@ func TestCacheSignature_ShortSignatureRejected(t *testing.T) {
|
|||||||
text := "Some text"
|
text := "Some text"
|
||||||
shortSig := "abc123" // Less than 50 chars
|
shortSig := "abc123" // Less than 50 chars
|
||||||
|
|
||||||
CacheSignature(sessionID, text, shortSig)
|
CacheSignature("test-model", sessionID, text, shortSig)
|
||||||
|
|
||||||
if got := GetCachedSignature(sessionID, text); got != "" {
|
if got := GetCachedSignature("test-model", sessionID, text); got != "" {
|
||||||
t.Errorf("Short signature should be rejected, got '%s'", got)
|
t.Errorf("Short signature should be rejected, got '%s'", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,15 +87,15 @@ func TestClearSignatureCache_SpecificSession(t *testing.T) {
|
|||||||
ClearSignatureCache("")
|
ClearSignatureCache("")
|
||||||
|
|
||||||
sig := "validSig1234567890123456789012345678901234567890123456"
|
sig := "validSig1234567890123456789012345678901234567890123456"
|
||||||
CacheSignature("session-1", "text", sig)
|
CacheSignature("test-model", "session-1", "text", sig)
|
||||||
CacheSignature("session-2", "text", sig)
|
CacheSignature("test-model", "session-2", "text", sig)
|
||||||
|
|
||||||
ClearSignatureCache("session-1")
|
ClearSignatureCache("session-1")
|
||||||
|
|
||||||
if got := GetCachedSignature("session-1", "text"); got != "" {
|
if got := GetCachedSignature("test-model", "session-1", "text"); got != "" {
|
||||||
t.Error("session-1 should be cleared")
|
t.Error("session-1 should be cleared")
|
||||||
}
|
}
|
||||||
if got := GetCachedSignature("session-2", "text"); got != sig {
|
if got := GetCachedSignature("test-model", "session-2", "text"); got != sig {
|
||||||
t.Error("session-2 should still exist")
|
t.Error("session-2 should still exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,15 +104,15 @@ func TestClearSignatureCache_AllSessions(t *testing.T) {
|
|||||||
ClearSignatureCache("")
|
ClearSignatureCache("")
|
||||||
|
|
||||||
sig := "validSig1234567890123456789012345678901234567890123456"
|
sig := "validSig1234567890123456789012345678901234567890123456"
|
||||||
CacheSignature("session-1", "text", sig)
|
CacheSignature("test-model", "session-1", "text", sig)
|
||||||
CacheSignature("session-2", "text", sig)
|
CacheSignature("test-model", "session-2", "text", sig)
|
||||||
|
|
||||||
ClearSignatureCache("")
|
ClearSignatureCache("")
|
||||||
|
|
||||||
if got := GetCachedSignature("session-1", "text"); got != "" {
|
if got := GetCachedSignature("test-model", "session-1", "text"); got != "" {
|
||||||
t.Error("session-1 should be cleared")
|
t.Error("session-1 should be cleared")
|
||||||
}
|
}
|
||||||
if got := GetCachedSignature("session-2", "text"); got != "" {
|
if got := GetCachedSignature("test-model", "session-2", "text"); got != "" {
|
||||||
t.Error("session-2 should be cleared")
|
t.Error("session-2 should be cleared")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,13 +151,13 @@ func TestCacheSignature_TextHashCollisionResistance(t *testing.T) {
|
|||||||
sig1 := "signature1_1234567890123456789012345678901234567890123456"
|
sig1 := "signature1_1234567890123456789012345678901234567890123456"
|
||||||
sig2 := "signature2_1234567890123456789012345678901234567890123456"
|
sig2 := "signature2_1234567890123456789012345678901234567890123456"
|
||||||
|
|
||||||
CacheSignature(sessionID, text1, sig1)
|
CacheSignature("test-model", sessionID, text1, sig1)
|
||||||
CacheSignature(sessionID, text2, sig2)
|
CacheSignature("test-model", sessionID, text2, sig2)
|
||||||
|
|
||||||
if GetCachedSignature(sessionID, text1) != sig1 {
|
if GetCachedSignature("test-model", sessionID, text1) != sig1 {
|
||||||
t.Error("text1 signature mismatch")
|
t.Error("text1 signature mismatch")
|
||||||
}
|
}
|
||||||
if GetCachedSignature(sessionID, text2) != sig2 {
|
if GetCachedSignature("test-model", sessionID, text2) != sig2 {
|
||||||
t.Error("text2 signature mismatch")
|
t.Error("text2 signature mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,9 +169,9 @@ func TestCacheSignature_UnicodeText(t *testing.T) {
|
|||||||
text := "한글 텍스트와 이모지 🎉 그리고 特殊文字"
|
text := "한글 텍스트와 이모지 🎉 그리고 特殊文字"
|
||||||
sig := "unicodeSig123456789012345678901234567890123456789012345"
|
sig := "unicodeSig123456789012345678901234567890123456789012345"
|
||||||
|
|
||||||
CacheSignature(sessionID, text, sig)
|
CacheSignature("test-model", sessionID, text, sig)
|
||||||
|
|
||||||
if got := GetCachedSignature(sessionID, text); got != sig {
|
if got := GetCachedSignature("test-model", sessionID, text); got != sig {
|
||||||
t.Errorf("Unicode text signature retrieval failed, got '%s'", got)
|
t.Errorf("Unicode text signature retrieval failed, got '%s'", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,10 +184,10 @@ func TestCacheSignature_Overwrite(t *testing.T) {
|
|||||||
sig1 := "firstSignature12345678901234567890123456789012345678901"
|
sig1 := "firstSignature12345678901234567890123456789012345678901"
|
||||||
sig2 := "secondSignature1234567890123456789012345678901234567890"
|
sig2 := "secondSignature1234567890123456789012345678901234567890"
|
||||||
|
|
||||||
CacheSignature(sessionID, text, sig1)
|
CacheSignature("test-model", sessionID, text, sig1)
|
||||||
CacheSignature(sessionID, text, sig2) // Overwrite
|
CacheSignature("test-model", sessionID, text, sig2) // Overwrite
|
||||||
|
|
||||||
if got := GetCachedSignature(sessionID, text); got != sig2 {
|
if got := GetCachedSignature("test-model", sessionID, text); got != sig2 {
|
||||||
t.Errorf("Expected overwritten signature '%s', got '%s'", sig2, got)
|
t.Errorf("Expected overwritten signature '%s', got '%s'", sig2, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,10 +203,10 @@ func TestCacheSignature_ExpirationLogic(t *testing.T) {
|
|||||||
text := "text"
|
text := "text"
|
||||||
sig := "validSig1234567890123456789012345678901234567890123456"
|
sig := "validSig1234567890123456789012345678901234567890123456"
|
||||||
|
|
||||||
CacheSignature(sessionID, text, sig)
|
CacheSignature("test-model", sessionID, text, sig)
|
||||||
|
|
||||||
// Fresh entry should be retrievable
|
// Fresh entry should be retrievable
|
||||||
if got := GetCachedSignature(sessionID, text); got != sig {
|
if got := GetCachedSignature("test-model", sessionID, text); got != sig {
|
||||||
t.Errorf("Fresh entry should be retrievable, got '%s'", got)
|
t.Errorf("Fresh entry should be retrievable, got '%s'", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func TestConvertClaudeRequestToAntigravity_ThinkingBlocks(t *testing.T) {
|
|||||||
|
|
||||||
// Derive session ID and cache the signature
|
// Derive session ID and cache the signature
|
||||||
sessionID := deriveSessionID(inputJSON)
|
sessionID := deriveSessionID(inputJSON)
|
||||||
cache.CacheSignature(sessionID, thinkingText, validSignature)
|
cache.CacheSignature("claude-sonnet-4-5-thinking", sessionID, thinkingText, validSignature)
|
||||||
defer cache.ClearSignatureCache(sessionID)
|
defer cache.ClearSignatureCache(sessionID)
|
||||||
|
|
||||||
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
||||||
@@ -268,7 +268,7 @@ func TestConvertClaudeRequestToAntigravity_ToolUse_WithSignature(t *testing.T) {
|
|||||||
|
|
||||||
// Derive session ID and cache the signature
|
// Derive session ID and cache the signature
|
||||||
sessionID := deriveSessionID(inputJSON)
|
sessionID := deriveSessionID(inputJSON)
|
||||||
cache.CacheSignature(sessionID, thinkingText, validSignature)
|
cache.CacheSignature("claude-sonnet-4-5-thinking", sessionID, thinkingText, validSignature)
|
||||||
defer cache.ClearSignatureCache(sessionID)
|
defer cache.ClearSignatureCache(sessionID)
|
||||||
|
|
||||||
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
||||||
@@ -308,7 +308,7 @@ func TestConvertClaudeRequestToAntigravity_ReorderThinking(t *testing.T) {
|
|||||||
|
|
||||||
// Derive session ID and cache the signature
|
// Derive session ID and cache the signature
|
||||||
sessionID := deriveSessionID(inputJSON)
|
sessionID := deriveSessionID(inputJSON)
|
||||||
cache.CacheSignature(sessionID, thinkingText, validSignature)
|
cache.CacheSignature("claude-sonnet-4-5-thinking", sessionID, thinkingText, validSignature)
|
||||||
defer cache.ClearSignatureCache(sessionID)
|
defer cache.ClearSignatureCache(sessionID)
|
||||||
|
|
||||||
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
||||||
@@ -519,7 +519,7 @@ func TestConvertClaudeRequestToAntigravity_TrailingSignedThinking_Kept(t *testin
|
|||||||
|
|
||||||
// Derive session ID and cache the signature
|
// Derive session ID and cache the signature
|
||||||
sessionID := deriveSessionID(inputJSON)
|
sessionID := deriveSessionID(inputJSON)
|
||||||
cache.CacheSignature(sessionID, thinkingText, validSignature)
|
cache.CacheSignature("claude-sonnet-4-5-thinking", sessionID, thinkingText, validSignature)
|
||||||
defer cache.ClearSignatureCache(sessionID)
|
defer cache.ClearSignatureCache(sessionID)
|
||||||
|
|
||||||
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
output := ConvertClaudeRequestToAntigravity("claude-sonnet-4-5-thinking", inputJSON, false)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ func TestConvertAntigravityResponseToClaude_SignatureCached(t *testing.T) {
|
|||||||
ConvertAntigravityResponseToClaude(ctx, "claude-sonnet-4-5-thinking", requestJSON, requestJSON, signatureChunk, ¶m)
|
ConvertAntigravityResponseToClaude(ctx, "claude-sonnet-4-5-thinking", requestJSON, requestJSON, signatureChunk, ¶m)
|
||||||
|
|
||||||
// Verify signature was cached
|
// Verify signature was cached
|
||||||
cachedSig := cache.GetCachedSignature(sessionID, thinkingText)
|
cachedSig := cache.GetCachedSignature("claude-sonnet-4-5-thinking", sessionID, thinkingText)
|
||||||
if cachedSig != validSignature {
|
if cachedSig != validSignature {
|
||||||
t.Errorf("Expected cached signature '%s', got '%s'", validSignature, cachedSig)
|
t.Errorf("Expected cached signature '%s', got '%s'", validSignature, cachedSig)
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ func TestConvertAntigravityResponseToClaude_MultipleThinkingBlocks(t *testing.T)
|
|||||||
ConvertAntigravityResponseToClaude(ctx, "claude-sonnet-4-5-thinking", requestJSON, requestJSON, block1Sig, ¶m)
|
ConvertAntigravityResponseToClaude(ctx, "claude-sonnet-4-5-thinking", requestJSON, requestJSON, block1Sig, ¶m)
|
||||||
|
|
||||||
// Verify first signature cached
|
// Verify first signature cached
|
||||||
if cache.GetCachedSignature(sessionID, firstThinkingText) != validSig1 {
|
if cache.GetCachedSignature("claude-sonnet-4-5-thinking", sessionID, firstThinkingText) != validSig1 {
|
||||||
t.Error("First thinking block signature should be cached")
|
t.Error("First thinking block signature should be cached")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ func TestConvertAntigravityResponseToClaude_MultipleThinkingBlocks(t *testing.T)
|
|||||||
ConvertAntigravityResponseToClaude(ctx, "claude-sonnet-4-5-thinking", requestJSON, requestJSON, block2Sig, ¶m)
|
ConvertAntigravityResponseToClaude(ctx, "claude-sonnet-4-5-thinking", requestJSON, requestJSON, block2Sig, ¶m)
|
||||||
|
|
||||||
// Verify second signature cached
|
// Verify second signature cached
|
||||||
if cache.GetCachedSignature(sessionID, secondThinkingText) != validSig2 {
|
if cache.GetCachedSignature("claude-sonnet-4-5-thinking", sessionID, secondThinkingText) != validSig2 {
|
||||||
t.Error("Second thinking block signature should be cached")
|
t.Error("Second thinking block signature should be cached")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user