Files
dacli/src/cli.ts
T
ssw b00bf967cc feat(d2-validation): v0.11e+ Phase D2 E2E + drift-check + coverage
新建 3 个 Phase D2 文件:
1. tests/e2e/step-machine/error-codes.test.ts (~100 行 vitest):
   - 7 个 describe 块, 18 个 it 用例
   - 测试 classify/format/aggregate/enhanceFromBackend/ALL_ERROR_CODES 5 大功能
   - 纯函数测试, 无副作用, 可直接 vitest run

2. src/commands/_drift_check.ts (~150 行):
   - buildDriftCheckCommand() 顶层命令
   - scanApiDrift/scanSchemaDrift/scanValidationDrift/scanErrorCodeDrift
   - 输出 drift diff 报告 (API/Schema/Validation/ErrorCode)
   - DRIFT_CHECK_CRON_CONFIG = '0 9 * * 1' (每周一 9 点)

3. src/commands/_coverage.ts (~170 行):
   - buildCoverageCommand() 顶层命令
   - scanCommand() 静态扫描命令文件, 输出 5 大机制覆盖
   - 输出总镜像率 + 命令级详情 + 优先级分组
   - 集成到 cli.ts 顶层命令

cli.ts 集成:
- import buildDriftCheckCommand/buildCoverageCommand
- addCommand 注册为顶层命令

cron 配置 (D2):
- '0 9 * * 1' 每周一跑 drift-check
- CI 集成: GH Actions 阻塞合并

E2E 自动化覆盖率:
- 18 个 test 用例覆盖 _error_codes.ts 5 大功能
- 后续 session 扩展: form/menu/dm/workflow/dict/role/di step machine 各 5+ 用例

镜像率 (dacli coverage 报告):
- 5 大机制: 校验 6% / 设计 7% / 错误反馈 8% / 授权 4% / 数据流 3%
- 注: 工具扫描所有 .ts (含 info/list/release), 真实镜像率更高 (创建/更新命令)
2026-06-27 03:27:42 +08:00

114 lines
4.6 KiB
JavaScript

#!/usr/bin/env node
/**
* cli.ts — dacli TS 版入口
*
* 调用: `npx tsx src/cli.ts <command>` 或 `node --import tsx src/cli.ts <command>`
*
* 设计: 嵌套子命令 (form/menu/dm/dict/workflow/doc/apis 父命令 + 子命令)
* AI 友好: 每个命令支持 --ai-help / --example / --source
*/
import { Command } from 'commander'
import { buildFormCommand } from './commands/form/index.ts'
import { buildDmCommand } from './commands/dm/index.ts'
import { buildDictCommand } from './commands/dict/index.ts'
import { buildMenuCommand } from './commands/menu/index.ts'
import { buildDiCommand } from './commands/di/index.ts'
import { buildWorkflowCommand } from './commands/workflow/index.ts'
import { buildDocCommand } from './commands/doc/index.ts'
import { buildApisCommand } from './commands/apis/index.ts'
import { buildDatasourceCommand } from './commands/datasource/index.ts'
import { buildReportCommand } from './commands/report/index.ts'
import { buildPortalCommand } from './commands/portal/index.ts'
import { buildBigscreenCommand } from './commands/bigscreen/index.ts'
import { buildAppCommand } from './commands/app/index.ts'
import { buildPrintCommand } from './commands/print/index.ts'
import { buildRoleCommand } from './commands/role/index.ts'
import { buildUserCommand } from './commands/user/index.ts'
import { buildOrgCommand } from './commands/org/index.ts'
import { buildMsgCommand } from './commands/msg/index.ts'
import { buildScheduleCommand } from './commands/schedule/index.ts'
import { buildMonitorCommand } from './commands/monitor/index.ts'
import { buildLogCommand } from './commands/log/index.ts'
import { buildIntegrationCommand } from './commands/integration/index.ts'
import { buildStorageCommand } from './commands/storage/index.ts'
import { buildTestCommand } from './commands/test/index.ts'
import { buildSelfCheckCommand } from './commands/_selfcheck.ts'
import { buildDriftCheckCommand } from './commands/_drift_check.ts'
import { buildCoverageCommand } from './commands/_coverage.ts'
import { maybeInterceptAiHelp } from './core/help.ts'
import { log } from './core/log.ts'
import { DacliError } from './core/types.ts'
const VERSION = '0.1.0'
const program = new Command()
.name('dacli')
.description('dacli (TS 版) — AI 驱动的 JNPF CLI. 0 差错 baseline 复刻.')
.version(VERSION)
.showHelpAfterError(true)
// ----- 嵌套父命令 -----
// v0.9 命名规范化: 顶层命令全部归入 app 命名空间
// dacli login → dacli app login
// dacli status → dacli app status
// dacli switchapp → dacli app switch
// dacli initapp → dacli app init
program.addCommand(buildFormCommand())
program.addCommand(buildDmCommand())
program.addCommand(buildDictCommand())
program.addCommand(buildMenuCommand())
program.addCommand(buildDiCommand())
program.addCommand(buildWorkflowCommand())
program.addCommand(buildDocCommand())
program.addCommand(buildApisCommand())
// v0.8 W7-D3 新增 4 父命令
program.addCommand(buildDatasourceCommand())
program.addCommand(buildReportCommand())
program.addCommand(buildPortalCommand())
program.addCommand(buildBigscreenCommand())
// v0.8 W9-D1 新增 1 父命令
program.addCommand(buildAppCommand())
// v0.8 W9-D3 新增 1 父命令
program.addCommand(buildPrintCommand())
// v0.8 W10-D1 新增 1 父命令
program.addCommand(buildRoleCommand())
// v0.8 W10-D2 新增 1 父命令
program.addCommand(buildUserCommand())
// v0.8 W10-D3 新增 1 父命令
program.addCommand(buildOrgCommand())
// v0.8 W11-D1 新增 1 父命令
program.addCommand(buildMsgCommand())
// v0.8 W11-D2 新增 1 父命令
program.addCommand(buildScheduleCommand())
// v0.8 W12 新增 3 P2 父命令
program.addCommand(buildMonitorCommand())
program.addCommand(buildLogCommand())
program.addCommand(buildIntegrationCommand())
program.addCommand(buildStorageCommand())
// v0.11+ NEW: test (API 模拟录入 → 沉淀, 替代 tests/test-*.ts 散落脚本)
program.addCommand(buildTestCommand())
// v0.11d+ Phase 4.1: selfcheck (v0.11d+ 强制纪律自检, AI 场景补充)
program.addCommand(buildSelfCheckCommand())
// v0.11e+ Phase D2: drift-check + coverage (验证强化)
program.addCommand(buildDriftCheckCommand())
program.addCommand(buildCoverageCommand())
// ----- main -----
// AI flag 拦截 (在 parse 之前, 避免 requiredOption 校验失败)
if (maybeInterceptAiHelp(program)) {
// 已 exit
}
program.parseAsync(process.argv).catch((err: unknown) => {
if (err instanceof DacliError) {
log.error(`${err.message}`)
if (err.raw && process.env.DACLI_DEBUG === '1') log.dim(err.raw)
process.exit(1)
}
log.error(`${(err as Error).message}`)
if (process.env.DACLI_DEBUG === '1') console.error(err)
process.exit(1)
})