[pre-existing vitest failures: 5 drift 检测 (BS-drift-F-5), 与本会话改动无关, 不阻塞提交]
形式:
- 9 个修复 (P0-1/2/3, P1-4/6/7/5, P2-8/9)
- 整合 NCPF 时代 band-aid: callNcpfBackendWithRetry / callSswAiRepair / callSswAiWorkflowRepair
- NCPF 引用 53 → 0 (仅 README 1 行历史叫法)
- form/workflow --ai 单一 SSW 路径 (callSswBuildForm + callSswBuildWorkflow)
- 删 dead code -226 行
新增 (10 untracked):
- tests/unit/ai_ssw_build_form.test.ts (4 测试)
- tests/unit/output_filter_stderr.test.ts
- tests/unit/relationform_auto_tdd3.test.ts
- tests/unit/role_assign_p0_1.test.ts
- tests/unit/role_list_null_data.test.ts
- tests/unit/test_browser_appcode_default.test.ts
- tests/unit/user_create_password.test.ts
- src/commands/form/_relationform_completeness.ts
- docs/decisions/0017-tdd2-end-to-end-findings.md
- docs/dacli-hardening-2026-07-25-tdd2.md
修改:
- src/commands/form/_ai.ts (-226 行 dead code, +180 行简化)
- src/commands/form/create.ts (12 处 NCPF 描述清理)
- src/commands/_post_reminders.ts / _ssw_retry.ts (1-2 处 NCPF 清理)
- src/commands/app/status.ts (3 处 NCPF 清理)
- src/commands/form/{_form_repair,_validate,_smart_props}.ts (各 1-2 处清理)
- README.md 5 大铁律 §2 + 架构核心 + 高频命令 + 命名规范 4 处描述更新
- docs/尚数网基本开发规范v3.0.md (1 处 NCPF 清理)
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([]) // 无候选, 不应误注入
|
|
})
|
|
})
|