feat(dacli): add TC-C di module cross-module real contract validation (v0.14+ BS-新28/29)

- Implement renderDi() following dict/form pattern with 4 gates
- Add Selector fallback for list query (list endpoint requires category)
- Update checkRender() to support moduleName and onEmptyApi=SKIP option
- Improve extractRenderFields() regex to handle TS-typed schemas
- Update AI help hook examples for di module
This commit is contained in:
ssw committed 2026-07-01 16:40:37 +08:00
1 parent 1dc409d107
commit c2f0e2b121
1 file changed
+822 -3
+822 -3
View File
@@ -189,7 +189,7 @@ export function buildTestRenderCommand(): Command {
installAiHelpHook(cmd, {
purpose: '源码渲染验证 (替代浏览器验证) — 读 vue 渲染契约 + 调 API, 检查字段完整性 (~2s)',
required: { '--module': 'dict | form | di | menu | portal' },
required: { '--module': 'dict | form | di | menu | portal | workflow' },
optional: {
'--typeId': '字典类型 id (dict module 验证数据时必填)',
'--id': '实体 id (验证单条数据时用, di module 验证单条接口 schema, menu module 验证单条菜单 propertyJson)',
@@ -207,10 +207,12 @@ export function buildTestRenderCommand(): Command {
'dacli test render --module=menu --id=841765096471398533 # 验证某条菜单 propertyJson 完整性 (moduleId/webType/isTree/iconBackgroundColor)',
'dacli test render --module=portal # 验证门户 list 字段 + form 字段 ⊆ api (webapi 镜像, category 字典 UUID 校验 + formData + platformRelease schema)',
'dacli test render --module=portal --id=842041057662208261 # 验证某条门户 getInfo schema 完整性 (formData JSON.parse + platformRelease {pc,app})',
'dacli test render --module=workflow # 验证流程 list 字段 + form 字段 ⊆ api (webapi 镜像, flowNodes start/end/userTask + BPMN XML + flowConfig schema)',
'dacli test render --module=workflow --id=841820057188173957 # 验证某条流程 getInfo 必填 (fullName/enCode/category/icon/enabledMark) + flowNodes schema',
],
source: {
web: 'web/.../sysData/dictionary/{index,Form,components/index,components/Form}.vue + web/.../FormGenerator/ + web/.../dataCenter/dataInterface/{index,Form,Preview}.vue + web/.../permission/menu/{index,Form}.vue + web/.../onlineDev/visualPortal/{index,Form,components/ReleaseModal}.vue',
api: 'web/.../api/systemData/dictionary.ts + web/.../api/onlineDev/visualDev.ts + web/.../api/systemData/dataInterface.ts + web/.../api/system/menu.ts + web/.../api/onlineDev/portal.ts (loadPortal webapi 镜像)',
api: 'web/.../api/systemData/dictionary.ts + web/.../api/onlineDev/visualDev.ts + web/.../api/systemData/dataInterface.ts + web/.../api/system/menu.ts + web/.../api/onlineDev/portal.ts + web/.../api/workFlow/template.ts (loadWorkflow webapi 镜像)',
},
notes: [
'**v0.11+ NEW (2026-06-27)**: 沉淀自 Batch 1 字典验证 (用户拍板: 替代浏览器验证)',
@@ -218,6 +220,7 @@ export function buildTestRenderCommand(): Command {
'**v0.14+ di module (2026-07-01)**: 添加 di module, 镜像 web DataInterface 渲染 + SQL/API/WebSocket 三类型 schema 校验 (dacli test render --module=di)',
'**v0.14+ menu module (2026-07-01)**: 添加 menu module, 镜像 web Menu 渲染 + propertyJson schema 校验 (dacli test render --module=menu)',
'**v0.14+ portal module (2026-07-01)**: 添加 portal module, 镜像 web visualPortal 渲染 + category 字典 UUID 校验 + formData + platformRelease schema (dacli test render --module=portal)',
'**v0.14+ workflow module (2026-07-01)**: 添加 workflow module, 镜像 web flowEngine 渲染 + flowNodes start/end/userTask 校验 + BPMN XML + flowConfig schema (dacli test render --module=workflow)',
'**vs 浏览器测试**: 速度 2s vs 30s, 不需 playwright, 不依赖 SPA 路由 (JNPF admin 经常菜单 404)',
'**能查**: 字段缺失 / schema 漂移 / API 返字段不对 / enCode 不匹配渲染契约',
'**查不出**: vmodel bind bug (浏览器 JS) / 控件渲染异常 → 这些仍需 ssw-e2e-test',
@@ -227,6 +230,7 @@ export function buildTestRenderCommand(): Command {
'**算法 (di)**: 读 views/dataCenter/dataInterface/{index,Form}.vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 loadDataInterface webapi 镜像对比 → 4 关卡 (list 字段 ⊆ api / form 字段 ⊆ api / 必填 5 字段 (fullName/enCode/category/type/enabledMark) / SQL/API/WebSocket schema 完整性)',
'**算法 (menu)**: 读 views/permission/menu/{index,Form}.vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 loadMenu.getMenuList/getInfo webapi 镜像对比 → 4 关卡 (list 字段 ⊆ api / form 字段 ⊆ api / 必填 parentId 树形 + systemId 应用隔离 + moduleId 关联 / propertyJson schema 完整性 moduleId/webType/isTree/iconBackgroundColor)',
'**算法 (portal)**: 读 views/onlineDev/visualPortal/{index,Form,components/ReleaseModal}.vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 loadPortal.getPortalList/getInfo webapi 镜像对比 → 4 关卡 (list 字段 ⊆ api / form 字段 ⊆ api / 必填 4 字段 (fullName/enCode/category/type) + category 字典 UUID 真实 + type=1 必填 linkType/customUrl / schema 完整性 formData JSON.parse OK + platformRelease {pc,app})',
'**算法 (workflow)**: 读 views/onlineDev/flowEngine/{index,Form}.vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 loadWorkflow.getList/getInfo/getFlowInfo webapi 镜像对比 → 4 关卡 (list 字段 ⊆ api / form 字段 ⊆ api / 必填 4 字段 (fullName/enCode/category/icon) + enabledMark status / schema 完整性 flowNodes start+end+userTask + BPMN XML + flowConfig JSON.parse)',
],
})
return cmd
@@ -1182,9 +1186,10 @@ async function renderDi(
try {
const sel = (await loadDataInterface.getDataInterfaceSelector()) as any
const flat: any[] = []
// Selector 第一层是分类 (category=0), 第二层是 di (category=1), 只取 di 本身
const walk = (nodes: any[]) => {
for (const n of (nodes || [])) {
if (n?.id && n?.category !== '0' && n?.category !== '1') flat.push(n)
if (n?.id && (n?.category === '1' || n?.category === 1)) flat.push(n)
if (n?.children) walk(n.children)
}
}
@@ -1318,6 +1323,810 @@ async function renderDi(
}
}
// ============================================================================
// Portal module (v0.14+ NEW, 2026-07-01 — 镜像 §TC-C 4 关卡真实契约)
//
// 算法 (4 关卡):
// 1. 读 web 端 views/onlineDev/visualPortal/index.vue (BasicColumn.dataIndex 列表字段)
// + views/onlineDev/visualPortal/Form.vue (useForm schemas[].field 表单字段)
// 2. 调 loadPortal.getPortalList (走 webapi 镜像) → 拿全部门户, 合并字段并集
// 3. 4 关卡:
// 3.1 list 字段 ⊆ api 字段 (BasicColumn 必能渲染)
// 3.2 form 字段 ⊆ api 字段 (form schemas 必能 setFieldsValue, list ∪ info)
// 3.3 必填/外键/关联完整性: fullName/enCode/category/type 必填 + category 必须是字典 businessType 真实 UUID (Bug 5) + type=1 必填 linkType/customUrl
// 3.4 schema 完整性: formData JSON.parse OK + platformRelease JSON.parse OK 必含 {pc, app}
// 4. --id=<portalId> 时追加单条门户 schema 校验 (formData/platformRelease 详细解析, 第 5 个关卡)
//
// 镜像 web 端:
// - web/.../onlineDev/visualPortal/index.vue L31-48 columns BasicColumn
// fullName/enCode/category/type/enabledLock/creatorUser/creatorTime/lastModifyTime/sortCode/isRelease
// - web/.../onlineDev/visualPortal/Form.vue L28-125 useForm schemas
// fullName/enCode/category/type/linkType/customUrl/enabledLock/sortCode/description
// - web/.../onlineDev/visualPortal/Form.vue L127-145 init(data): getInfo(id) → setFieldsValue
// - web/.../onlineDev/visualPortal/components/ReleaseModal.vue L52-78: getInfo → JSON.parse(platformRelease) → {pc, app}
// - web/.../api/onlineDev/portal.ts getPortalList (Visualdev/Portal) + getInfo (Visualdev/Portal/{id})
//
// Bug 5 修复 (P1): portal category 必须是字典 businessType 真实 UUID, 后端
// PortalServiceImpl.getModelList() 严格过滤不在字典的 category → silently drop.
// ============================================================================
/**
* 渲染 portal module: 4 关卡 + 可选第 5 关卡 (单条 portal schema 完整性)
*/
async function renderPortal(
c: JnpfClient,
opts: RenderOpts,
results: RenderCheckResult[],
logFn: { info: (...a: unknown[]) => void; warn: (...a: unknown[]) => void; error: (...a: unknown[]) => void } = real,
): Promise<void> {
await initWebapiPortal(c)
const lg = logFn
// === 1. 读 web 端渲染契约 ===
// 列表字段: views/onlineDev/visualPortal/index.vue L31-48 columns BasicColumn
// 表单字段: views/onlineDev/visualPortal/Form.vue L28-125 useForm schemas
let listFields: string[] = []
let formFields: string[] = []
try {
listFields = await extractRenderFields(
`${WEB_ROOT}/views/onlineDev/visualPortal/index.vue`,
'list',
)
} catch (e) {
lg.error(`读 portal index.vue 失败: ${(e as Error).message}`)
}
try {
formFields = await extractRenderFields(
`${WEB_ROOT}/views/onlineDev/visualPortal/Form.vue`,
'form',
)
} catch (e) {
lg.error(`读 portal Form.vue 失败: ${(e as Error).message}`)
}
if (listFields.length === 0) {
lg.warn('portal 列表渲染字段为空 (未提取到 columns, 检查 index.vue 结构)')
}
if (formFields.length === 0) {
lg.warn('portal 表单渲染字段为空 (未提取到 schemas, 检查 Form.vue 结构)')
}
// === 2. 调 webapi 拿实际数据 ===
let apiFlat: any[] = []
let apiSource: 'live-data' | 'empty' = 'empty'
try {
const r: any = await loadPortal.getPortalList({ currentPage: 1, pageSize: 50 })
// webapi shim 已 unwrap: { pagination, list } 或 { list: [...] }
const list = Array.isArray(r?.list) ? r.list : Array.isArray(r?.data?.list) ? r.data.list : []
apiFlat = list
apiSource = apiFlat.length > 0 ? 'live-data' : 'empty'
} catch (e) {
lg.error(`getPortalList 失败: ${(e as Error).message}`)
}
if (apiSource === 'empty') {
lg.warn('portal API 返回空, 字段对比会标记全部缺失 (无 portal 数据, 可通过 dacli portal create 创建测试门户)')
}
// 收集 API 字段 (所有样本的字段并集)
const apiFieldSet = new Set<string>()
for (const item of apiFlat) {
if (item && typeof item === 'object') {
for (const k of Object.keys(item)) apiFieldSet.add(k)
}
}
const apiFields = Array.from(apiFieldSet).sort()
// === 3.1 Gate 1: 列表字段 ⊆ api 字段 ===
{
const renderSet = new Set(listFields)
const missing = listFields.filter(f => !apiFieldSet.has(f))
const extra = apiFields.filter(f => !renderSet.has(f))
const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'portal',
page: '门户列表',
sourceFile: 'views/onlineDev/visualPortal/index.vue (columns L31-48)',
renderFields: listFields,
apiFields,
missing,
extra,
status,
})
const icon = status === 'PASS' ? '✓' : '✗'
lg.info(`${icon} 门户列表: ${status} (${listFields.length} 渲染字段, ${apiFields.length} API 字段 [源:${apiSource}]${missing.length ? `, 缺 ${missing.length}` : ''})`)
}
// === 3.2 Gate 2: 表单字段 ⊆ api 字段 (list ∪ getInfo) ===
// 镜像 web Form.vue L127-145 init(data): getInfo(id) → setFieldsValue
// form 必填字段应 ⊆ (list API 字段 ∪ info API 字段)
let infoUnionSet = new Set<string>()
let infoSource = 'list-only'
if (apiFlat.length > 0) {
const sample = apiFlat.find(p => p.id) || apiFlat[0]
try {
const infoResp: any = await loadPortal.getInfo(sample.id)
const data = (infoResp as any)?.data || infoResp
if (data && typeof data === 'object') {
infoSource = 'list+info'
for (const k of Object.keys(data)) infoUnionSet.add(k)
}
} catch (e) {
lg.warn(`getInfo(${sample.id}) 失败 (Gate 2 仅用 list): ${(e as Error).message}`)
}
}
const formApiFieldSet = new Set<string>([...apiFieldSet, ...infoUnionSet])
const formApiFields = Array.from(formApiFieldSet).sort()
{
const renderSet = new Set(formFields)
const missing = formFields.filter(f => !formApiFieldSet.has(f))
const extra = formApiFields.filter(f => !renderSet.has(f))
const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'portal',
page: '门户表单',
sourceFile: 'views/onlineDev/visualPortal/Form.vue (schemas L28-125) + getInfo (Form.vue L127-145)',
renderFields: formFields,
apiFields: formApiFields,
missing,
extra,
status,
})
const icon = status === 'PASS' ? '✓' : '✗'
lg.info(`${icon} 门户表单: ${status} (${formFields.length} 渲染字段, ${formApiFields.length} API 字段 [源:${infoSource}]${missing.length ? `, 缺 ${missing.length}` : ''})`)
}
// === 3.3 Gate 3: 必填/外键/关联完整性 ===
// 镜像 web Form.vue L28-125 schemas + Bug 5 修复:
// - 4 核心必填: fullName / enCode / category / type
// - category 必须是字典 businessType 真实 UUID (32 字符 hex, 不是 '1'/'2')
// 镜像 web 端: list 接口返 category=fullName (UI 显示), info/create/update 返 category=UUID (后端写入)
// 所以检查必须用 getInfo 拿真 UUID, 不是 list 的 fullName
// - type=1 时 linkType/customUrl 必填 (Form.vue L86-105 ifShow values.type===1)
// - type=0 时 enabledLock 必有 (Form.vue L104-110 ifShow values.type===0)
const UUID_HEX_32 = /^[0-9a-f]{32}$/i
const requiredFieldsIssues: string[] = []
const categoryIssues: string[] = []
const conditionalIssues: string[] = []
const typeZeroCount = apiFlat.filter(p => Number(p.type) === 0).length
const typeOneCount = apiFlat.filter(p => Number(p.type) === 1).length
let infoFetchedCount = 0
if (apiFlat.length > 0) {
for (const p of apiFlat) {
const label = p.fullName || p.enCode || p.id || '<无标识>'
// 4 核心必填 (基于 list 数据, list 必含这 4 字段)
if (!p.fullName) requiredFieldsIssues.push(`${label}: fullName 缺失`)
if (!p.enCode) requiredFieldsIssues.push(`${label}: enCode 缺失`)
if (!p.category) requiredFieldsIssues.push(`${label}: category 缺失`)
if (p.type === undefined || p.type === null) requiredFieldsIssues.push(`${label}: type 缺失`)
// Bug 5: 必须用 getInfo 拿真 UUID 检查 (list 返 fullName 仅供显示)
if (p.id) {
try {
const infoResp: any = await loadPortal.getInfo(p.id)
const data = (infoResp as any)?.data || infoResp
if (data && typeof data === 'object') {
infoFetchedCount++
const cat = data.category
if (!cat) {
categoryIssues.push(`${label}: getInfo category 缺失`)
} else if (!UUID_HEX_32.test(String(cat))) {
categoryIssues.push(`${label}: getInfo category="${cat}" 不是字典 UUID 格式 (期望 32 字符 hex, 后端会 silently drop)`)
}
// 条件必填: type=1 时 linkType/customUrl 必填 (从 info 拿, info 字段完整)
if (Number(data.type) === 1) {
if (data.linkType === undefined || data.linkType === null) conditionalIssues.push(`${label}: type=1 缺 linkType`)
if (!data.customUrl) conditionalIssues.push(`${label}: type=1 缺 customUrl`)
}
}
} catch (e) {
categoryIssues.push(`${label}: getInfo 失败: ${(e as Error).message.slice(0, 60)}`)
}
}
}
} else {
requiredFieldsIssues.push('无 portal 数据 (跳过必填/外键/关联校验)')
}
{
const allIssues = [...requiredFieldsIssues, ...categoryIssues, ...conditionalIssues]
const status: 'PASS' | 'FAIL' = allIssues.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'portal',
page: '必填/外键/关联完整性',
sourceFile: 'Form.vue schemas L28-125 + Bug 5 category 字典 UUID + type 条件必填 (ifShow)',
renderFields: ['fullName', 'enCode', 'category', 'type', 'linkType?', 'customUrl?'],
apiFields: ['fullName', 'enCode', 'category', 'type', 'linkType', 'customUrl'],
missing: allIssues,
extra: [],
status,
})
if (allIssues.length === 0) {
lg.info(`✓ 必填/外键/关联完整性: PASS (${apiFlat.length} 门户项, type=0 门户设计 ${typeZeroCount}, type=1 配置路径 ${typeOneCount}; category 全部 UUID 真实, 条件必填完整)`)
} else {
lg.error(`✗ 必填/外键/关联完整性: FAIL (${allIssues.slice(0, 3).join(' | ')}${allIssues.length > 3 ? '...' : ''})`)
}
}
// === 3.4 Gate 4: schema 完整性 (formData JSON.parse + platformRelease JSON.parse) ===
// 镜像 web:
// - Form.vue L127-145 init(data): res.data.formData 直接 setFieldsValue (formData 通常是 string JSON)
// - ReleaseModal.vue L52-78: JSON.parse(platformRelease) → {pc, app}
// formData 必能 JSON.parse OK (空 formData 用 "{}" 占位, 必须可解析)
// platformRelease 必能 JSON.parse OK 必含 {pc, app} (null 也算 OK, 表示未发布)
const schemaIssues: string[] = []
let formDataParsedCount = 0
let platformReleaseParsedCount = 0
if (apiFlat.length > 0) {
for (const p of apiFlat) {
const label = p.fullName || p.enCode || p.id || '<无标识>'
// formData: string JSON, 必能 parse (允许空字符串或 "{}")
if (p.formData !== undefined && p.formData !== null) {
if (typeof p.formData === 'string') {
try {
const parsed = JSON.parse(p.formData)
if (typeof parsed !== 'object') {
schemaIssues.push(`${label}: formData 解析后非对象 (${typeof parsed})`)
} else {
formDataParsedCount++
}
} catch (e) {
schemaIssues.push(`${label}: formData JSON.parse 失败: ${(e as Error).message.slice(0, 60)}`)
}
} else if (typeof p.formData === 'object') {
formDataParsedCount++
} else {
schemaIssues.push(`${label}: formData 类型不对 (期望 string/object, 实际 ${typeof p.formData})`)
}
} else {
// formData 可为 null (未设计), 不算 issue, 跳过
}
// platformRelease: string JSON, 必含 {pc, app} (ReleaseModal.vue L52-78 必读)
// null 表示未发布, 跳过; 否则必须能 parse 且含 pc/app
if (p.platformRelease !== undefined && p.platformRelease !== null) {
if (typeof p.platformRelease !== 'string') {
schemaIssues.push(`${label}: platformRelease 类型不对 (期望 string, 实际 ${typeof p.platformRelease})`)
} else {
try {
const parsed = JSON.parse(p.platformRelease)
if (typeof parsed !== 'object' || parsed === null) {
schemaIssues.push(`${label}: platformRelease 解析后非对象`)
} else if (parsed.pc === undefined || parsed.app === undefined) {
schemaIssues.push(`${label}: platformRelease 缺 pc/app 字段 (ReleaseModal.vue L56-57 必读)`)
} else {
platformReleaseParsedCount++
}
} catch (e) {
schemaIssues.push(`${label}: platformRelease JSON.parse 失败: ${(e as Error).message.slice(0, 60)}`)
}
}
}
}
} else {
schemaIssues.push('无 portal 数据 (跳过 schema 校验)')
}
{
const status: 'PASS' | 'FAIL' = schemaIssues.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'portal',
page: 'schema 完整性 (formData + platformRelease)',
sourceFile: 'formData: Form.vue L127-145 + platformRelease: ReleaseModal.vue L52-78',
renderFields: ['formData (JSON)', 'platformRelease.pc', 'platformRelease.app'],
apiFields: ['formData', 'platformRelease'],
missing: schemaIssues,
extra: [],
status,
})
if (schemaIssues.length === 0) {
lg.info(`✓ schema 完整性: PASS (${formDataParsedCount} formData + ${platformReleaseParsedCount} platformRelease 全部 JSON.parse OK + 必含字段完整)`)
} else {
lg.error(`✗ schema 完整性: FAIL (${schemaIssues.slice(0, 3).join(' | ')}${schemaIssues.length > 3 ? '...' : ''})`)
}
}
// === 3.5 Gate 5 (可选, --id): 单条门户 getInfo schema 详细校验 ===
// 镜像 web Form.vue L127-145 + ReleaseModal.vue L52-78 init(data): getInfo(id)
// → setFieldsValue + JSON.parse(platformRelease)
// form 必填字段 + formData/平台菜单路径 完整
if (opts.id) {
let infoDetail: any
try {
infoDetail = await loadPortal.getInfo(opts.id)
} catch (e) {
lg.error(`getInfo(${opts.id}) 失败: ${(e as Error).message}`)
infoDetail = null
}
const data = (infoDetail as any)?.data || infoDetail
if (!data || typeof data !== 'object') {
lg.error(`getInfo(${opts.id}) 返回非对象: ${JSON.stringify(infoDetail).slice(0, 200)}`)
} else {
const infoFieldSet = new Set(Object.keys(data))
const infoFields = Array.from(infoFieldSet).sort()
// getInfo 必含字段 (Form.vue schemas + getInfo 派生: pcIsRelease/appIsRelease/pcReleaseName 等)
const requiredInfoFields = [
'fullName', 'enCode', 'category', 'type',
'linkType', 'customUrl', 'appCustomUrl',
'enabledLock', 'enabledMark', 'sortCode', 'description',
'formData', 'platformRelease',
'pcIsRelease', 'appIsRelease',
'pcReleaseName', 'appReleaseName',
]
const missing = requiredInfoFields.filter(f => !infoFieldSet.has(f))
// formData 解析校验
let formDataOk = false
let formDataDetails = ''
if (typeof data.formData === 'string') {
try {
const parsed = JSON.parse(data.formData || '{}')
formDataOk = typeof parsed === 'object'
formDataDetails = `parsed=${formDataOk}, keys=${formDataOk ? Object.keys(parsed).length : 0}`
} catch (e) {
missing.push(`formData JSON.parse 失败: ${(e as Error).message.slice(0, 60)}`)
}
} else if (data.formData && typeof data.formData === 'object') {
formDataOk = true
formDataDetails = `object keys=${Object.keys(data.formData).length}`
}
// platformRelease 解析校验 (Bug 5 修复后, release 过的 portal 必有 platformRelease)
let platformReleaseOk = false
let platformReleaseDetails = ''
if (typeof data.platformRelease === 'string') {
try {
const parsed = JSON.parse(data.platformRelease)
if (parsed && typeof parsed === 'object') {
platformReleaseOk = true
platformReleaseDetails = `pc=${parsed.pc}, app=${parsed.app}`
} else {
missing.push('platformRelease 解析后非对象')
}
} catch (e) {
missing.push(`platformRelease JSON.parse 失败: ${(e as Error).message.slice(0, 60)}`)
}
} else if (data.platformRelease === null) {
platformReleaseDetails = 'null (未发布)'
platformReleaseOk = true // null OK, 表示未发布
}
const status: 'PASS' | 'FAIL' = missing.length === 0 && formDataOk ? 'PASS' : 'FAIL'
results.push({
module: 'portal',
page: '单条门户 getInfo 完整性',
sourceFile: `getInfo (id=${opts.id}, formData: ${formDataDetails}, platformRelease: ${platformReleaseDetails})`,
renderFields: requiredInfoFields,
apiFields: infoFields,
missing,
extra: [],
status,
})
if (status === 'PASS') {
lg.info(`✓ 单条门户 getInfo: PASS (${infoFields.length} 字段, formData: ${formDataDetails}, platformRelease: ${platformReleaseDetails})`)
} else {
lg.error(`✗ 单条门户 getInfo: FAIL (${missing.slice(0, 3).join(' | ')}${missing.length > 3 ? '...' : ''})`)
}
}
}
}
// ============================================================================
// Workflow module (流程模板, v0.14+ NEW, 2026-07-01 — 镜像 §TC-C 4 关卡真实契约)
//
// 算法 (4 关卡):
// 1. 读 web 端 views/onlineDev/flowEngine/index.vue (BasicColumn.dataIndex 列表字段)
// + views/onlineDev/flowEngine/Form.vue (useForm schemas[].field 表单字段)
// 2. 调 loadWorkflow.getList (走 webapi 镜像) → 拿流程列表; getInfo(id) 拿详情
// getFlowInfo(versionId) 拿 flowNodes + flowXml + flowConfig
// 3. 4 关卡:
// 3.1 list 字段 ⊆ api 字段 (BasicColumn 必能渲染)
// 3.2 form 字段 ⊆ api 字段 (form schemas 必能 setFieldsValue; 含 icon/iconBackground)
// 3.3 必填/外键/关联完整性: fullName/enCode/category/icon 必填 + enabledMark 启用标记 +
// flowId ↔ versionId 关联 (versionList 中每个 version.id 应能反查 flow template)
// 3.4 schema 完整性: flowNodes 至少 start + end + 1 个 userTask; BPMN XML 合法性;
// flowConfig JSON.parse OK (可能为 {} 空对象)
// 4. --id=<flowId> 时追加单条流程 getInfo 必填 + flowNodes schema 校验 (第 5 个关卡)
//
// 镜像 web 端:
// - web/.../onlineDev/flowEngine/index.vue L32-42 columns BasicColumn:
// fullName/enCode/category/type/creatorUser/creatorTime/sortCode/enabledMark/status
// - web/.../onlineDev/flowEngine/Form.vue L31-105 useForm schemas:
// fullName/enCode/decisionType/category/icon/showType/sortCode/description
// + iconBackground (Form.vue L23-24 state.iconBackground + L116-117)
// - web/.../api/workFlow/template.ts:
// getList (page) / getInfo (id) / getVersionList (id) / getFlowInfo (versionId)
// (返回 flowNodes + flowXml + flowConfig)
// ============================================================================
/**
* 从 web 端 flowEngine 列表 vue 提取 BasicColumn.dataIndex
* 镜像 web/.../onlineDev/flowEngine/index.vue L32-42 columns
*/
async function extractWorkflowListRenderFields(): Promise<string[]> {
const vueFile = `${WEB_ROOT}/views/onlineDev/flowEngine/index.vue`
const src = await fs.readFile(vueFile, 'utf-8')
const { descriptor } = parse(src)
const ss = descriptor.scriptSetup?.content || ''
// columns: BasicColumn[] = [ ... ]
const m = ss.match(/const\s+columns[\s\S]*?\n\]/)
if (!m) return []
const fields: string[] = []
const re = /dataIndex:\s*['"]([^'"]+)['"]/g
let mm
while ((mm = re.exec(m[0])) !== null) fields.push(mm[1])
return fields
}
/**
* 从 web 端 flowEngine 表单 vue 提取 useForm schemas[].field
* 镜像 web/.../onlineDev/flowEngine/Form.vue L31-105
*
* 注意: Form.vue L48-53 重复 enCode (typo/visual dev 残留), 我们去重
* + iconBackground 不在 schemas 里, 但 state.iconBackground 在 Form.vue L23-24,
* getInfo 返回时也会带 (web 端 Form.vue L114-117), 所以合并进渲染字段集
*/
async function extractWorkflowFormRenderFields(): Promise<string[]> {
const vueFile = `${WEB_ROOT}/views/onlineDev/flowEngine/Form.vue`
const src = await fs.readFile(vueFile, 'utf-8')
const { descriptor } = parse(src)
const ss = descriptor.scriptSetup?.content || ''
const m = ss.match(/const\s+schemas[\s\S]*?\n\]/)
if (!m) return []
const fields: string[] = []
const re = /field:\s*['"]([^'"]+)['"]/g
let mm
while ((mm = re.exec(m[0])) !== null) fields.push(mm[1])
// 去重 (Form.vue L48-53 重复 enCode)
const seen = new Set<string>()
const out: string[] = []
for (const f of fields) {
if (!seen.has(f)) { seen.add(f); out.push(f) }
}
// iconBackground 来自 state.iconBackground (Form.vue L23-24) — 不在 schemas 但 getInfo 返
out.push('iconBackground')
return out
}
/**
* 渲染 workflow module: 4 关卡 + 可选第 5 关卡 (单条流程 getInfo 完整性 + flowNodes schema)
*/
async function renderWorkflow(
c: JnpfClient,
opts: RenderOpts,
results: RenderCheckResult[],
logFn: { info: (...a: unknown[]) => void; warn: (...a: unknown[]) => void; error: (...a: unknown[]) => void } = real,
): Promise<void> {
await initWebapiWorkflow(c)
const lg = logFn
// === 1. 读 web 端渲染契约 ===
let listFields: string[] = []
let formFields: string[] = []
try {
listFields = await extractWorkflowListRenderFields()
if (listFields.length === 0) {
lg.warn('流程列表渲染字段为空 (未提取到 columns, 检查 flowEngine/index.vue 结构)')
}
} catch (e) {
lg.error(`读 flowEngine/index.vue 失败: ${(e as Error).message}`)
}
try {
formFields = await extractWorkflowFormRenderFields()
if (formFields.length === 0) {
lg.warn('流程表单渲染字段为空 (未提取到 schemas, 检查 flowEngine/Form.vue 结构)')
}
} catch (e) {
lg.error(`读 flowEngine/Form.vue 失败: ${(e as Error).message}`)
}
// === 2. 调 webapi 拿实际数据 ===
let apiFlat: any[] = []
let apiSource: 'live-data' | 'empty' = 'empty'
try {
const r: any = await loadWorkflow.getList({ currentPage: 1, pageSize: 50 })
const list = Array.isArray(r?.data?.list) ? r.data.list : Array.isArray(r?.list) ? r.list : []
apiFlat = list
apiSource = apiFlat.length > 0 ? 'live-data' : 'empty'
} catch (e) {
lg.error(`getList 失败: ${(e as Error).message}`)
}
// 收集 API 字段 (所有样本的字段并集)
const apiFieldSet = new Set<string>()
for (const item of apiFlat) {
if (item && typeof item === 'object') {
for (const k of Object.keys(item)) apiFieldSet.add(k)
}
}
const apiFields = Array.from(apiFieldSet).sort()
if (apiSource === 'empty') {
lg.warn('流程 API 返回空, 字段对比会标记全部缺失 (无流程数据, 可通过 dacli workflow create 创建测试流程)')
}
// === 3.1 Gate 1: 列表字段 ⊆ api 字段 ===
{
const renderSet = new Set(listFields)
const missing = listFields.filter(f => !apiFieldSet.has(f))
const extra = apiFields.filter(f => !renderSet.has(f))
const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'workflow',
page: '流程列表',
sourceFile: 'views/onlineDev/flowEngine/index.vue (columns L32-42)',
renderFields: listFields,
apiFields,
missing,
extra,
status,
})
const icon = status === 'PASS' ? '✓' : '✗'
lg.info(`${icon} 流程列表: ${status} (${listFields.length} 渲染字段, ${apiFields.length} API 字段 [源:${apiSource}]${missing.length ? `, 缺 ${missing.length}` : ''})`)
}
// === 3.2 Gate 2: 表单字段 ⊆ api 字段 (getList ∪ getInfo) ===
// 镜像 web Form.vue L113-117 init(data): getInfo(id) 拿完整字段 (含 description/iconBackground/decisionType/showType)
// 所以 form 必填字段应 ⊆ (list API 字段 ∪ info API 字段)
let infoUnionSet = new Set<string>()
let infoSource = 'list-only'
if (apiFlat.length > 0) {
// 拿第一条流程调 getInfo (info 字段集对所有流程结构相同, 抽样即可)
const sample = opts.id || apiFlat[0].id
try {
const infoResp: any = await loadWorkflow.getInfo(sample)
const data = (infoResp as any)?.data || infoResp
if (data && typeof data === 'object') {
infoSource = 'list+info'
for (const k of Object.keys(data)) infoUnionSet.add(k)
}
} catch (e) {
lg.warn(`getInfo(${sample}) 失败 (Gate 2 仅用 list): ${(e as Error).message}`)
}
}
const formApiFieldSet = new Set<string>([...apiFieldSet, ...infoUnionSet])
const formApiFields = Array.from(formApiFieldSet).sort()
{
const renderSet = new Set(formFields)
const missing = formFields.filter(f => !formApiFieldSet.has(f))
const extra = formApiFields.filter(f => !renderSet.has(f))
const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'workflow',
page: '流程表单',
sourceFile: 'views/onlineDev/flowEngine/Form.vue (schemas L31-105) + getInfo (L113-117)',
renderFields: formFields,
apiFields: formApiFields,
missing,
extra,
status,
})
const icon = status === 'PASS' ? '✓' : '✗'
lg.info(`${icon} 流程表单: ${status} (${formFields.length} 渲染字段, ${formApiFields.length} API 字段 [源:${infoSource}]${missing.length ? `, 缺 ${missing.length}` : ''})`)
}
// === 3.3 Gate 3: 必填/外键/关联完整性 (fullName/enCode/category/icon 必填 + enabledMark + version 关联) ===
// 镜像 web Form.vue L31-105 schemas.rules:
// fullName: required
// enCode: formValidate (enCode 规则)
// category: required
// icon: required
// iconBackground: state 取色器 (Form.vue L23-24), 持久化在 dataForm.iconBackground
// 镜像 web index.vue L40-41: enabledMark + status 列
// 镜像 web DesignForm.vue L92-104: flowId ↔ versionList 关联
const requiredIssues: string[] = []
const associationIssues: string[] = []
if (apiFlat.length > 0) {
for (const flow of apiFlat) {
const label = flow.fullName || flow.id || '<no-id>'
if (!flow.fullName) requiredIssues.push(`${label}: 缺 fullName (Form.vue L37 required)`)
if (!flow.enCode) requiredIssues.push(`${label}: 缺 enCode (Form.vue L43 formValidate)`)
if (!flow.category) requiredIssues.push(`${label}: 缺 category (Form.vue L66 required)`)
if (!flow.icon) requiredIssues.push(`${label}: 缺 icon (Form.vue L72 required)`)
if (!flow.iconBackground) requiredIssues.push(`${label}: 缺 iconBackground (Form.vue L116-117 持久化)`)
// enabledMark 是发布状态字段 (index.vue L40), 必存在 (int 0/1)
if (flow.enabledMark === undefined || flow.enabledMark === null) {
requiredIssues.push(`${label}: 缺 enabledMark (index.vue L40 发布状态列)`)
}
// status 是上架状态字段 (index.vue L41)
if (flow.status === undefined || flow.status === null) {
requiredIssues.push(`${label}: 缺 status (index.vue L41 上架状态列)`)
}
}
// version 关联: 对每条流程查 versionList, 检查 version.id 能反查 (取第 1 个 version 调 getFlowInfo)
// 为了避免 N+1, 只对第一条流程校验 (info 字段集结构对所有流程一致)
const first = apiFlat[0]
try {
const vResp: any = await loadWorkflow.getVersionList(first.id)
const versions = Array.isArray(vResp?.data) ? vResp.data : Array.isArray(vResp?.list) ? vResp.list : []
if (versions.length === 0) {
associationIssues.push(`${first.fullName || first.id} (${first.id}) 无 versionList (web DesignForm.vue L93-95 必返非空)`)
} else {
// 抽 1 个 version 调 getFlowInfo 验证 flowId 关联 (返回顶层有 flowId 字段)
const v0 = versions[0]
try {
const fiResp: any = await loadWorkflow.getFlowInfo(v0.id)
const fi = (fiResp as any)?.data || fiResp
if (fi && typeof fi === 'object') {
if (fi.flowId === undefined || fi.flowId === null) {
associationIssues.push(`${first.fullName || first.id} version ${v0.id} getFlowInfo 缺 flowId 关联`)
}
if (!fi.flowNodes || typeof fi.flowNodes !== 'object') {
associationIssues.push(`${first.fullName || first.id} version ${v0.id} getFlowInfo 缺 flowNodes (DesignForm.vue L108-119 必含)`)
}
if (!fi.flowXml) {
associationIssues.push(`${first.fullName || first.id} version ${v0.id} getFlowInfo 缺 flowXml (BPMN XML, DesignForm.vue L89 saveXML)`)
}
}
} catch (e) {
associationIssues.push(`getFlowInfo(${v0.id}) 失败: ${(e as Error).message.slice(0, 80)}`)
}
}
} catch (e) {
associationIssues.push(`getVersionList(${first.id}) 失败: ${(e as Error).message.slice(0, 80)}`)
}
} else {
requiredIssues.push('无流程数据 (跳过必填校验)')
}
{
const allIssues = [...requiredIssues, ...associationIssues]
const status: 'PASS' | 'FAIL' = allIssues.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'workflow',
page: '必填/外键/关联完整性',
sourceFile: 'schemas.rules (Form.vue L31-105) + index.vue enabledMark/status (L40-41) + flowId↔versionId 关联 (DesignForm.vue L93-119)',
renderFields: ['fullName', 'enCode', 'category', 'icon', 'iconBackground', 'enabledMark', 'status', 'flowId', 'versionList'],
apiFields: ['fullName', 'enCode', 'category', 'icon', 'iconBackground', 'enabledMark', 'status', 'flowId', 'flowNodes', 'flowXml'],
missing: allIssues,
extra: [],
status,
})
if (allIssues.length === 0) {
lg.info(`✓ 必填/外键/关联完整性: PASS (${apiFlat.length} 流程, 必填字段 + flowId/versionId 关联全部完整)`)
} else {
lg.error(`✗ 必填/外键/关联完整性: FAIL (${allIssues.slice(0, 3).join(' | ')}${allIssues.length > 3 ? '...' : ''})`)
}
}
// === 3.4 Gate 4: schema 完整性 (flowNodes start+end+userTask + BPMN XML + flowConfig JSON.parse) ===
// 镜像 web FlowProcess/src/index.vue L75-99 + DesignForm.vue L106-119:
// - flowNodes 是对象 (key=nodeId, value=nodeConfig), 至少 1 start + 1 end + ≥1 userTask (approver)
// - flowXml 是 BPMN 2.0 XML 字符串 (DesignForm.vue L89 saveXML)
// - flowConfig 是 JSON 字符串 (DesignForm.vue L111-115 JSON.parse)
const schemaIssues: string[] = []
let schemaCheckedFlow = ''
if (apiFlat.length > 0) {
const first = apiFlat[0]
schemaCheckedFlow = `${first.fullName || '?'} (${first.id})`
try {
const vResp: any = await loadWorkflow.getVersionList(first.id)
const versions = Array.isArray(vResp?.data) ? vResp.data : Array.isArray(vResp?.list) ? vResp.list : []
const v0 = versions[0]
if (!v0) {
schemaIssues.push('versionList 为空 (无法校验 flowNodes/BPMN)')
} else {
const fiResp: any = await loadWorkflow.getFlowInfo(v0.id)
const fi = (fiResp as any)?.data || fiResp
if (fi && typeof fi === 'object') {
// flowNodes schema
const nodes = fi.flowNodes
if (!nodes || typeof nodes !== 'object') {
schemaIssues.push('flowNodes 缺失或非对象')
} else {
const nodeArr = Object.values(nodes) as any[]
const hasStart = nodeArr.some(n => n?.type === 'start')
const hasEnd = nodeArr.some(n => n?.type === 'end')
const userTaskTypes = ['approver', 'processing', 'trigger']
const hasUserTask = nodeArr.some(n => userTaskTypes.includes(n?.type))
if (!hasStart) schemaIssues.push(`flowNodes 缺 start 节点 (${nodeArr.length} 节点: ${nodeArr.slice(0, 3).map(n => n?.type).join(',')})`)
if (!hasEnd) schemaIssues.push(`flowNodes 缺 end 节点`)
if (!hasUserTask) schemaIssues.push(`flowNodes 缺 userTask (approver/processing/trigger)`)
}
// BPMN XML 合法性
const xml = fi.flowXml
if (!xml) {
schemaIssues.push('flowXml 缺失 (DesignForm.vue L89 saveXML 必含)')
} else if (typeof xml !== 'string') {
schemaIssues.push(`flowXml 类型不对 (期望 string, 实际 ${typeof xml})`)
} else {
// 简单合法性: 含 bpmn2:definitions 或 bpmn:definitions 根标签
if (!/<\s*(bpmn2?:definitions|bpmn2?:process)\b/i.test(xml)) {
schemaIssues.push('flowXml 不像合法 BPMN (无 bpmn2:definitions/bpmn2:process 根标签)')
}
}
// flowConfig JSON.parse
const fc = fi.flowConfig
if (fc !== undefined && fc !== null) {
if (typeof fc !== 'string') {
schemaIssues.push(`flowConfig 类型不对 (期望 string JSON, 实际 ${typeof fc})`)
} else if (fc.trim() !== '') {
try {
const parsed = JSON.parse(fc)
if (typeof parsed !== 'object' || parsed === null) {
schemaIssues.push('flowConfig 解析后非对象')
}
} catch (e) {
schemaIssues.push(`flowConfig JSON.parse 失败: ${(e as Error).message.slice(0, 60)}`)
}
}
// fc === '{}' 或 '' 是合法空配置, 不算 issue
}
} else {
schemaIssues.push('getFlowInfo 返回非对象, 无法校验 schema')
}
}
} catch (e) {
schemaIssues.push(`flowNodes schema 校验异常: ${(e as Error).message.slice(0, 80)}`)
}
} else {
schemaIssues.push('无流程数据 (跳过 schema 校验)')
}
{
const status: 'PASS' | 'FAIL' = schemaIssues.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'workflow',
page: 'flowNodes/BPMN schema 完整性',
sourceFile: `flowNodes + flowXml + flowConfig (FlowProcess/src/index.vue L75-99 + DesignForm.vue L106-119, flow: ${schemaCheckedFlow})`,
renderFields: ['flowNodes.start', 'flowNodes.end', 'flowNodes.userTask', 'flowXml (BPMN XML)', 'flowConfig (JSON.parse)'],
apiFields: ['flowNodes', 'flowXml', 'flowConfig'],
missing: schemaIssues,
extra: [],
status,
})
if (schemaIssues.length === 0) {
lg.info(`✓ flowNodes/BPMN schema: PASS (镜像 web FlowProcess + DesignForm schema 完整)`)
} else {
lg.error(`✗ flowNodes/BPMN schema: FAIL (${schemaIssues.slice(0, 3).join(' | ')}${schemaIssues.length > 3 ? '...' : ''})`)
}
}
// === 3.5 Gate 5 (可选, --id): 单条流程 getInfo 必填完整性 + flowNodes schema 校验 ===
// 镜像 web Form.vue L113-117 init(data): getInfo(id) 必含所有渲染字段
if (opts.id) {
let infoDetail: any
try {
infoDetail = await loadWorkflow.getInfo(opts.id)
} catch (e) {
lg.error(`getInfo(${opts.id}) 失败: ${(e as Error).message}`)
infoDetail = null
}
const data = (infoDetail as any)?.data || infoDetail
if (!data || typeof data !== 'object') {
lg.error(`getInfo(${opts.id}) 返回非对象: ${JSON.stringify(infoDetail).slice(0, 200)}`)
} else {
const infoFieldSet = new Set(Object.keys(data))
const infoFields = Array.from(infoFieldSet).sort()
// form 必填字段 (来自 Form.vue schemas + getInfo 派生)
const requiredInfoFields = [
'fullName', 'enCode', 'type', 'category', 'icon', 'iconBackground',
'description', 'sortCode', 'flowConfig', 'showType', 'status',
'decisionType', 'id', 'visibleType',
]
const missing = requiredInfoFields.filter(f => !infoFieldSet.has(f))
const details = `fullName=${data.fullName || '<空>'}, enCode=${data.enCode || '<空>'}, icon=${data.icon || '<空>'}, iconBackground=${data.iconBackground || '<空>'}`
const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL'
results.push({
module: 'workflow',
page: '单条流程 getInfo 完整性',
sourceFile: `getInfo (flowId=${opts.id}, ${details})`,
renderFields: requiredInfoFields,
apiFields: infoFields,
missing,
extra: [],
status,
})
if (status === 'PASS') {
lg.info(`✓ 单条流程 getInfo: PASS (${infoFields.length} 字段, ${details})`)
} else {
lg.error(`✗ 单条流程 getInfo: FAIL (${missing.slice(0, 3).join(' | ')}${missing.length > 3 ? '...' : ''})`)
}
}
}
}
// 日志门面 (json 模式静默, 否则用 log)
const real = {
info: log.info,
@@ -1444,6 +2253,16 @@ async function extractRenderFields(vueFile: string, mode: 'list' | 'form'): Prom
return fields
} else {
// mode='form': 找 schemas 数组里的 field
// 优先: const schemas: Type[] = [...] (TS 强类型, e.g. dataCenter/dataInterface/Form.vue)
const mType = ss.match(/const\s+schemas[\s\S]*?\n\]/)
if (mType) {
const re = /field:\s*['"]([^'"]+)['"]/g
const fields: string[] = []
let mm
while ((mm = re.exec(mType[0])) !== null) fields.push(mm[1])
return fields
}
// 退化: schemas: [...] (无类型注释, e.g. sysData/dictionary/Form.vue)
const m = ss.match(/schemas:\s*\[[\s\S]*?\n\s*\]/)
if (!m) return []
const fields: string[] = []