feat: add priority demotion controls
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package store
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestEffectiveModelRateLimitPolicyTreatsModelRulesAsAuthoritative(t *testing.T) {
|
||||
policy := effectiveModelRateLimitPolicy(
|
||||
@@ -30,3 +33,31 @@ func TestEffectiveModelRateLimitPolicyTreatsModelRulesAsAuthoritative(t *testing
|
||||
t.Fatalf("expected missing model tpm limit to mean unlimited, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPriorityDemotionRecordFromEventPayloadKeepsReason(t *testing.T) {
|
||||
createdAt := time.Date(2026, 5, 12, 9, 30, 0, 0, time.UTC)
|
||||
record := priorityDemotionRecordFromEventPayload("event-1", "task-1", "fallback message", map[string]any{
|
||||
"platformId": "platform-1",
|
||||
"platformModelId": "platform-model-1",
|
||||
"reason": "priority_demote_policy",
|
||||
"errorCode": "rate_limit",
|
||||
"errorMessage": "upstream 429 rate limit",
|
||||
"category": "rate_limit",
|
||||
"statusCode": float64(429),
|
||||
"policySource": "gateway_runner_policies.priority_demote_policy",
|
||||
"policy": "priorityDemotePolicy",
|
||||
"policyRule": "categories",
|
||||
"matchedValue": "rate_limit",
|
||||
"dynamicPriority": float64(1511),
|
||||
}, createdAt)
|
||||
|
||||
if record.Reason != "priority_demote_policy" || record.ErrorMessage != "upstream 429 rate limit" {
|
||||
t.Fatalf("expected demotion reason and error message to survive, got %+v", record)
|
||||
}
|
||||
if record.StatusCode != 429 || record.DynamicPriority != 1511 {
|
||||
t.Fatalf("expected numeric demotion metadata, got %+v", record)
|
||||
}
|
||||
if !record.CreatedAt.Equal(createdAt) {
|
||||
t.Fatalf("expected createdAt %s, got %s", createdAt, record.CreatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user