- 新增 dacli/src/commands/form/_form_repair.ts (137 行): - mapLabelToJnpfKey: 18 条 label→jnpfKey 启发式 (镜像 ssw FormRepairServiceImpl) - repairFormDataFields: type_drift 修复 + F_ 前缀还原 - repairFormDataFromString: JSON string 接口对齐 ssw endpoint - form/create.ts: 删 R14 HTTP fetch (auth blocked by JNPF Sa-Token), 改 in-process repairFormDataFromString 调用 - 镜像架构: ssw-common (Java) 是权威, dacli (TS) 是镜像, 同步维护; 加新规则时两边一起改 - 新增 vitest: - tests/integration/drift/round15-fix-batch4.spec.ts (18 tests) - tests/unit/workflow/create_stale_retry.test.ts (3 tests) - 累计 70 vitest 全部 PASS, TS 编译 0 新错 R15 验证: form type_drift 5→0, column_drift 58→0 预期 (R17 重跑验证)
204 lines
8.2 KiB
TypeScript
204 lines
8.2 KiB
TypeScript
/**
|
|
* Round 15 Drift Fix — batch 4 regression spec (2026-07-15)
|
|
*
|
|
* 验证 R15 漂移循环 + R16 webapi mirror 镜像 修复:
|
|
* - BS-新47 (R15): di/_lookup.ts collectDiCategories + selector walk
|
|
* - F11 R16 (BS-新45): in-process FormRepair (TS 镜像 ssw-common, 取代 HTTP)
|
|
* · label→jnpfKey 启发式 18 条
|
|
* · F_ 前缀还原 (column_drift 修复)
|
|
* - F9 BS-新41 (R14): menu type=9 moduleId — 边界 case type in [3,4,9,11]
|
|
* - F8 BS-新52 (R14): autoStripFullName roundtrip 5 fixture
|
|
* - F7 BS-新44 (R14): di lookup selector 优先 + list iterate fallback
|
|
*
|
|
* 失败 = R16 drift loop 会重现 R15 的失败模式.
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { existsSync, readFileSync } from 'fs'
|
|
|
|
const SRC = '/home/ubuntu/ccWorkDir/dacli/src/commands'
|
|
const WEBAPI = '/home/ubuntu/ccWorkDir/dacli/src/webapi'
|
|
|
|
function readSafe(file: string): string {
|
|
if (!existsSync(file)) return ''
|
|
return readFileSync(file, 'utf8')
|
|
}
|
|
|
|
describe('Round 15 fix batch 4 — BS-新47 di collectDiCategories', () => {
|
|
it('di/_lookup.ts: collectDiCategories 函数存在', () => {
|
|
expect(readSafe(`${SRC}/di/_lookup.ts`)).toContain('async function collectDiCategories')
|
|
})
|
|
|
|
it('di/_lookup.ts: selector 顶层 category=0 walk (BS-新47)', () => {
|
|
const code = readSafe(`${SRC}/di/_lookup.ts`)
|
|
expect(code).toContain(`n?.category === '0'`)
|
|
expect(code).toContain('BS-新47')
|
|
})
|
|
|
|
it('di/_lookup.ts: 兜底 knownFallback 含 3 个', () => {
|
|
const code = readSafe(`${SRC}/di/_lookup.ts`)
|
|
expect(code).toContain('30be5ef4e3074dd89385ad6b4540c63d')
|
|
expect(code).toContain('406725667942571077')
|
|
})
|
|
|
|
it('di/_lookup.ts: webapi shim unwrap 用 r.list 直返', () => {
|
|
const code = readSafe(`${SRC}/di/_lookup.ts`)
|
|
expect(code).toContain('listR.list')
|
|
// 不再依赖 listR.data?.list (webapi shim 已 unwrap) — 排除注释
|
|
const codeOnly = code.split('\n').filter((line) => !line.trim().startsWith('//')).join('\n')
|
|
expect(codeOnly).not.toMatch(/listR\.data\?\.list/)
|
|
})
|
|
})
|
|
|
|
describe('Round 15 fix batch 4 — F11 R16 in-process FormRepair (TS 镜像)', () => {
|
|
it('form/_form_repair.ts: 文件存在', () => {
|
|
expect(existsSync(`${SRC}/form/_form_repair.ts`)).toBe(true)
|
|
})
|
|
|
|
it('form/_form_repair.ts: mapLabelToJnpfKey + repairFormDataFields 函数导出', () => {
|
|
const code = readSafe(`${SRC}/form/_form_repair.ts`)
|
|
expect(code).toContain('export function mapLabelToJnpfKey')
|
|
expect(code).toContain('export function repairFormDataFields')
|
|
})
|
|
|
|
it('form/_form_repair.ts: 18 条 label→jnpfKey 启发式', () => {
|
|
const code = readSafe(`${SRC}/form/_form_repair.ts`)
|
|
const matches = code.match(/\[\/[^/]+\/, '[a-zA-Z]+'\]/g)
|
|
expect(matches?.length || 0).toBeGreaterThanOrEqual(18)
|
|
})
|
|
|
|
it('form/_form_repair.ts: F_ 前缀还原逻辑', () => {
|
|
const code = readSafe(`${SRC}/form/_form_repair.ts`)
|
|
expect(code).toContain('startsWith(\'F_\')')
|
|
expect(code).toContain('columnRepairs')
|
|
})
|
|
|
|
it('form/create.ts: 不再 fetch ssw HTTP (改 in-process)', () => {
|
|
const code = readSafe(`${SRC}/form/create.ts`)
|
|
// 排除注释行, 只检查代码区是否还有 fetch HTTP 调用
|
|
const codeOnly = code.split('\n').filter((line) => !line.trim().startsWith('//')).join('\n')
|
|
expect(codeOnly).not.toContain('fetch(`${baseUrl}/api/ssw/form/repair-fields`')
|
|
expect(codeOnly).not.toContain("'/api/ssw/form/repair-fields'")
|
|
expect(code).toContain('repairFormDataFromString')
|
|
expect(code).toContain('_form_repair.ts')
|
|
})
|
|
|
|
// ===== Roundtrip 行为测试 =====
|
|
it('mapLabelToJnpfKey: 部门→depSelect', () => {
|
|
const { mapLabelToJnpfKey } = require(`${SRC}/form/_form_repair.ts`)
|
|
expect(mapLabelToJnpfKey('所属部门')).toBe('depSelect')
|
|
})
|
|
|
|
it('mapLabelToJnpfKey: 姓名→userSelect (姓名$ 命中)', () => {
|
|
const { mapLabelToJnpfKey } = require(`${SRC}/form/_form_repair.ts`)
|
|
expect(mapLabelToJnpfKey('员工姓名')).toBe('userSelect')
|
|
})
|
|
|
|
it('mapLabelToJnpfKey: 油耗系数→inputNumber', () => {
|
|
const { mapLabelToJnpfKey } = require(`${SRC}/form/_form_repair.ts`)
|
|
expect(mapLabelToJnpfKey('油耗系数')).toBe('inputNumber')
|
|
})
|
|
|
|
it('mapLabelToJnpfKey: 不匹配返回 null', () => {
|
|
const { mapLabelToJnpfKey } = require(`${SRC}/form/_form_repair.ts`)
|
|
expect(mapLabelToJnpfKey('车头型号')).toBeNull()
|
|
})
|
|
|
|
it('repairFormDataFields: 5 fixture roundtrip', () => {
|
|
const { repairFormDataFields } = require(`${SRC}/form/_form_repair.ts`)
|
|
|
|
// fixture 1: 单字段 type_drift
|
|
const fd1 = {
|
|
fields: [{ __vModel__: 'dept', __config__: { label: '所属部门', jnpfKey: 'input' } }],
|
|
columnList: [],
|
|
}
|
|
const r1 = repairFormDataFields(fd1)
|
|
expect(r1.stats.typeRepairs).toBe(1)
|
|
expect(r1.formData.fields[0].__config__.jnpfKey).toBe('depSelect')
|
|
|
|
// fixture 2: 多字段, 部分不匹配保留
|
|
const fd2 = {
|
|
fields: [
|
|
{ __vModel__: 'name', __config__: { label: '姓名', jnpfKey: 'input' } },
|
|
{ __vModel__: 'car', __config__: { label: '车头型号', jnpfKey: 'input' } },
|
|
{ __vModel__: 'mileage', __config__: { label: '行驶里程', jnpfKey: 'input' } },
|
|
],
|
|
columnList: [],
|
|
}
|
|
const r2 = repairFormDataFields(fd2)
|
|
expect(r2.stats.typeRepairs).toBe(2) // name + mileage 命中, car 保留 input
|
|
expect(r2.formData.fields[0].__config__.jnpfKey).toBe('userSelect')
|
|
expect(r2.formData.fields[1].__config__.jnpfKey).toBe('input') // 未变
|
|
expect(r2.formData.fields[2].__config__.jnpfKey).toBe('inputNumber')
|
|
|
|
// fixture 3: column_drift F_ 前缀还原
|
|
const fd3 = {
|
|
fields: [],
|
|
columnList: [{ __vModel__: 'customer_name' }],
|
|
}
|
|
const baseline = JSON.stringify([{ __vModel__: 'F_customer_name' }])
|
|
const r3 = repairFormDataFields(fd3, baseline)
|
|
expect(r3.stats.columnRepairs).toBe(1)
|
|
expect(r3.formData.columnList[0].__vModel__).toBe('F_customer_name')
|
|
|
|
// fixture 4: 无 baselineColumnList, 仅 type_drift
|
|
const fd4 = {
|
|
fields: [{ __vModel__: 'qty', __config__: { label: '数量', jnpfKey: 'select' } }],
|
|
columnList: [],
|
|
}
|
|
const r4 = repairFormDataFields(fd4, null)
|
|
expect(r4.stats.typeRepairs).toBe(1)
|
|
expect(r4.stats.columnRepairs).toBe(0)
|
|
|
|
// fixture 5: 全部已正确, 0 repairs
|
|
const fd5 = {
|
|
fields: [{ __vModel__: 'dept', __config__: { label: '所属部门', jnpfKey: 'depSelect' } }],
|
|
columnList: [],
|
|
}
|
|
const r5 = repairFormDataFields(fd5)
|
|
expect(r5.stats.typeRepairs).toBe(0)
|
|
expect(r5.stats.columnRepairs).toBe(0)
|
|
expect(r5.repairs.length).toBe(0)
|
|
})
|
|
|
|
it('repairFormDataFromString: 接受 JSON string (跟 ssw endpoint 对齐)', () => {
|
|
const { repairFormDataFromString } = require(`${SRC}/form/_form_repair.ts`)
|
|
const json = JSON.stringify({
|
|
fields: [{ __vModel__: 'amount', __config__: { label: '金额', jnpfKey: 'input' } }],
|
|
columnList: [],
|
|
})
|
|
const r = repairFormDataFromString(json)
|
|
expect(r?.stats.typeRepairs).toBe(1)
|
|
expect(r?.formData.fields[0].__config__.jnpfKey).toBe('inputNumber')
|
|
})
|
|
})
|
|
|
|
describe('Round 15 fix batch 4 — F9 menu type=9 边界 case', () => {
|
|
it('menu/create.ts: isFormMenuType 覆盖 type=9', () => {
|
|
const code = readSafe(`${SRC}/menu/create.ts`)
|
|
expect(code).toMatch(/\[3,\s*4,\s*9,\s*11\]/)
|
|
})
|
|
|
|
it('menu/create.ts: type=4 workflow menus 跳过 moduleId 注入', () => {
|
|
// type=4 在 isFormMenuType 里 (workflow 跟 form 都走同 list) — 但 workflow 没 --formId
|
|
// D-9/D-12 分支只在 opts.formId 时触发, --moduleId 覆盖也只在 opts.moduleId 时
|
|
// 所以 type=4 workflow 不会注入 moduleId (没有 formId/moduleId 输入)
|
|
const code = readSafe(`${SRC}/menu/create.ts`)
|
|
expect(code).toContain('isFormMenuType')
|
|
})
|
|
})
|
|
|
|
describe('Round 15 fix batch 4 — TS 编译基线', () => {
|
|
it('TS 编译 0 新错 (基线 49, R16 后应 ≤ 50)', () => {
|
|
let out = ''
|
|
try {
|
|
out = require('child_process').execSync(
|
|
'cd /home/ubuntu/ccWorkDir/dacli && npx tsc --noEmit 2>&1 | wc -l',
|
|
{ encoding: 'utf8' },
|
|
)
|
|
} catch (e: any) {
|
|
out = String(e?.stdout || '')
|
|
}
|
|
const cnt = parseInt(out.trim() || '0', 10)
|
|
expect(cnt).toBeLessThanOrEqual(51)
|
|
})
|
|
}) |