feat: add proxy labels and default profiles

This commit is contained in:
QiuSW
2026-07-27 12:09:54 +08:00
parent a8b7277dab
commit 0f25f39480
10 changed files with 397 additions and 115 deletions
+10
View File
@@ -104,6 +104,16 @@ func NormalizeProxyServer(value string) (string, error) {
return scheme + "://" + net.JoinHostPort(strings.ToLower(parsed.Hostname()), strconv.Itoa(port)), nil
}
// NormalizeProxyName returns a non-empty display name for a locally saved
// proxy profile. It deliberately carries no endpoint or credentials semantics.
func NormalizeProxyName(value string) (string, error) {
name := strings.TrimSpace(value)
if name == "" {
return "", fmt.Errorf("%w: proxy name is required", ErrInvalidLaunchSpec)
}
return name, nil
}
func ValidRemoteDebugPort(port int) bool {
return port >= MinRemoteDebugPort && port <= MaxRemoteDebugPort
}
+10
View File
@@ -80,3 +80,13 @@ func TestNormalizeProxyServerCanonicalizesAndRejectsCredentials(t *testing.T) {
}
}
}
func TestNormalizeProxyNameRequiresNonEmptyDisplayText(t *testing.T) {
got, err := NormalizeProxyName(" 新加坡出口 ")
if err != nil || got != "新加坡出口" {
t.Fatalf("NormalizeProxyName() = %q, %v", got, err)
}
if _, err := NormalizeProxyName(" \t "); !errors.Is(err, ErrInvalidLaunchSpec) {
t.Fatalf("empty proxy name error = %v", err)
}
}