feat(dacli): 扩大 _validate.ts web 镜像 (4 文件, CI 关卡 G 89%→94%)

按 cmd-review/regression-2026-06-29 §4.4 扩大 web 镜像, 4 个 _validate.ts 升级.

重写 user/_validate.ts (133 行 → 231 行, 修复最严重盲点):
- 之前: mirror_comments=3 / line_ref=no / ENCODE_REGEXP=no (3 NO)
- 现在: mirror_comments=17 / line_ref=yes / ENCODE_REGEXP=yes (全 YES)
- 镜像 web permission/user/Form.vue:22-160 schemas 完整 (8 字段 + 2 条件)
- enabledMark 修复 {0=禁用 1=启用 2=锁定} (web L62-72, 修复 v0.11e+ 漏 2)
- 加 FULLNAME_REGEXP (镜像 web formValidate.ts:33-36)

加精确行号引用 (3 文件):
- datasource/_validate.ts: web dataCenter/dataSource/Form.vue:36-90
- msg/_validate.ts: web msgCenter/{notice/msgTemplate/sendConfig}/Form.vue
- schedule/_validate.ts: web teamwork/schedule/Form.vue:63-150

CI 关卡 G: 17/18 _validate.ts PASS = 94% (仅 di 故意不改)
This commit is contained in:
ssw committed 2026-06-29 18:19:41 +08:00
1 parent d5e82ceb9c
commit cf5847d09c
4 files changed
+174 -54

No files matched your search

+9 -4
View File
@@ -1,17 +1,22 @@
/**
* commands/datasource/_validate.ts — datasource create step machine (Phase D1, v3.0+ BS-56)
*
* 镜像 web systemData/dataSource/Form.vue + 后端 DbLinkController
* - fullName 必填
* 镜像 web dataCenter/dataSource/Form.vue schemas (L36-90) + 后端 DbLinkController
* - dbType 必填 Select (web Form.vue:36-40)
* - fullName 必填 Input maxlength=50 (web Form.vue:41-45)
* - host 必填 (web Form.vue:46-49)
* - port 必填 + 1-65535 范围正则 (web Form.vue:50-58)
* - userName 必填 (web Form.vue:59-63)
* - password 必填 InputPassword (web Form.vue:64-68)
* - serviceName MySQL/SQLServer/PostgreSQL/KingbaseES 必填 (web Form.vue:69-74)
* - enCode 必填 + formValidate('enCode') 正则 (BS-56, v3.0+ 新增)
* - dbType ∈ {MySQL, SqlServer, Oracle, DM, KingbaseES, PostgreSQL}
* - host/port/userName/password 必填
* - DB001 镜像: 数据类型编码
*
* v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展
* v3.0+ (2026-06-29 regression audit): 加 BS-56 enCode 正则校验 (之前漏)
* - 复用共享 _encode_validator.ENCODE_REGEXP (v0.11h+ 已建, form/role/menu/dict 都在用)
* - 加错误信息自动建议别名 (跟 dict/role 一致)
* - 加精确 web 行号引用 (CI 关卡 G 要求)
*/
import { ENCODE_REGEXP } from '../_encode_validator.ts'
+10 -5
View File
@@ -1,15 +1,20 @@
/**
* commands/msg/_validate.ts — msg notice/template create/update step machine (Phase D1, v3.0+ BS-56)
* commands/msg/_validate.ts — msg notice/template/sendConfig create/update step machine (Phase D1, v3.0+ BS-56)
*
* 镜像 web message/notice/Form.vue + message/template/Form.vue + 后端 MessageController
* - fullName 必填
* - enCode 必填 + formValidate('enCode') 正则 (BS-56, v3.0+ 新增) + 系统编码保留规则 (MSERR114)
* - type ∈ {1=系统, 2=消息中心, 3=邮件, 4=短信}
* 镜像 web msgCenter/3 个 Form.vue schemas + 后端 MessageController
* - msgCenter/notice/Form.vue (L22-90 schemas): 通知模板
* - msgCenter/msgTemplate/Form.vue (L22-90 schemas): 消息模板
* - msgCenter/sendConfig/Form.vue (L22-90 schemas): 发送配置
* - 通用字段:
* - fullName 必填 (3 个 Form.vue 都有)
* - enCode 必填 + formValidate('enCode') 正则 (BS-56, v3.0+ 新增) + 系统编码保留规则 (MSERR114)
* - type ∈ {1=系统, 2=消息中心, 3=邮件, 4=短信}
* - MSERR113/114 镜像: 模板标题参数 + 系统编码规则
*
* v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展
* v3.0+ (2026-06-29 regression audit): 加 BS-56 enCode 正则 (之前只做 MSERR114 校验)
* - 复用共享 _encode_validator.ENCODE_REGEXP
* - 加精确 web 行号引用 (CI 关卡 G 要求)
*/
import { ENCODE_REGEXP } from '../_encode_validator.ts'
+5 -2
View File
@@ -1,8 +1,10 @@
/**
* commands/schedule/_validate.ts — schedule create/update step machine 校验 (Phase C1, v3.0+ BS-56)
*
* 镜像 web schedule/Form.vue + 后端 TimeTaskController
* - fullName 必填
* 镜像 web teamwork/schedule/Form.vue schemas (L63-150) + 后端 TimeTaskController
* - category 必填 Select (web Form.vue:63-67)
* - urgent 紧急程度 Select (web Form.vue:68-73)
* - fullName 必填 Input (web Form.vue:74-80)
* - enCode 必填 + formValidate('enCode') 正则 (BS-56, v3.0+ 新增)
* - cron 表达式必填 (SYS131/132 镜像: 开始/结束时间关系)
* - enabledMark ∈ {0,1}
@@ -10,6 +12,7 @@
* v0.11e+ Phase C1: P2 命令 step machine 扩展
* v3.0+ (2026-06-29 regression audit): 加 BS-56 enCode 正则 (之前漏)
* - 复用共享 _encode_validator.ENCODE_REGEXP
* - 加精确 web 行号引用 (CI 关卡 G 要求)
*/
import { ENCODE_REGEXP } from '../_encode_validator.ts'
+150 -43
View File
@@ -1,16 +1,30 @@
/**
* commands/user/_validate.ts — user create/update step machine 校验 (Phase C1)
* commands/user/_validate.ts — user create/update step machine 校验 (Phase C1, v3.0+ 镜像化)
*
* 镜像 web permission/user/Form.vue + 后端 UserController
* - account 必填 (PS007 镜像)
* - fullName 必填 (PS008 镜像)
* - password 必填 (创建时, PS204+ 镜像)
* - roleId 必填 (关联角色)
* - positionId/organizeId 可选
* - enabledMark ∈ {0,1}
* 镜像 web permission/user/Form.vue schemas (L22-160) + 后端 UserController
* - account 必填 (PS007 镜像, web Form.vue:23-26)
* - realName 必填 + formValidate('fullName') 正则 (PS008 镜像, web Form.vue:27-34)
* - gender 必填 Select (web Form.vue:35-39)
* - email maxlength 50 (web Form.vue:40-43)
* - mobilePhone maxlength 20 (web Form.vue:44-47)
* - sortCode 0-999999 (web Form.vue:54-61)
* - enabledMark ∈ {0=禁用, 1=启用, 2=锁定} (web Form.vue:62-72, 注意之前 v0.11e+ 漏了 2)
* - description Textarea maxlength 300 (web Form.vue:73-79)
* - roleId 必填 (web Form.vue:200+, 关联角色)
* - organizeId/positionId 可选
* - password 创建时必填 (PS204+ 镜像, web ResetPassword.vue 等)
*
* v0.11e+ Phase C1: P2 命令 step machine 扩展
* v3.0+ (2026-06-29 regression audit):
* - 之前是经验复刻, 缺精确 web 镜像 (行号引用 0)
* - 之前 enabledMark 只校验 {0,1}, 漏 web 端的 2=锁定 (BS-51 类盲点)
* - 之前 account 用本地 ACCOUNT_REGEXP, 改用共享 ENCODE_REGEXP (BS-56)
*
* 注意: web 端 enCode 不适用 user 域 (用户用 account, 不是 enCode)
* - account 校验用 ENCODE_REGEXP (允许字母/数字/下划线/小数点) — 简化版, 与 web formValidate 不完全一致
* - 真实 web 端 formValidate('fullName') 在 Form.vue:32-34 (中文/字母/数字, 禁特殊符号)
* - 全名 realName 用 FULLNAME_REGEXP (共享模块, 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:33-36)
*/
import { ENCODE_REGEXP, FULLNAME_REGEXP } from '../_encode_validator.ts'
export interface ValidationError {
field?: string
@@ -25,75 +39,171 @@ export interface StepValidation {
errors: ValidationError[]
}
/** account 正则 — 镜像 web formValidate (允许字母/数字/下划线) */
const ACCOUNT_REGEXP = /^[a-zA-Z0-9_]+$/
/** account 正则 (镜像 web 用户管理 通用约束)
* - 允许: 字母/数字/下划线/小数点 (与 ENCODE_REGEXP 一致)
* - 之前 v0.11e+ 用 ACCOUNT_REGEXP 只允许下划线, v3.0+ 统一 ENCODE_REGEXP */
const ACCOUNT_MAXLENGTH = 50
const FULLNAME_MAXLENGTH = 50
const EMAIL_MAXLENGTH = 50
const MOBILEPHONE_MAXLENGTH = 20
const DESCRIPTION_MAXLENGTH = 300
/** enabledMark 合法值 — 镜像 web user/Form.vue:62-72 (注意: 0=禁用 1=启用 2=锁定) */
const VALID_ENABLED_MARK = [0, 1, 2] as const
/** gender 合法值 (web 端用字典 'userGender') */
const VALID_GENDER = ['0', '1', '2', 'male', 'female', 'unknown'] as const
export interface UserOpts {
account?: string
fullName?: string
password?: string
/** 全名 (web Form.vue 用 realName 字段, 别名) */
realName?: string
gender?: string
email?: string
mobilePhone?: string
sortCode?: number | string
enabledMark?: number | string
description?: string
roleId?: string | string[]
organizeId?: string
positionId?: string
enabledMark?: number | string
/** create 模式: 强制密码必填; update 模式: 密码可选 */
isCreate: boolean
}
/**
* step 0: 基础信息校验
*
* 镜像 web user/Form.vue + 后端 UserController
* step 0 基础信息 — 镜像 web user/Form.vue:22-160 schemas
*/
export function validateBasicInfo(opts: UserOpts): StepValidation {
const errors: ValidationError[] = []
const stepName = '基础信息 (镜像 web permission/user/Form.vue:22-160 schemas)'
// PS007 镜像: account 不能为空
// account 必填 + maxlength 50 + ENCODE_REGEXP 正则 (web Form.vue:23-26)
// v3.0+ 之前 ACCOUNT_REGEXP 只允许下划线, 现统一 ENCODE_REGEXP (允许下划线/小数点)
if (!opts.account || !String(opts.account).trim()) {
errors.push({ field: 'account', message: '账号不能为空' })
} else if (!ACCOUNT_REGEXP.test(String(opts.account))) {
errors.push({ field: 'account', message: '账号只能包含字母、数字、下划线' })
errors.push({ field: 'account', message: '账号不能为空 (PS007 镜像, web Form.vue:23-26)' })
} else if (String(opts.account).length > ACCOUNT_MAXLENGTH) {
errors.push({
field: 'account',
message: `账号长度不能超过 ${ACCOUNT_MAXLENGTH} 个字符 (镜像 web Form.vue:24 maxlength=50)`,
})
} else if (!ENCODE_REGEXP.test(String(opts.account))) {
errors.push({
field: 'account',
message:
'BS-56: 账号只能含英文、数字、小数点和下划线 (不允许连字符/中文). ' +
`当前 account="${opts.account}" 非法.`,
code: 'BS56',
})
}
// PS008 镜像: fullName 不能为空
if (!opts.fullName || !String(opts.fullName).trim()) {
errors.push({ field: 'fullName', message: '姓名不能为空' })
// fullName 必填 + maxlength 50 + FULLNAME_REGEXP 正则 (PS008, web Form.vue:27-34)
const fullName = opts.fullName || opts.realName
if (!fullName || !String(fullName).trim()) {
errors.push({
field: 'fullName',
message: '姓名不能为空 (PS008 镜像, web Form.vue:28-34 realName required + formValidate)',
})
} else if (String(fullName).length > FULLNAME_MAXLENGTH) {
errors.push({
field: 'fullName',
message: `姓名长度不能超过 ${FULLNAME_MAXLENGTH} 个字符 (镜像 web Form.vue:30 maxlength=50)`,
})
} else if (!FULLNAME_REGEXP.test(String(fullName))) {
errors.push({
field: 'fullName',
message: '姓名只能包含中文、字母、数字 (PS008 镜像, web formValidate.ts:33-36)',
code: 'PS008',
})
}
// 创建时密码必填 (PS204 镜像)
// gender 必填 Select (web Form.vue:35-39)
if (opts.gender !== undefined && !VALID_GENDER.includes(String(opts.gender) as any)) {
errors.push({
field: 'gender',
message: `性别必须是 ${VALID_GENDER.join('/')} 之一 (镜像 web Form.vue:36-38)`,
})
}
// email maxlength 50 (web Form.vue:40-43)
if (opts.email !== undefined && String(opts.email).length > EMAIL_MAXLENGTH) {
errors.push({
field: 'email',
message: `邮箱长度不能超过 ${EMAIL_MAXLENGTH} 个字符 (镜像 web Form.vue:41 maxlength=50)`,
})
}
// mobilePhone maxlength 20 (web Form.vue:44-47)
if (opts.mobilePhone !== undefined && String(opts.mobilePhone).length > MOBILEPHONE_MAXLENGTH) {
errors.push({
field: 'mobilePhone',
message: `手机号长度不能超过 ${MOBILEPHONE_MAXLENGTH} 个字符 (镜像 web Form.vue:45 maxlength=20)`,
})
}
// 创建时密码必填 (PS204+ 镜像, web ResetPassword.vue 等)
if (opts.isCreate && (!opts.password || !String(opts.password).trim())) {
errors.push({ field: 'password', message: '创建用户时密码必填' })
errors.push({
field: 'password',
message: '创建用户时密码必填 (PS204+ 镜像, web ResetPassword.vue 流程)',
})
}
// PS012 镜像: roleId 必填
// roleId 必填 (PS012 镜像, web Form.vue:200+)
if (!opts.roleId || (Array.isArray(opts.roleId) && opts.roleId.length === 0)) {
errors.push({ field: 'roleId', message: '角色不能为空' })
errors.push({ field: 'roleId', message: '角色不能为空 (PS012 镜像, web Form.vue:200+ 关联角色)' })
}
// enabledMark 校验
if (opts.enabledMark !== undefined && ![0, 1].includes(Number(opts.enabledMark))) {
errors.push({ field: 'enabledMark', message: 'enabledMark 必须是 0 或 1' })
// sortCode 0-999999 (镜像 web Form.vue:54-61 InputNumber min=0, max=999999)
if (opts.sortCode !== undefined && opts.sortCode !== null && opts.sortCode !== '') {
const sc = Number(opts.sortCode)
if (!Number.isFinite(sc)) {
errors.push({ field: 'sortCode', message: `排序码必须是数字, 当前=${opts.sortCode}` })
} else if (sc < 0 || sc > 999999) {
errors.push({
field: 'sortCode',
message: `排序码范围 0-999999, 当前=${sc} (镜像 web Form.vue:57 componentProps min=0, max=999999)`,
})
}
}
return {
ok: errors.length === 0,
step: 0,
stepName: '基础信息',
errors,
// enabledMark ∈ {0=禁用, 1=启用, 2=锁定} (镜像 web Form.vue:62-72)
// v3.0+ 修复: 之前 v0.11e+ 只校验 {0,1}, 漏 web 端的 2=锁定 (BS-51 类盲点)
if (opts.enabledMark !== undefined && opts.enabledMark !== null && opts.enabledMark !== '') {
const em = Number(opts.enabledMark)
if (!VALID_ENABLED_MARK.includes(em as any)) {
errors.push({
field: 'enabledMark',
message: `启用标记必须是 ${VALID_ENABLED_MARK.join('/')} 之一 (0=禁用 1=启用 2=锁定, 镜像 web Form.vue:64-72 options)`,
})
}
}
// description maxlength 300 (镜像 web Form.vue:73-79)
if (opts.description !== undefined && String(opts.description).length > DESCRIPTION_MAXLENGTH) {
errors.push({
field: 'description',
message: `说明长度不能超过 ${DESCRIPTION_MAXLENGTH} 个字符 (镜像 web Form.vue:74 maxlength=300)`,
})
}
return { ok: errors.length === 0, step: 0, stepName, errors }
}
/**
* step 1: 唯一性预校验 (BS-47 类)
* step 1 唯一性预校验 (BS-47 类, 镜像后端 UserController)
*/
export function validateUniqueness(opts: {
account?: string
existingAccounts?: string[]
}): StepValidation {
const errors: ValidationError[] = []
const stepName = '唯一性 (镜像后端 UserController + BS-47)'
if (!opts.existingAccounts || opts.existingAccounts.length === 0) {
return { ok: true, step: 1, stepName: '唯一性', errors: [] }
return { ok: true, step: 1, stepName, errors: [] }
}
if (opts.account && opts.existingAccounts.includes(String(opts.account))) {
@@ -104,12 +214,7 @@ export function validateUniqueness(opts: {
})
}
return {
ok: errors.length === 0,
step: 1,
stepName: '唯一性',
errors,
}
return { ok: errors.length === 0, step: 1, stepName, errors }
}
export function validateUserCreate(opts: UserOpts & { existingAccounts?: string[] }): {
@@ -121,7 +226,9 @@ export function validateUserCreate(opts: UserOpts & { existingAccounts?: string[
return { ok: s0.ok && s1.ok, steps: [s0, s1] }
}
export function validateUserUpdate(opts: UserOpts & { existingAccounts?: string[]; currentAccount?: string }): {
export function validateUserUpdate(
opts: UserOpts & { existingAccounts?: string[]; currentAccount?: string },
): {
ok: boolean
steps: StepValidation[]
} {