漂移问题:
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 是已知预存问题
220 lines
10 KiB
TypeScript
220 lines
10 KiB
TypeScript
/**
|
|
* form-drift.spec.ts — Round 2 drift 测试 (2026-07-12)
|
|
*
|
|
* 目的: 捕获 dacli form create --ai 重建 form 时, 与 baseline (JNPF 平台真实示例)
|
|
* 产生的 schema 漂移, 防止未来回归.
|
|
*
|
|
* 数据源:
|
|
* - baseline: /tmp/dacli-loop/all-baseline.json (developSystem + workSystem 共 60 form)
|
|
* - rebuilt: testspace 应用 (admin / 123456), 5 张由 Round 2 重建
|
|
*
|
|
* 已知 3 类漂移 (Round 2 实测):
|
|
* 1. columnList prop 命名规范: baseline=F_SortCode (UPPER + F_), rebuilt=serial_num (snake)
|
|
* 2. AI 拆解复合字段: baseline="身份证号/护照" → rebuilt="护照号"+"证件类型"+"身份证号"
|
|
* 3. AI 改写 label: baseline="身份证" → rebuilt="身份证号"
|
|
*
|
|
* 重建 formId 见 /tmp/dacli-loop/round2-results.json
|
|
* 漂移报告见 /tmp/dacli-loop/round2-drift.json
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest'
|
|
import { readFileSync } from 'fs'
|
|
|
|
// 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: '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 修复后)
|
|
const DRIFT_COMPARE = {
|
|
'testreceivable': { before: [4, 0], after: [1, 1] }, // -3 missing
|
|
'testcustomer': { before: [3, 3], after: [1, 1] }, // -2/-2
|
|
'baomingguanli': { before: [0, 0], after: [1, 1] }, // +1/+1 (balanced)
|
|
'yaofangguanli': { before: [3, 8], after: [0, 1] }, // -3/-7 (大改善)
|
|
'hesuanjiancedengji': { before: [2, 4], after: [3, 6] }, // +1/+2 (略增)
|
|
}
|
|
|
|
function getBaseline(enCode: string): any {
|
|
const all = JSON.parse(readFileSync('/tmp/dacli-loop/all-baseline.json', 'utf-8'))
|
|
return all.forms.find((f: any) => f.f_en_code === enCode)
|
|
}
|
|
|
|
function getRebuilt(formId: string): any {
|
|
return JSON.parse(readFileSync(`/tmp/dacli-loop/info-${formId}.json`, 'utf-8'))
|
|
}
|
|
|
|
function getFieldLabels(formData: any): string[] {
|
|
return (formData?.fields || [])
|
|
.filter((f: any) => f?.__config__?.label)
|
|
.map((f: any) => f.__config__.label)
|
|
}
|
|
|
|
function getColumnProps(columnData: any): string[] {
|
|
return (columnData?.columnList || [])
|
|
.filter((c: any) => c?.prop)
|
|
.map((c: any) => c.prop)
|
|
}
|
|
|
|
describe('form-drift: columnList prop naming convention drift (BS-drift-1 RESOLVED)', () => {
|
|
/**
|
|
* 修复前: 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>
|
|
*
|
|
* 实测 (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 pattern', ({ enCode, rebuiltId, expectedConv }) => {
|
|
const base = getBaseline(enCode)
|
|
const rebuiltProps = getColumnProps(getRebuilt(rebuiltId).columnData)
|
|
const rebuiltFormFields = getRebuilt(rebuiltId).formData.fields || []
|
|
const rebuiltVModels = rebuiltFormFields.map((f: any) => f.__vModel__).filter(Boolean)
|
|
|
|
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)
|
|
}
|
|
})
|
|
|
|
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)
|
|
})
|
|
})
|
|
|
|
describe('form-drift: AI 拆解复合字段 (BS-drift-2)', () => {
|
|
/**
|
|
* 漂移模式: baseline 把 "身份证号/护照" 合并成一个字段,
|
|
* AI 拆成 "护照号" + "证件类型" + "身份证号" 多个独立字段.
|
|
* 影响: 字段数比 baseline 多, 存储结构变化, 数据迁移时丢失信息.
|
|
*/
|
|
it('hesuanjiancedengji rebuilt 字段数比 baseline 多 (拆解效果)', () => {
|
|
const base = getBaseline('hesuanjiancedengji')
|
|
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('检测机构')
|
|
})
|
|
})
|
|
|
|
describe('form-drift: AI 改写 label (BS-drift-3)', () => {
|
|
/**
|
|
* 漂移模式: AI 倾向于用更精确的词汇替换 baseline 的简略 label.
|
|
* 例: "身份证" → "身份证号", "手机" → "联系电话"
|
|
* 影响: 表单展示文案漂移, 用户识别困惑.
|
|
*/
|
|
it('hesuanjiancedengji rebuilt AI 改写 "身份证号/护照" → 拆分/重组', () => {
|
|
const base = getBaseline('hesuanjiancedengji')
|
|
const rebuilt = getRebuilt('845981168414228677')
|
|
const baseLabels = getFieldLabels(JSON.parse(base.f_form_data))
|
|
const rebuiltLabels = getFieldLabels(rebuilt.formData)
|
|
|
|
// baseline 含 "身份证号/护照" (合并字段)
|
|
expect(baseLabels).toContain('身份证号/护照')
|
|
// smartProps 修复后: rebuilt 用 "身份证号/护照号" (保留合并但更精确)
|
|
expect(rebuiltLabels).toContain('身份证号/护照号')
|
|
})
|
|
})
|
|
|
|
describe('form-drift: form data 结构完整性 (兜底)', () => {
|
|
/**
|
|
* 验证 rebuild 后 formData 至少有基本结构 (fields + tableName + formModel)
|
|
* 即使有漂移, 重建的 form 应是合法的 JNPF formData.
|
|
*/
|
|
it.each(REBUILT_FORMS)('rebuilt %s formData 基本结构合法', ({ enCode, rebuiltId }) => {
|
|
const rebuilt = getRebuilt(rebuiltId)
|
|
expect(rebuilt.formData).toBeDefined()
|
|
expect(rebuilt.formData.fields).toBeInstanceOf(Array)
|
|
expect(rebuilt.formData.fields.length).toBeGreaterThan(0)
|
|
expect(rebuilt.formData.tableName).toBeTruthy()
|
|
expect(rebuilt.formData.formModel).toBe('dataForm')
|
|
})
|
|
|
|
it.each(REBUILT_FORMS)('rebuilt %s columnData 基本结构合法', ({ enCode, rebuiltId }) => {
|
|
const rebuilt = getRebuilt(rebuiltId)
|
|
expect(rebuilt.columnData).toBeDefined()
|
|
expect(rebuilt.columnData.columnList).toBeInstanceOf(Array)
|
|
// dacli --ai 应该自动生成 columnList (B-15 修复)
|
|
expect(rebuilt.columnData.columnList.length).toBeGreaterThan(0)
|
|
})
|
|
})
|
|
|
|
describe('form-drift: smartProps 修复后漂移总量对比 (BS-rerun-1)', () => {
|
|
/**
|
|
* smartProps 修复后 (dacli/1eadac2) 重跑 5 form, 漂移数据:
|
|
* 修复前: missing=12 extra=15 总=27
|
|
* 修复后: missing=6 extra=10 总=16 (-11, -41%)
|
|
*
|
|
* 注意: hesuanjiancedengji 反而 +1/+2 (AI 拆得更细), 但全局改善明显.
|
|
* 字段数对齐: baseline 55 → 修复前 58 → 修复后 59 (更接近 baseline 55)
|
|
*
|
|
* 数据源: /tmp/dacli-loop/round2-rerun-drift.json + DRIFT_COMPARE
|
|
*/
|
|
it('总漂移数应小于修复前 (missing+extra < 27)', () => {
|
|
let total = 0
|
|
for (const enc of Object.keys(DRIFT_COMPARE)) {
|
|
total += DRIFT_COMPARE[enc as keyof typeof DRIFT_COMPARE].after[0]
|
|
total += DRIFT_COMPARE[enc as keyof typeof DRIFT_COMPARE].after[1]
|
|
}
|
|
expect(total).toBeLessThan(27)
|
|
expect(total).toBe(16) // 实测: 6+10
|
|
})
|
|
|
|
it('yaofangguanli 漂移改善最大 (-3/-7)', () => {
|
|
const before = DRIFT_COMPARE.yaofangguanli.before
|
|
const after = DRIFT_COMPARE.yaofangguanli.after
|
|
expect(after[0]).toBeLessThan(before[0])
|
|
expect(after[1]).toBeLessThan(before[1])
|
|
})
|
|
|
|
it('testreceivable missing 从 4 降到 1 (smartProps 加了正确字段)', () => {
|
|
expect(DRIFT_COMPARE.testreceivable.before[0]).toBe(4)
|
|
expect(DRIFT_COMPARE.testreceivable.after[0]).toBe(1)
|
|
})
|
|
}) |