fix(BS-drift-1): columnList 命名规范适配 baseline (--column-naming)

漂移问题:
  baseline columnList prop 命名 3 种规范并存 (60 form 分布):
    F_prefix  2/60  (F_SortCode, F_Depname — 老 jnpf 2.x)
    auto     34/60  (comInputField101, billRuleField119 — JNPF 设计器默认)
    snake     6/60  (f_order_code, f_real_name — 带 f_ 前缀)
  dacli --ai 默认输出 snake_case 语义名 → 0% 重叠 (严重漂移)

解决方案:
  - 新增 src/commands/form/_naming_convention.ts
    * detectNamingConvention(form) → 'auto' | 'snake' | 'f_prefix'
    * applyNamingConvention(formData, columnData, conv) → 重命名 __vModel__ + columnList prop
  - dacli form create 新增 --column-naming <style> 选项
  - 检测 baseline 风格, 传 --column-naming 让 dacli 适配

实测 (rerun 5 form):
  testreceivable     F_prefix → dacli 输出 F_<UpperCamel> ✓
  testcustomer       F_prefix → dacli 输出 F_<UpperCamel> ✓
  baomingguanli      auto    → dacli 输出 comInputField<N>, dateField<N> ✓
  yaofangguanli      auto    → dacli 输出 comInputField<N> ✓
  hesuanjiancedengji auto    → dacli 输出 comInputField<N> ✓

vitest 21/21 PASS (BS-drift-1 解决后 convention pattern 100% 匹配)

剩余漂移: 具体词 (F_SortCode vs F_SerialNo), 编号 (comInputField115 vs comInputField1)
  都是 AI 生成或新编号, 不可比. 但 pattern 一致.

注: CI 关卡 G kb FAIL 是已知预存问题
This commit is contained in:
ssw committed 2026-07-12 13:30:17 +08:00
1 parent e0a130c69f
commit a2a0efaced
3 files changed
+257 -29

No files matched your search

+64 -29
View File
@@ -20,16 +20,19 @@
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'fs'
// baseline → rebuilt 映射 (RERUN after smartProps fix, 2026-07-12)
// 修复前 IDs (round2-results.json):
// testreceivable=845971477676163205 testcustomer=845972410011222149 ...
// 修复后 IDs (round2-rerun-results.json):
// baseline → rebuilt 映射 (BS-drift-1 解决后 rerun, 2026-07-12)
// 检测 baseline convention → 传 --column-naming 让 dacli 适配
// testreceivable baseline=F_prefix → rebuilt F_xxx
// testcustomer baseline=F_prefix → rebuilt F_xxx
// baomingguanli baseline=auto → rebuilt comInputField<N>
// yaofangguanli baseline=auto → rebuilt comInputField<N>
// hesuanjiancedengji baseline=auto → rebuilt comInputField<N>
const REBUILT_FORMS = [
{ enCode: 'testreceivable', rebuiltId: '845977113713443013' },
{ enCode: 'testcustomer', rebuiltId: '845977187294118085' },
{ enCode: 'baomingguanli', rebuiltId: '845977246400250053' },
{ enCode: 'yaofangguanli', rebuiltId: '845977309763600581' },
{ enCode: 'hesuanjiancedengji', rebuiltId: '845977384954888389' },
{ enCode: 'testreceivable', rebuiltId: '845980792919163077', expectedConv: 'f_prefix' },
{ enCode: 'testcustomer', rebuiltId: '845980867380641989', expectedConv: 'f_prefix' },
{ enCode: 'baomingguanli', rebuiltId: '845980928957219013', expectedConv: 'auto' },
{ enCode: 'yaofangguanli', rebuiltId: '845981084716892357', expectedConv: 'auto' },
{ enCode: 'hesuanjiancedengji', rebuiltId: '845981168414228677', expectedConv: 'auto' },
]
// 漂移对比数据 (修复前 vs smartProps 修复后)
@@ -62,29 +65,61 @@ function getColumnProps(columnData: any): string[] {
.map((c: any) => c.prop)
}
describe('form-drift: columnList prop naming convention drift (BS-drift-1)', () => {
describe('form-drift: columnList prop naming convention drift (BS-drift-1 RESOLVED)', () => {
/**
* 漂移模式: baseline columnList prop 命名有 3 种规范并存:
* - F_ 前缀 (老 form, e.g. testcustomer 11/11)
* - 自动生成名 (comInputField101, billRuleField102 等, 新 form 默认)
* - snake_case 语义名 (dacli --ai 默认输出)
* 影响: web 列表查询返回字段名跟后端 columnList 配置不一致, 前端绑定会断.
* 修复前: baseline columnList prop 命名 3 种规范并存, dacli 始终输出 snake_case 语义名,
* 0% 重叠 (5/5 form 完全不匹配).
* 修复后 (dacli --column-naming): 自动检测 baseline 风格, 重命名 columnList prop 跟 baseline 一致.
* - F_prefix baseline → dacli 输出 F_<UpperCamel> (同 pattern)
* - auto baseline → dacli 输出 comInputField<N> / dateField<N> (同 pattern)
* - snake baseline → dacli 输出 f_<snake_case>
*
* 实测 (Round 2): baseline 跟 rebuilt 命名规范匹配率 0/14, 0/11, 0/10, 0/16, 0/7
* 实测 (BS-drift-1 解决后 rerun): convention pattern 100% 匹配
* - testcustomer baseline F_SortCode ↔ rebuilt F_SerialNo (同 F_+Camel 模式)
* - baomingguanli baseline comInputField115 ↔ rebuilt comInputField1 (同 pattern)
*
* 剩余漂移: 具体词 (F_SortCode vs F_SerialNo, 都是"序号"合理命名),
* 编号 (comInputField115 vs comInputField1) — 都是新生成的, 不可比.
*/
it.each(REBUILT_FORMS)('rebuilt %s 跟 baseline prop 完全不匹配', ({ enCode, rebuiltId }) => {
it.each(REBUILT_FORMS)('rebuilt %s 命名规范匹配 baseline pattern', ({ enCode, rebuiltId, expectedConv }) => {
const base = getBaseline(enCode)
const baseProps = getColumnProps(JSON.parse(base.f_column_data))
const rebuiltProps = getColumnProps(getRebuilt(rebuiltId).columnData)
const rebuiltFormFields = getRebuilt(rebuiltId).formData.fields || []
const rebuiltVModels = rebuiltFormFields.map((f: any) => f.__vModel__).filter(Boolean)
const baseSet = new Set(baseProps)
const overlap = rebuiltProps.filter((p: string) => baseSet.has(p))
if (expectedConv === 'f_prefix') {
// 所有 prop + __vModel__ 都应是 F_<UpperCamel> 格式
const allMatch = [...rebuiltProps, ...rebuiltVModels].every((p: string) =>
/^F_[A-Z][A-Za-z0-9]*$/.test(p)
)
expect(allMatch).toBe(true)
} else if (expectedConv === 'auto') {
// 所有 prop + __vModel__ 都应是 <Prefix>Field<Number> 格式
const autoPattern = /^(comInput|comSelect|input|inputNumber|select|date|number|switch|radio|checkbox|table|cascader|upload|tree|area|popup|signature|rate|slider|color|organize|user|users|dep|post|area|group|relation|popupTable|popupSelect|billRule|component)Field\d+$/
const allMatch = [...rebuiltProps, ...rebuiltVModels].every((p: string) => autoPattern.test(p))
expect(allMatch).toBe(true)
}
})
// 漂移证据: 0 重叠 (实测已知, 全部 5 张 form prop 命名都不一样)
expect(overlap.length).toBe(0)
// rebuilt 用 snake_case 语义名 (dacli 默认)
const snakeCount = rebuiltProps.filter((p: string) => /^[a-z][a-z0-9_]*$/.test(p)).length
expect(snakeCount).toBe(rebuiltProps.length)
it('BS-drift-1 修复: convention pattern 全 5 form 匹配', () => {
let allPassed = 0
for (const r of REBUILT_FORMS) {
const rebuiltProps = getColumnProps(getRebuilt(r.rebuiltId).columnData)
const rebuiltFormFields = getRebuilt(r.rebuiltId).formData.fields || []
const rebuiltVModels = rebuiltFormFields.map((f: any) => f.__vModel__).filter(Boolean)
const all = [...rebuiltProps, ...rebuiltVModels]
let pass = false
if (r.expectedConv === 'f_prefix') {
pass = all.every((p: string) => /^F_[A-Z][A-Za-z0-9]*$/.test(p))
} else if (r.expectedConv === 'auto') {
pass = all.every((p: string) =>
/^(comInput|comSelect|input|inputNumber|select|date|number|switch|radio|checkbox|table|cascader|upload|tree|area|popup|signature|rate|slider|color|organize|user|users|dep|post|area|group|relation|popupTable|popupSelect|billRule|component)Field\d+$/.test(p)
)
}
if (pass) allPassed++
}
expect(allPassed).toBe(5)
})
})
@@ -96,15 +131,15 @@ describe('form-drift: AI 拆解复合字段 (BS-drift-2)', () => {
*/
it('hesuanjiancedengji rebuilt 字段数比 baseline 多 (拆解效果)', () => {
const base = getBaseline('hesuanjiancedengji')
const rebuilt = getRebuilt('845977384954888389')
const rebuilt = getRebuilt('845981168414228677')
const baseLabels = getFieldLabels(JSON.parse(base.f_form_data))
const rebuiltLabels = getFieldLabels(rebuilt.formData)
// baseline 9 字段, rebuilt 12 字段 (smartProps 修复后 AI 加语义字段)
expect(rebuiltLabels.length).toBeGreaterThan(baseLabels.length)
// 包含 AI 推理的语义字段 (baseline 没有)
expect(rebuiltLabels).toContain('证件类型')
expect(rebuiltLabels).toContain('联系方式类型')
expect(rebuiltLabels).toContain('是否已采集身份证')
expect(rebuiltLabels).toContain('核酸结果')
expect(rebuiltLabels).toContain('检测机构')
})
})
@@ -116,7 +151,7 @@ describe('form-drift: AI 改写 label (BS-drift-3)', () => {
*/
it('hesuanjiancedengji rebuilt AI 改写 "身份证号/护照" → 拆分/重组', () => {
const base = getBaseline('hesuanjiancedengji')
const rebuilt = getRebuilt('845977384954888389')
const rebuilt = getRebuilt('845981168414228677')
const baseLabels = getFieldLabels(JSON.parse(base.f_form_data))
const rebuiltLabels = getFieldLabels(rebuilt.formData)