55 lines
2.1 KiB
Go
55 lines
2.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestZCodeNoMonthlyCap: an older GLM Coding plan's reply (#366) — the
|
|
// five hours untouched, no week, and the month's MCP tool calls with no
|
|
// cap given as 100% used. The account is not out: only the five hours
|
|
// count, and the uncapped month reads as nothing used.
|
|
func TestZCodeNoMonthlyCap(t *testing.T) {
|
|
now := time.Now()
|
|
reset := now.Add(3 * time.Hour).UnixMilli()
|
|
month := now.Add(20 * 24 * time.Hour).UnixMilli()
|
|
var d zhipuLimits
|
|
if err := json.Unmarshal([]byte(`{"level":"pro","limits":[
|
|
{"type":"TOKENS_LIMIT","unit":3,"number":5,"percentage":0,"nextResetTime":`+strconv.FormatInt(reset, 10)+`},
|
|
{"type":"TIME_LIMIT","unit":5,"number":1,"usage":0,"currentValue":0,"remaining":0,"percentage":100,"nextResetTime":`+strconv.FormatInt(month, 10)+`}]}`), &d); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ws := d.windows()
|
|
if len(ws) != 2 || ws[0].Name != "5 hours" || ws[0].Aside || ws[1].Name != "MCP · Month" || !ws[1].Aside || ws[1].Used != 0 {
|
|
t.Fatalf("windows: %+v", ws)
|
|
}
|
|
a := allowanceOf(ws, now)
|
|
if used, _ := a.For("glm-5.1", now); used != 0 {
|
|
t.Fatalf("used %v, want 0", used)
|
|
}
|
|
if full := a.Full("glm-5.1", 100, now); !full.IsZero() {
|
|
t.Fatalf("full until %v", full)
|
|
}
|
|
|
|
// the MCP calls used up on a plan that caps them don't stop the models
|
|
// either, and still show as used
|
|
d = zhipuLimits{}
|
|
json.Unmarshal([]byte(`{"limits":[
|
|
{"type":"TOKENS_LIMIT","unit":3,"number":5,"percentage":10,"nextResetTime":`+strconv.FormatInt(reset, 10)+`},
|
|
{"type":"TOKENS_LIMIT","unit":6,"number":1,"percentage":30,"nextResetTime":`+strconv.FormatInt(month, 10)+`},
|
|
{"type":"TIME_LIMIT","unit":5,"number":1,"usage":100,"currentValue":100,"remaining":0,"percentage":100,"nextResetTime":`+strconv.FormatInt(month, 10)+`}]}`), &d)
|
|
ws = d.windows()
|
|
if len(ws) != 3 || ws[2].Used != 100 || !ws[2].Aside || ws[1].Aside {
|
|
t.Fatalf("capped: %+v", ws)
|
|
}
|
|
a = allowanceOf(ws, now)
|
|
if used, _ := a.For("glm-5.1", now); used != 30 {
|
|
t.Fatalf("capped used %v, want 30", used)
|
|
}
|
|
if full := a.Full("glm-5.1", 100, now); !full.IsZero() {
|
|
t.Fatalf("capped full until %v", full)
|
|
}
|
|
}
|