开发检查点:收尾项目生命周期并接入资源读取隔离,待统一测试

This commit is contained in:
xuans committed 2026-09-28 21:20:20 +08:00
1 parent fd767b23c3
commit 709c1ef063
27 files changed
+785 -68

No files matched your search

+5 -1
View File
@@ -13,6 +13,10 @@ const DefaultProjectID = "default"
var projectIDPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,35}$`)
func ValidProjectID(id string) bool {
return projectIDPattern.MatchString(id)
}
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
@@ -41,7 +45,7 @@ func (p Project) Normalize() Project {
}
func (p Project) Validate() error {
if !projectIDPattern.MatchString(p.ID) {
if !ValidProjectID(p.ID) {
return errors.New("项目 ID 必须为 1~36 位小写字母、数字、连字符或下划线,并以字母或数字开头")
}
if !utf8.ValidString(p.Name) || strings.TrimSpace(p.Name) == "" || utf8.RuneCountInString(p.Name) > 128 {
+13
View File
@@ -22,6 +22,19 @@ func TestNewProject(t *testing.T) {
}
}
func TestValidProjectID(t *testing.T) {
for _, id := range []string{DefaultProjectID, "a", "1", "project_a-1", strings.Repeat("a", 36)} {
if !ValidProjectID(id) {
t.Fatalf("拒绝合法项目标识:%q", id)
}
}
for _, id := range []string{"", "UPPERCASE", strings.Repeat("a", 37), " project", "project ", "_project", "../project", "项目"} {
if ValidProjectID(id) {
t.Fatalf("接受无效项目标识:%q", id)
}
}
}
func TestProjectValidation(t *testing.T) {
cases := []struct {
name string