feat: sync deployed v1.0.0-rc.38-custom.67
This commit is contained in:
1 parent
d2e03ab7e8
commit
ffc8cf56db
154 files changed
+39540
-20509
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
fingerprint "github.com/QuantumNous/new-api/pkg/model_fingerprint"
|
||||
"github.com/QuantumNous/new-api/service"
|
||||
"github.com/QuantumNous/new-api/setting"
|
||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -51,10 +52,11 @@ func TestStatusPageDatabaseMatrix(t *testing.T) {
|
||||
oldType, oldLogType := common.MainDatabaseType(), common.LogDatabaseType()
|
||||
oldRedis, oldSecret, oldSecure := common.RedisEnabled, common.SessionSecret, common.SessionCookieSecure
|
||||
oldGroups := setting.UserUsableGroups2JSONString()
|
||||
oldRatios := ratio_setting.GroupRatio2JSONString()
|
||||
model.DB, model.LOG_DB = db, db
|
||||
common.SetDatabaseTypes(common.DatabaseType(dialect), common.DatabaseType(dialect))
|
||||
common.RedisEnabled, common.SessionSecret, common.SessionCookieSecure = false, "status-test-only", true
|
||||
rows := []any{&model.Option{}, &model.Channel{}, &model.Ability{}, &model.SystemTask{}, &model.DetectionRun{}, &model.DetectionCall{}, &model.DetectionSchedule{}, &model.Log{}, &model.PerfMetric{}, &model.User{}, &model.UserSession{}}
|
||||
rows := []any{&model.GroupMetadata{}, &model.Option{}, &model.Channel{}, &model.Ability{}, &model.SystemTask{}, &model.DetectionRun{}, &model.DetectionCall{}, &model.DetectionSchedule{}, &model.Log{}, &model.PerfMetric{}, &model.User{}, &model.UserSession{}}
|
||||
require.NoError(t, db.AutoMigrate(rows...))
|
||||
require.NoError(t, db.Table("audit_logs").AutoMigrate(&model.AuditLog{}))
|
||||
t.Cleanup(func() {
|
||||
@@ -66,6 +68,7 @@ func TestStatusPageDatabaseMatrix(t *testing.T) {
|
||||
common.SetDatabaseTypes(oldType, oldLogType)
|
||||
common.RedisEnabled, common.SessionSecret, common.SessionCookieSecure = oldRedis, oldSecret, oldSecure
|
||||
require.NoError(t, setting.UpdateUserUsableGroupsByJSONString(oldGroups))
|
||||
require.NoError(t, ratio_setting.UpdateGroupRatioByJSONString(oldRatios))
|
||||
groupCacheSnapshot.updated = time.Time{}
|
||||
require.NoError(t, conn.Close())
|
||||
})
|
||||
@@ -77,15 +80,17 @@ func TestStatusPageDatabaseMatrix(t *testing.T) {
|
||||
require.NoError(t, db.Raw(q).Scan(&version).Error)
|
||||
t.Log("database version:", version)
|
||||
require.NoError(t, setting.UpdateUserUsableGroupsByJSONString(`{"internal":"","shared":"","hidden":""}`))
|
||||
require.NoError(t, ratio_setting.UpdateGroupRatioByJSONString(`{"internal":0.25,"shared":0,"hidden":1}`))
|
||||
now := time.Now().Unix()
|
||||
channels := []model.Channel{{Id: 1, Name: "private-channel", Key: "private-key", Group: "internal,shared", Models: fingerprint.Model, Status: 1}, {Id: 2, Group: "hidden", Models: fingerprint.Model, Status: 1}, {Id: 3, Group: "internal", Models: "disabled-model", Status: 2}}
|
||||
require.NoError(t, db.Create(&channels).Error)
|
||||
abilities := []model.Ability{{Group: "internal", Model: fingerprint.Model, ChannelId: 1, Enabled: true}, {Group: "shared", Model: fingerprint.Model, ChannelId: 1, Enabled: true}, {Group: "hidden", Model: fingerprint.Model, ChannelId: 2, Enabled: true}, {Group: "internal", Model: "disabled-model", ChannelId: 3, Enabled: true}, {Group: "internal", Model: "disabled-ability", ChannelId: 1}}
|
||||
require.NoError(t, db.Create(&abilities).Error)
|
||||
state, err := common.Marshal(service.AstraSamplingState{Rounds: []service.AstraSamplingRound{{ID: "old-round", ChannelID: 1, StartedAt: now - 20, FinishedAt: now - 10, Result: fingerprint.Result{Status: "match", Closest: fingerprint.Model, ValidSamples: 3}}}})
|
||||
require.NoError(t, db.Create(&model.Log{Type: model.LogTypeConsume, TokenId: 1, ChannelId: 1, Group: "internal", ModelName: fingerprint.Model, Quota: 50, PromptTokens: 1000, CreatedAt: now - 10, Other: `{}`}).Error)
|
||||
state, err := common.Marshal(service.AstraSamplingState{Rounds: []service.AstraSamplingRound{{ID: "old-round", ChannelID: 1, StartedAt: now - 20, FinishedAt: now - 10, Result: fingerprint.Result{Engine: fingerprint.Version, Status: "match", Closest: fingerprint.Model, ValidSamples: 3}}}})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.Create(&model.SystemTask{TaskID: "old-task", Type: service.AstraSamplingTaskType, Status: model.SystemTaskStatusSucceeded, CreatedAt: now - 20, State: string(state)}).Error)
|
||||
runs := []model.DetectionRun{{ID: "old-work", RequestKey: "old-work", ChannelID: 1, GroupName: "internal", Kind: "pelican", Status: "succeeded", Quality: "normal", CreatedAt: now - 20, Settled: true, HTML: "<h1>art</h1>", Charged: 17}, {ID: "in-flight", RequestKey: "in-flight", ChannelID: 1, Kind: "pelican", Status: "running", CreatedAt: now - 10}, {ID: "hidden-art", RequestKey: "hidden-art", ChannelID: 2, Kind: "pelican", Status: "succeeded", CreatedAt: now - 20, HTML: "hidden"}}
|
||||
runs := []model.DetectionRun{{ID: "old-work", RequestKey: "old-work", ChannelID: 1, GroupName: "internal", Kind: "benchmark", Status: "succeeded", Quality: "normal", CreatedAt: now - 20, Settled: true, HTML: "<h1>art</h1>", Charged: 17}, {ID: "in-flight", RequestKey: "in-flight", ChannelID: 1, Kind: "benchmark", Status: "running", CreatedAt: now - 10}, {ID: "hidden-art", RequestKey: "hidden-art", ChannelID: 2, Kind: "benchmark", Status: "succeeded", CreatedAt: now - 20, HTML: "hidden"}}
|
||||
require.NoError(t, db.Create(&runs).Error)
|
||||
tokens := map[int]string{}
|
||||
for _, role := range []int{1, 10} {
|
||||
@@ -131,23 +136,32 @@ func TestStatusPageDatabaseMatrix(t *testing.T) {
|
||||
groupCacheSnapshot.updated = time.Time{}
|
||||
res := request("GET", "/api/uptime/status", "", "", "")
|
||||
require.Equal(t, 200, res.Code, res.Body.String())
|
||||
assert.NotContains(t, res.Body.String(), "model_costs")
|
||||
for _, secret := range []string{"internal", "secret-alias", "private-channel", "private-key", "disabled-model", "disabled-ability"} {
|
||||
assert.NotContains(t, res.Body.String(), secret)
|
||||
}
|
||||
assert.Contains(t, res.Body.String(), "#688")
|
||||
fallback := model.DetectionRun{ID:"fallback-completed",RequestKey:"fallback-completed",Kind:"pelican",ChannelID:1,GroupName:"internal",Status:"running",Quality:"normal",HTML:"<html>pelican</html>",CreatedAt:now,Deadline:now+600}
|
||||
require.NoError(t,db.Create(&fallback).Error)
|
||||
require.NoError(t,db.Create(&model.DetectionCall{ID:fallback.ID,RunID:fallback.ID,SecretHash:"fallback-only-test",State:"finished"}).Error)
|
||||
processLocalPelican(context.Background(),fallback)
|
||||
require.NoError(t,db.First(&fallback,"id = ?",fallback.ID).Error)
|
||||
assert.Equal(t,"succeeded",fallback.Status)
|
||||
assert.Equal(t,"unknown",fallback.Quality)
|
||||
assert.Equal(t,"<html>pelican</html>",fallback.HTML)
|
||||
assert.True(t,fallback.Settled)
|
||||
require.NoError(t,db.Delete(&model.DetectionCall{},"id = ?",fallback.ID).Error)
|
||||
require.NoError(t,db.Delete(&model.DetectionRun{},"id = ?",fallback.ID).Error)
|
||||
assert.Contains(t, res.Body.String(), `"group_ratio":0.25`)
|
||||
require.NoError(t, model.SaveGroupMetadata(context.Background(), map[string]model.GroupMetadataValue{"internal": {Tags: []string{"打野", "不稳定"}}}))
|
||||
service.InvalidateGroupQualityCache()
|
||||
visitorSite := request("GET", "/api/group-status", "", "", "")
|
||||
require.Equal(t, 200, visitorSite.Code)
|
||||
var siteData struct {
|
||||
Data []UptimeGroupResult `json:"data"`
|
||||
}
|
||||
require.NoError(t, common.Unmarshal(visitorSite.Body.Bytes(), &siteData))
|
||||
require.NotEmpty(t, siteData.Data)
|
||||
for _, monitor := range siteData.Data[0].Monitors {
|
||||
if monitor.Group == "internal" {
|
||||
require.Equal(t, []string{"打野", "不稳定"}, monitor.Tags)
|
||||
require.NotNil(t, monitor.ModelCosts[fingerprint.Model].USDPerMillion)
|
||||
assert.Equal(t, int64(1), monitor.ModelCosts[fingerprint.Model].Requests)
|
||||
}
|
||||
if monitor.Group == "shared" {
|
||||
assert.Empty(t, monitor.ModelCosts, "shared channel membership must not copy another group's billed usage")
|
||||
}
|
||||
}
|
||||
assert.NotContains(t, request("GET", "/api/uptime/status", "", "", "").Body.String(), "model_costs")
|
||||
assert.Contains(t, visitorSite.Body.String(), `"group":"hidden"`)
|
||||
assert.Contains(t, visitorSite.Body.String(), `"name":"internal"`)
|
||||
assert.NotContains(t, visitorSite.Body.String(), "#688")
|
||||
@@ -171,9 +185,9 @@ func TestStatusPageDatabaseMatrix(t *testing.T) {
|
||||
}
|
||||
assert.Empty(t, byGroup["internal"].Fingerprint.History)
|
||||
assert.Nil(t, byGroup["internal"].Fingerprint.Rate)
|
||||
assert.Empty(t, byGroup["internal"].Pelican.History)
|
||||
assert.Empty(t, byGroup["internal"].Benchmark.History)
|
||||
assert.Len(t, byGroup["shared"].Fingerprint.History, 1)
|
||||
assert.Len(t, byGroup["shared"].Pelican.History, 2)
|
||||
assert.Len(t, byGroup["shared"].Benchmark.History, 2)
|
||||
assert.True(t, byGroup["hidden"].Hidden)
|
||||
assert.Equal(t, []string{fingerprint.Model}, byGroup["internal"].Models)
|
||||
require.NoError(t, model.SaveStatusPageGroup(context.Background(), "internal", &model.StatusPageGroup{Alias: "#689", Hidden: true}))
|
||||
@@ -187,13 +201,13 @@ func TestStatusPageDatabaseMatrix(t *testing.T) {
|
||||
require.NoError(t, db.First(&retained, "id = ?", "old-work").Error)
|
||||
assert.Equal(t, 17, retained.Charged)
|
||||
assert.Equal(t, "<h1>art</h1>", retained.HTML)
|
||||
require.NoError(t, db.Create(&model.DetectionRun{ID: "new-work", RequestKey: "new-work", ChannelID: 1, Kind: "pelican", Status: "succeeded", Quality: "normal", CreatedAt: settings["internal"].ResetBefore + 1, Settled: true}).Error)
|
||||
require.NoError(t, db.Create(&model.DetectionRun{ID: "new-work", RequestKey: "new-work", ChannelID: 1, Kind: "benchmark", Status: "succeeded", Quality: "normal", CreatedAt: settings["internal"].ResetBefore + 1, Settled: true}).Error)
|
||||
groups, err = currentGroupMonitors(context.Background(), true)
|
||||
require.NoError(t, err)
|
||||
for _, m := range groups[0].Monitors {
|
||||
if m.Group == "internal" {
|
||||
require.Len(t, m.Pelican.History, 1)
|
||||
assert.Equal(t, "new-work", m.Pelican.History[0].ID)
|
||||
require.Len(t, m.Benchmark.History, 1)
|
||||
assert.Equal(t, "new-work", m.Benchmark.History[0].ID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user