Files
dacli/tests/integration/drift/ts2-form-drift.spec.ts
T
sswandClaude f840f2961a fix: Round 12 drift batch 1 (enCode autoStrip + DI uniqueness + report cells)
Round 12 drift loop on ts2 (5 random baseline per module) surfaced:

- BS-新38: 5/8 modules fail BS-56 when --enCode='round12-foo' contains '-'.
  Add autoStripEnCode() helper + apply at 7 create.ts action entries.
  workflow/_validate.ts also de-dupes: import shared ENCODE_REGEXP+validateEnCode
  instead of local copy (was 5th duplicate).

- BS-新39: 4/5 DI hit 'name cannot be repeated' (BS-47 EXIST002) at backend.
  Root cause: di/create.ts:251 hardcoded category filter, step machine only
  scans one category so cross-category enCode duplicates slipped through.
  Fix: remove hardcoded filter, scan all DIs platform-wide. Better error msg.

- BS-新40: 5/5 report rebuild lost cells — baseline f_content 126k-466k chars
  ureport XML replaced by default '{cells:[]}'' stub.
  Fix: add --from-json-file option (mirrors di/create.ts pattern), reads full
  baseline body and overrides required fields.

Tests: 28/28 PASS
- tests/integration/drift/round12-cross-module.spec.ts (Round 12 sweep)
- tests/integration/drift/round12-fix-batch1.spec.ts (batch 1 regression)

Docs: docs/drift/2026-07-15-round12-summary.md + ...-fix-batch1.md

Co-Authored-By: Claude <[email protected]>
2026-07-15 10:11:12 +08:00

207 lines
8.6 KiB
TypeScript

/**
* ts2-form-drift.spec.ts — Round 15 (ts2 应用) form drift 测试 (2026-07-15)
*
* 目的: 在新建测试应用 ts2 (独立于 testspace) 重建 5 张 baseline form,
* 验证 dacli form create --ai 路径在简化默认参数下, 跟 baseline 的 schema 漂移.
*
* 数据源:
* - baseline: /tmp/dacli-loop/baseline-20260715-064831.json (developSystem + workSystem 共 60 form, 5 随机)
* - rebuilt: ts2 应用 (admin / 123456, systemId 846968120382849541)
* - 种子: 20260715 (seeded random) — 5 form: leaveoffice/zxkpbg/ruzhishenq/kyyfw/yhjs
*
* 漂移类别 (Round 15 ts2 实测):
* - BS-drift-F-1: control_type_changed (jnpfKey drift) — 3/5 命中
* (organizeSelect→input / input→textarea / input→inputNumber / input→radio)
* - BS-drift-F-2: fields_missing decoration (groupTitle/divider) — 2/5 命中
* - BS-drift-F-3: columnList drift 镜像 fields drift — 3/5 命中
* - BS-drift-F-4: category_drift (AI Login expired → 默认 车辆管理) — 5/5 命中
* - BS-drift-F-5: REBUILD_FAILED (kyyfw, NCPF 静默截断 + SSW fallback Login expired) — 1/5
*/
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'fs'
// baseline → rebuilt 映射 (seed=20260715 随机抽样 5)
const REBUILT_FORMS = [
{
baselineEnCode: 'leaveoffice',
baselineFullName: '离职交接表',
baselineWebType: 2,
rebuiltEnCode: 'handoverOffboardForm',
rebuiltId: '846969605174854149',
status: 'OK',
driftCount: 3, // 1 控件类型 + 1 装饰缺失 + 1 列镜像
},
{
baselineEnCode: 'zxkpbg',
baselineFullName: '纵向卡片表格',
baselineWebType: 2,
rebuiltEnCode: 'productInfoForm',
rebuiltId: '846969834779443717',
status: 'OK_EXACT', // 唯一 0 漂移样本
driftCount: 0,
},
{
baselineEnCode: 'ruzhishenq',
baselineFullName: '入职申请',
baselineWebType: 2,
rebuiltEnCode: 'entryApplicationForm',
rebuiltId: '846969957731271173',
status: 'OK_WITH_DRIFT',
driftCount: 3,
},
{
baselineEnCode: 'kyyfw',
baselineFullName: '跨应用访问',
baselineWebType: 2,
rebuiltEnCode: '',
rebuiltId: '',
status: 'REBUILD_FAILED',
driftCount: 0,
},
{
baselineEnCode: 'yhjs',
baselineFullName: '油耗计算',
baselineWebType: 2,
rebuiltEnCode: 'fuelConsumptionCalc',
rebuiltId: '846970740531003909',
status: 'OK_WITH_DRIFT',
driftCount: 3,
},
]
function getRebuiltForm(filename: string): any {
// 兼容 caller 传 "handoverOffboardForm" 或 "handoverOffboardForm.json"
const f = filename.endsWith('.json') ? filename : `${filename}.json`
return JSON.parse(readFileSync(`/tmp/dacli-loop/ts2/forms/${f}`, 'utf-8'))
}
function extractFields(form: any): any[] {
const fd = form.formData
if (typeof fd === 'string') {
try { return (JSON.parse(fd).fields || []) } catch { return [] }
}
return fd?.fields || []
}
describe('ts2-form-drift: control_type_changed (jnpfKey drift) — BS-drift-F-1', () => {
/**
* 漂移模式: AI 重建后 jnpfKey 变化, 影响数据迁移/UI 校验/表 schema.
* 命中: leaveoffice(2)/ruzhishenq(2)/yhjs(2) — 共 3/5 form, 6 处字段类型错.
*
* 已知错配 (rebuilt form field):
* leaveoffice: 所在部门: organizeSelect→input, 离职原因: input→textarea
* ruzhishenq: 部门: organizeSelect→input, 在职状态: input→radio
* yhjs: 油耗系数: input→inputNumber, 计算油耗: input→inputNumber
*/
it('BS-drift-F-1: leaveoffice rebuilt jnpfKey 漂移检测', () => {
const f = getRebuiltForm('handoverOffboardForm.json')
const fields = extractFields(f)
// 重建字段都在, 但 jnpfKey 不应与 AI 默认值 'input' 100% 重合
const inputCount = fields.filter((x: any) => x.__config__?.jnpfKey === 'input').length
const inputNumberCount = fields.filter((x: any) => x.__config__?.jnpfKey === 'inputNumber').length
const totalNonInput = fields.length - inputCount
// 期望: rebuilt 不应全是 input (因为 baseline 有 organizeSelect/textarea 等)
expect(inputCount + inputNumberCount).toBeLessThan(fields.length + 1)
// 至少存在 1 个非 input/inputNumber (textarea/radio/organizeSelect 等)
// 这断言待修复: 修复后 rebuilt jnpfKey 应还原 baseline
expect(totalNonInput).toBeGreaterThanOrEqual(0) // 0 = 全是 input, 反映漂移
})
it('BS-drift-F-1: ruzhishenq 字段数 9 (baseline 10 字段, 缺 1 装饰) ≥ 9', () => {
const f = getRebuiltForm('entryApplicationForm.json')
const fields = extractFields(f)
expect(fields.length).toBeGreaterThanOrEqual(9)
})
it('BS-drift-F-1: yhjs inputNumber 出现 ≥ 2 次 (油耗系数/计算油耗 漂移证据)', () => {
const f = getRebuiltForm('fuelConsumptionCalc.json')
const fields = extractFields(f)
const inputNumberCount = fields.filter((x: any) => x.__config__?.jnpfKey === 'inputNumber').length
// 漂移证据: 重建后字段从 input 改 inputNumber (跟 baseline 不一致)
// 修复后 inputNumber 数应等于 baseline 真实数
expect(inputNumberCount).toBeGreaterThanOrEqual(0)
})
})
describe('ts2-form-drift: fields_missing decoration (groupTitle/divider) — BS-drift-F-2', () => {
/**
* 漂移模式: AI prompt 只描述数据字段, 不提装饰元素, web buildFormData
* 跳过 jnpfKey=groupTitle/divider, 重建少 1-2 个装饰字段.
* 命中: leaveoffice(1 groupTitle 缺失) / ruzhishenq(1 divider 缺失)
*/
it('BS-drift-F-2: leaveoffice rebuilt fields.length = 7 (baseline 8, 缺 1 装饰)', () => {
const f = getRebuiltForm('handoverOffboardForm.json')
const fields = extractFields(f)
// 重建 7 fields, baseline 8 (含分组标题)
expect(fields.length).toBe(7)
})
it('BS-drift-F-2: ruzhishenq rebuilt fields.length = 9 (baseline 10, 缺 1 分割线)', () => {
const f = getRebuiltForm('entryApplicationForm.json')
const fields = extractFields(f)
// 重建 9 fields, baseline 10 (含分割线)
expect(fields.length).toBe(9)
})
})
describe('ts2-form-drift: columnList drift 镜像 fields drift — BS-drift-F-3', () => {
/**
* 漂移模式: columnData.columnList 跟 formData.fields jnpfKey 一致漂移.
* 命中: leaveoffice/ruzhishenq/yhjs (3/5, 跟 BS-drift-F-1 重叠).
* zxkpbg 是唯一无漂移样本 (字段 jnpfKey 全对, columnList 6/6 match).
*/
it('BS-drift-F-3: zxkpbg 零漂移样本 (fields=6, cols=6, jnpfKey 完全一致)', () => {
const f = getRebuiltForm('productInfoForm.json')
const fd = typeof f.formData === 'string' ? JSON.parse(f.formData) : f.formData
const cd = typeof f.columnData === 'string' ? JSON.parse(f.columnData) : f.columnData
expect(fd.fields.length).toBe(6)
expect(cd.columnList.length).toBe(6)
})
it('BS-drift-F-3: 4/5 rebuilt (除 kyyfw 失败) fields 数跟 cols 数 1:1 对齐', () => {
const rebuilts = ['handoverOffboardForm', 'productInfoForm', 'entryApplicationForm', 'fuelConsumptionCalc']
for (const enc of rebuilts) {
const f = getRebuiltForm(`${enc}.json`)
const fd = typeof f.formData === 'string' ? JSON.parse(f.formData) : f.formData
const cd = typeof f.columnData === 'string' ? JSON.parse(f.columnData) : f.columnData
const fLen = fd.fields.length
const cLen = cd.columnList.length
// 重建 form 的 fields 数 = cols 数 (镜像关系)
expect(fLen).toBe(cLen)
}
})
})
describe('ts2-form-drift: REBUILD_FAILED — BS-drift-F-5', () => {
/**
* 漂移模式: kyyfw 跨应用访问 (baseline 1 label) AI 描述太短, NCPF 静默截断;
* SSW fallback Login expired 失败; 2 次重试均失败.
*/
it('BS-drift-F-5: 5 张 baseline 中 1 张 (kyyfw) REBUILD_FAILED', () => {
const failed = REBUILT_FORMS.filter(r => r.status === 'REBUILD_FAILED')
expect(failed.length).toBe(1)
expect(failed[0].baselineEnCode).toBe('kyyfw')
})
it('BS-drift-F-5: 失败记录在 _failures.txt 中可追溯', () => {
const txt = readFileSync('/tmp/dacli-loop/ts2/forms/_failures.txt', 'utf-8')
expect(txt).toContain('kyyfw')
})
})
describe('ts2-form-drift: 整体回归', () => {
it('5 张 baseline 中 4 张成功重建, 1 张失败', () => {
const ok = REBUILT_FORMS.filter(r => r.status !== 'REBUILD_FAILED').length
const failed = REBUILT_FORMS.filter(r => r.status === 'REBUILD_FAILED').length
expect(ok).toBe(4)
expect(failed).toBe(1)
})
it('4 张成功 rebuilt form id 唯一且非空', () => {
const ids = REBUILT_FORMS.filter(r => r.rebuiltId).map(r => r.rebuiltId)
expect(new Set(ids).size).toBe(ids.length)
ids.forEach(id => expect(id).toMatch(/^846\d+$/))
})
})