Files
dacli/tests/integration/drift/round13-fix-batch3.spec.ts
T
ssw 3e279325f3 feat(dacli): R16 in-process FormRepair (TS 镜像 ssw, 替代 HTTP)
- 新增 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 重跑验证)
2026-07-15 15:45:20 +08:00

199 lines
8.2 KiB
TypeScript

/**
* Round 13 Drift Fix — batch 3 regression spec (2026-07-15)
*
* 验证 R13 漂移循环发现的 5 项修复:
* - BS-新44 (P0): di _lookup.ts 用 getDataInterfaceSelector 优先 + category iterate fallback
* - BS-新52 (P1): form/dict/workflow/menu fullName autoStrip
* - BS-新41 (P1): menu type=9 (自定义表单) moduleId 注入
* - BS-新43b (P2): workflow stale pre-validate cleanup + retry
* - BS-新45 (R14): ssw-common FormRepairService (type_drift + column_drift)
*
* 失败 = R14 drift loop 会重现 R13 的失败模式.
*/
import { describe, it, expect } from 'vitest'
import { existsSync, readFileSync } from 'fs'
import { execSync } from 'node:child_process'
const SRC = '/home/ubuntu/ccWorkDir/dacli/src/commands'
const WEBAPI = '/home/ubuntu/ccWorkDir/dacli/src/webapi'
const SSW_COMMON = '/home/ubuntu/ccWorkDir/boot/ssw-common'
function grepCount(file: string, pattern: string): number {
if (!existsSync(file)) return 0
const cnt = execSync(`grep -c "${pattern}" "${file}" 2>/dev/null || echo 0`, { encoding: 'utf8' })
return parseInt(cnt.trim() || '0', 10)
}
function readSafe(file: string): string {
if (!existsSync(file)) return ''
return readFileSync(file, 'utf8')
}
describe('Round 13 fix batch 3 — di _lookup category iterate (BS-新44)', () => {
it('di/_lookup.ts: 优先调 getDataInterfaceSelector', () => {
expect(grepCount(`${SRC}/di/_lookup.ts`, 'getDataInterfaceSelector')).toBeGreaterThanOrEqual(1)
})
it('di/_lookup.ts: fallback category iterate (collectDiCategories)', () => {
expect(grepCount(`${SRC}/di/_lookup.ts`, 'collectDiCategories')).toBeGreaterThanOrEqual(1)
})
it('webapi/di.ts: 导出 getDataInterfaceSelector', () => {
const code = readSafe(`${WEBAPI}/di.ts`)
expect(code).toContain('export async function getDataInterfaceSelector')
})
it('di/_lookup.ts: Selector walk 找 category=1 (DI 实体)', () => {
expect(grepCount(`${SRC}/di/_lookup.ts`, `category === '1'`)).toBeGreaterThanOrEqual(1)
})
})
describe('Round 13 fix batch 3 — form fullName autoStrip (BS-新52)', () => {
it('_encode_validator.ts: autoStripFullName 函数存在', () => {
expect(grepCount(`${SRC}/_encode_validator.ts`, 'export function autoStripFullName')).toBe(1)
})
it('form/create.ts: 调 autoStripFullName + WARN', () => {
expect(grepCount(`${SRC}/form/create.ts`, 'autoStripFullName')).toBeGreaterThanOrEqual(1)
expect(grepCount(`${SRC}/form/create.ts`, 'BS-新52')).toBeGreaterThanOrEqual(1)
})
it('dict/typecreate.ts: 调 autoStripFullName (在 soften 之后)', () => {
expect(grepCount(`${SRC}/dict/typecreate.ts`, 'autoStripFullName')).toBeGreaterThanOrEqual(1)
})
it('workflow/create.ts: 调 autoStripFullName', () => {
expect(grepCount(`${SRC}/workflow/create.ts`, 'autoStripFullName')).toBeGreaterThanOrEqual(1)
})
it('menu/create.ts: 调 autoStripFullName', () => {
expect(grepCount(`${SRC}/menu/create.ts`, 'autoStripFullName')).toBeGreaterThanOrEqual(1)
})
it('autoStripFullName: 行为正确 (roundtrip 5 fixture)', () => {
// 直接 import 跑 roundtrip — 不依赖源码字符串 grep
const { autoStripFullName } = require(`${SRC}/_encode_validator.ts`)
// fixture 1: 半角空格 strip
const r1 = autoStripFullName('round14 客户管理')
expect(r1.wasStriped).toBe(true)
expect(r1.value).toBe('round14客户管理')
// fixture 2: 全角括号 strip
const r2 = autoStripFullName('客户管理(集成助手)')
expect(r2.wasStriped).toBe(true)
expect(r2.value).toBe('客户管理集成助手')
// fixture 3: 半角括号 strip
const r3 = autoStripFullName('表单(test)')
expect(r3.wasStriped).toBe(true)
expect(r3.value).toBe('表单test')
// fixture 4: 中英文标点 strip
const r4 = autoStripFullName('你好,世界!')
expect(r4.wasStriped).toBe(true)
expect(r4.value).toBe('你好世界')
// fixture 5: 干净输入不 strip
const r5 = autoStripFullName('客户管理表')
expect(r5.wasStriped).toBe(false)
expect(r5.value).toBe('客户管理表')
// fixture 6: undefined 输入
const r6 = autoStripFullName(undefined as any)
expect(r6.value).toBe('')
expect(r6.wasStriped).toBe(false)
})
})
describe('Round 13 fix batch 3 — menu type=9 moduleId (BS-新41)', () => {
it('menu/create.ts: isFormMenuType 包含 3,4,9,11', () => {
const code = readSafe(`${SRC}/menu/create.ts`)
expect(code).toContain('isFormMenuType')
expect(code).toMatch(/\[3,\s*4,\s*9,\s*11\]/)
})
it('menu/create.ts: D-9 自动填 moduleId 用 isFormMenuType (不只 type===3)', () => {
expect(grepCount(`${SRC}/menu/create.ts`, 'isFormMenuType')).toBeGreaterThanOrEqual(3)
})
it('menu/create.ts: --moduleId 注入用 isFormMenuType', () => {
const code = readSafe(`${SRC}/menu/create.ts`)
// 不再用 type === 3 单一条件
expect(code).not.toMatch(/if \(opts\.moduleId && type === 3\)/)
})
})
describe('Round 13 fix batch 3 — workflow stale cleanup (BS-新43b)', () => {
it('workflow/create.ts: BS-新43b stale cleanup 块存在', () => {
expect(grepCount(`${SRC}/workflow/create.ts`, 'BS-新43b')).toBeGreaterThanOrEqual(2)
})
it('workflow/create.ts: 检测 stale pre-validate 关键词', () => {
const code = readSafe(`${SRC}/workflow/create.ts`)
expect(code).toMatch(/已存在|SU001|预校验|already exists/)
})
it('workflow/create.ts: stale cleanup 用 loadWorkflow.delFlow', () => {
const code = readSafe(`${SRC}/workflow/create.ts`)
expect(code).toContain('loadWorkflow.delFlow')
})
it('workflow/create.ts: retry ONCE after cleanup', () => {
expect(grepCount(`${SRC}/workflow/create.ts`, 'retry create ONCE')).toBeGreaterThanOrEqual(1)
})
})
describe('Round 13 fix batch 3 — ssw-common FormRepairService (BS-新45)', () => {
it('ssw-common FormRepairService 接口存在', () => {
expect(existsSync(`${SSW_COMMON}/ssw-common-biz/src/main/java/ssw/common/service/FormRepairService.java`)).toBe(true)
})
it('ssw-common FormRepairServiceImpl 存在', () => {
expect(existsSync(`${SSW_COMMON}/ssw-common-biz/src/main/java/ssw/common/service/impl/FormRepairServiceImpl.java`)).toBe(true)
})
it('ssw-common SswFormRepairController 存在', () => {
expect(existsSync(`${SSW_COMMON}/ssw-common-controller/src/main/java/ssw/common/controller/SswFormRepairController.java`)).toBe(true)
})
it('FormRepairServiceImpl: mapLabelToJnpfKey 关键词映射 ≥ 10 条', () => {
const code = readSafe(`${SSW_COMMON}/ssw-common-biz/src/main/java/ssw/common/service/impl/FormRepairServiceImpl.java`)
// 数 LABEL_TO_JNPFKEY 数组里的 add() 调用次数
// R14 修: Map.entry → AbstractMap.SimpleEntry (Java 8 兼容)
const matches = code.match(/add\(new AbstractMap\.SimpleEntry/g)
expect(matches?.length || 0).toBeGreaterThanOrEqual(15)
})
it('FormRepairServiceImpl: 处理 column_drift (F_ 前缀还原)', () => {
const code = readSafe(`${SSW_COMMON}/ssw-common-biz/src/main/java/ssw/common/service/impl/FormRepairServiceImpl.java`)
expect(code).toContain('baselineColumnList')
expect(code).toContain('F_')
expect(code).toContain('columnRepairs')
})
it('SswFormRepairController: 端点 /api/ssw/form/repair-fields', () => {
const code = readSafe(`${SSW_COMMON}/ssw-common-controller/src/main/java/ssw/common/controller/SswFormRepairController.java`)
expect(code).toContain('/api/ssw/form/repair-fields')
expect(code).toContain('@PostMapping')
})
it('dacli form/create.ts: 调 ssw /repair-fields post-create', () => {
expect(grepCount(`${SRC}/form/create.ts`, '/api/ssw/form/repair-fields')).toBeGreaterThanOrEqual(1)
expect(grepCount(`${SRC}/form/create.ts`, 'BS-新45')).toBeGreaterThanOrEqual(1)
})
})
describe('Round 13 fix batch 3 — TS 编译基线', () => {
it('TS 编译 0 新错 (基线 49, R14 后应 ≤ 49)', () => {
// 跑 tsc, 错误数 ≤ 49 (含 pre-existing baseline errors)
let out = ''
try {
out = 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(50) // baseline 49 + 最多 1 个小容忍
})
})