fix(openai): preserve Codex usage percentages in scheduling threshold

This commit is contained in:
wucm667
2026-08-10 04:29:08 +08:00
parent 48eb3766d2
commit 99b31067f7
2 changed files with 18 additions and 3 deletions
@@ -245,7 +245,7 @@ func openAIThresholdCandidate(extra map[string]any, window string) *accountSched
}
return &accountSchedulingThresholdCandidate{
window: window,
usedPercent: utilizationAsPercent(usedPercent),
usedPercent: schedulingPercentValue(usedPercent),
until: parseSchedulingResetAt(extra[resetAtKey]),
}
}
@@ -96,7 +96,7 @@ func TestEvaluateAccountSchedulingThreshold_AnthropicIgnoresExpiredFiveHourWindo
require.True(t, wantUntil.Equal(*decision.Until))
}
func TestEvaluateAccountSchedulingThreshold_FractionalPlatformsKeepFractionSemantics(t *testing.T) {
func TestEvaluateAccountSchedulingThreshold_OpenAIPreservesPercentageSemantics(t *testing.T) {
t.Parallel()
now := time.Date(2026, 6, 3, 12, 0, 0, 0, time.UTC)
@@ -104,17 +104,32 @@ func TestEvaluateAccountSchedulingThreshold_FractionalPlatformsKeepFractionSeman
openAIAccount := &Account{
Platform: PlatformOpenAI,
Extra: map[string]any{
"codex_5h_used_percent": 0.91,
"codex_5h_used_percent": 1.0,
"codex_5h_reset_at": openAIUntil.Format(time.RFC3339),
},
}
candidate := openAIThresholdCandidate(openAIAccount.Extra, "5h")
require.NotNil(t, candidate)
require.Equal(t, 1.0, candidate.usedPercent)
openAIDecision := EvaluateAccountSchedulingThreshold(openAIAccount, map[string]int{
PlatformOpenAI: 90,
}, now)
require.False(t, openAIDecision.ShouldPause)
openAIAccount.Extra["codex_5h_used_percent"] = 91.0
openAIDecision = EvaluateAccountSchedulingThreshold(openAIAccount, map[string]int{
PlatformOpenAI: 90,
}, now)
require.True(t, openAIDecision.ShouldPause)
require.Equal(t, 91.0, openAIDecision.UsedPercent)
}
func TestEvaluateAccountSchedulingThreshold_AnthropicPreservesFractionalUtilizationSemantics(t *testing.T) {
t.Parallel()
now := time.Date(2026, 6, 3, 12, 0, 0, 0, time.UTC)
anthropicUntil := now.Add(5 * time.Hour)
anthropicAccount := &Account{