fix(v0.1): sanitize session id for PVC name (RFC 1123 subdomain compliance)

session id 允许任意字符(含下划线/大写/点),但 PVC name 必须符合
RFC 1123 subdomain(小写字母数字 + '-' + '.',首尾必须 alphanumeric)。

sanitizeSessionIdForPvc 把非法字符替换为 '-',全空 fallback 到 'default'。
selftest 增加 3 case 覆盖下划线/大写/纯符号。
This commit is contained in:
Codex
2026-06-03 19:47:29 +08:00
parent e8cfa4c692
commit da797c907c
2 changed files with 9 additions and 2 deletions
+5 -1
View File
@@ -38,9 +38,13 @@ const defaultPvcSize = "1Gi";
const defaultSubdir = "sessions";
export function sessionPvcNameFor(sessionId: string): string {
return `agentrun-v01-session-${sessionId}`;
const sanitized = sanitizeSessionIdForPvc(sessionId);
return `agentrun-v01-session-${sanitized.length > 0 ? sanitized : "default"}`;
}
export function sanitizeSessionIdForPvc(sessionId: string): string {
return sessionId.toLowerCase().replace(/[^a-z0-9-]+/gu, "-").replace(/^-+|-+$/gu, "");
}
export function buildSessionPvcSpec(input: { sessionId: string; namespace?: string; options: SessionPvcOptions }): SessionPvcSpec {
const namespace = input.namespace ?? "agentrun-v01";
return {