package service import ( "context" "testing" "time" ) // TestHasRetryBudget 模型重试预算判定: // 无 deadline 视为充足;剩余不足 aiRecommendRetryMinBudget 时不允许再发起一次模型调用(改为服务端补齐)。 func TestHasRetryBudget(t *testing.T) { if !hasRetryBudget(context.Background()) { t.Fatal("no deadline should be treated as budget available") } short, cancelShort := context.WithTimeout(context.Background(), 60*time.Second) defer cancelShort() if hasRetryBudget(short) { t.Fatalf("60s remaining should be insufficient (min budget %s)", aiRecommendRetryMinBudget) } enough, cancelEnough := context.WithTimeout(context.Background(), 5*time.Minute) defer cancelEnough() if !hasRetryBudget(enough) { t.Fatal("5m remaining should allow one model retry") } }