From f56e77eb8d04c193ef969d62155c746c59ae8fa6 Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 2 Jul 2026 12:48:37 +0800 Subject: [PATCH] =?UTF-8?q?R3.6=20=E4=BF=AE=E5=A4=8D:=20di=20test=20--dry-?= =?UTF-8?q?run=20=E4=BB=85=E6=98=BE=E7=A4=BA=20body=20=E4=B8=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20(2026-07-02)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit audit 2026-07-02 §role/print/di 报告 P2 #8: - di test 调 Preview 端点, body 期望 DataInterfaceParamModel - 当前 --data 直接传, type=1 SQL DI 需要 {paramList: '[{field,defaultValue}...]'} - 用户传错 → SYS006 invalid param, 不知根因 - 缺 dry-run 调试 修复: - 加 --dry-run 选项, 仅显示将发送的 body 格式 - 端点路径 + body 内容 + 后端期望格式提示 - 提示用户先用 web 设计器测试一次, 看正确 body 格式 - 保留 --data JSON 解析 + 实际调用流程 - help hook 加 dry-run example 审计: dacli/docs/cmd-review/role-print-di-audit-2026-07-02.md --- src/commands/di/test.ts | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/commands/di/test.ts b/src/commands/di/test.ts index 00d3e53..fa32880 100644 --- a/src/commands/di/test.ts +++ b/src/commands/di/test.ts @@ -13,6 +13,8 @@ import { initWebapi, loadDataInterface } from '../../webapi/di.ts' interface Opts { id: string data?: string + // v0.15+ (R3.6): --dry-run 仅显示 body, 不实际调用 + dryRun?: boolean json?: boolean } @@ -21,6 +23,7 @@ export function buildDiTestCommand(): Command { .description('数据接口测试调用 (Preview, v0.11+ webapi)') .requiredOption('--id ', '数据接口 id') .option('--data ', '请求参数 JSON (默认空 {})', '{}') + .option('--dry-run', '仅显示将发送的 body, 不实际调用 (调试用)', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() @@ -32,6 +35,21 @@ export function buildDiTestCommand(): Command { log.error(`--data JSON 解析失败: ${(e as Error).message}`) process.exit(2) } + + // v0.15+ (R3.6): --dry-run 仅显示将发送的 body, 不实际调用 + // 用途: 调试时确认 body 格式对, 避免误调用破坏性 DI + if (opts.dryRun) { + log.info('=== dry-run 模式, 不会实际调用 ===') + log.info(`端点: POST /api/system/DataInterface/${opts.id}/Actions/Preview`) + log.info(`body: ${JSON.stringify(body)}`) + log.info('提示: 后端 DataInterfaceController.callPreview 期望 DataInterfaceParamModel:') + log.info(' { paramList: "[{field:\\"key1\\",defaultValue:\\"v1\\"},...]" }') + log.info(' 当前 body 直接传, type=1 SQL DI 需要 paramList 包成 JSON 字符串') + log.info(' 建议先用 web 设计器测试一次, 看正确 body 格式') + if (opts.json) printJson({ dryRun: true, endpoint: `/api/system/DataInterface/${opts.id}/Actions/Preview`, body }) + return + } + log.info(`loadDataInterface.getDataInterfaceRes (id=${opts.id})`) const r = (await loadDataInterface.getDataInterfaceRes(opts.id, body)) as { code?: number; msg?: string; data?: unknown } if (r.code !== 200 && r.code !== undefined) { @@ -46,10 +64,22 @@ export function buildDiTestCommand(): Command { installAiHelpHook(cmd, { purpose: '数据接口测试调用. AI 验证 DI 配置正确性 (链路, 鉴权, 返回值).', required: { '--id': '数据接口 id' }, - optional: { '--data': '请求参数 JSON (默认 {})', '--json': '原始 JSON 输出' }, - example: ['dacli di test --id=1234567890', 'dacli di test --id=1234567890 --data=\'{"userId":"u1"}\''], + optional: { + '--data': '请求参数 JSON (默认 {})', + '--dry-run': '仅显示将发送的 body, 不实际调用 (调试用)', + '--json': '原始 JSON 输出', + }, + example: [ + 'dacli di test --id=1234567890', + 'dacli di test --id=1234567890 --data=\'{"userId":"u1"}\'', + 'dacli di test --id=1234567890 --data=\'{}\' --dry-run # 调试 body 格式', + ], source: { api: 'POST /api/system/DataInterface/{id}/Actions/Preview', ref: 'web/.../api/systemData/dataInterface.ts getDataInterfaceRes()' }, - notes: ['v0.11+ 改用 webapi 镜像 (loadDataInterface.getDataInterfaceRes)'], + notes: [ + 'v0.11+ 改用 webapi 镜像 (loadDataInterface.getDataInterfaceRes)', + '**v0.15+ (R3.6)**: 加 --dry-run 选项, 仅显示 body 不调用, 防误传破坏性 DI', + '**body 格式提示**: 后端期望 DataInterfaceParamModel { paramList: "JSON 字符串" }, type=1 SQL DI 需要', + ], }) return cmd }