本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
102 lines
3.5 KiB
TypeScript
102 lines
3.5 KiB
TypeScript
/**
|
|
* 2.3 P1-5 复现测试: tdd3 5/5 form 实战中 --ai 把 f_supplier_id jnpfKey=select,
|
|
* 期望 autoDetectAndInjectRelationForm 自动改为 relationForm
|
|
*/
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
/**
|
|
* 模拟 deriveTargetEnCodes 逻辑 (镜像 _relationForm_auto.ts:80-119)
|
|
*/
|
|
const RELATION_SUFFIXES = ['_space', '_id', '_code']
|
|
const SKIP_FIELDS = new Set(['f_id', 'f_tenant_id', 'f_flow_id'])
|
|
|
|
function deriveTargetEnCodes(vmodel: string): string[] {
|
|
if (!vmodel || !vmodel.startsWith('f_')) return []
|
|
if (SKIP_FIELDS.has(vmodel)) return []
|
|
const body = vmodel.slice(2)
|
|
for (const suf of RELATION_SUFFIXES) {
|
|
if (body.endsWith(suf)) {
|
|
const stem = body.slice(0, -suf.length)
|
|
if (!stem) return []
|
|
const candidates: string[] = []
|
|
candidates.push(stem)
|
|
candidates.push(stem.replace(/_/g, ''))
|
|
const parts = stem.split('_')
|
|
if (parts.length > 1) {
|
|
candidates.push(parts[parts.length - 1])
|
|
const last = parts[parts.length - 1]
|
|
candidates.push(last.charAt(0).toUpperCase() + last.slice(1).toLowerCase())
|
|
}
|
|
const pascal = parts.map(p => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()).join('')
|
|
candidates.push(pascal)
|
|
candidates.push(stem.toLowerCase())
|
|
return Array.from(new Set(candidates))
|
|
}
|
|
}
|
|
return []
|
|
}
|
|
|
|
/**
|
|
* 模拟 formList 匹配逻辑 (3 层: exact / lowercase / includes)
|
|
*/
|
|
function matchForm(
|
|
candidates: string[],
|
|
formList: Array<{ enCode: string }>,
|
|
): { enCode: string } | null {
|
|
// 1. 精确
|
|
for (const cand of candidates) {
|
|
const m = formList.find(f => f.enCode === cand)
|
|
if (m) return m
|
|
}
|
|
// 2. lowercase
|
|
for (const cand of candidates) {
|
|
const candLower = cand.toLowerCase()
|
|
const m = formList.find(f => f.enCode && f.enCode.toLowerCase() === candLower)
|
|
if (m) return m
|
|
}
|
|
// 3. includes
|
|
for (const cand of candidates) {
|
|
const candLower = cand.toLowerCase()
|
|
const m = formList.find(f => {
|
|
if (!f.enCode) return false
|
|
const encLower = f.enCode.toLowerCase()
|
|
return encLower.includes(candLower) || candLower.includes(encLower)
|
|
})
|
|
if (m) return m
|
|
}
|
|
return null
|
|
}
|
|
|
|
describe('2.3: tdd3 FK 字段自动匹配 relationForm 实际行为', () => {
|
|
it('f_supplier_id 在 tdd3supplier formList 应匹配 (via includes 兜底)', () => {
|
|
const cands = deriveTargetEnCodes('f_supplier_id')
|
|
expect(cands).toContain('supplier')
|
|
const tdd3List = [{ enCode: 'tdd3supplier' }, { enCode: 'tdd3material' }, { enCode: 'tdd3notice' }]
|
|
const m = matchForm(cands, tdd3List)
|
|
expect(m?.enCode).toBe('tdd3supplier') // 实际能匹配 via includes 兜底
|
|
})
|
|
|
|
it('f_purchase_order_id 应匹配 tdd3purchaseorder', () => {
|
|
const cands = deriveTargetEnCodes('f_purchase_order_id')
|
|
expect(cands.length).toBeGreaterThan(0)
|
|
const tdd3List = [{ enCode: 'tdd3supplier' }, { enCode: 'tdd3material' }, { enCode: 'tdd3purchaseorder' }]
|
|
const m = matchForm(cands, tdd3List)
|
|
expect(m?.enCode).toBe('tdd3purchaseorder') // includes 兜底
|
|
})
|
|
|
|
it('f_id 系统字段应被 SKIP_FIELDS 跳过', () => {
|
|
const cands = deriveTargetEnCodes('f_id')
|
|
expect(cands).toEqual([]) // 系统列跳过
|
|
})
|
|
|
|
it('f_tenant_id 系统字段应被跳过', () => {
|
|
const cands = deriveTargetEnCodes('f_tenant_id')
|
|
expect(cands).toEqual([])
|
|
})
|
|
|
|
it('f_unit 普通字段无 _id/_space/_code 后缀应返空 (无候选, 不应注入)', () => {
|
|
const cands = deriveTargetEnCodes('f_unit')
|
|
expect(cands).toEqual([]) // 无候选, 不应误注入
|
|
})
|
|
})
|