dacli v0.22: tdd5 实战 8 项 P1/P2/P3 修复
- app status: menuIntegrity 跳 type=1 容器菜单 + 失败汇总只打实际 fail 项 (P1-1, P2-6) - workflow create: BS-E5 已知 6 中文分类放行 (P1-2) - form bindflow: start 节点 formId 3 路径兜底 (formId / nodeJson.formId / customForm.formId) (P1-3) - di create: from-json-file 4 段 schema 预校验 + dataConfigJson 透传 SQL/API 落库验证 (P1-4, P1-5) - workflow list: --use-selector 走 web 端 getFlowSelector, 避开 list 偶发 Login expired (P2-7) - app list: --human 默认 ON, 强制 flush log 输出表格 (P3-9) - log last: 自动打印 key context (account / dbLinkId) (P3-10) unit test 488/488 PASS, typecheck 0 错误 (validate-baseline + prompt-ab-static 与本轮修复无关, JNPF Java 源码未 clone, 跳过) Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
42a9958e18
commit
b19361ce3c
8 files changed
+140
-18
No files matched your search
@@ -31,12 +31,15 @@ interface ListOpts {
|
||||
json?: boolean
|
||||
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
|
||||
verbose?: boolean
|
||||
/** v0.22+ (2026-07-28 tdd5 实战): --human 强制 flush log 输出表格 (默认 quiet 模式下 log.info 走 buffer) */
|
||||
human?: boolean
|
||||
}
|
||||
|
||||
export function buildAppListCommand(): Command {
|
||||
const cmd = new Command('list')
|
||||
.description('列出所有应用 (JNPF 多 app 生命周期, v3.0+ 走 webapi/system 镜像)')
|
||||
.option('--keyword <k>', '按名称/编码模糊搜索')
|
||||
.option('--human', '人类可读表格输出 (默认 ON, --json 时自动关闭)', true)
|
||||
addOutputOptions(cmd)
|
||||
.action(async (opts: ListOpts) => {
|
||||
setupOutputFilter(opts)
|
||||
@@ -68,6 +71,8 @@ export function buildAppListCommand(): Command {
|
||||
printJson({ list })
|
||||
return ctx.success(summary)
|
||||
}
|
||||
// v0.22+ (tdd5 实战): --human 默认 ON, 强制 flush log (避免 quiet 模式下表格走 buffer 看不到)
|
||||
if (opts.human) log.setQuiet(false)
|
||||
log.info(`共 ${list.length} 个应用`)
|
||||
log.printRawTable(
|
||||
['ID', 'FULL_NAME', 'ENCODE', 'DEL'],
|
||||
@@ -86,7 +91,7 @@ export function buildAppListCommand(): Command {
|
||||
})
|
||||
installHelpHook(cmd, {
|
||||
purpose: '列出所有应用 (JNPF 多 app 生命周期, 不同于当前登录 appCode). v3.0+ 走 webapi/system.getSystemList',
|
||||
optional: { '--keyword': '按名称/编码模糊搜索' },
|
||||
optional: { '--keyword': '按名称/编码模糊搜索', '--human': '人类可读表格输出 (默认 ON, --json 时自动关闭)' },
|
||||
example: 'dacli app list\ndacli app list --keyword=tds',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/appCenter/index.vue',
|
||||
@@ -97,6 +102,7 @@ export function buildAppListCommand(): Command {
|
||||
' 旧实现: 直接 c.get(\'/system/System\'), 与 web 端 schema 漂移风险',
|
||||
' 新实现: 复用 web 端 getSystemList (含 query 参数处理 + 错误响应)',
|
||||
' 详见 dacli/docs/archive/review/regression-2026-06-29.md',
|
||||
'v0.22+ (2026-07-28 tdd5 实战): --human 默认 ON, 强制 flush log 输出表格 (旧版 quiet 模式下表格走 buffer 看不到)',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
|
||||
@@ -83,15 +83,19 @@ async function runHealthChecks(c: JnpfClient | null): Promise<Array<{ name: stri
|
||||
|
||||
// [3] menu integrity — 当前 user 的 menuList.urlAddress 不空 (SPA 路由防 404)
|
||||
// 已知 BS-56: 跨 app 引用未传 --urlAddress 时 menuList 缺 urlAddress → SPA 404
|
||||
// v0.22+ (2026-07-28 tdd5 实战): 跳过 type=1 容器菜单 (dataCenter/integrationCenter/commonCenter/systemCenter
|
||||
// 等内置 4 项), 这些是 JNPF 平台目录节点, 本来就没 urlAddress, --fix-menu-url 也修不掉 (tdd5 debug.md §2.1)
|
||||
{
|
||||
const t0 = Date.now()
|
||||
try {
|
||||
if (!c) throw new Error('no client')
|
||||
const r = await c.get<{ menuList?: Array<{ urlAddress?: string; enCode?: string; id?: string; fullName?: string }> } | any>('/oauth/CurrentUser', { isBackend: 0 })
|
||||
const r = await c.get<{ menuList?: Array<{ urlAddress?: string; enCode?: string; id?: string; fullName?: string; type?: number }> } | any>('/oauth/CurrentUser', { isBackend: 0 })
|
||||
// c.get 返回 { code, data, msg } 结构, data 含 menuList (跟 test/browser.ts 同模式)
|
||||
const data = (r as any).data || r
|
||||
const list = data?.menuList || []
|
||||
const empty = list.filter((m: { urlAddress?: string }) => !m.urlAddress || m.urlAddress.trim() === '')
|
||||
// 过滤掉 type=1 容器菜单 (无 urlAddress 是预期行为)
|
||||
const leaves = list.filter((m: { type?: number }) => m.type !== 1)
|
||||
const empty = leaves.filter((m: { urlAddress?: string }) => !m.urlAddress || m.urlAddress.trim() === '')
|
||||
if (empty.length > 0) {
|
||||
// 提取所有空 urlAddress 的 menu id, 给用户修复命令 (--fix 自动重建 model/{enCode})
|
||||
const sample = empty.slice(0, 5).map((m: { id?: string; enCode?: string; fullName?: string }) =>
|
||||
@@ -285,9 +289,15 @@ export function buildAppStatusCommand(): Command {
|
||||
if (!allOk) {
|
||||
log.error('')
|
||||
log.error('⚠ 深度检查失败, 部分功能可能不可用:')
|
||||
log.error(' - dbPing fail → 数据库连不上, dm/form 写入会失败 (BS-E14)')
|
||||
log.error(' - llmPing fail → --ai 路径会 15s 后才发现, 浪费时间')
|
||||
log.error(' - menuIntegrity fail → SPA 路由可能 404 (BS-56)')
|
||||
// v0.22+ (2026-07-28 tdd5 实战): 只打印**实际 fail** 项的解释, 不混打全量说明
|
||||
// 旧版无论 fail 几项都打印全 3 行, 容易误判"3 项全挂" (debug.md §2.1)
|
||||
const failed = deepChecks.filter((c) => !c.ok)
|
||||
for (const f of failed) {
|
||||
if (f.name === 'dbPing') log.error(' - dbPing fail → 数据库连不上, dm/form 写入会失败 (BS-E14)')
|
||||
else if (f.name === 'llmPing') log.error(' - llmPing fail → --ai 路径会 15s 后才发现, 浪费时间')
|
||||
else if (f.name === 'menuIntegrity') log.error(' - menuIntegrity fail → SPA 路由可能 404 (BS-56, 已跳过 type=1 容器菜单)')
|
||||
else log.error(` - ${f.name} fail → ${f.error || '未知错误'}`)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,20 @@ export function buildDiCreateCommand(): Command {
|
||||
}
|
||||
try {
|
||||
const jsonBody = JSON.parse(readFileSync(opts.fromJsonFile, 'utf-8'))
|
||||
// v0.22+ (2026-07-28 tdd5 实战): 后端 AD102 强制要求 7 段 schema 齐全
|
||||
// (dataConfigJson/fieldJson/parameterJson + dataCountJson/dataEchoJson/dataJsJson/dataExceptionJson)
|
||||
// 缺一段就报 400 "System abnormality", 但**事前无提示**
|
||||
// 修复: dacli 端先校验 7 段齐全再 POST, 缺段直接报清晰错 (避免后端模糊错误)
|
||||
const REQUIRED_7_KEYS = [
|
||||
'dataConfigJson', 'fieldJson', 'parameterJson',
|
||||
'dataCountJson', 'dataEchoJson', 'dataJsJson', 'dataExceptionJson',
|
||||
]
|
||||
const missing = REQUIRED_7_KEYS.filter((k) => !(k in jsonBody) || jsonBody[k] === undefined)
|
||||
if (missing.length > 0) {
|
||||
const errMsg = `BS-E-drift-DI-file: --from-json-file 缺 ${missing.length} 段后端必填 schema: ${missing.join(', ')}\n 解决: 从已有 DI 跑 'dacli di export --id=<id>' 取完整 baseline, 或显式传空对象占位 (例: "dataCountJson":"[]")`
|
||||
log.error(errMsg)
|
||||
return ctx.fail(errMsg, { enCode: opts.enCode, missing })
|
||||
}
|
||||
// 必填字段覆盖 (file 提供的是 raw schema, 不含全字段)
|
||||
jsonBody.fullName = opts.fullName
|
||||
jsonBody.enCode = opts.enCode
|
||||
@@ -206,6 +220,34 @@ export function buildDiCreateCommand(): Command {
|
||||
newId = (await lookupDataInterfaceIdByEnCode(opts.enCode)) || undefined
|
||||
}
|
||||
log.ok(`✓ DI 创建成功 id=${newId || '(unknown)'} enCode=${opts.enCode}`)
|
||||
// v0.22+ (2026-07-28 tdd5 实战, BS-drift-DI-3): 创建后立即 GET info 验证透传字段落库
|
||||
// 旧版仅看 create 返 200 就报 PASS, 但 dataConfigJson 透传 SQL 时, 后端实际丢弃 (requestMethod/url 全空)
|
||||
// → DI 后续 `dacli di test` 必失败 ("Interface request failed")
|
||||
// 修复: type=1 (SQL) 或 type=3 (API) 时, 创建后 500ms GET info 验证 dataConfigJson.sqlData.sql / apiData.url 持久化
|
||||
// type=2 (静态数据) 跳过 (静态数据在 dataConfigJson.staticData, 不需要再验证)
|
||||
if (newId && opts.type && Number(opts.type) !== 2) {
|
||||
try {
|
||||
await new Promise((r) => setTimeout(r, 500)) // 等待后端落库
|
||||
const infoR = (await loadDataInterface.getDataInterfaceInfo?.(newId)) as
|
||||
{ data?: { dataConfigJson?: string; requestMethod?: number; url?: string; method?: number } } | undefined
|
||||
const infoData = infoR?.data as { dataConfigJson?: string; requestMethod?: number; url?: string; method?: number } | undefined
|
||||
const dcfg = (() => { try { return infoData?.dataConfigJson ? JSON.parse(infoData.dataConfigJson) : null } catch { return null } })()
|
||||
const persistedMethod = infoData?.requestMethod ?? infoData?.method
|
||||
const persistedUrl = infoData?.url ?? dcfg?.apiData?.url
|
||||
const persistedSql = dcfg?.sqlData?.sql
|
||||
if (Number(opts.type) === 1 && (!persistedSql || persistedSql.trim() === '')) {
|
||||
log.warn(`BS-drift-DI-3: DI id=${newId} 落库后 dataConfigJson.sqlData.sql 为空 (BS-drift-DI-3 实测, 后端丢弃)`)
|
||||
log.warn(` 解决: 改用 --type=2 静态数据, 或 web 端 DataInterface Form.vue 重新保存`)
|
||||
} else if (Number(opts.type) === 3 && (!persistedMethod || !persistedUrl)) {
|
||||
log.warn(`BS-drift-DI-3: DI id=${newId} 落库后 apiData.url/method 为空 (后端丢弃)`)
|
||||
log.warn(` 解决: web 端 DataInterface Form.vue 重新保存 url`)
|
||||
} else {
|
||||
log.ok(` ↳ 透传验证 PASS (method=${persistedMethod ?? '?'}, url=${persistedUrl?.slice(0, 40) || '?'}${persistedSql ? ', sql len=' + persistedSql.length : ''})`)
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn(` ↳ 透传验证异常: ${(e as Error).message?.slice(0, 60)}`)
|
||||
}
|
||||
}
|
||||
const summary = { id: newId, enCode: opts.enCode, ...(r.data as object) }
|
||||
if (opts.json) printJson(summary)
|
||||
ctx.success(summary)
|
||||
|
||||
@@ -118,22 +118,31 @@ export function buildFormBindFlowCommand(): Command {
|
||||
}
|
||||
|
||||
// 2.3 找 start 节点, 设置 formId
|
||||
// v0.22+ (2026-07-28 tdd5 实战): start 节点的 formId 字段位置可能不同:
|
||||
// - flowNodes[id].formId (BS-New-4 原路径, 部分模板)
|
||||
// - flowNodes[id].nodeJson.formId (bpmn-moddle 序列化, 部分模板)
|
||||
// - flowNodes[id].nodeJson.customForm.formId (嵌套, 部分模板, 实际最常见)
|
||||
// 同时设三处, 防止 workflow 端持久化只命中部分字段
|
||||
const startNodeId = Object.keys(flowNodes).find(
|
||||
(nid) => flowNodes[nid]?.type === 'start' || flowNodes[nid]?.nodeJson?.includes('"type":"start"'),
|
||||
)
|
||||
if (startNodeId) {
|
||||
log.info(`[2.2] 找到 start node: ${startNodeId}, 设置 formId=${opts.formId}`)
|
||||
// 节点 formId 在 flowNodes[id].formId 或 .nodeJson (parse 后)
|
||||
if (typeof flowNodes[startNodeId].formId !== 'undefined') {
|
||||
flowNodes[startNodeId].formId = opts.formId
|
||||
} else if (flowNodes[startNodeId].nodeJson) {
|
||||
const node = flowNodes[startNodeId]
|
||||
// 路径 1: 节点顶层 .formId
|
||||
node.formId = opts.formId
|
||||
// 路径 2: nodeJson 解析后顶层 .formId
|
||||
if (node.nodeJson) {
|
||||
try {
|
||||
const nj = typeof flowNodes[startNodeId].nodeJson === 'string'
|
||||
? JSON.parse(flowNodes[startNodeId].nodeJson)
|
||||
: flowNodes[startNodeId].nodeJson
|
||||
const nj = typeof node.nodeJson === 'string' ? JSON.parse(node.nodeJson) : node.nodeJson
|
||||
nj.formId = opts.formId
|
||||
flowNodes[startNodeId].nodeJson = JSON.stringify(nj)
|
||||
} catch {}
|
||||
// 路径 3: nodeJson.customForm.formId (JNPF 实际持久化位置, tdd5 实战确认)
|
||||
if (nj.customForm) nj.customForm.formId = opts.formId
|
||||
node.nodeJson = JSON.stringify(nj)
|
||||
log.ok(` ↳ nodeJson + customForm.formId 已写 (3 路径兜底)`)
|
||||
} catch (e) {
|
||||
log.warn(` ↳ nodeJson parse 失败: ${(e as Error).message?.slice(0, 60)}`)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.warn(` ↳ 未找到 start 节点 (类型 type==='start'), 跳过 node 修改`)
|
||||
|
||||
@@ -104,6 +104,19 @@ export function buildLogLastCommand(): Command {
|
||||
|
||||
log.info(formatLogSummary(cmdLog))
|
||||
|
||||
// v0.22+ (2026-07-28 tdd5 实战): 自动打印 systemId/dbLinkId 等 key context
|
||||
// 旧版只打印 command + result, AI 接手时拿不到 app 上下文 (要再跑 app context --json)
|
||||
// 修复: log last 自动从 token.json + context 补 systemId/dbLinkId 到输出
|
||||
const tokenInfo = token as { dbLinkId?: string; currentSystemId?: string; account?: string }
|
||||
const contextLines: string[] = []
|
||||
if (tokenInfo.account) contextLines.push(` account: ${tokenInfo.account}`)
|
||||
if (tokenInfo.currentSystemId) contextLines.push(` systemId: ${tokenInfo.currentSystemId}`)
|
||||
if (tokenInfo.dbLinkId) contextLines.push(` dbLinkId: ${tokenInfo.dbLinkId}`)
|
||||
if (contextLines.length > 0) {
|
||||
log.info('━━ key context (auto, v0.22+):')
|
||||
for (const l of contextLines) log.info(l)
|
||||
}
|
||||
|
||||
if (opts.detail && cmdLog.raw) {
|
||||
log.info('━━ 原始请求/响应:')
|
||||
if (cmdLog.raw.request) {
|
||||
|
||||
@@ -161,9 +161,16 @@ export function buildWorkflowCreateCommand(): Command {
|
||||
for (const item of list as Array<Record<string, unknown>>) {
|
||||
if (item.category) allCategories.add(String(item.category))
|
||||
}
|
||||
// 32 位 hex hash (baseline 数据常见) 也可能匹配不到 (selector 不返回所有 category)
|
||||
// 所以加宽松判断: 直接 32 位 hex 不报错
|
||||
if (!allCategories.has(opts.category) && !/^[a-f0-9]{32}$/.test(opts.category)) {
|
||||
// v0.22+ (2026-07-28 tdd5 实战): 中文分类名 (项目管理/费用相关) 在全新 app selector 里查不到
|
||||
// 因为 selector 只返回本 app 已有 workflow 的 category。允许:
|
||||
// ① 32 位 hex hash (baseline 数据, 跨 app 通用, 如 802fb04ab5b84aa5bcc5dc53372a271d)
|
||||
// ② 已知 6 个 JNPF 平台内置中文分类 (项目管理/费用相关/人事管理/仓库管理/车辆管理/日常工作)
|
||||
// 这些是 JNPF 后端硬编码全局 category, 任何 app 都可使用 (后端二次转换显示)
|
||||
// 修复: 中文名不再报 BS-E5, 直接放行 (后端会落库并显示)
|
||||
const KNOWN_ZH_CATEGORIES = new Set(['项目管理', '费用相关', '人事管理', '仓库管理', '车辆管理', '日常工作'])
|
||||
const is32Hex = /^[a-f0-9]{32}$/.test(opts.category)
|
||||
const isKnownZh = KNOWN_ZH_CATEGORIES.has(opts.category)
|
||||
if (!allCategories.has(opts.category) && !is32Hex && !isKnownZh) {
|
||||
log.error(`BS-E5: workflow --category="${opts.category}" 不存在`)
|
||||
log.error(` 跑 'dacli workflow selector' 看真实分类 id (32 位 hash 或中文)`)
|
||||
return ctx.fail(`BS-E5: workflow --category="${opts.category}" 不存在`, { enCode: opts.enCode })
|
||||
|
||||
@@ -10,6 +10,7 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { setupOutputFilter, wrapCommand } from '../_output_filter.ts' // v2.2+ wrapCommand 收口 5c 样板
|
||||
import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts'
|
||||
|
||||
interface ListOpts {
|
||||
category?: string
|
||||
@@ -17,6 +18,8 @@ interface ListOpts {
|
||||
pageSize?: string
|
||||
json?: boolean
|
||||
verbose?: boolean
|
||||
/** v0.22+ (2026-07-28 tdd5 实战): --use-selector 强制走 web 端 getFlowSelector (避免 list 端偶发 Login expired) */
|
||||
useSelector?: boolean
|
||||
}
|
||||
|
||||
export function buildWorkflowListCommand(): Command {
|
||||
@@ -27,6 +30,7 @@ export function buildWorkflowListCommand(): Command {
|
||||
.option('--pageSize <s>', '每页', '50')
|
||||
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.option('--use-selector', '走 web 端 getFlowSelector (避开某些 app /workflow/template 偶发 Login expired)', false)
|
||||
.action(async (opts: ListOpts) => {
|
||||
setupOutputFilter(opts)
|
||||
const c = await JnpfClient.fromToken()
|
||||
@@ -41,6 +45,30 @@ export function buildWorkflowListCommand(): Command {
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
const todo = Number(opts.todo || '0')
|
||||
// v0.22+ (2026-07-28 tdd5 实战): --use-selector 走 web 端 getFlowSelector (与 selector.ts 同源)
|
||||
if (todo === 0 && opts.useSelector) {
|
||||
await initWebapi(c)
|
||||
const resp = (await loadWorkflow.getFlowSelector({
|
||||
category: opts.category,
|
||||
})) as Array<{ id: string; fullName: string; enCode?: string; category?: string; flowId?: string; enabledMark?: number; status?: number }> | { list?: unknown[] }
|
||||
const list = (Array.isArray(resp) ? resp : (resp as { list?: unknown[] })?.list || []) as Array<Record<string, unknown>>
|
||||
const summary = { path: '/workflow/template/Selector', total: list.length, category: opts.category, todo }
|
||||
if (opts.json) {
|
||||
printJson(list)
|
||||
return ctx.success(summary)
|
||||
}
|
||||
log.info(`${summary.path} 共 ${list.length} 条 (走 selector)`)
|
||||
log.printRawTable(
|
||||
['ID', 'FULL_NAME', 'ENCODE', 'CATEGORY'],
|
||||
list.map((t) => [
|
||||
String(t.id || ''),
|
||||
String(t.fullName || ''),
|
||||
String(t.enCode || ''),
|
||||
String(t.category || ''),
|
||||
]),
|
||||
)
|
||||
return ctx.success(summary)
|
||||
}
|
||||
const path = todo > 0
|
||||
? `/workflow/operator/List/${todo}`
|
||||
: `/workflow/template${opts.category ? `?category=${opts.category}` : ''}`
|
||||
|
||||
@@ -122,6 +122,13 @@ export function formatLogSummary(log: CommandLog): string {
|
||||
if (log.summary.error) {
|
||||
lines.push(` 错误: ${log.summary.error}`)
|
||||
}
|
||||
// v0.22+ (2026-07-28 tdd5 实战): 自动打印 key context (appCode/systemId/dbLinkId 等)
|
||||
// 旧版 dacli log last 只打印 command + result, AI 接手时拿不到 app 上下文 (要再跑 app context --json)
|
||||
// 修复: 从 CommandLog 摘要 + JNPF token 拼出完整 key context
|
||||
// 注: systemId/dbLinkId 在 CommandLog 里没有, 需从 token.json 加载并补到摘要
|
||||
// 这里只先打印 log 自带的字段, 后续可加 token 联动
|
||||
if (log.appCode) lines.push(` appCode: ${log.appCode}`)
|
||||
if (log.summary?.id) lines.push(` 资源 id: ${log.summary.id}`)
|
||||
lines.push('')
|
||||
|
||||
if (log.silent_fixes.length > 0 || log.assertive_fixes.length > 0) {
|
||||
|
||||
Reference in new issue
Block a user