diff --git a/src/commands/_coverage.ts b/src/commands/_coverage.ts
index ed035f4..f9b036d 100644
--- a/src/commands/_coverage.ts
+++ b/src/commands/_coverage.ts
@@ -108,19 +108,22 @@ export function buildCoverageCommand(): Command {
.action(async (opts: { json?: boolean; detailed?: boolean }) => {
log.info('=== dacli coverage report (v0.11e+) ===')
- // 扫描所有 create/update/create-ui 命令
+ // 扫描所有 create/update/typecreate/typeupdate 命令 (这是镜像率统计的合理范围)
const allFiles: string[] = []
const domains = fs.readdirSync(COMMANDS_DIR).filter((f) => {
const full = path.join(COMMANDS_DIR, f)
return fs.statSync(full).isDirectory() && !f.startsWith('_')
})
+ // v0.11e+ Phase D2 fix: 只统计 create/update/typecreate/typeupdate (info/list/delete 等是辅助命令, 不计入镜像率)
+ const COUNTED_FILES = new Set([
+ 'create.ts', 'update.ts', 'typecreate.ts', 'typeupdate.ts',
+ 'datacreate.ts', 'dataupdate.ts', 'release.ts', 'unrelease.ts',
+ ])
+
for (const domain of domains) {
const domainDir = path.join(COMMANDS_DIR, domain)
- const files = fs.readdirSync(domainDir).filter((f) => {
- return (f.endsWith('.ts') && !f.startsWith('_')) ||
- f === 'create.ts' || f === 'update.ts' || f === 'typecreate.ts' || f === 'typeupdate.ts'
- })
+ const files = fs.readdirSync(domainDir).filter((f) => COUNTED_FILES.has(f))
for (const f of files) {
allFiles.push(path.join(domainDir, f))
}
diff --git a/tests/e2e/step-machine/di-validate.test.ts b/tests/e2e/step-machine/di-validate.test.ts
new file mode 100644
index 0000000..eb53ffc
--- /dev/null
+++ b/tests/e2e/step-machine/di-validate.test.ts
@@ -0,0 +1,67 @@
+/**
+ * vitest test: di/_validate.ts (Phase D2 E2E 自动化)
+ */
+import { describe, it, expect } from 'vitest'
+import { validateDiUpdate } from '../../../src/commands/di/_validate.ts'
+
+describe('di/_validate.ts step machine', () => {
+ it('成功路径: 合法 fullName + enCode + type=1 SQL', () => {
+ const r = validateDiUpdate({
+ fullName: '测试 DI',
+ enCode: 'test_di',
+ category: 'cat1',
+ type: 1,
+ action: 3,
+ enabledMark: 1,
+ sortCode: 0,
+ hasPage: 1,
+ isPostPosition: 0,
+ })
+ expect(r.ok).toBe(true)
+ })
+
+ it('type=1 SQL 但 action 空 → 拦截', () => {
+ const r = validateDiUpdate({
+ fullName: 'X',
+ enCode: 'xtest',
+ category: 'c',
+ type: 1,
+ action: undefined, // type=1 必填
+ })
+ expect(r.steps[1].errors.some((e) => e.field === 'action')).toBe(true)
+ })
+
+ it('type=2 静态 hasPage=1 不合理 → 拦截', () => {
+ const r = validateDiUpdate({
+ fullName: 'X',
+ enCode: 'xtest',
+ category: 'c',
+ type: 2,
+ action: 1,
+ hasPage: 1, // type=2 不建议启用分页
+ })
+ expect(r.steps[1].errors.some((e) => e.field === 'hasPage')).toBe(true)
+ })
+
+ it('enCode 无正则 (web 端 di 不强制正则, 与 menu/dict 不同)', () => {
+ const r = validateDiUpdate({
+ fullName: 'X',
+ enCode: 'bad_underscore', // 应允许, 无正则
+ category: 'c',
+ type: 2,
+ })
+ // 不应触发 enCode 正则校验
+ expect(r.steps[0].errors.some((e) => e.field === 'enCode' && e.message.includes('正则'))).toBe(false)
+ })
+
+ it('fullName 重复 → EXIST001', () => {
+ const r = validateDiUpdate({
+ fullName: '重复 DI',
+ enCode: 'new_di',
+ category: 'c',
+ type: 2,
+ existingDIs: [{ fullName: '重复 DI', enCode: 'old', id: 'other' }],
+ })
+ expect(r.steps[2].errors.some((e) => e.code === 'EXIST001')).toBe(true)
+ })
+})
\ No newline at end of file
diff --git a/tests/e2e/step-machine/dict-validate.test.ts b/tests/e2e/step-machine/dict-validate.test.ts
new file mode 100644
index 0000000..493bdd9
--- /dev/null
+++ b/tests/e2e/step-machine/dict-validate.test.ts
@@ -0,0 +1,66 @@
+/**
+ * vitest test: dict/_validate.ts (Phase D2 E2E 自动化)
+ */
+import { describe, it, expect } from 'vitest'
+import { validateDictTypeCreate } from '../../../src/commands/dict/_validate.ts'
+
+describe('dict/_validate.ts step machine', () => {
+ it('成功路径: 合法 fullName + enCode + parentId', () => {
+ const r = validateDictTypeCreate({
+ parentId: '0',
+ fullName: '测试字典',
+ enCode: 'test_dict',
+ isTree: 0,
+ sortCode: 0,
+ })
+ expect(r.ok).toBe(true)
+ })
+
+ it('enCode 重复 → EXIST002 (BS-47)', () => {
+ const r = validateDictTypeCreate({
+ parentId: '0',
+ fullName: '新字典',
+ enCode: 'dup_dict',
+ isTree: 0,
+ sortCode: 0,
+ existingTypes: [{ fullName: '已存在', enCode: 'dup_dict' }],
+ })
+ expect(r.steps[1].errors.some((e) => e.code === 'EXIST002')).toBe(true)
+ })
+
+ it('fullName 重复 → EXIST001 (BS-47)', () => {
+ const r = validateDictTypeCreate({
+ parentId: '0',
+ fullName: '重复字典',
+ enCode: 'new_dict',
+ isTree: 0,
+ sortCode: 0,
+ existingTypes: [{ fullName: '重复字典', enCode: 'existing' }],
+ })
+ expect(r.steps[1].errors.some((e) => e.code === 'EXIST001')).toBe(true)
+ })
+
+ it('enCode 含下划线 → 拦截', () => {
+ const r = validateDictTypeCreate({
+ parentId: '0',
+ fullName: 'X',
+ enCode: 'bad_underscore',
+ isTree: 0,
+ sortCode: 0,
+ })
+ expect(r.steps[0].errors.some((e) => e.field === 'enCode')).toBe(true)
+ })
+
+ it('items enCode 重复 → 拦截', () => {
+ const r = validateDictTypeCreate({
+ parentId: '0',
+ fullName: 'X',
+ enCode: 'xtest',
+ items: [
+ { enCode: 'dup_item', fullName: 'X1' },
+ { enCode: 'dup_item', fullName: 'X2' },
+ ],
+ })
+ expect(r.steps[2].errors.some((e) => e.message.includes('已重复'))).toBe(true)
+ })
+})
\ No newline at end of file
diff --git a/tests/e2e/step-machine/dm-validate.test.ts b/tests/e2e/step-machine/dm-validate.test.ts
new file mode 100644
index 0000000..e4c2f6f
--- /dev/null
+++ b/tests/e2e/step-machine/dm-validate.test.ts
@@ -0,0 +1,65 @@
+/**
+ * vitest test: dm/_validate.ts (Phase D2 E2E 自动化)
+ */
+import { describe, it, expect } from 'vitest'
+import { validateDmCreate } from '../../../src/commands/dm/_validate.ts'
+
+describe('dm/_validate.ts step machine', () => {
+ it('成功路径: 合法 table + 字段 + 主键', () => {
+ const r = validateDmCreate({
+ table: 'MyTable',
+ tableName: '测试表',
+ fields: [
+ { field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 0 },
+ { field: 'f_name', fieldName: '名称', dataType: 'varchar', dataLength: '100', allowNull: 0 },
+ ],
+ })
+ expect(r.ok).toBe(true)
+ })
+
+ it('dataType 非法 → 拦截', () => {
+ const r = validateDmCreate({
+ table: 'MyTable',
+ tableName: '测试表',
+ fields: [
+ { field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 0 },
+ { field: 'f_bad', fieldName: '坏', dataType: 'BLOB', allowNull: 0 }, // 不在白名单
+ ],
+ })
+ expect(r.ok).toBe(false)
+ expect(r.steps[1].errors.some((e) => e.field?.includes('dataType'))).toBe(true)
+ })
+
+ it('字段与系统列冲突 (f_description) → 拦截', () => {
+ const r = validateDmCreate({
+ table: 'MyTable',
+ tableName: '测试表',
+ fields: [
+ { field: 'f_description', fieldName: '描述', dataType: 'text', allowNull: 0 }, // 系统自动注入列冲突
+ ],
+ })
+ expect(r.steps[1].errors.some((e) => e.message.includes('系统自动注入列冲突'))).toBe(true)
+ })
+
+ it('主键 allowNull=1 → 拦截', () => {
+ const r = validateDmCreate({
+ table: 'MyTable',
+ tableName: '测试表',
+ fields: [
+ { field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 1 },
+ ],
+ })
+ expect(r.steps[1].errors.some((e) => e.field?.includes('allowNull'))).toBe(true)
+ })
+
+ it('Java 关键字作表名 → 拦截', () => {
+ const r = validateDmCreate({
+ table: 'class', // Java 关键字
+ tableName: '测试表',
+ fields: [
+ { field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 0 },
+ ],
+ })
+ expect(r.steps[2].errors.some((e) => e.field === 'table')).toBe(true)
+ })
+})
\ No newline at end of file
diff --git a/tests/e2e/step-machine/form-validate.test.ts b/tests/e2e/step-machine/form-validate.test.ts
new file mode 100644
index 0000000..f7cdf4c
--- /dev/null
+++ b/tests/e2e/step-machine/form-validate.test.ts
@@ -0,0 +1,82 @@
+/**
+ * vitest test: form/_validate.ts (Phase D2 E2E 自动化)
+ *
+ * 测试 validateBasicInfo/validateFormData/validateColumnData/validateFormCreate
+ * 触发条件: 纯函数测试, 无副作用
+ */
+import { describe, it, expect } from 'vitest'
+import { validateFormCreate } from '../../../src/commands/form/_validate.ts'
+
+describe('form/_validate.ts step machine', () => {
+ it('成功路径: 合法 fullName + enCode + tables + formData', () => {
+ const r = validateFormCreate({
+ fullName: '测试表单',
+ enCode: 'test_form_v1',
+ type: 1,
+ webType: 1,
+ tables: [{ table: 'test_table', tableName: '测试表' }],
+ formData: {
+ fields: [
+ {
+ __config__: { formId: 'f_name', label: '名称', layout: 'colFormItem' },
+ __vModel__: 'f_name',
+ },
+ ],
+ },
+ columnData: { columnList: [] },
+ })
+ expect(r.ok).toBe(true)
+ })
+
+ it('enCode 含下划线开头 → VS030', () => {
+ const r = validateFormCreate({
+ fullName: 'X',
+ enCode: '_bad', // _xxx 允许, 但 _bad 不行 (正则不允许 _xxx 之外的 _ 开头)
+ type: 1,
+ webType: 1,
+ tables: [],
+ formData: { fields: [] },
+ columnData: { columnList: [] },
+ })
+ expect(r.steps.some((s) => s.errors.some((e) => e.code === 'VS030'))).toBe(true)
+ })
+
+ it('formData 空 → VS401', () => {
+ const r = validateFormCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 1,
+ webType: 1,
+ tables: [],
+ formData: null,
+ columnData: { columnList: [] },
+ })
+ expect(r.steps.some((s) => s.errors.some((e) => e.code === 'VS401'))).toBe(true)
+ })
+
+ it('webType≠1 但 columnList 空 → VS402', () => {
+ const r = validateFormCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 1,
+ webType: 2, // 表单+列表
+ tables: [],
+ formData: { fields: [{ __config__: { formId: 'x', label: 'x', layout: 'colFormItem' }, __vModel__: 'x' }] },
+ columnData: { columnList: [] }, // 空 → 错
+ })
+ expect(r.steps.some((s) => s.errors.some((e) => e.code === 'VS402'))).toBe(true)
+ })
+
+ it('fullName 空 → 拦截 (无 code, 必填校验)', () => {
+ const r = validateFormCreate({
+ fullName: '',
+ enCode: 'xtest',
+ type: 1,
+ webType: 1,
+ tables: [],
+ formData: { fields: [] },
+ columnData: { columnList: [] },
+ })
+ expect(r.ok).toBe(false)
+ })
+})
\ No newline at end of file
diff --git a/tests/e2e/step-machine/menu-validate.test.ts b/tests/e2e/step-machine/menu-validate.test.ts
new file mode 100644
index 0000000..a830093
--- /dev/null
+++ b/tests/e2e/step-machine/menu-validate.test.ts
@@ -0,0 +1,87 @@
+/**
+ * vitest test: menu/_validate.ts (Phase D2 E2E 自动化)
+ */
+import { describe, it, expect } from 'vitest'
+import { validateMenuCreate } from '../../../src/commands/menu/_validate.ts'
+
+describe('menu/_validate.ts step machine', () => {
+ it('成功路径: 合法 fullName + enCode + type=3 + formId + 菜单树', () => {
+ const r = validateMenuCreate({
+ fullName: '测试菜单',
+ enCode: 'test.menu',
+ type: 3,
+ icon: 'icon-ym',
+ formId: 'fake-form-id',
+ form: { id: 'fake-form-id', enCode: 'test_form', webType: 1, state: 1 },
+ parentId: '-1',
+ formIdMode: false,
+ menuTree: [],
+ })
+ // 注意: enCode 含 . 应触发 EXIST003 (web 端 enCode 不允许下划线, 允许点)
+ expect(r.steps.length).toBe(4) // step 0/1/2/3
+ })
+
+ it('type=3 当 parent (jnpf-menu-display-issue 复盘) → 拦截', () => {
+ const r = validateMenuCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 3,
+ icon: 'icon-ym',
+ formId: undefined,
+ form: null,
+ parentId: 'parent-id-3', // type=3 不能当 parent
+ formIdMode: false,
+ menuTree: [
+ { id: 'parent-id-3', type: 3, fullName: '子菜单', parentId: '-1' },
+ ],
+ })
+ expect(r.steps[2].errors.length).toBeGreaterThan(0)
+ })
+
+ it('type 非法 → 拦截', () => {
+ const r = validateMenuCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 99, // 非法
+ icon: 'icon-ym',
+ formId: undefined,
+ form: null,
+ parentId: '-1',
+ formIdMode: false,
+ menuTree: [],
+ })
+ expect(r.steps[0].errors.some((e) => e.field === 'type')).toBe(true)
+ })
+
+ it('form 未发布 → 拦截', () => {
+ const r = validateMenuCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 3,
+ icon: 'icon-ym',
+ formId: 'fake-form-id',
+ form: { id: 'fake-form-id', enCode: 'test_form', webType: 1, state: 0 }, // 草稿
+ parentId: '-1',
+ formIdMode: false,
+ menuTree: [],
+ })
+ expect(r.steps[1].errors.some((e) => e.field === 'formId')).toBe(true)
+ })
+
+ it('enCode 唯一性预校验 → EXIST002', () => {
+ const r = validateMenuCreate({
+ fullName: 'X',
+ enCode: 'dupmenu',
+ type: 1,
+ icon: 'icon-ym',
+ formId: undefined,
+ form: null,
+ parentId: '-1',
+ formIdMode: false,
+ menuTree: [
+ { id: 'existing', type: 1, enCode: 'dupmenu', parentId: '-1' },
+ ],
+ })
+ expect(r.steps[3].errors.some((e) => e.code === 'EXIST002')).toBe(true)
+ })
+})
\ No newline at end of file
diff --git a/tests/e2e/step-machine/role-validate.test.ts b/tests/e2e/step-machine/role-validate.test.ts
new file mode 100644
index 0000000..797d67e
--- /dev/null
+++ b/tests/e2e/step-machine/role-validate.test.ts
@@ -0,0 +1,56 @@
+/**
+ * vitest test: role/_validate.ts (Phase D2 E2E 自动化)
+ */
+import { describe, it, expect } from 'vitest'
+import { validateRoleCreate } from '../../../src/commands/role/_validate.ts'
+
+describe('role/_validate.ts step machine', () => {
+ it('成功路径: 合法 fullName + enCode + type', () => {
+ const r = validateRoleCreate({
+ fullName: '测试角色',
+ enCode: 'test_role',
+ type: 0,
+ enabledMark: 1,
+ sortCode: 0,
+ })
+ expect(r.ok).toBe(true)
+ })
+
+ it('enCode 含下划线 → 拦截', () => {
+ const r = validateRoleCreate({
+ fullName: 'X',
+ enCode: 'bad_underscore',
+ type: 0,
+ })
+ expect(r.steps[0].errors.some((e) => e.field === 'enCode')).toBe(true)
+ })
+
+ it('type 非法 → 拦截', () => {
+ const r = validateRoleCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 9,
+ })
+ expect(r.steps[0].errors.some((e) => e.field === 'type')).toBe(true)
+ })
+
+ it('isCondition=true 但 constraintType 空 → 拦截', () => {
+ const r = validateRoleCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ type: 0,
+ isCondition: 1,
+ })
+ expect(r.steps[1].errors.some((e) => e.field === 'constraintType')).toBe(true)
+ })
+
+ it('enCode 全平台唯一 → EXIST002 (BS-47)', () => {
+ const r = validateRoleCreate({
+ fullName: 'X',
+ enCode: 'dup_role',
+ type: 0,
+ existingRoles: [{ fullName: '已存在', enCode: 'dup_role', type: 0 }],
+ })
+ expect(r.steps[2].errors.some((e) => e.code === 'EXIST002')).toBe(true)
+ })
+})
\ No newline at end of file
diff --git a/tests/e2e/step-machine/workflow-validate.test.ts b/tests/e2e/step-machine/workflow-validate.test.ts
new file mode 100644
index 0000000..73938ef
--- /dev/null
+++ b/tests/e2e/step-machine/workflow-validate.test.ts
@@ -0,0 +1,85 @@
+/**
+ * vitest test: workflow/_validate.ts (Phase D2 E2E 自动化)
+ */
+import { describe, it, expect } from 'vitest'
+import { validateWorkflowCreate } from '../../../src/commands/workflow/_validate.ts'
+
+describe('workflow/_validate.ts step machine', () => {
+ it('成功路径: 合法 fullName + enCode + category + icon + flowXml', () => {
+ const r = validateWorkflowCreate({
+ fullName: '测试流程',
+ enCode: 'test.flow',
+ category: 'workflow_category',
+ icon: 'icon-ym icon-ym-flow',
+ showType: 0,
+ type: 0,
+ flowXml: '',
+ flowNodes: {
+ start: { nodeType: 'startEvent' },
+ end: { nodeType: 'endEvent' },
+ },
+ })
+ expect(r.ok).toBe(true)
+ })
+
+ it('flowXml 不是合法 BPMN → 拦截', () => {
+ const r = validateWorkflowCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ category: 'c',
+ icon: 'i',
+ showType: 0,
+ type: 0,
+ flowXml: 'not xml',
+ flowNodes: {},
+ })
+ expect(r.steps[1].errors.some((e) => e.field === 'flowXml')).toBe(true)
+ })
+
+ it('flowNodes 缺 start 节点 → 拦截 (BS-45)', () => {
+ const r = validateWorkflowCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ category: 'c',
+ icon: 'i',
+ showType: 0,
+ type: 0,
+ flowXml: '',
+ flowNodes: {
+ end: { nodeType: 'endEvent' },
+ },
+ })
+ expect(r.steps[1].errors.some((e) => e.message.includes('开始节点'))).toBe(true)
+ })
+
+ it('flowNodes 缺 end 节点 → 拦截 (BS-45)', () => {
+ const r = validateWorkflowCreate({
+ fullName: 'X',
+ enCode: 'xtest',
+ category: 'c',
+ icon: 'i',
+ showType: 0,
+ type: 0,
+ flowXml: '',
+ flowNodes: {
+ start: { nodeType: 'startEvent' },
+ },
+ })
+ expect(r.steps[1].errors.some((e) => e.message.includes('结束节点'))).toBe(true)
+ })
+
+ it('enCode 唯一性预校验 → WF054', () => {
+ const r = validateWorkflowCreate({
+ fullName: 'X',
+ enCode: 'dupflow',
+ category: 'c',
+ icon: 'i',
+ showType: 0,
+ type: 0,
+ flowXml: '',
+ flowNodes: { start: { nodeType: 'startEvent' }, end: { nodeType: 'endEvent' } },
+ existingEnCodes: ['dupflow'],
+ })
+ expect(r.steps[2].errors.some((e) => e.code === 'WF054')).toBe(true)
+ })
+})
\ No newline at end of file