diff --git a/src/commands/test/render.ts b/src/commands/test/render.ts index a75e3c8..b34a977 100644 --- a/src/commands/test/render.ts +++ b/src/commands/test/render.ts @@ -113,6 +113,11 @@ interface RenderOpts { relationFormDataStrict?: boolean // 弹窗数据空时返回 FAIL (默认 OFF=WARN) requiredFieldCheck?: boolean // 必填字段 vmodel 完整性 (默认 ON) columnListRequired?: boolean // columnList 完整性 (默认 ON, webType≠1) + // === v0.21+ TC-C 加深 (2026-07-12, BS-drift-1 / BS-NCPF-400 followup) === + jnpfKeyValidCheck?: boolean // jnpfKey 在 web FormGenerator 白名单 (默认 ON) + dictBindValidCheck?: boolean // 字典绑定 dictionaryType 在 dict 表存在 (默认 ON) + labelCompleteCheck?: boolean // formItem label 非空 + 唯一 (默认 ON) + requiredControlTypeCheck?: boolean // 必填字段不能在 switch/button/table 容器 (默认 ON) } export function buildTestRenderCommand(): Command { @@ -129,6 +134,11 @@ export function buildTestRenderCommand(): Command { .option('--no-relation-form-data-check', '关闭 relationForm 弹窗数据可达性校验 (默认 ON, 默认 WARN 模式)') .option('--relation-form-data-strict', '弹窗数据为空时返回 FAIL 而非 WARN (默认 OFF=WARN)') .option('--no-column-list-required', '关闭 columnList 列配置完整性校验 (默认 ON, webType≠1)') + // === v0.21+ TC-C 加深 (2026-07-12) === + .option('--no-jnpfkey-valid-check', '关闭 jnpfKey 有效性校验 (镜像 web FormGenerator 白名单, 默认 ON)') + .option('--no-dict-bind-valid-check', '关闭字典绑定有效性校验 (dictionaryType 在 dict 表存在, 默认 ON)') + .option('--no-label-complete-check', '关闭 formItem label 完整性校验 (非空 + 唯一, 默认 ON)') + .option('--no-required-control-type-check', '关闭必填字段控件类型校验 (必填不能在 switch/button 容器, 默认 ON)') .action(async (opts: RenderOpts) => { const c = await JnpfClient.fromToken() const results: RenderCheckResult[] = [] @@ -138,6 +148,11 @@ export function buildTestRenderCommand(): Command { opts.relationFormDataCheck = opts.relationFormDataCheck !== false opts.columnListRequired = opts.columnListRequired !== false opts.relationFormDataStrict = !!opts.relationFormDataStrict + // v0.21+ TC-C 加深 defaults + opts.jnpfKeyValidCheck = opts.jnpfKeyValidCheck !== false + opts.dictBindValidCheck = opts.dictBindValidCheck !== false + opts.labelCompleteCheck = opts.labelCompleteCheck !== false + opts.requiredControlTypeCheck = opts.requiredControlTypeCheck !== false try { if (opts.module === 'dict') { @@ -657,6 +672,219 @@ async function renderForm( lg.error(`✗ columnList 列配置: FAIL (${issues.slice(0, 3).join(' | ')}${issues.length > 3 ? '...' : ''})`) } } + + // ========================================================================== + // v0.21+ TC-C 加深 (2026-07-12, BS-drift-1 / BS-NCPF-400 followup) + // 思路: 在 TC-C 层 (静态) 多发现 50% 漂移, 减少 TC-B 浏览器层重排雷 + // 4 个新关卡 (E/F/G/H): + // E. jnpfKey 有效性 (白名单, 镜像 web FormGenerator 白名单) + // F. 字典绑定有效性 (dictionaryType 字段在 dict 表存在) + // G. formItem label 完整性 (label 非空 + 不重复) + // H. 必填字段 vs 控件类型 (必填不能是 switch/button/table 容器) + // ========================================================================== + + // === Step E: jnpfKey 有效性 (v0.21+ 加深) === + // 镜像 web FormGenerator/.../index.vue (renderComponentByConfig) 接受的白名单 + // 漂移: AI 生成的字段可能用错 jnpfKey (e.g. 'int' 应为 'inputNumber'), 浏览器渲染会失败 + const VALID_JNPF_KEYS = new Set([ + // 基础输入 + 'input', 'textarea', 'inputNumber', 'password', + // 选择 + 'select', 'radio', 'checkbox', 'switch', 'cascader', 'treeSelect', + // 日期时间 + 'datePicker', 'timePicker', + // 上传 + 'upload', 'uploadImg', 'uploadFz', 'fileUpload', + // 关联 + 'relationForm', 'popupSelect', 'popupTable', 'organizeSelect', 'userSelect', 'depSelect', 'postSelect', + // 富文本 + 'editor', 'richText', + // 其他 + 'rate', 'slider', 'colorPicker', 'signature', + 'divider', 'alert', 'text', 'button', + // JNPF 内置控件 (v0.21+ 加深发现) + 'groupTitle', // 分组标题 + 'billRule', // 单据规则编码 + 'uploadFile', // 文件上传 (vben 风格, 不同 uploadImg) + 'areaSelect', // 行政区划联动 (JNPF 自研) + // 容器 + 'table', 'tab', 'collapse', 'card', 'rowFormItem', 'colFormItem', + ]) + if (opts.jnpfKeyValidCheck !== false) { + const fieldsArr = formData.fields || [] + const invalidKeys: { vModel: string; jnpfKey: string; label: string }[] = [] + const seenKeys = new Set() + for (const f of fieldsArr) { + const cfg = f?.__config__ || {} + const k = cfg.jnpfKey + if (k && !VALID_JNPF_KEYS.has(k) && !seenKeys.has(k)) { + seenKeys.add(k) + invalidKeys.push({ vModel: f.__vModel__ || '', jnpfKey: k, label: cfg.label || '' }) + } + } + const status: 'PASS' | 'FAIL' = invalidKeys.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'form', + page: 'jnpfKey 有效性 (web FormGenerator 白名单)', + sourceFile: `formData.fields[].__config__.jnpfKey (formId=${formId})`, + renderFields: fieldsArr.map((f: any) => f?.__config__?.jnpfKey).filter(Boolean), + apiFields: Array.from(VALID_JNPF_KEYS).sort(), + missing: invalidKeys.map(k => `${k.label}(${k.vModel}) 用了非法 jnpfKey="${k.jnpfKey}"`), + extra: [], + status, + }) + if (invalidKeys.length === 0) { + lg.info(`✓ jnpfKey 有效性: PASS (${fieldsArr.length} 字段 jnpfKey 全部在白名单内)`) + } else { + lg.error(`✗ jnpfKey 有效性: FAIL (${invalidKeys.length} 个非法 jnpfKey: ${invalidKeys.slice(0, 3).map(k => k.jnpfKey).join(', ')}${invalidKeys.length > 3 ? '...' : ''})`) + } + } + + // === Step F: 字典绑定有效性 (v0.21+ 加深) === + // 镜像 web 端 select/dict 类型组件: dictionaryType 字段必须在 dict 表存在 + // 漂移: formSchema 引用了被删/不存在的字典 → 浏览器 select 渲染空, 用户选不到值 + if (opts.dictBindValidCheck !== false) { + const fieldsArr = formData.fields || [] + // 找所有需要字典的字段 + const dictFields = fieldsArr.filter((f: any) => { + const cfg = f?.__config__ || {} + const k = cfg.jnpfKey + return k && (k === 'select' || k === 'radio' || k === 'checkbox' || k === 'treeSelect') && cfg.dictionaryType + }) + const dictInvalid: { vModel: string; label: string; dictType: string; reason: string }[] = [] + const dictValid: { vModel: string; label: string; dictType: string }[] = [] + + // 拿 dict 列表 (webapi) + let dictList: any[] = [] + try { + const { loadDict } = await import('../../webapi/dict.ts') + const { initWebapi: initWebapiDict } = await import('../../webapi/dict.ts') + await initWebapiDict(c) + const r = (await loadDict.getDictionaryAll()) as any + dictList = Array.isArray(r?.data) ? r.data : Array.isArray(r) ? r : [] + } catch (e) { + lg.warn(`getDictionaryAll 失败: ${(e as Error).message}, 跳过字典绑定校验`) + } + + const dictIdSet = new Set(dictList.map((d: any) => d.id).filter(Boolean)) + const dictEnSet = new Set(dictList.map((d: any) => d.enCode || d.dictionaryType).filter(Boolean)) + const dictFullNameSet = new Set(dictList.map((d: any) => d.fullName || d.dictionaryName).filter(Boolean)) + + for (const f of dictFields) { + const label = f.__config__?.label || f.__vModel__ || '' + const dt = f.__config__.dictionaryType + // 字典可能用 id / enCode / fullName 引用 + const exists = dictIdSet.has(dt) || dictEnSet.has(dt) || dictFullNameSet.has(dt) + if (exists) { + dictValid.push({ vModel: f.__vModel__ || '', label, dictType: dt }) + } else { + dictInvalid.push({ vModel: f.__vModel__ || '', label, dictType: dt, reason: 'dict 表不存在' }) + } + } + + const summary = `${dictValid.length} 有效 / ${dictInvalid.length} 无效 (共 ${dictFields.length} 个字典字段)` + const status: 'PASS' | 'FAIL' = dictInvalid.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'form', + page: '字典绑定有效性 (dictionaryType 在 dict 表存在)', + sourceFile: `formData.fields[select/radio/checkbox].dictionaryType + dict list (formId=${formId})`, + renderFields: dictFields.map((f: any) => `${f.__config__?.label}=${f.__config__.dictionaryType}`), + apiFields: dictList.map((d: any) => `${d.id}/${d.enCode || d.dictionaryType}: ${d.fullName || d.dictionaryName}`).slice(0, 20), + missing: dictInvalid.map(d => `${d.label}(${d.vModel}) 引用 dict "${d.dictType}" 不存在`), + extra: [], + status, + }) + if (dictInvalid.length === 0 && dictFields.length > 0) { + lg.info(`✓ 字典绑定: PASS (${summary})`) + } else if (dictFields.length === 0) { + lg.info(`○ 字典绑定: 跳过 (该 form 无字典字段)`) + } else { + lg.error(`✗ 字典绑定: FAIL (${summary}; 失败: ${dictInvalid.slice(0, 3).map(d => d.dictType).join(', ')})`) + } + } + + // === Step G: formItem label 完整性 (v0.21+ 加深) === + // 镜像 web 端 FormGenerator.label 渲染: label 非空 + 不重复 + // 漂移: AI 生成可能有空 label 或重复 label, 浏览器列表展示混乱 + if (opts.labelCompleteCheck !== false) { + const fieldsArr = formData.fields || [] + const emptyLabels: string[] = [] + const duplicateLabels = new Map() + for (const f of fieldsArr) { + const cfg = f?.__config__ || {} + const label = (cfg.label || '').trim() + const vmodel = f.__vModel__ || '' + if (cfg.jnpfKey === 'table' || cfg.layout === 'colFormItem' || cfg.layout === 'rowFormItem') { + // 容器/布局字段不需要 label + continue + } + if (!label) { + emptyLabels.push(vmodel) + } else { + duplicateLabels.set(label, (duplicateLabels.get(label) || 0) + 1) + } + } + const dups: string[] = [] + for (const [label, n] of duplicateLabels) { + if (n > 1) dups.push(`${label}×${n}`) + } + const issues: string[] = [ + ...emptyLabels.map(v => `${v}: 空 label`), + ...dups, + ] + const status: 'PASS' | 'FAIL' = issues.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'form', + page: 'formItem label 完整性', + sourceFile: `formData.fields[].__config__.label (formId=${formId})`, + renderFields: fieldsArr.filter((f: any) => f?.__config__?.label).map((f: any) => f.__config__.label), + apiFields: [], + missing: issues, + extra: [], + status, + }) + if (issues.length === 0) { + lg.info(`✓ formItem label: PASS (${fieldsArr.length} 字段 label 都非空且唯一)`) + } else { + lg.error(`✗ formItem label: FAIL (${emptyLabels.length} 空 + ${dups.length} 重复)`) + } + } + + // === Step H: 必填字段 vs 控件类型 (v0.21+ 加深) === + // 镜像 web 端 form/_validate.ts 校验规则 + // 必填字段如果是 switch/button/divider/table 容器, 浏览器必渲染失败 + // 漂移: AI 把 "table" (子表) 设为 required, 必填校验时整个子表必填, 实际操作无法满足 + if (opts.requiredControlTypeCheck !== false) { + const fieldsArr = formData.fields || [] + const NON_REQUIRED_CONTROLS = new Set(['switch', 'button', 'divider', 'alert', 'text', 'table', 'tab', 'collapse', 'card', 'rowFormItem', 'colFormItem']) + const invalidRequired: { vModel: string; label: string; jnpfKey: string }[] = [] + for (const f of fieldsArr) { + const cfg = f?.__config__ || {} + if (cfg.required === true && NON_REQUIRED_CONTROLS.has(cfg.jnpfKey)) { + invalidRequired.push({ + vModel: f.__vModel__ || '', + label: cfg.label || '', + jnpfKey: cfg.jnpfKey, + }) + } + } + const status: 'PASS' | 'FAIL' = invalidRequired.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'form', + page: '必填字段 vs 控件类型', + sourceFile: `formData.fields[required] (formId=${formId})`, + renderFields: invalidRequired.map(r => `${r.label}(${r.vModel}) 必填 ${r.jnpfKey}`), + apiFields: Array.from(NON_REQUIRED_CONTROLS).sort(), + missing: invalidRequired.map(r => `${r.label}(${r.vModel}): jnpfKey="${r.jnpfKey}" 不能必填`), + extra: [], + status, + }) + if (invalidRequired.length === 0) { + lg.info(`✓ 必填控件类型: PASS (无必填在 switch/button/divider/table 容器)`) + } else { + lg.error(`✗ 必填控件类型: FAIL (${invalidRequired.length} 个非法必填: ${invalidRequired.slice(0, 3).map(r => r.jnpfKey).join(', ')})`) + } + } } // ============================================================================