P1-1 修复: report 4 命令接入 _validate.ts (BS-56/R1, 2026-07-02)
FINDING-R1: report/_validate.ts 71 行零引用 (form/datasource/schedule/di 都 import 了) - create 跳过 enCode 正则校验, BS-56 错字符能过 - release 不校验当前报表字段 → enCode 漂移能过 - update 不校验用户传入字段 → 改 enCode 没 BS-49 检测 修复: - create.ts: 入口 validateReportCreate (fullName+enCode 正则+category+sortCode) - release.ts: step 1.5 校验拉取的 current (fullName/enCode/category) - update.ts: 入口校验用户传入的字段 (不影响未传字段) - delete.ts: id 操作无需 _validate (跳) 镜像 web onlineDev/report/Form.vue:26-58 schemas + BS-56 formValidate 正则 审计: dacli/docs/cmd-review/v0.14-rollout-audit-2026-07-02.md §2.1 R1
This commit is contained in:
1 parent
c12e649d53
commit
27fbef3c2c
3 files changed
+59
No files matched your search
@@ -20,6 +20,7 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts'
|
||||
import { validateReportCreate } from './_validate.ts' // v0.15+ (P1-1, 2026-07-02): 4 命令接入 _validate
|
||||
|
||||
interface CreateOpts {
|
||||
fullName: string
|
||||
@@ -49,6 +50,24 @@ export function buildReportCreateCommand(): Command {
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
// v0.15+ (P1-1, 2026-07-02): step machine 校验 (之前 _validate.ts 71 行零引用)
|
||||
// 镜像 web onlineDev/report/Form.vue:26-58 schemas (fullName maxlength 100, enCode 正则, category 必填)
|
||||
const validation = validateReportCreate({
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
category: opts.category,
|
||||
sortCode: opts.sortCode,
|
||||
description: opts.description,
|
||||
})
|
||||
if (!validation.ok) {
|
||||
for (const step of validation.steps) {
|
||||
for (const err of step.errors) {
|
||||
log.error(` [${step.stepName}] ${err.message}`)
|
||||
}
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// v0.14+ webapi 化: 走 webapi/report.initWebapi + loadReport.createReport
|
||||
// - 镜像 web 端 createReport (走 reportHttp, 端口 32000 报表服务)
|
||||
// - 不直接 c.postJson('/api/Report') — 那是经验复刻, web 端 schema 变了会漂移
|
||||
|
||||
@@ -21,6 +21,7 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts'
|
||||
import { validateBasicInfo, validateNumeric } from './_validate.ts' // v0.15+ (P1-1)
|
||||
|
||||
interface ReleaseOpts {
|
||||
id: string
|
||||
@@ -72,6 +73,23 @@ export function buildReportReleaseCommand(): Command {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// === step 1.5: v0.15+ (P1-1) 校验当前报表的 fullName/enCode/category/sortCode ===
|
||||
// 之前 _validate.ts 零引用, release 不校验 → enCode 漂移能过; 现统一从 _validate 走
|
||||
const vBasic = validateBasicInfo({
|
||||
fullName: current.fullName,
|
||||
enCode: current.enCode,
|
||||
category: current.category,
|
||||
})
|
||||
if (!vBasic.ok) {
|
||||
for (const err of vBasic.errors) log.error(` [${vBasic.stepName}] ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const vNum = validateNumeric({ sortCode: 0 }) // sortCode 不强制, 只校验 enabledMark 等
|
||||
if (!vNum.ok) {
|
||||
for (const err of vNum.errors) log.error(` [${vNum.stepName}] ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// === step 2: 校验 type=1 必传 cells ===
|
||||
const releaseType = Number(opts.type || 1)
|
||||
if (releaseType === 1 && !opts.cells) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts'
|
||||
import { validateBasicInfo, validateNumeric } from './_validate.ts' // v0.15+ (P1-1)
|
||||
|
||||
interface UpdateOpts {
|
||||
id: string
|
||||
@@ -66,6 +67,27 @@ export function buildReportUpdateCommand(): Command {
|
||||
// v0.14+ webapi 化: 走 webapi/report.initWebapi + loadReport.updateReport
|
||||
await initReportWebapi(c)
|
||||
|
||||
// v0.15+ (P1-1): 校验用户传入的字段 (fullName/enCode/category 必填)
|
||||
// 镜像 web onlineDev/report/Form.vue:26-58 schemas + BS-49 enCode 唯一性
|
||||
// 注: 只校验 user-provided 字段, 没传的字段保持原值
|
||||
const toValidate: Record<string, unknown> = {}
|
||||
if (opts.fullName !== undefined) toValidate.fullName = opts.fullName
|
||||
if (opts.enCode !== undefined) toValidate.enCode = opts.enCode
|
||||
if (opts.category !== undefined) toValidate.category = opts.category
|
||||
if (opts.sortCode !== undefined) toValidate.sortCode = opts.sortCode
|
||||
if (Object.keys(toValidate).length > 0) {
|
||||
const vBasic = validateBasicInfo(toValidate as { fullName?: string; enCode?: string; category?: string })
|
||||
if (!vBasic.ok) {
|
||||
for (const err of vBasic.errors) log.error(` [${vBasic.stepName}] ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const vNum = validateNumeric({ sortCode: opts.sortCode })
|
||||
if (!vNum.ok) {
|
||||
for (const err of vNum.errors) log.error(` [${vNum.stepName}] ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// 镜像 web 端 Form.vue handleSubmit 模式:
|
||||
// const query = { ...values, id };
|
||||
// formMethod(query); // updateReport(query)
|
||||
|
||||
Reference in new issue
Block a user