feat: publish v1.0.0-rc.36-custom.1
This commit is contained in:
commit
3a7e8f3b54
2381 files changed
+551494
No files matched your search
@@ -0,0 +1,11 @@
|
||||
package billing_setting
|
||||
|
||||
// Built-in token prices use actual USD per million tokens. Keep new model
|
||||
// defaults here instead of splitting them across the legacy ratio tables.
|
||||
var builtinBillingExpr = map[string]string{
|
||||
// https://developers.openai.com/api/docs/models/gpt-6-astra
|
||||
// Standard pricing; the long-context rates apply to the whole request.
|
||||
// Do not infer service-tier discounts from incoming request parameters:
|
||||
// channels filter service_tier by default, so it may not reach the upstream.
|
||||
"gpt-6-astra": `len <= 272000 ? tier("standard", p * 10 + c * 50 + cr * 1 + cc * 12.5) : tier("long_context", p * 20 + c * 75 + cr * 2 + cc * 25)`,
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package billing_setting_test
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/controller"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/QuantumNous/new-api/pkg/billingexpr"
|
||||
"github.com/QuantumNous/new-api/relaykit/dto"
|
||||
"github.com/QuantumNous/new-api/service"
|
||||
"github.com/QuantumNous/new-api/setting/billing_setting"
|
||||
"github.com/QuantumNous/new-api/setting/config"
|
||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGPT6AstraBuiltinBilling(t *testing.T) {
|
||||
settings := config.GlobalConfig.Get("billing_setting").(*billing_setting.BillingSetting)
|
||||
saved := *settings
|
||||
savedRatios, savedPrices := ratio_setting.ModelRatio2JSONString(), ratio_setting.ModelPrice2JSONString()
|
||||
savedOptions := common.OptionMap
|
||||
t.Cleanup(func() {
|
||||
*settings, common.OptionMap = saved, savedOptions
|
||||
require.NoError(t, ratio_setting.UpdateModelRatioByJSONString(savedRatios))
|
||||
require.NoError(t, ratio_setting.UpdateModelPriceByJSONString(savedPrices))
|
||||
})
|
||||
common.OptionMap = map[string]string{"billing_setting.billing_mode": `{}`, "billing_setting.billing_expr": `{}`}
|
||||
require.NoError(t, config.GlobalConfig.LoadFromDB(common.OptionMap))
|
||||
require.NoError(t, ratio_setting.UpdateModelRatioByJSONString(`{}`))
|
||||
require.NoError(t, ratio_setting.UpdateModelPriceByJSONString(`{}`))
|
||||
assert.Equal(t, billing_setting.BillingModeTieredExpr, billing_setting.GetBillingMode("gpt-6-astra"))
|
||||
expression, ok := billing_setting.GetBillingExpr("gpt-6-astra")
|
||||
require.True(t, ok)
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
input, output, cached, written int
|
||||
request string
|
||||
quota int
|
||||
}{
|
||||
{"standard", 1000, 100, 0, 0, `{}`, 7500},
|
||||
{"client flex cannot discount standard pricing", 1000, 100, 0, 0, `{"service_tier":"flex"}`, 7500},
|
||||
{"cache at context boundary", 272000, 1000, 200000, 20000, `{}`, 510000},
|
||||
{"whole request above boundary", 272001, 1000, 200000, 20000, `{}`, 1007510},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
usage := &dto.Usage{
|
||||
PromptTokens: tc.input, CompletionTokens: tc.output,
|
||||
PromptTokensDetails: dto.InputTokenDetails{CachedTokens: tc.cached, CacheWriteTokens: tc.written},
|
||||
}
|
||||
params := service.BuildTieredTokenParams(usage, false, billingexpr.UsedVars(expression))
|
||||
result, err := billingexpr.ComputeTieredQuotaWithRequest(&billingexpr.BillingSnapshot{
|
||||
ExprString: expression, GroupRatio: 1, QuotaPerUnit: 500000,
|
||||
}, params, billingexpr.RequestInput{Body: []byte(tc.request)})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.quota, result.ActualQuotaAfterGroup)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("admin options expose defaults without persisting them", func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
controller.GetOptions(ctx)
|
||||
var response struct {
|
||||
Success bool
|
||||
Data []model.Option
|
||||
}
|
||||
require.NoError(t, common.Unmarshal(recorder.Body.Bytes(), &response))
|
||||
require.True(t, response.Success)
|
||||
found := map[string]string{}
|
||||
for _, option := range response.Data {
|
||||
if _, ok := common.OptionMap[option.Key]; ok {
|
||||
assert.NotContains(t, found, option.Key)
|
||||
var values map[string]string
|
||||
require.NoError(t, common.UnmarshalJsonStr(option.Value, &values))
|
||||
found[option.Key] = values["gpt-6-astra"]
|
||||
assert.Equal(t, `{}`, common.OptionMap[option.Key])
|
||||
}
|
||||
}
|
||||
assert.Equal(t, map[string]string{"billing_setting.billing_mode": "tiered_expr", "billing_setting.billing_expr": expression}, found)
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name, mode, expr, ratios, prices, wantMode string
|
||||
}{
|
||||
{"custom expression overrides legacy price", "tiered_expr", "p * 7", `{"gpt-6-astra":8}`, `{}`, "tiered_expr"},
|
||||
{"explicit ratio mode", "ratio", "", `{}`, `{}`, "ratio"},
|
||||
{"existing free token price", "", "", `{"gpt-6-astra":0}`, `{}`, "ratio"},
|
||||
{"existing per-call price", "", "", `{}`, `{"gpt-6-astra":0.1}`, "ratio"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
*settings = billing_setting.BillingSetting{BillingMode: map[string]string{}, BillingExpr: map[string]string{}}
|
||||
if tc.mode != "" {
|
||||
settings.BillingMode["gpt-6-astra"] = tc.mode
|
||||
}
|
||||
if tc.expr != "" {
|
||||
settings.BillingExpr["gpt-6-astra"] = tc.expr
|
||||
}
|
||||
require.NoError(t, ratio_setting.UpdateModelRatioByJSONString(tc.ratios))
|
||||
require.NoError(t, ratio_setting.UpdateModelPriceByJSONString(tc.prices))
|
||||
assert.Equal(t, tc.wantMode, billing_setting.GetBillingMode("gpt-6-astra"))
|
||||
actual, ok := billing_setting.GetBillingExpr("gpt-6-astra")
|
||||
assert.Equal(t, tc.expr, actual)
|
||||
assert.Equal(t, tc.expr != "", ok)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
package billing_setting
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/pkg/billingexpr"
|
||||
"github.com/QuantumNous/new-api/pkg/jsplugin"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
"github.com/QuantumNous/new-api/relaykit/dto"
|
||||
"github.com/QuantumNous/new-api/setting/config"
|
||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
const (
|
||||
BillingModeRatio = "ratio"
|
||||
BillingModeTieredExpr = "tiered_expr"
|
||||
BillingModeField = "billing_mode"
|
||||
BillingExprField = "billing_expr"
|
||||
maxTaskExprSmokeTests = 64
|
||||
)
|
||||
|
||||
// BillingSetting is managed by config.GlobalConfig.Register.
|
||||
// DB keys: billing_setting.billing_mode, billing_setting.billing_expr
|
||||
type BillingSetting struct {
|
||||
BillingMode map[string]string `json:"billing_mode"`
|
||||
BillingExpr map[string]string `json:"billing_expr"`
|
||||
GroupBillingExpr map[string]map[string]string `json:"group_billing_expr"`
|
||||
}
|
||||
|
||||
var billingSetting = BillingSetting{
|
||||
BillingMode: make(map[string]string),
|
||||
BillingExpr: make(map[string]string),
|
||||
GroupBillingExpr: make(map[string]map[string]string),
|
||||
}
|
||||
|
||||
func init() {
|
||||
config.GlobalConfig.Register("billing_setting", &billingSetting)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Read accessors (hot path, must be fast)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func GetBillingMode(model string) string {
|
||||
if mode, ok := billingSetting.BillingMode[model]; ok {
|
||||
return mode
|
||||
}
|
||||
if _, ok := builtinBillingExpr[model]; ok {
|
||||
// Existing administrator-configured legacy prices take precedence over
|
||||
// a newly introduced built-in expression unless a mode was explicit.
|
||||
if ratio_setting.HasConfiguredModelRatio(model) {
|
||||
return BillingModeRatio
|
||||
}
|
||||
if _, configured := ratio_setting.GetModelPrice(model, false); configured {
|
||||
return BillingModeRatio
|
||||
}
|
||||
return BillingModeTieredExpr
|
||||
}
|
||||
return BillingModeRatio
|
||||
}
|
||||
|
||||
func GetBillingExpr(model string) (string, bool) {
|
||||
if expr, ok := billingSetting.BillingExpr[model]; ok {
|
||||
return expr, true
|
||||
}
|
||||
if GetBillingMode(model) == BillingModeTieredExpr {
|
||||
expr, ok := builtinBillingExpr[model]
|
||||
return expr, ok
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func GetBuiltinBillingExpr(model string) (string, bool) {
|
||||
expression, ok := builtinBillingExpr[model]
|
||||
return expression, ok
|
||||
}
|
||||
|
||||
func GetBuiltinBillingExprCopy() map[string]string {
|
||||
return lo.Assign(builtinBillingExpr)
|
||||
}
|
||||
|
||||
func GetGroupBillingExpr(group, model string) (string, bool) {
|
||||
expr, ok := billingSetting.GroupBillingExpr[group][model]
|
||||
return expr, ok
|
||||
}
|
||||
|
||||
func GetBillingExprForGroup(group, model string) (string, bool) {
|
||||
if expr, ok := GetGroupBillingExpr(group, model); ok {
|
||||
return expr, true
|
||||
}
|
||||
return GetBillingExpr(model)
|
||||
}
|
||||
|
||||
func GetBillingModeCopy() map[string]string {
|
||||
modes := lo.Assign(billingSetting.BillingMode)
|
||||
for model := range builtinBillingExpr {
|
||||
if _, configured := modes[model]; !configured && GetBillingMode(model) == BillingModeTieredExpr {
|
||||
modes[model] = BillingModeTieredExpr
|
||||
}
|
||||
}
|
||||
return modes
|
||||
}
|
||||
|
||||
func GetBillingExprCopy() map[string]string {
|
||||
expressions := lo.Assign(billingSetting.BillingExpr)
|
||||
for model := range builtinBillingExpr {
|
||||
if _, configured := expressions[model]; configured {
|
||||
continue
|
||||
}
|
||||
if expression, ok := GetBillingExpr(model); ok {
|
||||
expressions[model] = expression
|
||||
}
|
||||
}
|
||||
return expressions
|
||||
}
|
||||
|
||||
func GetPricingSyncData(base map[string]any) map[string]any {
|
||||
extra := make(map[string]any, 2)
|
||||
if modes := GetBillingModeCopy(); len(modes) > 0 {
|
||||
extra[BillingModeField] = modes
|
||||
}
|
||||
if exprs := GetBillingExprCopy(); len(exprs) > 0 {
|
||||
extra[BillingExprField] = exprs
|
||||
}
|
||||
return lo.Assign(base, extra)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Smoke test (called externally for validation before save)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func SmokeTestExpr(exprStr string) error {
|
||||
return smokeTestExpr(exprStr)
|
||||
}
|
||||
|
||||
func smokeTestExpr(exprStr string) error {
|
||||
if _, err := billingexpr.CompileFromCache(exprStr); err != nil {
|
||||
return err
|
||||
}
|
||||
usageKeys := billingexpr.UsedUsageKeys(exprStr)
|
||||
if len(usageKeys) > 0 {
|
||||
sortedKeys := make([]string, 0, len(usageKeys))
|
||||
for key := range usageKeys {
|
||||
sortedKeys = append(sortedKeys, key)
|
||||
}
|
||||
sort.Strings(sortedKeys)
|
||||
return fmt.Errorf("expression references usage keys %v but the model has no task plugin usage schema", sortedKeys)
|
||||
}
|
||||
|
||||
vectors := []billingexpr.TokenParams{
|
||||
{P: 0, C: 0, Len: 0},
|
||||
{P: 1000, C: 1000, Len: 1000},
|
||||
{P: 100000, C: 100000, Len: 100000},
|
||||
{P: 1000000, C: 1000000, Len: 1000000},
|
||||
}
|
||||
|
||||
for _, v := range vectors {
|
||||
for _, request := range billingExprSmokeRequests() {
|
||||
result, _, err := billingexpr.RunExprWithRequest(exprStr, v, request)
|
||||
if err != nil {
|
||||
return fmt.Errorf("vector {p=%g, c=%g}: run failed: %w", v.P, v.C, err)
|
||||
}
|
||||
if math.IsNaN(result) || math.IsInf(result, 0) || result < 0 {
|
||||
return fmt.Errorf("vector {p=%g, c=%g}: result must be finite and non-negative, got %f", v.P, v.C, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SmokeTestTaskExpr validates a task usage expression against the usage facts
|
||||
// declared by its plugin. Literal u() keys must be declared; dynamic calls are
|
||||
// still exercised by the generated runtime vectors when possible.
|
||||
func SmokeTestTaskExpr(exprStr string, schema map[string]jsplugin.UsageFieldSchema) error {
|
||||
if _, err := billingexpr.CompileFromCache(exprStr); err != nil {
|
||||
return err
|
||||
}
|
||||
for key := range billingexpr.UsedUsageKeys(exprStr) {
|
||||
if _, declared := schema[key]; !declared {
|
||||
return fmt.Errorf("usage key %q is not declared by the task plugin", key)
|
||||
}
|
||||
}
|
||||
|
||||
for _, usage := range taskUsageSmokeVectors(schema) {
|
||||
for _, request := range billingExprSmokeRequests() {
|
||||
request.Usage = usage
|
||||
result, _, err := billingexpr.RunExprWithRequest(exprStr, billingexpr.TokenParams{}, request)
|
||||
if err != nil {
|
||||
return fmt.Errorf("usage vector %v: run failed: %w", usage, err)
|
||||
}
|
||||
if math.IsNaN(result) || math.IsInf(result, 0) || result < 0 {
|
||||
return fmt.Errorf("usage vector %v: result must be finite and non-negative, got %f", usage, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type usageSmokeDimension struct {
|
||||
name string
|
||||
values []any
|
||||
}
|
||||
|
||||
func taskUsageSmokeVectors(schema map[string]jsplugin.UsageFieldSchema) []map[string]any {
|
||||
names := make([]string, 0, len(schema))
|
||||
for name := range schema {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
dimensions := make([]usageSmokeDimension, 0, len(names))
|
||||
for _, name := range names {
|
||||
field := schema[name]
|
||||
if len(field.Enum) > 0 {
|
||||
values := make([]any, len(field.Enum))
|
||||
for index, value := range field.Enum {
|
||||
values[index] = value
|
||||
}
|
||||
dimensions = append(dimensions, usageSmokeDimension{name: name, values: values})
|
||||
continue
|
||||
}
|
||||
if field.Type == "boolean" {
|
||||
dimensions = append(dimensions, usageSmokeDimension{name: name, values: []any{false, true}})
|
||||
continue
|
||||
}
|
||||
limit := relaycommon.MaxTaskDurationSeconds
|
||||
if field.Unit == "count" {
|
||||
limit = dto.MaxImageN
|
||||
}
|
||||
if field.Unit == "token" || field.Unit == "credit" {
|
||||
limit = common.MaxQuota
|
||||
}
|
||||
dimensions = append(dimensions, usageSmokeDimension{
|
||||
name: name,
|
||||
values: []any{float64(0), float64(1), float64(limit)},
|
||||
})
|
||||
}
|
||||
|
||||
if usageSmokeCombinationCount(dimensions, maxTaskExprSmokeTests) > maxTaskExprSmokeTests {
|
||||
for index := range dimensions {
|
||||
field := schema[dimensions[index].name]
|
||||
if len(field.Enum) <= 2 {
|
||||
continue
|
||||
}
|
||||
dimensions[index].values = []any{field.Enum[0], field.Enum[len(field.Enum)-1]}
|
||||
}
|
||||
}
|
||||
|
||||
vectors := make([]map[string]any, 0, maxTaskExprSmokeTests)
|
||||
var appendVectors func(int, map[string]any)
|
||||
appendVectors = func(index int, current map[string]any) {
|
||||
if len(vectors) >= maxTaskExprSmokeTests {
|
||||
return
|
||||
}
|
||||
if index == len(dimensions) {
|
||||
vector := make(map[string]any, len(current))
|
||||
maps.Copy(vector, current)
|
||||
vectors = append(vectors, vector)
|
||||
return
|
||||
}
|
||||
for _, value := range dimensions[index].values {
|
||||
current[dimensions[index].name] = value
|
||||
appendVectors(index+1, current)
|
||||
}
|
||||
delete(current, dimensions[index].name)
|
||||
}
|
||||
appendVectors(0, make(map[string]any, len(dimensions)))
|
||||
|
||||
combinationCount := usageSmokeCombinationCount(dimensions, maxTaskExprSmokeTests)
|
||||
if combinationCount > maxTaskExprSmokeTests && len(vectors) > 0 {
|
||||
last := make(map[string]any, len(dimensions))
|
||||
for _, dimension := range dimensions {
|
||||
last[dimension.name] = dimension.values[len(dimension.values)-1]
|
||||
}
|
||||
vectors[len(vectors)-1] = last
|
||||
}
|
||||
return vectors
|
||||
}
|
||||
|
||||
func usageSmokeCombinationCount(dimensions []usageSmokeDimension, stopAfter int) int {
|
||||
count := 1
|
||||
for _, dimension := range dimensions {
|
||||
if len(dimension.values) == 0 {
|
||||
return 0
|
||||
}
|
||||
if count > stopAfter/len(dimension.values) {
|
||||
return stopAfter + 1
|
||||
}
|
||||
count *= len(dimension.values)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func billingExprSmokeRequests() []billingexpr.RequestInput {
|
||||
return []billingexpr.RequestInput{
|
||||
{},
|
||||
{
|
||||
Headers: map[string]string{
|
||||
"anthropic-beta": "fast-mode-2026-02-01",
|
||||
},
|
||||
Body: []byte(`{"service_tier":"fast","stream_options":{"include_usage":true},"messages":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]}`),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package billing_setting
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/pkg/jsplugin"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
"github.com/QuantumNous/new-api/relaykit/dto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSmokeTestTaskExprValidatesDeclaredUsageVectors(t *testing.T) {
|
||||
videoSchema := map[string]jsplugin.UsageFieldSchema{
|
||||
"seconds": {Type: "number", Unit: "second"},
|
||||
"mode": {Enum: []string{"std", "pro"}},
|
||||
"quality": {Enum: []string{"sd", "hd"}},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
schema map[string]jsplugin.UsageFieldSchema
|
||||
expression string
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "declared numeric and enum facts",
|
||||
schema: videoSchema,
|
||||
expression: `u("mode") == "pro" ? tier("pro", u("seconds") * 0.8) : tier("std", u("seconds") * 0.4)`,
|
||||
},
|
||||
{
|
||||
name: "undeclared literal key",
|
||||
schema: videoSchema,
|
||||
expression: `tier("base", u("clips") * 0.1)`,
|
||||
expectedError: `usage key "clips" is not declared`,
|
||||
},
|
||||
{
|
||||
name: "negative duration boundary",
|
||||
schema: videoSchema,
|
||||
expression: fmt.Sprintf(`u("seconds") == %d ? -1 : 0`, relaycommon.MaxTaskDurationSeconds),
|
||||
expectedError: "result must be finite and non-negative",
|
||||
},
|
||||
{
|
||||
name: "negative count boundary",
|
||||
schema: map[string]jsplugin.UsageFieldSchema{"clips": {Type: "number", Unit: "count"}},
|
||||
expression: fmt.Sprintf(`u("clips") == %d ? -1 : 0`, dto.MaxImageN),
|
||||
expectedError: "result must be finite and non-negative",
|
||||
},
|
||||
{
|
||||
name: "negative token boundary",
|
||||
schema: map[string]jsplugin.UsageFieldSchema{"tokens": {Type: "number", Unit: "token"}},
|
||||
expression: fmt.Sprintf(`u("tokens") == %d ? -1 : 0`, common.MaxQuota),
|
||||
expectedError: "result must be finite and non-negative",
|
||||
},
|
||||
{
|
||||
name: "negative credit boundary",
|
||||
schema: map[string]jsplugin.UsageFieldSchema{"units": {Type: "number", Unit: "credit"}},
|
||||
expression: fmt.Sprintf(`u("units") == %d ? -1 : 0`, common.MaxQuota),
|
||||
expectedError: "result must be finite and non-negative",
|
||||
},
|
||||
{
|
||||
name: "negative enum combination",
|
||||
schema: videoSchema,
|
||||
expression: `u("mode") == "pro" && u("quality") == "hd" ? -1 : 0`,
|
||||
expectedError: "result must be finite and non-negative",
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range tests {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
err := SmokeTestTaskExpr(testCase.expression, testCase.schema)
|
||||
if testCase.expectedError == "" {
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
require.ErrorContains(t, err, testCase.expectedError)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSmokeTestTaskExprCapsOversizedEnumProductsAtLastCombination(t *testing.T) {
|
||||
schema := make(map[string]jsplugin.UsageFieldSchema, 7)
|
||||
condition := ""
|
||||
for index := range 7 {
|
||||
schema[fmt.Sprintf("enum_%d", index)] = jsplugin.UsageFieldSchema{Enum: []string{"first", "middle", "last"}}
|
||||
if condition != "" {
|
||||
condition += " && "
|
||||
}
|
||||
condition += fmt.Sprintf(`u("enum_%d") == "last"`, index)
|
||||
}
|
||||
|
||||
err := SmokeTestTaskExpr(condition+" ? -1 : 0", schema)
|
||||
require.ErrorContains(t, err, "result must be finite and non-negative")
|
||||
}
|
||||
|
||||
func TestSmokeTestExprRejectsTaskUsageWithoutSchema(t *testing.T) {
|
||||
err := SmokeTestExpr(`u("mode") == "std" ? 1 : 2`)
|
||||
require.Error(t, err)
|
||||
assert.ErrorContains(t, err, "mode")
|
||||
assert.ErrorContains(t, err, "no task plugin usage schema")
|
||||
|
||||
require.NoError(t, SmokeTestExpr(`tier("base", p * 2 + c * 8)`))
|
||||
}
|
||||
Reference in new issue
Block a user