mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-27 15:29:23 +00:00
fix(openai): preserve Codex usage percentages in scheduling threshold
This commit is contained in:
1 parent
48eb3766d2
commit
99b31067f7
2 files changed
+18
-3
No files matched your search
@@ -245,7 +245,7 @@ func openAIThresholdCandidate(extra map[string]any, window string) *accountSched
|
|||||||
}
|
}
|
||||||
return &accountSchedulingThresholdCandidate{
|
return &accountSchedulingThresholdCandidate{
|
||||||
window: window,
|
window: window,
|
||||||
usedPercent: utilizationAsPercent(usedPercent),
|
usedPercent: schedulingPercentValue(usedPercent),
|
||||||
until: parseSchedulingResetAt(extra[resetAtKey]),
|
until: parseSchedulingResetAt(extra[resetAtKey]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func TestEvaluateAccountSchedulingThreshold_AnthropicIgnoresExpiredFiveHourWindo
|
|||||||
require.True(t, wantUntil.Equal(*decision.Until))
|
require.True(t, wantUntil.Equal(*decision.Until))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvaluateAccountSchedulingThreshold_FractionalPlatformsKeepFractionSemantics(t *testing.T) {
|
func TestEvaluateAccountSchedulingThreshold_OpenAIPreservesPercentageSemantics(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
now := time.Date(2026, 6, 3, 12, 0, 0, 0, time.UTC)
|
now := time.Date(2026, 6, 3, 12, 0, 0, 0, time.UTC)
|
||||||
@@ -104,17 +104,32 @@ func TestEvaluateAccountSchedulingThreshold_FractionalPlatformsKeepFractionSeman
|
|||||||
openAIAccount := &Account{
|
openAIAccount := &Account{
|
||||||
Platform: PlatformOpenAI,
|
Platform: PlatformOpenAI,
|
||||||
Extra: map[string]any{
|
Extra: map[string]any{
|
||||||
"codex_5h_used_percent": 0.91,
|
"codex_5h_used_percent": 1.0,
|
||||||
"codex_5h_reset_at": openAIUntil.Format(time.RFC3339),
|
"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{
|
openAIDecision := EvaluateAccountSchedulingThreshold(openAIAccount, map[string]int{
|
||||||
PlatformOpenAI: 90,
|
PlatformOpenAI: 90,
|
||||||
}, now)
|
}, 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.True(t, openAIDecision.ShouldPause)
|
||||||
require.Equal(t, 91.0, openAIDecision.UsedPercent)
|
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)
|
anthropicUntil := now.Add(5 * time.Hour)
|
||||||
anthropicAccount := &Account{
|
anthropicAccount := &Account{
|
||||||
|
|||||||
Reference in new issue
Block a user