From f840f2961aaedb245a9df4ecb869678708dec82d Mon Sep 17 00:00:00 2001 From: ssw Date: Wed, 15 Jul 2026 10:11:12 +0800 Subject: [PATCH] fix: Round 12 drift batch 1 (enCode autoStrip + DI uniqueness + report cells) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- docs/drift/2026-07-15-round12-fix-batch1.md | 69 ++++++ docs/drift/2026-07-15-round12-summary.md | 105 +++++++++ src/commands/_encode_validator.ts | 35 +++ src/commands/di/_validate.ts | 13 +- src/commands/di/create.ts | 20 +- src/commands/dict/typecreate.ts | 16 ++ src/commands/form/create.ts | 11 + src/commands/menu/create.ts | 10 + src/commands/report/create.ts | 60 ++++- src/commands/role/create.ts | 9 + src/commands/workflow/_validate.ts | 23 +- src/commands/workflow/create.ts | 10 + .../drift/round12-cross-module.spec.ts | 71 ++++++ .../drift/round12-fix-batch1.spec.ts | 84 +++++++ .../drift/ts2-datascreen-drift.spec.ts | 109 +++++++++ tests/integration/drift/ts2-di-drift.spec.ts | 131 +++++++++++ .../integration/drift/ts2-dict-drift.spec.ts | 155 +++++++++++++ .../integration/drift/ts2-form-drift.spec.ts | 206 ++++++++++++++++++ .../integration/drift/ts2-menu-drift.spec.ts | 122 +++++++++++ .../drift/ts2-report-drift.spec.ts | 101 +++++++++ .../integration/drift/ts2-role-drift.spec.ts | 74 +++++++ .../drift/ts2-round12-drift.spec.ts | 126 +++++++++++ .../drift/ts2-workflow-drift.spec.ts | 102 +++++++++ 23 files changed, 1639 insertions(+), 23 deletions(-) create mode 100644 docs/drift/2026-07-15-round12-fix-batch1.md create mode 100644 docs/drift/2026-07-15-round12-summary.md create mode 100644 tests/integration/drift/round12-cross-module.spec.ts create mode 100644 tests/integration/drift/round12-fix-batch1.spec.ts create mode 100644 tests/integration/drift/ts2-datascreen-drift.spec.ts create mode 100644 tests/integration/drift/ts2-di-drift.spec.ts create mode 100644 tests/integration/drift/ts2-dict-drift.spec.ts create mode 100644 tests/integration/drift/ts2-form-drift.spec.ts create mode 100644 tests/integration/drift/ts2-menu-drift.spec.ts create mode 100644 tests/integration/drift/ts2-report-drift.spec.ts create mode 100644 tests/integration/drift/ts2-role-drift.spec.ts create mode 100644 tests/integration/drift/ts2-round12-drift.spec.ts create mode 100644 tests/integration/drift/ts2-workflow-drift.spec.ts diff --git a/docs/drift/2026-07-15-round12-fix-batch1.md b/docs/drift/2026-07-15-round12-fix-batch1.md new file mode 100644 index 0000000..2c53288 --- /dev/null +++ b/docs/drift/2026-07-15-round12-fix-batch1.md @@ -0,0 +1,69 @@ +# Round 12 Drift Fix — Batch 1 Summary + +**Date**: 2026-07-15 +**Driver**: Round 12 drift loop output (`/tmp/dacli-loop/ts2/{module}/round12-drift-summary.json`) +**App**: ts2 (漂移测试场2) + +## 修复的 3 项 + +### F1 (BS-新38) — 跨模块 enCode autoStrip +**Round 12 现象**: 5/8 模块 (form / dict / di / menu / role) 因 `--enCode=round12-foo` 含 `-` 触发 BS-56, AI 必须手动重试 strip 后才能 create. + +**修法**: `_encode_validator.ts` 加 `autoStripEnCode()` helper, 6 个 create.ts + 1 typecreate.ts 在 action entry 早期调用 + WARN log. + +**影响文件** (7): +- `src/commands/_encode_validator.ts` (新加 `autoStripEnCode` 函数) +- `src/commands/role/create.ts` +- `src/commands/menu/create.ts` +- `src/commands/di/create.ts` +- `src/commands/form/create.ts` +- `src/commands/report/create.ts` +- `src/commands/workflow/create.ts` +- `src/commands/dict/typecreate.ts` (含 fullName soften) + +**额外**: `workflow/_validate.ts:47` 去重, 改 import 共享 `ENCODE_REGEXP + validateEnCode`. 旧本地常量与其他 4 模块重复. + +**smoke test**: +``` +$ dacli dict typeCreate --enCode=r12-test-strip --fullName="r12 strip test" +! ! autoStrip enCode: r12-test-strip → r12teststrip (BS-新38, 下次别用 - 或 _) +``` + +### F2 (BS-新39) — DI uniqueness 全平台扫 +**Round 12 现象**: 4/5 DI 重建时 hit 后端 "name cannot be repeated" (BS-47 EXIST002). +**根因**: `di/create.ts:251` 硬编码 `category: '30be5ef4e3074dd89385ad6b4540c63d'`, step machine 只看一个 category, 跨 category 的 enCode 重复检测不到. + +**修法**: 移除硬编码 category filter, 平台全扫 + 错误信息加改名建议 + 标 BS-新39 标签. + +**影响文件** (2): +- `src/commands/di/create.ts:248-251` +- `src/commands/di/_validate.ts:184-211` + +### F6 (BS-新40) — 报告 cells baseline 透传 +**Round 12 现象**: 5/5 report 重建后 baseline 126k-466k chars `f_content` 全丢, rebuilt 永远是 `{"cells":[]}`. + +**修法**: 加 `--from-json-file` 选项, 跟 DI 一致, 文件读完整 baseline body 然后覆盖必填字段. + +**影响文件** (1): +- `src/commands/report/create.ts` (option + branch) + +## 验证 + +- TS 编译: 49 errors before == 49 errors after (我加的 0 个新错误) +- vitest: 28/28 PASS (`round12-cross-module.spec.ts` + `round12-fix-batch1.spec.ts`) +- Smoke: `dacli dict typeCreate --enCode=r12-test-strip` 正确 autoStrip + WARN + +## 未修 (out of scope this batch) + +- **F3** workflow --ai trivial 3-node BPMN: 需重写 `callAiWorkflow` 走 webapi `getAiInfo` 而不是裸 `POST /workflow/ai`. 影响文件 2-3 个 (`create.ts` + `_ai.ts`), 改 web `loadWorkflow.getAiInfo` 入口, 风险较高. 建议 P0 next batch. +- **F4** create response id 兜底 list-find: dict/menu 已有 `_lookup.ts`, role/di/workflow 是 inline 实现. 抽取 `role/_lookup.ts` + `di/_lookup.ts` (≈ 5 文件). +- **F5** form smartProps fallback: `_smart_props.ts:115-128` AI 失败时返 null → 所有 required=false. 需 enhance fallback. 影响 `_smart_props.ts` + `create.ts:836`. + +## 跨模块 reg-test 输出 + +``` +✓ tests/integration/drift/round12-fix-batch1.spec.ts (14 tests) 91ms +✓ tests/integration/drift/round12-cross-module.spec.ts (14 tests) 9ms +Test Files 2 passed (2) + Tests 28 passed (28) +``` diff --git a/docs/drift/2026-07-15-round12-summary.md b/docs/drift/2026-07-15-round12-summary.md new file mode 100644 index 0000000..0f5fc95 --- /dev/null +++ b/docs/drift/2026-07-15-round12-summary.md @@ -0,0 +1,105 @@ +# Round 12 Drift Loop — Cross-Module Sweep Summary + +**Date**: 2026-07-15 +**App**: ts2 (漂移测试场2, systemId=846968120382849541) +**Method**: 按 USAGE.md, 8 模块各随机 5/全部 baseline, dacli 重建 + diff +**Random seed**: 20260715 (Python `random.seed`) +**Rebuild total**: 40 records (8 modules × 5 records) + +--- + +## Per-module result + +| # | Module | ran | ok | fail | 主要漂移 | drift 类别数 | +|---|--------|-----|----|----|----------|------------| +| 1 | form | 5 | 5 | 0 | AI 不还原业务 jnpfKey, smartProps 全 false, columnList F_ 前缀不还原 | missing=34, extra=5, type=25, required=25, column=25 | +| 2 | workflow | 5 | 5 | 0 | 5/5 都只生 global 节点, no flow nodes | missing_nodes=31, flowId_match=0 | +| 3 | di | 5 | 0 | 5 | API code=400 "name cannot be repeated" (BS-47 类似); 2/5 created 缺 id | fieldJson=0, parameterJson=0, dataConfigJson=0 | +| 4 | menu | 5 | 5 | 0 | parentId 平台级, ts2 重置 (预期) | parent_lost=5 (预期), url/type=0 | +| 5 | dict | 5 | 4 | 1 | baseline fullName 含 `-` 被 BS-charset 拒; cross-app fullName BS-47 冲突 | BS-47=4, charset_dash=1 | +| 6 | role | 5 | 5 | 0 | BS-56 enCode 连字符拒, 需 strip | BS-56=5, id_undefined=5 | +| 7 | report | 5 | 5 | 0 | cells JSON 100% 丢 (baseline 126k-466k chars, rebuilt null) | cells_drift=5, category_drift=5 | +| 8 | datascreen | 5 | 1 | 4 | blade-visual 微服务返 500 on ts2 (大屏 save 端点) | service_5xx=4, category_lost=1 | + +**总计**: ran=40, ok=30, fail=10 (8 di + 1 datascreen + 1 dict + 0 form/workflow/menu/role/report) + +--- + +## 跨模块共性发现 (优先级排序) + +### S0 — 致命 (P0, 影响功能) +1. **workflow --ai 不携带节点**: 5/5 baseline 4-10 节点流程 → 重建后只有 global 配置 (no real flow nodes). 任何复杂流程重建后等于空. + - 路径: `dacli/src/commands/workflow/create.ts` AI 路径 + - 修法: 必须传 --flowXml 直接, 或接 webapi mirror buildFlowNodes +2. **datascreen /api/blade-visual/visual/save 500**: ts2 调大屏保存端点持续返 HTTP 500, 即使 health check 200. 是 ts2 app + blade-visual 微服务的具体兼容问题. +3. **DI BS-47-API-level "name cannot be repeated"**: 即使 step machine 通过, 后端 reject 4/5 (enCode 已 strip, fullName 平台级冲突). + +### S1 — 重要 (P1, 导致 schema 漂移) +4. **smartProps 全 false**: NCPF backend 报"Login expired", 5/5 form smartProps 失败, required=true 全失真. 25 条 required_drift 主因. +5. **AI 不还原 F_ 前缀列名**: columnList 用 baseline F_xxx 列名, 但 AI 重建给业务命名, 25 条 column_drift 主因. +6. **report cells JSON 透传缺**: baseline f_content 是 8k-466k chars 的 ureport XML cells, dacli create 只接受 '{"cells":[]}' 默认, 全丢. + +### S2 — 一致性 (P2, 已加固) +7. **enCode 跨模块不一致 (BS-新 38)**: form/dict/di 用 `round12{enCode}` (strip 连字符), workflow 用 `r12.{enCode}` (含 dot), role 必 fail 若含连字符. 一个项目内 enCode 命名不统一 → round12 模板统一一版. +8. **id=undefined create response**: workflow.create / role.create / di.create 返 `{}` 而非带 id 的 data. 都用 list 后 grep 拉回. +9. **BS-56 跨模块**: form/dict/di/menu/dict 字符串 'round12-{enCode}' 含连字符被拒, 要 strip. workflow/datascreen 用 `r12.{enCode}` 或 `round12-screen-{id}` 含 dot 是允许的. + +### S3 — 预期 (不算 fail) +10. **menu parent_lost**: baseline 父菜单都在 developSystem/workSystem, ts2 不会同步, 全挂顶级是预期. +11. **API code=undefined transient**: 4/5 dict 一开始 API 拒, 后重试 OK. JNPF 后端瞬时问题. +12. **dict items_missing**: baseline 大部分不带 items, round12 不传 items 是正确行为, Round 9 BS-drift-DICT-3 已闭环. + +--- + +## 修复优先级建议 + +| 优先级 | 修复点 | 涉及模块 | 工作量 | +|--------|--------|----------|--------| +| **P0** | workflow --ai 增加显式 --flowXml 入口 (webapi 镜像 buildFlowNodes) | workflow | 大 | +| **P0** | DI --from-json-file "name cannot be repeated" 错误码分类 | di | 中 | +| **P0** | datascreen blade-visual 微服务 500 排查 ts2 specific | datascreen | 小 (infra) | +| **P1** | smartProps fallback 处理 (AI 失败时必需字段 default) | form | 中 | +| **P1** | report --cells / --snapshot 透传 baseline ureport XML | report | 中 | +| **P2** | enCode 命名规范化到 USAGE.md (round12{X}) | all | 小 | +| **P2** | create 响应体 + id 返回统一 | workflow/role/di | 小 | + +--- + +## Round 12 vs Round 11 比较 + +| 指标 | Round 11 | Round 12 | +|------|----------|----------| +| 模块覆盖 | 8 | 8 | +| ran | 40 | 40 | +| ok | 28 | 30 | +| fail | 12 | 10 | +| 新发现漂移 | 14 | 8 (本轮) | +| enCode 命名 bug | 5 modules 漂移 | 收敛到 3 | + +**收敛原因**: form/dict/menu/dict 我已熟悉 BS-56 脱连字符. workflow/datascreen/report 新发现. + +--- + +## 输出物清单 + +``` +/tmp/dacli-loop/ts2/ +├── round12-picks.json # 确定性随机挑选 (seed=20260715) +├── round12-final-summary.md # 本文件 +├── forms/round12-{*.json} # 5 重建 form schema +├── forms/round12-drift-summary.json # AI 报告 +├── workflow/round12-{*.json} # 5 重建 workflow + create log +├── workflow/round12-drift-summary.json +├── di/round12-{baseline,payload}/*.json +├── di/round12-drift-summary.json +├── menu/round12-{*.json} # 5 + drift summary +├── dict/round12-{*.json} # 4 重建 dict + drift summary +├── role/round12-{raw-results,drift-summary}.json +├── report/round12-{*.json} # 5 + drift summary +└── datascreen/round12-{*.json} # 5 + drift summary +``` + +下一步: +1. **P0 修复**: workflow --ai + DI name conflict + datascreen 500 → Polishing 会话 +2. **vitest**: `dacli/tests/integration/drift/round12-spec.ts` 4 链 assertion (`module-drift-summary.json` 存在 + counts > 0) +3. **commit**: Round 12 drift sweep + vitest diff --git a/src/commands/_encode_validator.ts b/src/commands/_encode_validator.ts index c583e06..856093e 100644 --- a/src/commands/_encode_validator.ts +++ b/src/commands/_encode_validator.ts @@ -86,6 +86,41 @@ export function suggestEnCode(enCode: string): string { .replace(/\s+/g, '') // 去空格 } +/** + * v0.21+ (Round 12 fix, BS-新38): 自动 strip 的 enCode + log helper. + * + * 用于各 create 命令 action() 入口早期调用: + * - 给 `round12-foo` → `round12foo` (去 `-`) + * - 静默 strip, 但返回 wasStriped=true 让调用方打 WARN log + * + * 原因: Round 12 drift loop 5/8 模块 (form/dict/di/menu/role) 因 enCode 含 `-` 触发 BS-56 fail, + * 必须手动重试. 加这个 helper, AI 一次提交就能跑通, 不用 retry. + * + * 注意: + * - workflow 用 `r12.{enCode}` 含 dot (BS-56 允许), 不需要 strip + * - bigscreen construct 没用 enCode, skip + * - 只 strip `_` 和 `-`, 保留 `.` 和中文 (中文走 validateEnCode 拒) + * + * @param enCode 原始 enCode (字符串或 undefined) + * @returns { value: 修正后 enCode, wasStriped: 是否做了修正, original: 原始值 } + */ +export function autoStripEnCode(enCode: string | undefined): { + value: string + wasStriped: boolean + original: string +} { + const original = String(enCode || '') + if (!original) { + return { value: '', wasStriped: false, original } + } + const stripped = suggestEnCode(original) + return { + value: stripped, + wasStriped: stripped !== original, + original, + } +} + /** * 校验 fullName (中文/字母/数字) */ diff --git a/src/commands/di/_validate.ts b/src/commands/di/_validate.ts index 36ec5ae..2e66ac5 100644 --- a/src/commands/di/_validate.ts +++ b/src/commands/di/_validate.ts @@ -182,12 +182,17 @@ export function validateUniqueness(opts: { } // 镜像后端 L254-256 fullName 唯一 (EXIST001) + // v0.21+ (Round 12 BS-新39): 改成扩到全平台, 跟后端 L254-256 一致 (不再限定 category) if (opts.fullName) { const dup = opts.existingDIs.find( (d) => d.fullName === opts.fullName && d.id !== opts.currentId, ) if (dup) { - errors.push({ field: 'fullName', message: `名称"${opts.fullName}"已存在 (BS-47, 后端 EXIST001)`, code: 'EXIST001' }) + errors.push({ + field: 'fullName', + message: `名称"${opts.fullName}"已存在 (BS-47 + BS-新39, 后端 EXIST001 全平台唯一). 建议改名 (加 appCode 前缀, 例: appName.${opts.fullName})`, + code: 'EXIST001', + }) } } @@ -197,7 +202,11 @@ export function validateUniqueness(opts: { (d) => d.enCode === opts.enCode && d.id !== opts.currentId, ) if (dup) { - errors.push({ field: 'enCode', message: `编码"${opts.enCode}"已存在 (BS-47, 后端 EXIST002)`, code: 'EXIST002' }) + errors.push({ + field: 'enCode', + message: `编码"${opts.enCode}"已存在 (BS-47 + BS-新39, 后端 EXIST002 全平台唯一). 建议改名 (加后缀, 例: ${opts.enCode}v2)`, + code: 'EXIST002', + }) } } diff --git a/src/commands/di/create.ts b/src/commands/di/create.ts index 31ac9f6..67b9801 100644 --- a/src/commands/di/create.ts +++ b/src/commands/di/create.ts @@ -19,6 +19,7 @@ import { log, printJson } from '../../core/log.ts' import { initWebapi, loadDataInterface, getDataInterfaceList } from '../../webapi/di.ts' // v0.15+ (P0-8): getDataInterfaceList 替代 c.get import { validateDiUpdate, type DiOpts } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { autoStripEnCode } from '../_encode_validator.ts' interface CreateOpts { fullName: string @@ -68,6 +69,20 @@ export function buildDiCreateCommand(): Command { const c = await JnpfClient.fromToken() await initWebapi(c) + // v0.21+ (Round 12 BS-新38): enCode 含 `-`/`_` 自动 strip + WARN (即便 web DI 不强制, 但 cross-mod 一致) + const _encStrip = autoStripEnCode(opts.enCode) + if (_encStrip.wasStriped) { + log.warn(`! autoStrip enCode: ${_encStrip.original} → ${_encStrip.value} (BS-新38, 下次别用 - 或 _)`) + opts.enCode = _encStrip.value + } + + // v0.21+ (Round 12 BS-新38): fullName 含 `-` 软化 (用 · 替代, 同 dict) + if (opts.fullName && /[-—–_]/.test(opts.fullName)) { + const softened = String(opts.fullName).replace(/[-—–_]/g, '·') + log.warn(`! fullName 含特殊符号 - 自动 soften: ${opts.fullName} → ${softened} (BS-新38)`) + opts.fullName = softened + } + // v0.11d+ Phase di: step machine 校验 (复用 _validate.ts) await runDiStepMachineCreate(c, opts) @@ -228,12 +243,15 @@ async function runDiStepMachineCreate( ): Promise { // 1. 拉全 DI 列表 (供 step 2 唯一性预校验, BS-47) // v0.15+ (P0-8) 走 webapi/getDataInterfaceList, 替代 c.get + // v0.21+ (Round 12 fix BS-新39): **不要** filter `category='30be5ef4...'` + // 旧: 硬编码只看一个 category, 跨 category 的 enCode 重复检测不到, 后端返 "name cannot be repeated" (BS-新39) + // 新: 不带 category filter, 平台全扫, 跟 dict/menu/role 一致 (BS-47 是全平台唯一, 不是分类内唯一) let existingDIs: Array<{ fullName?: string; enCode?: string; id?: string }> = [] try { const r = (await getDataInterfaceList({ currentPage: 1, pageSize: 1000, - category: '30be5ef4e3074dd89385ad6b4540c63d', // BS-17 fix + // 不带 category — 全平台扫 (Round 12 BS-新39 修复) })) as { data?: { list?: Array } } | unknown const list = ((r as { data?: { list?: Array } })?.data?.list) || [] existingDIs = list.map((d: any) => ({ diff --git a/src/commands/dict/typecreate.ts b/src/commands/dict/typecreate.ts index 72010ac..7221860 100644 --- a/src/commands/dict/typecreate.ts +++ b/src/commands/dict/typecreate.ts @@ -13,6 +13,7 @@ import { initWebapi, loadDict } from '../../webapi/dict.ts' import { validateDictTypeCreate, type DictItemLite } from './_validate.ts' import { lookupTypeIdByEnCode, lookupDataIdByEnCode } from './_lookup.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { autoStripEnCode } from '../_encode_validator.ts' interface Opts { enCode: string @@ -45,6 +46,21 @@ export function buildDictTypeCreateCommand(): Command { const c = await JnpfClient.fromToken() await initWebapi(c) + // v0.21+ (Round 12 BS-新38): enCode 含 `-`/`_` 自动 strip + WARN (同 role/menu/di/form) + const _encStrip = autoStripEnCode(opts.enCode) + if (_encStrip.wasStriped) { + log.warn(`! autoStrip enCode: ${_encStrip.original} → ${_encStrip.value} (BS-新38, 下次别用 - 或 _)`) + opts.enCode = _encStrip.value + } + + // v0.21+ (Round 12 BS-新38): fullName 含 `-` 等会触发 BS-56-FULLNAME-FORMAT + // 已有 validateFullName 报错, 这里加一个 soften: 自动替换 `-` 为 `·`, WARN + if (opts.fullName && /[-—–_]/.test(opts.fullName)) { + const softened = String(opts.fullName).replace(/[-—–_]/g, '·') + log.warn(`! fullName 含特殊符号 - 自动 soften: ${opts.fullName} → ${softened} (BS-新38, fullName 校验不允许 -)`) + opts.fullName = softened + } + // 解析 --items JSON 字符串 (step 2 校验需要 array) let itemsArray: DictItemLite[] = [] if (opts.items) { diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index ae5929a..8218066 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -28,6 +28,7 @@ import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' import { loadAppContext } from '../app/context.ts' import { loadToken } from '../../core/config.ts' import { applyNamingConvention, type NamingConvention } from './_naming_convention.ts' +import { autoStripEnCode } from '../_encode_validator.ts' interface CreateOpts { fullName?: string @@ -229,6 +230,16 @@ export function buildFormCreateCommand(): Command { // 不传 = 默认 snake_case 语义名 (dacli --ai 旧行为, baseline 0/60) .option('--column-naming