fix(panel): 建服表单按后端规则即时校验名称和子域名,控制台命令历史的下键不再跳到最早一条,补请求体测试

This commit is contained in:
Lemon-miaow committed 2026-09-27 06:30:07 +08:00
1 parent 6943d9c4c6
commit aa73a8ca28
8 files changed
+405 -20

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
package naming
import (
"os"
"regexp"
"slices"
"strings"
"testing"
)
// The panel's create form checks names as they are typed with its own copy of
// this rule (panel/src/lib/naming.ts). A name reserved or a length changed here
// without the panel would let the form send what the API refuses, or refuse what
// it takes, so the copy is compared to the source.
func TestPanelMirrorsServerNameRule(t *testing.T) {
raw, err := os.ReadFile("../../panel/src/lib/naming.ts")
if err != nil {
t.Fatal(err)
}
src := string(raw)
list := regexp.MustCompile(`(?s)RESERVED_SERVER_NAMES: readonly string\[\] = \[(.*?)\];`).FindStringSubmatch(src)
if list == nil {
t.Fatal("panel/src/lib/naming.ts: RESERVED_SERVER_NAMES not found")
}
var panel []string
for _, m := range regexp.MustCompile(`"([^"]*)"`).FindAllStringSubmatch(list[1], -1) {
panel = append(panel, m[1])
}
var api []string
for name := range reserved {
api = append(api, name)
}
slices.Sort(panel)
slices.Sort(api)
if !slices.Equal(panel, api) {
t.Errorf("panel reserves %v, API reserves %v", panel, api)
}
if want := "const SERVER_NAME_RE = /" + serverNameRE.String() + "/;"; !strings.Contains(src, want) {
t.Errorf("panel/src/lib/naming.ts lacks %q", want)
}
}