auto(bfc0cfa2c3a4): session end @ 2026-07-21T11:03:58 (+5f)

This commit is contained in:
ssw committed 2026-07-21 11:04:00 +08:00
1 parent 42fe387621
commit 2c849e1604
5 files changed
+268 -39

No files matched your search

+86 -28
View File
@@ -28,7 +28,8 @@ import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { fetchMenuTree } from './_helpers.ts'
import { lookupMenuIdByEnCode } from './_lookup.ts'
import { initWebapi, loadMenu } from '../../webapi/menu.ts'
import { autoStripEnCode, autoStripFullName } from '../_encode_validator.ts'
import { runCommandAutoFix } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix pipeline (替代原 inline autoStripEnCode/FullName)
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘
interface Opts {
fullName: string
@@ -49,6 +50,7 @@ interface Opts {
/** 新增: 支持 App 菜单 (web Form.vue 下拉 Web/App 二选一) */
category?: string
json?: boolean
verbose?: boolean
}
export function buildMenuCreateCommand(): Command {
@@ -73,26 +75,45 @@ export function buildMenuCreateCommand(): Command {
.option('--sortCode <n>', '低级模式: sortCode 排序 (默认 0)', '0')
// 新增: 支持 App 菜单 (默认 Web)
.option('--category <c>', '菜单分类 (Web | App, 默认 Web)', 'Web')
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => {
// 输出过滤: 默认静默 (quiet mode), --verbose 走完整日志, --json 走原始 JSON
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
// (Round 12 enCode 含 `-`/`_` 自动 strip + WARN
if (opts.enCode) {
const _encStrip = autoStripEnCode(opts.enCode)
if (_encStrip.wasStriped) {
log.warn(`! autoStrip enCode: ${_encStrip.original} → ${_encStrip.value} (BS-新38, 下次别用 - 或 _)`)
opts.enCode = _encStrip.value
}
// v2.1+ (2026-07-21): 命令级 auto-fix pipeline (替代原 inline autoStripEnCode/FullName)
// S-X1 enCode strip silent (BS-新38)
// S-X2 fullName soften silent (BS-新52)
// G-X1 BS-47 重名 suggest
const cmdFix = runCommandAutoFix(opts as unknown as Record<string, unknown>, {
existingForms: [],
existingDicts: [],
existingMenus: [],
appCode: c.appCode,
})
if (cmdFix.silent.length > 0) {
Object.assign(opts, cmdFix.opts)
}
// fix (fullName 含 space/parens 自动 strip + WARN
if (opts.fullName) {
const _fnStrip = autoStripFullName(opts.fullName)
if (_fnStrip.wasStriped) {
log.warn(`! autoStrip fullName: ${_fnStrip.original} → ${_fnStrip.value} (BS-新52, 下次别用空格/括号/标点)`)
opts.fullName = _fnStrip.value
}
// 命令级 printCommandEnd helper (避免重复样板)
const printEnd = (
result: 'success' | 'failure' | 'partial',
summary?: Record<string, unknown>,
error?: string,
) => {
printCommandEnd({
command: 'menu create',
appCode: c.appCode,
result,
summary,
error,
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
}
// P3.1: 第二层防御 — blindspot guard (等)
@@ -127,11 +148,17 @@ export function buildMenuCreateCommand(): Command {
log.warn(` BS-New-8 自动取 form.info 失败: ${(e as Error).message?.slice(0, 80)}`)
}
if (!opts.fullName) {
log.error('--formId 模式: --fullName 必填 (form.info 没拿到 fullName, 请手动 --fullName=...)')
const errMsg = '--formId 模式: --fullName 必填 (form.info 没拿到 fullName, 请手动 --fullName=...)'
log.error(errMsg)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printEnd('failure', { formId: opts.formId }, errMsg)
process.exit(2)
}
if (!opts.enCode) {
log.error('--formId 模式: --enCode 必填 (form.info 没拿到 enCode, 请手动 --enCode=...)')
const errMsg = '--formId 模式: --enCode 必填 (form.info 没拿到 enCode, 请手动 --enCode=...)'
log.error(errMsg)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printEnd('failure', { formId: opts.formId }, errMsg)
process.exit(2)
}
}
@@ -178,7 +205,10 @@ export function buildMenuCreateCommand(): Command {
}
}
if (!opts.fullName) {
log.error('--formId 模式: --fullName 必填 (form.info 没拿到 fullName)')
const errMsg = '--formId 模式: --fullName 必填 (form.info 没拿到 fullName)'
log.error(errMsg)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printEnd('failure', { formId: opts.formId }, errMsg)
process.exit(2)
}
// D-4 (盲点 40 防御): form webType=4 (视图) 走 Actions/Module 会 400, 自动 fallback 低级 API
@@ -221,14 +251,19 @@ export function buildMenuCreateCommand(): Command {
log.info(`POST /system/Menu (D-4 fallback) ${lowBody.enCode} type=3 webType=4`)
const r = await c.postJson<{ id?: string }>('/system/Menu', lowBody)
if (r.code !== 200) {
log.error(`D-4 fallback menu create 失败 code=${r.code}: ${r.msg}`)
const errMsg = `D-4 fallback menu create 失败 code=${r.code}: ${r.msg}`
log.error(errMsg)
if (opts.json) printJson(r)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printEnd('failure', { formId: opts.formId, mode: 'D-4-fallback' }, errMsg)
process.exit(1)
}
// D-4 视图菜单也不返 id, 用 lookup 反查
const d4MenuId = await lookupMenuIdByEnCode(formEnCode || opts.enCode || opts.fullName)
log.ok(`✓ 视图菜单创建成功 (formId=${opts.formId}, webType=4): id=${d4MenuId || r.data?.id || '(unknown)'} (B-19)`)
if (opts.json) printJson({ id: d4MenuId, formId: opts.formId, ...(r.data || {}) })
// v2.1+ (2026-07-21): D-4 fallback 成功 — 落 CommandLog
printEnd('success', { id: d4MenuId, formId: opts.formId, mode: 'D-4-fallback' })
return
}
} catch (e) {
@@ -238,7 +273,10 @@ export function buildMenuCreateCommand(): Command {
const pc = opts.pc === false ? 0 : 1
const app = opts.app ? 1 : 0
if (!pc && !app) {
log.error('至少一个发布平台 (pc / app), 当前都是 0')
const errMsg = '至少一个发布平台 (pc / app), 当前都是 0'
log.error(errMsg)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printEnd('failure', { formId: opts.formId }, errMsg)
process.exit(2)
}
// fix (盲点 23 续): 不传 --pcParents 时, 自动从 /system/Menu/SelectorFilter/0
@@ -295,6 +333,8 @@ export function buildMenuCreateCommand(): Command {
log.ok(`✓ 菜单发布成功 (重试后顶级, formId=${opts.formId}, pc=${pc}, app=${app})`)
log.ok(' ↳ 后端已自动构造 moduleId/propertyJson/urlAddress/pageAddress + 给当前角色授权')
if (opts.json) printJson(rr)
// v2.1+ (2026-07-21): 重试成功 — 落 CommandLog
printEnd('success', { formId: opts.formId, mode: 'A-retry' })
return
}
log.error(` ↳ 重试仍失败 code=${rr.code}: ${rr.msg}`)
@@ -336,6 +376,8 @@ export function buildMenuCreateCommand(): Command {
const enhanced = enhanceFromBackend(r.msg || '', 'menu', { entity: 'menu' })
log.error(` ${formatErrorLine(enhanced, { step: 3, stepName: '后端API' })}`)
if (opts.json) printJson(r)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printEnd('failure', { formId: opts.formId }, `Actions/Module 失败 code=${r.code}: ${r.msg}`)
process.exit(1)
}
log.ok(`✓ 菜单发布成功 (formId=${opts.formId}, pc=${pc}, app=${app})`)
@@ -354,12 +396,21 @@ export function buildMenuCreateCommand(): Command {
}
log.ok(` ↳ 菜单 id=${menuId || '(unknown)'} (B-19 反查自 ModuleBySystem)`)
if (opts.json) printJson({ id: menuId, formId: opts.formId, fullName: opts.fullName })
// v2.1+ (2026-07-21): Mode A Actions/Module 成功 — 落 CommandLog
printEnd('success', { id: menuId, formId: opts.formId, fullName: opts.fullName, mode: 'A' })
return
}
// 模式 B: 低级 POST /system/Menu (目录/外链等) — 复用 runLowLevelPath
// Mode A Actions/Module "找不到该上级" 失败时也走这个函数 (强制 type=3, icon=form 默认)
await runLowLevelPath(c, opts)
const modeBResult = await runLowLevelPath(c, opts)
// v2.1+ (2026-07-21): Mode B 完成 — 落 CommandLog (L3)
if (modeBResult?.success) {
printEnd('success', modeBResult.summary, undefined)
} else {
printEnd('failure', modeBResult?.summary, modeBResult?.error || 'Mode B 失败')
if (modeBResult?.shouldExit) process.exit(1)
}
return
})
@@ -413,11 +464,15 @@ export function buildMenuCreateCommand(): Command {
* + --moduleId 覆盖 (跨 app 引用 form)
* + --sortCode 透传 (默认 0)
*/
async function runLowLevelPath(c: JnpfClient, opts: Opts): Promise<void> {
async function runLowLevelPath(
c: JnpfClient,
opts: Opts,
): Promise<{ success: boolean; summary?: Record<string, unknown>; error?: string; shouldExit?: boolean }> {
// Mode B fullName 仍必填 (后端 MenuCrForm 必填, 且没有 form 可推导)
if (!opts.fullName) {
log.error('--fullName 必填 (低级模式, 目录/外链等)')
process.exit(2)
const errMsg = '--fullName 必填 (低级模式, 目录/外链等)'
log.error(errMsg)
return { success: false, error: errMsg, shouldExit: true }
}
const enCode = opts.enCode || opts.fullName
const type = parseInt(opts.type || '1', 10)
@@ -501,8 +556,9 @@ async function runLowLevelPath(c: JnpfClient, opts: Opts): Promise<void> {
propertyJson,
}
if (type === 7 && !opts.urlAddress) {
log.error('type=7 (外链) 必须传 --urlAddress')
process.exit(2)
const errMsg = 'type=7 (外链) 必须传 --urlAddress'
log.error(errMsg)
return { success: false, error: errMsg, shouldExit: true }
}
if (resolvedUrl) {
body.urlAddress = resolvedUrl
@@ -511,11 +567,12 @@ async function runLowLevelPath(c: JnpfClient, opts: Opts): Promise<void> {
log.info(`POST /system/Menu ${enCode} (type=${type})`)
const r = await c.postJson<{ id?: string }>('/system/Menu', body)
if (r.code !== 200) {
log.error(`menu create 失败 code=${r.code}: ${r.msg}`)
const errMsg = `menu create 失败 code=${r.code}: ${r.msg}`
log.error(errMsg)
// Phase A1: 后端错误增强 — 自动从 msg 提取 ErrorCode
const enhanced = enhanceFromBackend(r.msg || '', 'menu', { entity: 'menu' })
log.error(` ${formatErrorLine(enhanced, { step: 3, stepName: '后端API' })}`)
process.exit(1)
return { success: false, error: errMsg, summary: { enCode }, shouldExit: true }
}
// JNPF POST /system/Menu 返 {data:null}, 反查真实 id (B-15 dict 镜像)
let menuId: string | null = (r.data?.id as string | undefined) || null
@@ -524,6 +581,7 @@ async function runLowLevelPath(c: JnpfClient, opts: Opts): Promise<void> {
}
log.ok(`✓ 创建: id=${menuId || '(unknown)'} enCode=${enCode}`)
if (opts.json) printJson({ id: menuId, enCode, ...body })
return { success: true, summary: { id: menuId, enCode, mode: 'B' } }
}
/**
+80 -4
View File
@@ -26,6 +26,8 @@ import {
getPortalList,
} from '../../webapi/portal.ts'
import { initWebapi as initDictWebapi, loadDict } from '../../webapi/dict.ts'
import { runCommandAutoFix } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix pipeline
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘
interface CreateOpts {
fullName: string
@@ -41,6 +43,7 @@ interface CreateOpts {
appCustomUrl?: string
linkType?: string
formData?: string
verbose?: boolean
}
/**
@@ -134,9 +137,21 @@ export function buildPortalCreateCommand(): Command {
'--formData <json>',
'门户布局 formData (JSON 字符串, 镜像 PortalCrForm.formData)',
)
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
// 输出过滤: 默认静默 (quiet mode), --verbose 走完整日志, --json 走原始 JSON
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
// v2.1+ (2026-07-21): 命令级 auto-fix pipeline
const cmdFix = runCommandAutoFix(opts as unknown as Record<string, unknown>, {
appCode: c.appCode,
})
if (cmdFix.silent.length > 0) {
Object.assign(opts, cmdFix.opts)
}
// v3.0+ Bug 5 修复 (P1): 先解析 category (从字典 businessType 拿真实 UUID)
// 在 step machine 之前, 拿到 id 才能让后续校验走到对的地方
@@ -150,7 +165,20 @@ export function buildPortalCreateCommand(): Command {
`✓ Bug 5: category 解析为真实 UUID (${resolvedCategory.matched}): ${resolvedCategory.name} (id=${resolvedCategory.id})`,
)
} catch (e) {
log.error(`Bug 5 修复 - category 解析失败: ${(e as Error).message?.slice(0, 300)}`)
const errMsg = `Bug 5 修复 - category 解析失败: ${(e as Error).message?.slice(0, 300)}`
log.error(errMsg)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'portal create',
appCode: c.appCode,
result: 'failure',
error: errMsg,
summary: { enCode: opts.enCode, category: opts.category },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
const realCategoryId = resolvedCategory.id
@@ -166,11 +194,25 @@ export function buildPortalCreateCommand(): Command {
link: opts.link,
})
if (!validation.ok) {
const errMsg = `step machine 校验失败 (${validation.steps.flatMap((s) => s.errors).length} 错误)`
log.error(errMsg)
for (const s of validation.steps) {
for (const e of s.errors) {
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
}
}
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'portal create',
appCode: c.appCode,
result: 'failure',
error: errMsg,
summary: { enCode: opts.enCode },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
@@ -204,8 +246,21 @@ export function buildPortalCreateCommand(): Command {
}
const rCode = r.code ?? 200
if (rCode !== 200) {
const errMsg = `portal create 失败 (code=${rCode}): ${r.msg}`
const enhanced = enhanceFromBackend(r.msg || '', 'portal', { entity: 'portal' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'portal create',
appCode: c.appCode,
result: 'failure',
error: errMsg,
summary: { enCode: opts.enCode },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
let id: string | undefined = r.id
@@ -231,10 +286,21 @@ export function buildPortalCreateCommand(): Command {
}
// BS-新12 (jxcj 2026-07-01): 必查 id, list 反查仍空则报 silent fail
if (!id) {
log.error(
`BS-新12 silent fail: 后端返回 code=200 但 r.id=undefined, list 反查也找不到. 实际 raw 响应: ${JSON.stringify(r).slice(0, 200)}`,
)
const errMsg = `BS-新12 silent fail: 后端返回 code=200 但 r.id=undefined, list 反查也找不到. 实际 raw 响应: ${JSON.stringify(r).slice(0, 200)}`
log.error(errMsg)
log.error('可能原因: 1) jnpf 响应格式变化 2) category/type 不被接受 3) systemId 没传')
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'portal create',
appCode: c.appCode,
result: 'failure',
error: errMsg,
summary: { enCode: opts.enCode },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
log.info(
@@ -242,6 +308,16 @@ export function buildPortalCreateCommand(): Command {
)
if (opts.json)
printJson({ ...(r as object), id, category: realCategoryId, categoryName: resolvedCategory.name })
// v2.1+ (2026-07-21): 成功路径落 CommandLog
printCommandEnd({
command: 'portal create',
appCode: c.appCode,
summary: { id, enCode: opts.enCode, category: realCategoryId, categoryName: resolvedCategory.name },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
})
installHelpHook(cmd, {
purpose: '新建门户 (首页/工作台设计器产物)',
+36 -7
View File
@@ -11,7 +11,8 @@ import { log, printJson } from '../../core/log.ts'
import { validateRoleCreate } from './_validate.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { initWebapi, loadRole } from '../../webapi/role.ts'
import { autoStripEnCode } from '../_encode_validator.ts'
import { runCommandAutoFix } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix pipeline (替代原 inline autoStripEnCode)
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘
import { lookupRoleIdByEnCode } from './_lookup.ts'
interface CreateOpts {
@@ -20,6 +21,7 @@ interface CreateOpts {
type?: string
userIds?: string
json?: boolean
verbose?: boolean
}
export function buildRoleCreateCommand(): Command {
@@ -30,17 +32,22 @@ export function buildRoleCreateCommand(): Command {
.option('--type <t>', '角色类型: 0=全局 1=业务', '0')
// v0.11e+ Phase A3: 跨命令事务 — 镜像 web roleRelationService.create (建角色后批量绑用户)
.option('--user-ids <ids>', '关联用户 id 列表 (逗号分隔, 例: 1,2,3). v0.11e+ Phase A3 跨命令事务 (镜像 web roleRelationService.create)')
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
// 输出过滤: 默认静默 (quiet mode), --verbose 走完整日志, --json 走原始 JSON
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
await initWebapi(c)
// v0.21+ (Round 12 BS-新38): enCode 含 `-`/`_` 触发 BS-56 fail 时自动 strip + WARN
// 修法: enCode 默认接受 `round12-foo` 类格式, 自动 → `round12foo`, 让 AI 一次提交就跑通
const _encStrip = autoStripEnCode(opts.enCode)
if (_encStrip.wasStriped) {
log.warn(`! autoStrip enCode: ${_encStrip.original} → ${_encStrip.value} (BS-新38, 下次别用 - 或 _)`)
opts.enCode = _encStrip.value
// v2.1+ (2026-07-21): 命令级 auto-fix pipeline (替代原 inline autoStripEnCode)
const cmdFix = runCommandAutoFix(opts as unknown as Record<string, unknown>, {
existingRoles: [],
appCode: c.appCode,
})
if (cmdFix.silent.length > 0) {
Object.assign(opts, cmdFix.opts)
}
// v0.11d+ Phase 3.4: step machine 校验 (镜像 web role/Form.vue + 后端 RoleController.create)
@@ -72,6 +79,18 @@ export function buildRoleCreateCommand(): Command {
// v0.11e+ Phase A1: 后端错误增强 — 自动从 msg 提取 ErrorCode
const enhanced = enhanceFromBackend(r.msg || '', 'role', { entity: 'role' })
log.error(` ${formatErrorLine(enhanced, { step: 2, stepName: '后端API' })}`)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'role create',
appCode: c.appCode,
result: 'failure',
error: `role create 失败 (code=${r.code}): ${r.msg}`,
summary: { enCode: opts.enCode },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
let id = r.data?.id
@@ -81,6 +100,16 @@ export function buildRoleCreateCommand(): Command {
}
log.info(`✓ 角色创建成功 id=${id}${userIdsArray.length > 0 ? ` (含 ${userIdsArray.length} 个用户绑定)` : ''}`)
if (opts.json) printJson({ ...(r.data as object), id })
// v2.1+ (2026-07-21): 成功路径落 CommandLog
printCommandEnd({
command: 'role create',
appCode: c.appCode,
summary: { id, enCode: opts.enCode, userIdsCount: userIdsArray.length },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
})
installHelpHook(cmd, {
purpose: '新建角色 (P1 权限三角核心). v0.11d+ 加 step machine 校验 (3 step 镜像 web role/Form.vue + 后端 RoleController.create, BS-47 唯一性预校验, 约束字段联动校验, 聚合错误). v0.11e+ Phase A3 加 --user-ids 跨命令事务 (建角色后批量绑用户, 镜像 web roleRelationService.create).',
+28
View File
@@ -24,6 +24,7 @@ import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installHelpHookWithPatterns } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘
interface RunOpts {
formId: string
@@ -37,6 +38,7 @@ interface RunOpts {
joinCheck?: boolean
joinRules?: string
businessRules?: string
verbose?: boolean
}
interface StepResult {
@@ -74,9 +76,13 @@ export function buildTestRunCommand(): Command {
.option('--join-rules <json>', 'join 规则 JSON (例: \'[{"fkField":"f_team_id","targetEnCode":"jxcj_team","checkField":"f_team_name"}]\')')
// 业务规则校验
.option('--business-rules <json>', '业务规则 JSON (例: \'[{"field":"f_team_size","rule":">=3","msg":"团队人数下限 3 人"}]\')')
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: RunOpts) => {
// 输出过滤: 默认静默 (quiet mode), --verbose 走完整日志, --json 走原始 JSON
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
const steps: StepResult[] = []
let testDataId: string | null = null
let sample: Record<string, unknown> = {}
@@ -510,6 +516,17 @@ export function buildTestRunCommand(): Command {
if (opts.json) {
printJson(report)
// v2.1+ (2026-07-21): --json 模式也落 CommandLog
printCommandEnd({
command: 'test run',
appCode: c.appCode,
result: failCount > 0 ? 'partial' : 'success',
error: failCount > 0 ? `${failCount} 个 step 失败` : undefined,
summary: { formId: opts.formId, pass: passCount, fail: failCount, skip: skipCount },
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
return
}
@@ -521,6 +538,17 @@ export function buildTestRunCommand(): Command {
} else {
console.log(md)
}
// v2.1+ (2026-07-21): 落 CommandLog (L3) — 测试报告天然适合历史查询
printCommandEnd({
command: 'test run',
appCode: c.appCode,
result: failCount > 0 ? 'partial' : 'success',
error: failCount > 0 ? `${failCount} 个 step 失败` : undefined,
summary: { formId: opts.formId, pass: passCount, fail: failCount, skip: skipCount },
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
// 退出码: fail > 0 退出 1
if (failCount > 0) process.exit(1)
})
+38
View File
@@ -12,6 +12,8 @@ import { encryptByMd5 } from '../../core/crypto.ts'
import { initWebapi, loadUser } from '../../webapi/user.ts'
import { validateUserCreate } from './_validate.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { runCommandAutoFix } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix pipeline
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘
interface CreateOpts {
account: string
@@ -24,6 +26,7 @@ interface CreateOpts {
description?: string
roleId?: string
json?: boolean
verbose?: boolean
}
export function buildUserCreateCommand(): Command {
@@ -38,11 +41,24 @@ export function buildUserCreateCommand(): Command {
.option('--sortCode <n>', '排序', '0')
.option('--description <d>', '说明')
.option('--roleId <id>', 'v0.11e+ Phase C1: 角色 id (PS012 必填, 镜像 web user/Form.vue)')
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
// 输出过滤: 默认静默 (quiet mode), --verbose 走完整日志, --json 走原始 JSON
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
await initWebapi(c)
// v2.1+ (2026-07-21): 命令级 auto-fix pipeline (account ↔ enCode, realName ↔ fullName)
const cmdFix = runCommandAutoFix(opts as unknown as Record<string, unknown>, {
appCode: c.appCode,
fieldAliases: { enCode: 'account', fullName: 'realName' },
})
if (cmdFix.silent.length > 0) {
Object.assign(opts, cmdFix.opts)
}
// v0.11e+ Phase C1: step machine 校验 (镜像 web user/Form.vue + PS007/008/012/204/EXIST006)
const validation = validateUserCreate({
account: opts.account,
@@ -81,6 +97,18 @@ export function buildUserCreateCommand(): Command {
if (r.code !== 200 && r.code !== undefined) {
const enhanced = enhanceFromBackend(r.msg || '', 'user', { entity: 'user' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'user create',
appCode: c.appCode,
result: 'failure',
error: `user create 失败 (code=${r.code}): ${r.msg}`,
summary: { account: opts.account },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
let id = r.id || r.data?.id
@@ -93,6 +121,16 @@ export function buildUserCreateCommand(): Command {
}
log.info(`✓ 用户创建成功 id=${id}`)
if (opts.json) printJson({ ...(r.data as object || r), id })
// v2.1+ (2026-07-21): 成功路径落 CommandLog
printCommandEnd({
command: 'user create',
appCode: c.appCode,
summary: { id, account: opts.account, realName: opts.realName },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
})
installHelpHook(cmd, {
purpose: '新建用户 (P1 权限三角 2 号)',