Files
dacli/tests/integration/drift/round12-fix-batch1.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

85 lines
3.5 KiB
TypeScript

/**
* Round 12 Drift Fix — batch 1 regression spec (2026-07-15)
*
* 验证 Round 12 漂移循环发现的 3 个 P0/P1/P2 修复:
* - F1 (BS-新38): cross-module enCode autoStrip
* - F2 (BS-新39): DI uniqueness 全平台扫 (移除硬编码 category filter)
* - F6 (BS-新40): report --from-json-file 完整 body 透传 (避免 cells 默认空 stub)
*
* 失败 = 漂移循环 Round 13 会重现 Round 12 的失败模式.
*/
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'
function grepCount(file: string, pattern: string): number {
if (!existsSync(file)) return 0
const cnt = execSync(`grep -c "${pattern}" "${file}" || true`, { encoding: 'utf8' })
return parseInt(cnt.trim() || '0', 10)
}
describe('Round 12 fix batch 1 — enCode autoStrip (F1, BS-新38)', () => {
const modulesWithAutoStrip = [
'role/create.ts',
'menu/create.ts',
'di/create.ts',
'form/create.ts',
'report/create.ts',
'workflow/create.ts',
'dict/typecreate.ts',
]
for (const m of modulesWithAutoStrip) {
it(`${m}: autoStrip 在 action entry 调用 + WARN log`, () => {
// 至少 3 个引用: import + check + WARN log
const cnt = grepCount(`${SRC}/${m}`, 'autoStrip')
expect(cnt).toBeGreaterThanOrEqual(2)
})
}
it('helpers/_encode_validator.ts: autoStripEnCode helper exported', () => {
expect(existsSync(`${SRC}/_encode_validator.ts`)).toBe(true)
expect(grepCount(`${SRC}/_encode_validator.ts`, 'export function autoStripEnCode')).toBe(1)
})
it('workflow/_validate.ts: 用共享 validateEnCode (去掉本地 ENCODE_REGEXP)', () => {
// 旧: const ENCODE_REGEXP = /^[a-z0-9].../, 新: import { ENCODE_REGEXP, validateEnCode } from '../_encode_validator.ts'
expect(grepCount(`${SRC}/workflow/_validate.ts`, "import.*validateEnCode.*_encode_validator")).toBe(1)
expect(grepCount(`${SRC}/workflow/_validate.ts`, 'validateEnCode(opts.enCode')).toBe(1)
// 没有本地常量声明 (旧 pattern)
expect(grepCount(`${SRC}/workflow/_validate.ts`, 'const ENCODE_REGEXP')).toBe(0)
})
})
describe('Round 12 fix batch 1 — DI uniqueness 全平台 (F2, BS-新39)', () => {
it('di/create.ts: 移除硬编码 category filter (Round 12 cause)', () => {
// 旧: category: '30be5ef4e3074dd89385ad6b4540c63d'
// 新: 不带 category, 全平台扫
expect(grepCount(`${SRC}/di/create.ts`, "category: '30be5ef4e3074dd89385ad6b4540c63d'")).toBe(0)
})
it('di/_validate.ts: BS-新39 全平台唯一性 + 改名建议', () => {
expect(grepCount(`${SRC}/di/_validate.ts`, 'BS-新39')).toBeGreaterThanOrEqual(2)
})
})
describe('Round 12 fix batch 1 — report --from-json-file (F6, BS-新40)', () => {
it('report/create.ts: --from-json-file 选项声明', () => {
expect(grepCount(`${SRC}/report/create.ts`, 'from-json-file')).toBeGreaterThanOrEqual(2)
})
it('report/create.ts: --from-json-file 优先于默认 cells stub', () => {
// 顶部 log 不能把默认 stub 直接当 query 用, 必须有 --from-json-file 分支
expect(grepCount(`${SRC}/report/create.ts`, 'BS-新40')).toBeGreaterThanOrEqual(1)
expect(grepCount(`${SRC}/report/create.ts`, 'opts.fromJsonFile')).toBeGreaterThanOrEqual(2)
})
})
describe('Round 12 vitest sanity', () => {
it('原 round12-cross-module.spec.ts 还在', () => {
expect(existsSync('/home/ubuntu/ccWorkDir/dacli/tests/integration/drift/round12-cross-module.spec.ts')).toBe(true)
})
})