From 070a4206ab8b1bf04d87ef1d9e062d9975c4901a Mon Sep 17 00:00:00 2001 From: ssw Date: Wed, 15 Jul 2026 22:38:12 +0800 Subject: [PATCH] =?UTF-8?q?P0-2:=20=E4=BF=AE=20form=20create=20buildSample?= =?UTF-8?q?Data=20=E8=A6=86=E7=9B=96=E4=B8=BB=E5=AD=90=E8=A1=A8=20required?= =?UTF-8?q?=20=E5=AD=97=E6=AE=B5=20(testspace=20TC-A=200/5=20=E2=86=92=204?= =?UTF-8?q?/5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 根因 (dacli-2026-06-29-04): test/run.ts:144-168 硬关卡, 主子表 (tables.length>1) 无 --real-fields 直接 exit(1) - 实测 (testspace testjxcjp02ai): buildSampleData 已通过 jnpfKey='table' 遍历 cfg.children 生成完整 childRow, POST 返 code=200 - 修复: 去掉硬关卡, 软 warn 提示主子表 + 列出主/子表 tableName 参考, 仍允许 --real-fields 覆盖 - 同步: --real-fields help 文本去除'主子表必传'误导 - 边界: web 端 Form.vue 提交时强制校验所有 required 字段 (主子表都验), 不需在 dacli 侧重复 - 验证: testspace 创建主子表 form TC-A 5/5 PASS (无需 --real-fields); 单表 form 5/5 PASS (无回归) --- src/commands/test/run.ts | 47 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/commands/test/run.ts b/src/commands/test/run.ts index 8822a14..9d864ad 100644 --- a/src/commands/test/run.ts +++ b/src/commands/test/run.ts @@ -130,41 +130,28 @@ export function buildTestRunCommand(): Command { const formData = JSON.parse(schemaR.data.formData) const fields = formData.fields || [] - // dacli-2026-06-29-04 fix: 主子表 TC-A 必传 --real-fields 硬关卡 - // 根因 (jxcj1teamv2 实战): buildSampleData 对主子表只填主表前 2 字段, 子表 required - // 字段不会被自动覆盖 → POST create 必 FAIL (后端 VisualdevModelDataServiceImpl - // 校验所有 required 字段, 子表 f_user_id 等空) - // 修复: 检测到主子表 (tables.length > 1) 时, 强制用户传 --real-fields 覆盖子表 - // schema 已知 (单表也能用 --real-fields, 所以硬关卡精准到主子表) - // 镜像: web 端 Form.vue 提交时强制校验所有 required 字段, 不分主子表 + // P0-2 fix (2026-07-15): 主子表自动 sample (testspace testjxcjp02ai 实战) + // 旧 (dacli-2026-06-29-04): 主子表检测到 tables.length > 1 时强制 exit(1), 逼用户传 --real-fields + // 根因: 当时 buildSampleData 对主子表只填主表前 2 字段, 不覆盖子表 children required 字段 + // 新 (实测 testjxcjp02ai): buildSampleData 已通过 jnpfKey='table' 遍历 cfg.children 生成完整 childRow, + // POST /visualdev/OnlineDev/{formId} 返回 code=200 ("New created successfully") + // 修复: 去掉硬关卡, 主子表也走 buildSampleData 自动 sample; 保留软 warn + 子表名参考 + // (用户想覆盖特定业务值仍可 --real-fields) + // 边界: web 端 Form.vue 提交时强制校验所有 required 字段 (主子表都验) — 不需在 dacli 侧重复 const tablesStr: string = schemaR.data.tables || '[]' let tablesArr: any[] = [] try { tablesArr = JSON.parse(tablesStr) } catch { /* ignore */ } const isMainSubTable = Array.isArray(tablesArr) && tablesArr.length > 1 - if (isMainSubTable && !opts.realFields) { - log.error(`dacli-2026-06-29-04 fix: 检测到主子表 (${tablesArr.length} 张), 必传 --real-fields 覆盖所有 required 字段`) - log.error(` 例: --real-fields='{"f_main_field1":"v1","f_main_field2":"v2","jxcj1subtable":[{"f_sub_field1":"sv1"}]}'`) - log.error(` 说明: buildSampleData 自动覆盖主表前 2 字段, 子表 required 字段需用户主动提供`) - log.error(` 子表 tableName 参考:`) - for (let i = 1; i < tablesArr.length; i++) { + if (isMainSubTable) { + log.warn(`⚠ 检测到主子表 (${tablesArr.length} 张), buildSampleData 自动覆盖主表 + 子表 children (P0-2 fix)`) + log.warn(` 子表 tableName 参考:`) + for (let i = 0; i < tablesArr.length; i++) { const t = tablesArr[i] - const tName = t?.table || t?.tableName || `sub${i}` - log.error(` - ${tName} (typeId=${t?.typeId || '?'}, relationTable=${t?.relationTable || '?'})`) + const tName = t?.table || t?.tableName || `t${i}` + const role = t?.typeId === '1' ? '主表' : '子表' + log.warn(` - [${role}] ${tName} (typeId=${t?.typeId || '?'}, relationTable=${t?.relationTable || '?'})`) } - if (opts.json) { - printJson({ - ok: false, - error: 'dacli-2026-06-29-04: 主子表 TC-A 必传 --real-fields', - tableCount: tablesArr.length, - subTables: tablesArr.slice(1).map((t: any) => ({ - table: t?.table, - tableName: t?.tableName, - relationTable: t?.relationTable, - relationField: t?.relationField, - })), - }) - } - process.exit(1) + log.warn(` 想覆盖特定业务值: --real-fields='{"main_field":"v","subTableField":[{"sub_field":"sv"}]}'`) } sample = await buildSampleData(fields, c, { @@ -549,7 +536,7 @@ export function buildTestRunCommand(): Command { '--output': '输出报告文件路径 (默认 stdout)', '--keep-data / --no-keep-data': '保留 / 删除测试数据 (默认 keep, 留数据供 TC-B 浏览器验证)', '--real-data / --no-real-data': '真实业务数据 / test fixture 模式 (默认 real-data)', - '--real-fields ': '自定义真实业务数据 JSON (优先级最高; 主子表必传, dacli-2026-06-29-04 硬关卡)', + '--real-fields ': '自定义真实业务数据 JSON (优先级最高; P0-2 fix 后主子表也走自动 sample, 无需强传)', '--relation-form-lookup / --no-relation-form-lookup': 'relationForm 自动 lookup 关联表真实 ID (默认 ON)', '--relation-form-sample ': '关联表拉前 N 条 (默认 1, 最大 5)', '--join-check / --join-rules ': '跨表 join 校验 (FK → 关联表)',