From 5ead157903ee5305785f4d78b2faef0ea5e4515a Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 21 Jul 2026 17:35:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(dacli):=20P1=20dm/drop=20TTY=20=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=20+=20workflow=20shim=20=E6=B8=85=E7=90=86=20(11=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P1 (0.5h): - dm/drop.ts 加 TTY 拦截 — 镜像 form/delete.ts:25 + print/delete.ts:46 + report/delete.ts:39 已稳定的 pattern: `if (!opts.yes && process.stdin.isTTY)` 时 warn + exit 1; 非 TTY 模式 (CI/脚本) 静默 --yes 走即可. 同步 DOC 注释 + 移除 TODO. - storage/info.ts:38 DacliError 分叉 — 验证**实际不存在** (`class DacliError` 仅 src/core/types.ts:57 一处定义, 已被 storage/_helpers.ts:21 正确 import). ADR 0015 §2.2 早期记述有误, 修订清空. shim 清理 (0.5h): - 11 个 workflow 子命令 (approve/create/decision/delete/info/launch/list/ selector/syncForm/tasks/update) 把 `import { ... } from './_output.ts'` 改成 `from '../_output_filter.ts'` (1 行 sed × 11 文件). - 删除 src/commands/workflow/_output.ts shim 文件 (D 掉), 减少 1 个间接层. - 不影响 L1 输出过滤 / L3 CommandLog 落盘, 因接口签名不变. 验证: - TS compile: 56 errors baseline 不变, 0 新错误 - 68/68 单元测试 PASS (含 tests/unit/workflow/create_stale_retry) - 端到端: dacli dm drop --help + dacli workflow info --help 完整 --- docs/decisions/0015-source-leftovers.md | 19 ++++++++++++------- src/commands/dm/drop.ts | 14 +++++++++----- src/commands/workflow/_output.ts | 23 ----------------------- src/commands/workflow/approve.ts | 2 +- src/commands/workflow/create.ts | 2 +- src/commands/workflow/decision.ts | 2 +- src/commands/workflow/delete.ts | 2 +- src/commands/workflow/info.ts | 2 +- src/commands/workflow/launch.ts | 2 +- src/commands/workflow/list.ts | 2 +- src/commands/workflow/selector.ts | 2 +- src/commands/workflow/syncForm.ts | 2 +- src/commands/workflow/tasks.ts | 2 +- src/commands/workflow/update.ts | 2 +- 14 files changed, 32 insertions(+), 46 deletions(-) delete mode 100644 src/commands/workflow/_output.ts diff --git a/docs/decisions/0015-source-leftovers.md b/docs/decisions/0015-source-leftovers.md index 1d9ef57..70c2f9c 100644 --- a/docs/decisions/0015-source-leftovers.md +++ b/docs/decisions/0015-source-leftovers.md @@ -64,14 +64,18 @@ wrapCommand({ **端到端验证**: `datasource list/test --json`, `--help`, validation fail 路径 (bscode 含 `!` + dbType=MySQL 缺 serviceName) → exit 1 + 错误 log 完整保留. -### 2.2 P1: 已知 baseline 坑 (2 类, 各 1 文件) +### 2.2 P1: 已知 baseline 坑 (1 类, 1 文件) -| 文件 | 问题 | 修法 | -|------|------|------| -| `dacli/src/commands/dm/drop.ts` | 缺 TTY 拦截, 跑在 CI 会无确认删表 | 加 `if (!opts.yes && process.stdin.isTTY)` 同 datasource/delete | -| `dacli/src/commands/storage/info.ts:38` | 同文件内 `DacliError` 类分叉 (vs `src/core/types.ts` 统一) | 统一 import `'../../core/types.ts'` | +| 文件 | 问题 | 修法 | 状态 | +|------|------|------|------| +| `dacli/src/commands/dm/drop.ts` | 缺 TTY 拦截, 跑在 CI 会无确认删表 | 加 `if (!opts.yes && process.stdin.isTTY)` 同 form/delete.ts:25 / print/delete.ts:46 / report/delete.ts:39 | ✅ done (本 session) | -**工作量**: 0.5h, 1 文件 P0-1, 1 文件 import 修改. +**storage/info.ts:38 DacliError 分叉 (ADR 早期记的)**: **实际不存在**. +8 维度扫 (本 session) 确认 `class DacliError` 仅 `src/core/types.ts:57` 一处定义, +`storage/_helpers.ts` 已正确 `import { DacliError } from '../../core/types.ts'`. +ADR 0015 早期记述有误, 现清空. + +**工作量**: 0.5h, 1 文件. ### 2.3 P2: 25+ 高严重度文件批量改造 (validator 模式) @@ -128,7 +132,8 @@ wrapCommand({ |---|--------|------|------|-------------------| | **P0** | 1h | 极高 | ✅ **DONE** | c637a58 (wrapCommand helper + 6 文件迁移 + 17 单测) | | **P3** | 1h | 中 | ✅ **DONE** | 715fcb9 (18 `_validate.ts` 删本地说法, 改 `import { ValidationError } from '../_error_codes.ts'`, 净减 113 行) | -| **P1** | 0.5h | 高 | 待 | `dacli/src/commands/dm/drop.ts` + `dacli/src/commands/storage/info.ts:38` | +| **P1** | 0.5h | 高 | ✅ **DONE** | dm/drop.ts TTY 拦截 (镜像 form/delete.ts:25); storage/info.ts:38 DacliError 分叉**实际不存在** (ADR §2.2 修订) | +| **shim** | 0.5h | 低 | (本 session) | workflow/_output.ts 11 import 改写 + 删 shim | | P2 | 2-3h | 高 | 待 | form/create.ts 子模块验证函数审查清单 | | P3 | 1h | 中 | 待 | 18 个 `**/_validate.ts` 改错误码 import | | P4 | 1h | 中 | 待 | `addOutputOptions` 已加, stdout 文案不统一 → 走 log.flush | diff --git a/src/commands/dm/drop.ts b/src/commands/dm/drop.ts index a90bd18..2f8b23c 100644 --- a/src/commands/dm/drop.ts +++ b/src/commands/dm/drop.ts @@ -4,7 +4,10 @@ * v0.11+ Phase 2 (2026-06-25): 改用 webapi 镜像 (loadDataModel.delDataModel) * 替代 v0.10 直接 c.del('/system/DataModel/{dbLinkId}/Table/{table}') * - * ⚠️ 危险操作, 表数据不可恢复. 真实执行需双重人工确认 (TODO: 加 TTY 拦截) + * ⚠️ 危险操作, 表数据不可恢复. + * P1 修复 (2026-07-21): 加 TTY 拦截 — TTY 模式无 --yes 主动 exit 1 引导用户 + * 确认; 非 TTY 模式 (CI / 脚本) 静默执行 (脚本需自己传 --yes). 镜像 + * form/delete.ts:25 + print/delete.ts:46 + report/delete.ts:39 同款 pattern. */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -25,10 +28,11 @@ export function buildDmDropCommand(): Command { .option('--dbLinkId ', '业务库 id') .option('--yes', '跳过确认', false) .action(async (opts: DropOpts) => { - if (!opts.yes) { - log.warn(`即将删除表: ${opts.table}`) - log.warn('传 --yes 确认 (数据不可恢复)') - process.exit(2) + // P1 修复 (2026-07-21): TTY 拦截 — 交互模式无 --yes 引导确认; 脚本模式照常执行 (跳过提示). + // 镜像 form/delete.ts:25 同款. command 不发起 AP I, 仅校验 + UX, 不落 CommandLog. + if (!opts.yes && process.stdin.isTTY) { + log.warn(`即将删除表: ${opts.table}, 加 --yes 跳过提示`) + process.exit(1) } const c = await JnpfClient.fromToken() // BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId diff --git a/src/commands/workflow/_output.ts b/src/commands/workflow/_output.ts deleted file mode 100644 index 473fe02..0000000 --- a/src/commands/workflow/_output.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * commands/workflow/_output.ts — workflow 命令输出过滤 shim (2026-07-21) - * - * ⚠️ 真实实现已迁移到 commands/_output_filter.ts (跨命令通用 helper, v2.1+). - * 保留此文件仅为向后兼容现有 import 路径: - * - commands/workflow/{info,approve,create,tasks,syncForm,decision,list,launch,delete,update,selector}.ts - * 共 11 个 workflow 文件 import from './_output.ts'. - * - * 迁移要点 (2026-07-21): - * - printCommandEnd 签名变了 — 旧 (opts, command, summary) → 新 printCommandEnd({ command, appCode, summary, fixes, ... }) - * 旧签名的 1 个调用方 (workflow/create.ts:383) 需更新; 本 shim 不再转发旧签名. - * - setupOutputFilter / addOutputOptions 签名不变, 11 个调用方无需修改. - * - printCommandEndSimple 已删除 (dead code, 全 codebase 0 调用方). - * - * 新代码请直接 import from '../_output_filter.ts'. - */ - -// L1 输出过滤 + 选项 (11 个 workflow 命令使用, 签名不变) -export { setupOutputFilter, addOutputOptions } from '../_output_filter.ts' - -// L3 CommandLog 落盘 (仅 workflow/create.ts:383 使用, 签名已变 — 调用方需同步更新) -export { printCommandEnd } from '../_output_filter.ts' -export type { PrintCommandEndArgs, OutputOpts } from '../_output_filter.ts' diff --git a/src/commands/workflow/approve.ts b/src/commands/workflow/approve.ts index 971d741..276c378 100644 --- a/src/commands/workflow/approve.ts +++ b/src/commands/workflow/approve.ts @@ -7,7 +7,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' interface Opts { operatorId: string diff --git a/src/commands/workflow/create.ts b/src/commands/workflow/create.ts index f34145e..9485306 100644 --- a/src/commands/workflow/create.ts +++ b/src/commands/workflow/create.ts @@ -23,7 +23,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHookWithPatterns } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter, printCommandEnd } from './_output.ts' +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' import { callAiWorkflow, detectTrivialFlowXml } from '../form/_ai.ts' import { buildFlowNodes, validateFlowNodeStructure } from './_webapi_helpers.ts' import { autoLayoutFlowXml, isLayoutNeeded } from './_autoLayout.ts' diff --git a/src/commands/workflow/decision.ts b/src/commands/workflow/decision.ts index f86203c..caea4d2 100644 --- a/src/commands/workflow/decision.ts +++ b/src/commands/workflow/decision.ts @@ -14,7 +14,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' interface DecisionOpts { list?: boolean diff --git a/src/commands/workflow/delete.ts b/src/commands/workflow/delete.ts index 754dad1..407e4de 100644 --- a/src/commands/workflow/delete.ts +++ b/src/commands/workflow/delete.ts @@ -8,7 +8,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' interface Opts { id: string; yes?: boolean; verbose?: boolean; json?: boolean } diff --git a/src/commands/workflow/info.ts b/src/commands/workflow/info.ts index 66f85a4..13d8ba7 100644 --- a/src/commands/workflow/info.ts +++ b/src/commands/workflow/info.ts @@ -11,7 +11,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' diff --git a/src/commands/workflow/launch.ts b/src/commands/workflow/launch.ts index d0dc830..9510312 100644 --- a/src/commands/workflow/launch.ts +++ b/src/commands/workflow/launch.ts @@ -13,7 +13,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' interface Opts { flowId: string diff --git a/src/commands/workflow/list.ts b/src/commands/workflow/list.ts index fd4a160..cfb0af4 100644 --- a/src/commands/workflow/list.ts +++ b/src/commands/workflow/list.ts @@ -9,7 +9,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter, printCommandEnd } from './_output.ts' +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' interface ListOpts { category?: string diff --git a/src/commands/workflow/selector.ts b/src/commands/workflow/selector.ts index e77ce37..981caee 100644 --- a/src/commands/workflow/selector.ts +++ b/src/commands/workflow/selector.ts @@ -11,7 +11,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' interface Opts { diff --git a/src/commands/workflow/syncForm.ts b/src/commands/workflow/syncForm.ts index ad329b0..60444dd 100644 --- a/src/commands/workflow/syncForm.ts +++ b/src/commands/workflow/syncForm.ts @@ -21,7 +21,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' interface SyncFormOpts { flowId: string diff --git a/src/commands/workflow/tasks.ts b/src/commands/workflow/tasks.ts index 30275a4..5a54600 100644 --- a/src/commands/workflow/tasks.ts +++ b/src/commands/workflow/tasks.ts @@ -13,7 +13,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' interface Opts { category?: string diff --git a/src/commands/workflow/update.ts b/src/commands/workflow/update.ts index acca06e..7a6e5b8 100644 --- a/src/commands/workflow/update.ts +++ b/src/commands/workflow/update.ts @@ -8,7 +8,7 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' -import { setupOutputFilter } from './_output.ts' +import { setupOutputFilter } from '../_output_filter.ts' import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts'