mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-22 02:52:46 +08:00
- Updated Antigravity Credits fallback to handle KV store unavailability as a service error. - Enhanced signature caching mechanisms with request-time KV access and sliding expiration. - Added and improved tests for KV client interactions, including error handling and expiration behaviors. - Introduced `CacheSignatureBestEffort` for non-critical signature caching and clarified function flows with required context. - Ensured consistent error reporting for missing or unavailable KV stores in various scenarios. - Replaced direct `homekv` calls with injectable KV client interfaces for `antigravity` and `codex_reasoning_replay` modules. - Improved error reporting and handling for KV operations, including `KVGet`, `KVSet`, `KVDel`, and `KVExpire`. - Introduced dedicated fake KV clients for expanded and granular test coverage. - Added new unit tests to validate KV client behaviors and error scenarios, ensuring robustness and sliding expiration functionality.
28 lines
793 B
Go
28 lines
793 B
Go
package helps
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v7/internal/config"
|
|
homekv "github.com/router-for-me/CLIProxyAPI/v7/internal/home"
|
|
)
|
|
|
|
func TestSetCodexCacheRequiredHomeUnavailableReturnsError(t *testing.T) {
|
|
homekv.SetCurrent(homekv.New(config.HomeConfig{Enabled: false}))
|
|
t.Cleanup(homekv.ClearCurrent)
|
|
|
|
errSet := SetCodexCacheRequired(context.Background(), "cpa:codex:prompt-cache:test", CodexCache{
|
|
ID: "cache-id",
|
|
Expire: time.Now().Add(time.Hour),
|
|
})
|
|
if errSet == nil {
|
|
t.Fatal("SetCodexCacheRequired() error = nil, want home kv unavailable error")
|
|
}
|
|
if !strings.Contains(errSet.Error(), "home kv store unavailable") {
|
|
t.Fatalf("SetCodexCacheRequired() error = %v, want home kv store unavailable", errSet)
|
|
}
|
|
}
|