feat(test render): v0.11g+ 真实渲染契约升级 (4 类校验, 解决 TC-C 形式 PASS 但 relationForm 弹窗空)
旧 TC-C 只对比 vue 字段 ⊆ API 字段, PASS 但 relationForm 弹窗可能空 → 用户填不完必填外键 → 保存失败. 新增 4 选项 (默认全 ON, 都可 --no-xxx 关): - --no-required-field-check 关闭必填字段 vmodel 完整性校验 - --no-relation-form-data-check 关闭 relationForm 弹窗数据可达性校验 (默认 WARN) - --relation-form-data-strict 弹窗数据为空时返回 FAIL 而非 WARN - --no-column-list-required 关闭 columnList 列配置完整性校验 (webType≠1) 新增 4 校验 (Step A/B/C/D): - Step A 必填字段 vmodel: formData.fields 中所有 required 字段都有 __vModel__ - Step B relationForm 配置: modelId + propsValue + relationField 三必填 - Step C relationForm 弹窗数据可达: getVisualDevList + getModelList 验证关联表 ≥1 条 (默认 WARN) - Step D columnList 列配置: webType≠1 时 columnList ≥1 + 字段名匹配 API 镜像 web 端契约: - web/.../FormGenerator/getData() + form/_validate.ts:validateFormData (Step A) - web/.../RRelationForm/index.vue + form/_validate.ts:validateRelationForm (Step B) - web/.../RRelationForm/index.vue 弹窗加载 (Step C) - web/.../ColumnDesign/getData() line 278-282 (Step D) 验证 (jxcj team form 840790355585531909, 1 个 relationForm → jxcj_competition_info): 旧 TC-C: PASS (无任何提示) 新 TC-C (默认 WARN): PASS + ⚠ relationForm 弹窗数据可达性: WARN (0 可达 / 1 空 / 0 错) 新 TC-C (--strict): FAIL (CI 用) SKILL.md §test render 详细说明 加 v0.11g+ 章节. 驱动文档: .claude/templates/flow-jxcj-rerun-process.md §二 TC-C 升级方案 MEMORY: dacli-test-render-real-contract-2026-06-28.md
This commit is contained in:
1 parent
634ae10288
commit
f9edebb3ea
1 file changed
+200
@@ -95,6 +95,11 @@ interface RenderOpts {
|
||||
id?: string
|
||||
formId?: string
|
||||
json?: boolean
|
||||
// === v0.11g+ 真实渲染契约升级 (2026-06-28, 镜像 §TC-C 真实业务) ===
|
||||
relationFormDataCheck?: boolean // relationForm 弹窗数据可达性 (默认 ON, WARN)
|
||||
relationFormDataStrict?: boolean // 弹窗数据空时返回 FAIL (默认 OFF=WARN)
|
||||
requiredFieldCheck?: boolean // 必填字段 vmodel 完整性 (默认 ON)
|
||||
columnListRequired?: boolean // columnList 完整性 (默认 ON, webType≠1)
|
||||
}
|
||||
|
||||
export function buildTestRenderCommand(): Command {
|
||||
@@ -106,10 +111,21 @@ export function buildTestRenderCommand(): Command {
|
||||
.option('--id <id>', '实体 id (验证单条数据时用)')
|
||||
.option('--formId <id>', '表单 id (form module 必填)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
// === v0.11g+ 真实渲染契约升级 (2026-06-28) ===
|
||||
.option('--no-required-field-check', '关闭必填字段 vmodel 完整性校验 (默认 ON)')
|
||||
.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)')
|
||||
.action(async (opts: RenderOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const results: RenderCheckResult[] = []
|
||||
|
||||
// 默认 ON (Commander negation 默认 true → false)
|
||||
opts.requiredFieldCheck = opts.requiredFieldCheck !== false
|
||||
opts.relationFormDataCheck = opts.relationFormDataCheck !== false
|
||||
opts.columnListRequired = opts.columnListRequired !== false
|
||||
opts.relationFormDataStrict = !!opts.relationFormDataStrict
|
||||
|
||||
try {
|
||||
if (opts.module === 'dict') {
|
||||
await renderDict(c, opts, results, opts.json ? silent : real)
|
||||
@@ -380,6 +396,190 @@ async function renderForm(
|
||||
} else {
|
||||
lg.warn(`form 列表: columnData.columnList 为空, 跳过 (该 form 可能只有编辑表单, 无列表)`)
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// v0.11g+ 真实渲染契约升级 (2026-06-28, 镜像 §TC-C 真实业务)
|
||||
// 解决: 旧 TC-C 只对比 vue 字段 ⊆ API 字段, PASS 但 relationForm 弹窗空,
|
||||
// 必填字段无 vmodel, columnList 列缺失都不验
|
||||
// ==========================================================================
|
||||
|
||||
// === Step A: 必填字段 vmodel 完整性 ===
|
||||
// 镜像 web 端 FormGenerator.getData() 控件校验 + form/_validate.ts
|
||||
// 必填字段必须在 formData.fields 配 vmodel + 控件标签
|
||||
if (opts.requiredFieldCheck !== false) {
|
||||
const fieldsArr = formData.fields || []
|
||||
const requiredFields = fieldsArr.filter((f: any) => f?.__config__?.required === true)
|
||||
const missingVmodel: string[] = []
|
||||
for (const rf of requiredFields) {
|
||||
if (!rf.__vModel__) {
|
||||
missingVmodel.push(rf.__config__?.label || '<no-label>')
|
||||
}
|
||||
}
|
||||
const status: 'PASS' | 'FAIL' = missingVmodel.length === 0 ? 'PASS' : 'FAIL'
|
||||
results.push({
|
||||
module: 'form',
|
||||
page: '必填字段 vmodel',
|
||||
sourceFile: `formData.fields[required] (formId=${formId})`,
|
||||
renderFields: requiredFields.map((f: any) => f.__vModel__ || f.__config__?.label).filter(Boolean),
|
||||
apiFields: [],
|
||||
missing: missingVmodel,
|
||||
extra: [],
|
||||
status,
|
||||
})
|
||||
if (missingVmodel.length === 0) {
|
||||
lg.info(`✓ 必填字段 vmodel: PASS (${requiredFields.length} 个 required 字段全部有 vmodel)`)
|
||||
} else {
|
||||
lg.error(`✗ 必填字段 vmodel: FAIL (${missingVmodel.length} 个 required 字段缺 vmodel: ${missingVmodel.slice(0, 3).join(', ')}${missingVmodel.length > 3 ? '...' : ''})`)
|
||||
}
|
||||
}
|
||||
|
||||
// === Step B: relationForm 配置完整性 (三必填) ===
|
||||
// 镜像 web 端 RRelationForm/index.vue + form/_validate.ts:validateRelationForm
|
||||
// relationForm 必须三必填: modelId (关联表 enCode) + propsValue (字段名) + relationField (显示字段)
|
||||
const relationFormFields = (formData.fields || []).filter((f: any) => f?.__config__?.jnpfKey === 'relationForm')
|
||||
const relationFormConfigIssues: string[] = []
|
||||
for (const rf of relationFormFields) {
|
||||
const label = rf.__config__?.label || rf.__vModel__ || '<no-label>'
|
||||
if (!rf.modelId) relationFormConfigIssues.push(`${label}: 缺 modelId`)
|
||||
if (!rf.propsValue) relationFormConfigIssues.push(`${label}: 缺 propsValue`)
|
||||
if (!rf.relationField) relationFormConfigIssues.push(`${label}: 缺 relationField`)
|
||||
}
|
||||
if (relationFormFields.length > 0) {
|
||||
const status: 'PASS' | 'FAIL' = relationFormConfigIssues.length === 0 ? 'PASS' : 'FAIL'
|
||||
results.push({
|
||||
module: 'form',
|
||||
page: 'relationForm 配置完整性',
|
||||
sourceFile: `formData.fields[relationForm] (formId=${formId})`,
|
||||
renderFields: relationFormFields.map((f: any) => `${f.__config__?.label}=${f.modelId || '<no-modelId>'}`),
|
||||
apiFields: [],
|
||||
missing: relationFormConfigIssues,
|
||||
extra: [],
|
||||
status,
|
||||
})
|
||||
if (relationFormConfigIssues.length === 0) {
|
||||
lg.info(`✓ relationForm 配置: PASS (${relationFormFields.length} 个 relationForm 全部三必填完整)`)
|
||||
} else {
|
||||
lg.error(`✗ relationForm 配置: FAIL (${relationFormConfigIssues.length} 项缺: ${relationFormConfigIssues.slice(0, 3).join(' | ')}${relationFormConfigIssues.length > 3 ? '...' : ''})`)
|
||||
}
|
||||
} else {
|
||||
lg.info(`○ relationForm 配置: 跳过 (该 form 无 relationForm 字段)`)
|
||||
}
|
||||
|
||||
// === Step C: relationForm 弹窗数据可达性 (真实业务契约核心) ===
|
||||
// 镜像 web 端 RRelationForm/index.vue 弹窗加载 OnlineDev/{modelId}/List 调分页
|
||||
// 弹窗数据 0 条 → 浏览器渲染时弹窗列表空白 → 用户填不完必填外键 → 保存失败
|
||||
if (opts.relationFormDataCheck !== false && relationFormFields.length > 0) {
|
||||
const dataReachable: { label: string; modelId: string; count: number }[] = []
|
||||
const dataEmpty: { label: string; modelId: string }[] = []
|
||||
const dataError: { label: string; modelId: string; err: string }[] = []
|
||||
|
||||
for (const rf of relationFormFields) {
|
||||
const label = rf.__config__?.label || rf.__vModel__ || '<no-label>'
|
||||
const modelId = rf.modelId
|
||||
if (!modelId) continue // Step B 已报缺 modelId, 这里跳过避免重复报错
|
||||
try {
|
||||
// 镜像 web 端: getVisualDevList + keyword 模糊匹配 enCode
|
||||
const r = (await loadVisualDev.getVisualDevList({ keyword: modelId, currentPage: 1, pageSize: 10 })) as any
|
||||
const list = Array.isArray(r?.data?.list) ? r.data.list : Array.isArray(r?.list) ? r.list : []
|
||||
// 取第一个精确 enCode 匹配项, 然后查其 modelId (formId) 再调 getModelList
|
||||
const exact = list.find((x: any) => x?.enCode === modelId)
|
||||
if (!exact) {
|
||||
dataEmpty.push({ label, modelId })
|
||||
continue
|
||||
}
|
||||
const formIdForTarget = exact.id
|
||||
const lr = (await loadVisualDev.getModelList({ modelId: formIdForTarget, currentPage: 1, pageSize: 1 })) as any
|
||||
const targetList = Array.isArray(lr?.data?.list) ? lr.data.list : Array.isArray(lr?.list) ? lr.list : []
|
||||
const count = targetList.length
|
||||
if (count === 0) {
|
||||
dataEmpty.push({ label, modelId })
|
||||
} else {
|
||||
dataReachable.push({ label, modelId, count })
|
||||
}
|
||||
} catch (e) {
|
||||
dataError.push({ label, modelId, err: (e as Error).message })
|
||||
}
|
||||
}
|
||||
|
||||
const summary = `${dataReachable.length} 可达 / ${dataEmpty.length} 空 / ${dataError.length} 错 (共 ${relationFormFields.length} 个 relationForm)`
|
||||
if (opts.relationFormDataStrict) {
|
||||
// 严格模式: 任一空 → FAIL
|
||||
const status: 'PASS' | 'FAIL' = (dataEmpty.length === 0 && dataError.length === 0) ? 'PASS' : 'FAIL'
|
||||
results.push({
|
||||
module: 'form',
|
||||
page: 'relationForm 弹窗数据可达性',
|
||||
sourceFile: `getVisualDevList + getModelList (formId=${formId})`,
|
||||
renderFields: relationFormFields.map((f: any) => `${f.__config__?.label}=${f.modelId}`),
|
||||
apiFields: dataReachable.map(d => `${d.modelId}: ${d.count} 条`),
|
||||
missing: [...dataEmpty.map(d => `${d.label}(${d.modelId}) 弹窗空`), ...dataError.map(d => `${d.label}(${d.modelId}) 查失败: ${d.err}`)],
|
||||
extra: [],
|
||||
status,
|
||||
})
|
||||
if (dataEmpty.length === 0 && dataError.length === 0) {
|
||||
lg.info(`✓ relationForm 弹窗数据可达性: PASS [STRICT] (${summary})`)
|
||||
} else {
|
||||
const emptyStr = dataEmpty.slice(0, 3).map(d => `${d.label}(${d.modelId})`).join(', ')
|
||||
lg.error(`✗ relationForm 弹窗数据可达性: FAIL [STRICT] (${summary}; 空: ${emptyStr}${dataEmpty.length > 3 ? '...' : ''})`)
|
||||
}
|
||||
} else {
|
||||
// 默认 WARN 模式: 不阻断, 但明确提示
|
||||
const summary2 = `${dataReachable.length}/${relationFormFields.length} 弹窗有数据`
|
||||
results.push({
|
||||
module: 'form',
|
||||
page: 'relationForm 弹窗数据可达性',
|
||||
sourceFile: `getVisualDevList + getModelList (formId=${formId})`,
|
||||
renderFields: relationFormFields.map((f: any) => `${f.__config__?.label}=${f.modelId}`),
|
||||
apiFields: dataReachable.map(d => `${d.modelId}: ${d.count} 条`),
|
||||
missing: [...dataEmpty.map(d => `${d.label}(${d.modelId}) 弹窗空`), ...dataError.map(d => `${d.label}(${d.modelId}) 查失败: ${d.err}`)],
|
||||
extra: [],
|
||||
status: 'PASS', // WARN 不计入 FAIL
|
||||
})
|
||||
if (dataEmpty.length === 0 && dataError.length === 0) {
|
||||
lg.info(`✓ relationForm 弹窗数据可达性: PASS [WARN] (${summary})`)
|
||||
} else {
|
||||
const emptyStr = dataEmpty.slice(0, 3).map(d => `${d.label}(${d.modelId})`).join(', ')
|
||||
lg.warn(`⚠ relationForm 弹窗数据可达性: WARN (${summary}; 空: ${emptyStr}${dataEmpty.length > 3 ? '...' : ''}; 浏览器弹窗空, 外键填不全 → 必填保存会失败)`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Step D: columnList 列配置完整性 (webType≠1) ===
|
||||
// 镜像 web 端 ColumnDesign.getData() line 278-282 (columnList 至少 1 + 字段名匹配)
|
||||
// webType=1 (仅表单) 跳过; webType=2/3/4 至少 1 个 column + 字段名匹配 API
|
||||
const webType = formDetail.webType || (formDetail as any).WebType || 2
|
||||
if (opts.columnListRequired !== false && webType !== 1) {
|
||||
const columnList = columnData?.columnList || []
|
||||
const issues: string[] = []
|
||||
if (columnList.length === 0) {
|
||||
issues.push('columnList 为空 (webType≠1 至少 1 个字段)')
|
||||
} else {
|
||||
for (const col of columnList) {
|
||||
const prop = col.prop || col.field
|
||||
if (!prop) {
|
||||
issues.push(`列配置缺字段名: ${JSON.stringify(col).slice(0, 50)}`)
|
||||
} else if (apiSource !== 'empty' && !apiFieldSet.has(prop)) {
|
||||
// 字段名匹配 API: 字段在 list 但 API 实际不返回 → 浏览器渲染白屏
|
||||
issues.push(`列 ${prop} 不在 API 返回字段中 (浏览器列表白屏)`)
|
||||
}
|
||||
}
|
||||
}
|
||||
const status: 'PASS' | 'FAIL' = issues.length === 0 ? 'PASS' : 'FAIL'
|
||||
results.push({
|
||||
module: 'form',
|
||||
page: 'columnList 列配置完整性',
|
||||
sourceFile: `columnData.columnList (formId=${formId}, webType=${webType})`,
|
||||
renderFields: columnList.map((c: any) => c.prop || c.field),
|
||||
apiFields,
|
||||
missing: issues,
|
||||
extra: [],
|
||||
status,
|
||||
})
|
||||
if (issues.length === 0) {
|
||||
lg.info(`✓ columnList 列配置: PASS (${columnList.length} 列全部字段名匹配 API)`)
|
||||
} else {
|
||||
lg.error(`✗ columnList 列配置: FAIL (${issues.slice(0, 3).join(' | ')}${issues.length > 3 ? '...' : ''})`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in new issue
Block a user