R3.6 修复: di test --dry-run 仅显示 body 不调用 (2026-07-02)

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
This commit is contained in:
ssw committed 2026-07-02 12:48:37 +08:00
1 parent 0413c106d9
commit f56e77eb8d
1 file changed
+33 -3
+33 -3
View File
@@ -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>', '数据接口 id')
.option('--data <json>', '请求参数 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
}