Files
ai_site/platform/internal/schema/dbname_test.go
whm 4b6c90904b fix: Z35 map Chinese display names to stable physical DB names
Keep Chinese on Binding for UI; Agents use user_{id} or db{hash}; sanitize on attach/heal/publish.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 02:12:55 +08:00

34 lines
1.0 KiB
Go

package schema
import "testing"
func TestSafeSyncDatabaseName(t *testing.T) {
// 有用户:中文昵称 → 稳定 user_{id}(改昵称不换库)
if got := SafeSyncDatabaseName("婷婷管理员", 12, 34); got != "user_34" {
t.Fatalf("want user_34, got %s", got)
}
// 无用户:中文/非法标签 → 稳定哈希
h1 := SafeSyncDatabaseName("婷婷管理员", 12, 0)
h2 := SafeSyncDatabaseName("婷婷管理员", 12, 0)
if h1 != h2 || !ValidDBName(h1) || h1[:2] != "db" {
t.Fatalf("hash mapping bad: %s", h1)
}
if SafeSyncDatabaseName("另一中文", 12, 0) == h1 {
t.Fatal("different labels should hash differently")
}
if got := SafeSyncDatabaseName("ok_db", 1, 2); got != "ok_db" {
t.Fatalf("want ok_db, got %s", got)
}
if !ValidDBName("user_1") || ValidDBName("婷婷管理员") {
t.Fatal("ValidDBName mismatch")
}
}
func TestHashLabelDBNameStable(t *testing.T) {
a := HashLabelDBName("宇信达", 7)
b := HashLabelDBName("宇信达", 7)
if a != b || !ValidDBName(a) {
t.Fatalf("unstable or invalid: %s", a)
}
}