fix(v0.11+): P0 修复 3 处端点错误 (假 PASS)

Phase 1 审计发现 3 处 P0 端点错误 (AI 调用返 success 但实际不生效):

1. integration emailTest
   - v0.10 错误: /message/SendMessageConfig/testSendConfig
   - v0.11+ 正确: /message/AccountConfig/testSendMail
   - 重构: 先拉 config, 再走 testConfig({...config, testSendEmail, testEmailTitle, testEmailContent, testType})

2. integration smsTest
   - v0.10 错误: /system/SmsTemplate/testSent
   - v0.11+ 正确: /message/AccountConfig/testSendSms
   - 重构: 同上模式 (testPhone + testType)

3. integration webhookTest
   - v0.10 错误: /message/SendMessageConfig/testSendConfig
   - v0.11+ 正确: /message/AccountConfig/testSendWebhook
   - 重构: 支持 --configId 或 --url 两种模式

4. msg templateCreate
   - v0.10 错误: /api/system/MessageTemplate
   - v0.11+ 正确: /api/message/MessageTemplateConfig

端点来源: web/api/msgCenter/accountConfig.ts:29 testConfig() + msgTemplate.ts:14 create()
影响: 这是 cmd-review/ 23 报告中 P0 必修项, 修复后避免 AI 误判 PASS

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-06-25 15:01:25 +08:00
1 parent b9c9e318af
commit 90a8b4eecb
4 files changed
+169 -67

No files matched your search

+43 -15
View File
@@ -1,7 +1,11 @@
/**
* commands/integration/emailtest.ts — 邮件测试发送
*
* 走 JNPF SendMessageConfig/testSendConfig 端点
* 走 JNPF AccountConfig 端点 (web 真实端点, v0.11+ P0 修复)
*
* 修复历史:
* - v0.10 错误端点: /message/SendMessageConfig/testSendConfig (假 PASS)
* - v0.11+ 正确端点: /message/AccountConfig/testSendMail (web Test.vue 验证)
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
@@ -11,35 +15,59 @@ import { log } from '../../core/log.ts'
interface EmailTestOpts {
configId: string
email?: string
title?: string
content?: string
}
export function buildIntegrationEmailTestCommand(): Command {
const cmd = new Command('emailTest')
.alias('email-test')
.description('邮件测试发送 (走 SendMessageConfig/testSendConfig)')
.requiredOption('--configId <id>', '发送配置 id')
.option('--email <e>', '目标邮箱')
.description('邮件测试发送 (走 AccountConfig/testSendMail)')
.requiredOption('--configId <id>', 'AccountConfig id (从 integration configList 获取)')
.option('--email <e>', '目标邮箱 (必填, 必填收件人)', '[email protected]')
.option('--title <t>', '测试邮件标题', 'Test from dacli')
.option('--content <c>', '测试邮件内容', 'This is a test email sent by dacli.')
.action(async (opts: EmailTestOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.postJson('/message/SendMessageConfig/testSendConfig', {
id: opts.configId,
email: opts.email,
})
// 1. 拉取 config 详情 (AccountConfig/testSendMail 需要 config dataForm)
const configR = await c.get<Record<string, unknown>>(`/message/AccountConfig/${opts.configId}`)
if (configR.code !== 200 || !configR.data) {
log.error(`integration emailtest 配置拉取失败: ${configR.msg || 'id 不存在'}`)
process.exit(1)
}
const config = configR.data
// 2. 拼装 test 请求 (web Test.vue 模式: {...config, testSendEmail, testEmailTitle, testEmailContent, testType})
const body = {
...config,
testSendEmail: [opts.email],
testEmailTitle: opts.title,
testEmailContent: opts.content,
testType: 'testSendMail',
}
// 3. 走 AccountConfig/testSendMail (web 端真实端点)
const r = await c.postJson('/message/AccountConfig/testSendMail', body)
if (r.code !== 200) {
log.error(`integration emailtest 失败: ${r.msg}`)
process.exit(1)
}
log.info(`✓ 邮件测试发送 OK (configId=${opts.configId})`)
log.info(`✓ 邮件测试发送 OK (configId=${opts.configId}, to=${opts.email})`)
})
installAiHelpHook(cmd, {
purpose: '邮件测试发送 (决策 8: 邮件通道)',
required: { '--configId': '发送配置 id' },
optional: { '--email': '目标邮箱' },
purpose: '邮件测试发送 (修复 v0.10 假 PASS 端点)',
required: { '--configId': 'AccountConfig id' },
optional: {
'--email': '目标邮箱',
'--title': '测试邮件标题',
'--content': '测试邮件内容',
},
example: 'dacli integration emailtest --configId=123 [email protected]',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/integrationCenter/email/index.vue',
api: 'POST /api/message/SendMessageConfig/testSendConfig',
ref: 'doc/v0.8-endpoints.md §3.3',
web: 'web/apps/jnpf-web-apps-main/src/views/integrationCenter/email/Test.vue',
api: 'POST /api/message/AccountConfig/testSendMail',
ref: 'web/.../api/msgCenter/accountConfig.ts:29 testConfig()',
},
})
return cmd
+45 -20
View File
@@ -1,7 +1,11 @@
/**
* commands/integration/smstest.ts — 短信测试发送
*
* API: POST /api/system/SmsTemplate/testSent
* 走 JNPF AccountConfig 端点 (web 真实端点, v0.11+ P0 修复)
*
* 修复历史:
* - v0.10 错误端点: /system/SmsTemplate/testSent (与 web 端不一致)
* - v0.11+ 正确端点: /message/AccountConfig/testSendSms (web api/msgCenter/accountConfig.ts)
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
@@ -9,40 +13,61 @@ import { installAiHelpHook } from '../../core/help.ts'
import { log } from '../../core/log.ts'
interface SmsTestOpts {
templateId: string
configId: string
phone?: string
json?: boolean
templateId?: string
}
export function buildIntegrationSmsTestCommand(): Command {
const cmd = new Command('smsTest')
.alias('sms-test')
.description('短信测试发送 (走 SmsTemplate/testSent 端点)')
.requiredOption('--templateId <id>', '短信模板 id')
.option('--phone <n>', '目标手机号')
.description('短信测试发送 (走 AccountConfig/testSendSms)')
.requiredOption('--configId <id>', 'AccountConfig id')
.option('--phone <n>', '目标手机号', '13800138000')
.option('--templateId <t>', '短信模板 ID (覆盖 config 默认模板)')
.action(async (opts: SmsTestOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.postJson('/system/SmsTemplate/testSent', {
templateId: opts.templateId,
phone: opts.phone,
})
// 1. 拉取 config 详情
const configR = await c.get<Record<string, unknown>>(`/message/AccountConfig/${opts.configId}`)
if (configR.code !== 200 || !configR.data) {
log.error(`integration smstest 配置拉取失败: ${configR.msg || 'id 不存在'}`)
process.exit(1)
}
const config = configR.data
// 2. 拼装 test 请求
const body: Record<string, unknown> = {
...config,
testPhone: opts.phone,
testType: 'testSendSms',
}
if (opts.templateId) {
body.testTemplateId = opts.templateId
}
// 3. 走 AccountConfig/testSendSms
const r = await c.postJson('/message/AccountConfig/testSendSms', body)
if (r.code !== 200) {
log.error(`integration smstest 失败: ${r.msg}`)
process.exit(1)
}
log.info(`✓ 短信测试发送 OK (templateId=${opts.templateId})`)
log.info(`✓ 短信测试发送 OK (configId=${opts.configId}, to=${opts.phone})`)
})
installAiHelpHook(cmd, {
purpose: '短信测试发送 (决策 8: 短信通道)',
required: { '--templateId': '短信模板 id' },
optional: { '--phone': '目标手机号' },
example: 'dacli integration smstest --templateId=123 --phone=13800138000',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/integrationCenter/sms/index.vue',
api: 'POST /api/system/SmsTemplate/testSent',
ref: 'doc/v0.8-endpoints.md §3.3',
purpose: '短信测试发送 (修复 v0.10 假 PASS 端点)',
required: { '--configId': 'AccountConfig id' },
optional: {
'--phone': '目标手机号',
'--templateId': '短信模板 ID',
},
notes: ['**决策 8**: 短信走 integrationCenter/sms, 不用 msgCenter'],
example: 'dacli integration smstest --configId=123 --phone=13800138000',
source: {
web: 'web/apps/jnpf-web-apps-main/src/api/msgCenter/accountConfig.ts:29 testConfig()',
api: 'POST /api/message/AccountConfig/testSendSms',
ref: 'dacli/docs/cmd-review/integration.md §端点错误',
},
notes: ['v0.10 端点 `/system/SmsTemplate/testSent` 已被 web 端废弃, v0.11+ 修复'],
})
return cmd
}
+54 -20
View File
@@ -1,5 +1,11 @@
/**
* commands/integration/webhooktest.ts — Webhook 测试发送
*
* 走 JNPF AccountConfig 端点 (web 真实端点, v0.11+ P0 修复)
*
* 修复历史:
* - v0.10 错误端点: /message/SendMessageConfig/testSendConfig (web 端不存在 webhook 测试)
* - v0.11+ 正确端点: /message/AccountConfig/testSendWebhook
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
@@ -7,48 +13,76 @@ import { installAiHelpHook } from '../../core/help.ts'
import { log } from '../../core/log.ts'
interface WebhookTestOpts {
url: string
configId?: string
url?: string
payload?: string
}
export function buildIntegrationWebhookTestCommand(): Command {
const cmd = new Command('webhookTest')
.alias('webhook-test')
.description('Webhook 测试发送')
.requiredOption('--url <u>', '目标 URL')
.option('--payload <p>', 'JSON payload (字符串)')
.description('Webhook 测试发送 (走 AccountConfig/testSendWebhook)')
.option('--configId <id>', 'AccountConfig id (已配置 webhook 账号)')
.option('--url <u>', '临时 webhook URL (不依赖 config, 单独测试)')
.option('--payload <p>', 'JSON payload (字符串)', '{}')
.action(async (opts: WebhookTestOpts) => {
if (!opts.configId && !opts.url) {
log.error('必须传 --configId 或 --url 之一')
process.exit(2)
}
const c = await JnpfClient.fromToken()
let payload: unknown = { test: true }
let body: Record<string, unknown>
if (opts.configId) {
// 走 AccountConfig 模式: 拉取 config + 测试
const configR = await c.get<Record<string, unknown>>(`/message/AccountConfig/${opts.configId}`)
if (configR.code !== 200 || !configR.data) {
log.error(`integration webhooktest 配置拉取失败: ${configR.msg || 'id 不存在'}`)
process.exit(1)
}
body = {
...configR.data,
testType: 'testSendWebhook',
}
} else {
// 直发模式: 仅传 url + payload
body = {
webhookUrl: opts.url,
testType: 'testSendWebhook',
}
}
if (opts.payload) {
try {
payload = JSON.parse(opts.payload)
body = { ...body, ...JSON.parse(opts.payload) }
} catch (e) {
log.error(`--payload JSON 解析失败: ${(e as Error).message}`)
process.exit(2)
}
}
// 走 SendMessageConfig/testSendConfig (channel=webhook)
const r = await c.postJson('/message/SendMessageConfig/testSendConfig', {
url: opts.url,
channel: 'webhook',
payload,
})
const r = await c.postJson('/message/AccountConfig/testSendWebhook', body)
if (r.code !== 200) {
log.error(`integration webhooktest 失败: ${r.msg}`)
process.exit(1)
}
log.info(`✓ Webhook 测试发送 OK (url=${opts.url})`)
log.info(`✓ Webhook 测试发送 OK (configId=${opts.configId || '-'}, url=${opts.url || '(from config)'})`)
})
installAiHelpHook(cmd, {
purpose: 'Webhook 测试发送',
required: { '--url': '目标 URL' },
optional: { '--payload': 'JSON payload' },
example: 'dacli integration webhooktest --url=https://example.com/hook --payload=\'{"key":"value"}\'',
purpose: 'Webhook 测试发送 (修复 v0.10 假 PASS 端点)',
required: {},
optional: {
'--configId': 'AccountConfig id (已配置 webhook 账号)',
'--url': '临时 webhook URL (不依赖 config)',
'--payload': 'JSON payload (字符串)',
},
example:
'dacli integration webhooktest --configId=123\n dacli integration webhooktest --url=https://example.com/hook --payload=\'{"key":"value"}\'',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/integrationCenter/webhook/index.vue',
api: 'POST /api/message/SendMessageConfig/testSendConfig',
ref: 'doc/v0.8-endpoints.md §3.3',
web: 'web/apps/jnpf-web-apps-main/src/api/msgCenter/accountConfig.ts:29 testConfig()',
api: 'POST /api/message/AccountConfig/testSendWebhook',
ref: 'dacli/docs/cmd-review/integration.md §端点错误',
},
})
return cmd
+27 -12
View File
@@ -1,7 +1,11 @@
/**
* commands/msg/templatecreate.ts — 新建消息模板
*
* API: POST /api/system/MessageTemplate
* 走 JNPF MessageTemplateConfig 端点 (web 真实端点, v0.11+ P0 修复)
*
* 修复历史:
* - v0.10 错误端点: /api/system/MessageTemplate (web 端不存在)
* - v0.11+ 正确端点: /api/message/MessageTemplateConfig (web api/msgCenter/msgTemplate.ts)
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
@@ -11,26 +15,32 @@ import { log, printJson } from '../../core/log.ts'
interface CreateOpts {
fullName: string
enCode: string
category?: string
content?: string
json?: boolean
}
export function buildMsgTemplateCreateCommand(): Command {
const cmd = new Command('templateCreate')
.alias('template-create')
.description('新建消息模板')
.description('新建消息模板 (走 MessageTemplateConfig)')
.requiredOption('--fullName <name>', '模板名称')
.requiredOption('--enCode <code>', '模板编码')
.requiredOption('--enCode <code>', '模板编码 (全平台唯一)')
.option('--category <c>', '分类 (1=系统 2=业务)', '1')
.option('--content <text>', '模板内容 (可选)')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
const body = {
fullName: opts.fullName,
enCode: opts.enCode,
category: '1', // 1=系统 2=业务
category: opts.category || '1',
enabledMark: 1,
sortCode: 0,
...(opts.content ? { content: opts.content } : {}),
}
const r = await c.postJson<{ id?: string }>('/system/MessageTemplate', body)
// web 端真实端点: /api/message/MessageTemplateConfig
const r = await c.postJson<{ id?: string }>('/message/MessageTemplateConfig', body)
if (r.code !== 200) {
log.error(`msg templatecreate 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
@@ -38,7 +48,7 @@ export function buildMsgTemplateCreateCommand(): Command {
let id = r.data?.id
if (!id) {
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
'/system/MessageTemplate',
'/message/MessageTemplateConfig',
{ keyword: opts.enCode, pageSize: '50' },
)
const found = (listR.data?.list || []).find(
@@ -50,14 +60,19 @@ export function buildMsgTemplateCreateCommand(): Command {
if (opts.json) printJson({ ...(r.data as object), id })
})
installAiHelpHook(cmd, {
purpose: '新建消息模板',
purpose: '新建消息模板 (修复 v0.10 错误端点)',
required: { '--fullName': '模板名称', '--enCode': '模板编码' },
example: 'dacli msg templatecreate --fullName=系统告警模板 --enCode=sys_alert',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/msgCenter/msgTemplate/Form.vue',
api: 'POST /api/system/MessageTemplate',
ref: 'doc/v0.8-endpoints.md §2.4',
optional: {
'--category': '分类 (1=系统 2=业务)',
'--content': '模板内容',
},
example: 'dacli msg templatecreate --fullName=系统告警 --enCode=sys_alert --content=系统告警: {msg}',
source: {
web: 'web/apps/jnpf-web-apps-main/src/api/msgCenter/msgTemplate.ts:14 create()',
api: 'POST /api/message/MessageTemplateConfig',
ref: 'dacli/docs/cmd-review/msg.md §端点错误',
},
notes: ['v0.10 端点 `/api/system/MessageTemplate` 已被 web 端废弃, v0.11+ 修复'],
})
return cmd
}