diff --git a/tests/unit/_browser_construct.test.ts b/tests/unit/_browser_construct.test.ts
deleted file mode 100644
index 63b9e6e..0000000
--- a/tests/unit/_browser_construct.test.ts
+++ /dev/null
@@ -1,281 +0,0 @@
-// dacli/tests/unit/_browser_construct.test.ts
-/**
- * _browser_construct 单元测试
- *
- * 覆盖:
- * - sampleValueForJnpfKey: 静态字段 8 种 (含 v12 decimal 修复)
- * - buildSamples: select/radio/checkbox 静态 enum (跳过网络)
- * - buildSamples: 13 种 skip 类型 (workSystem 实测)
- *
- * 网络拉取 (字典/数据接口/系统选择器) 留到 Task 1.5+ 集成测试
- */
-import { describe, it, expect } from 'vitest'
-import {
- sampleValueForJnpfKey,
- buildSamples,
- MissingSampleError,
- type FieldConfig,
-} from '../../src/commands/form/_browser_construct'
-
-describe('sampleValueForJnpfKey - 静态字段 (v0.7 + v12 decimal 修复)', () => {
- it('input 文本字段 → string', () => {
- expect(sampleValueForJnpfKey('f_name', 'input')).toMatch(/^test-/)
- expect(sampleValueForJnpfKey('f_fullName', 'input')).toMatch(/^test-/)
- })
-
- it('inputNumber 整数 → number', () => {
- expect(sampleValueForJnpfKey('f_age', 'inputNumber')).toBe(18)
- expect(sampleValueForJnpfKey('f_count', 'inputNumber')).toBe(18)
- })
-
- it('inputNumber 金额字段 (decimal) → number 含小数 (v12 盲点 32 修复)', () => {
- expect(sampleValueForJnpfKey('f_amount', 'inputNumber')).toBe(99.99)
- expect(sampleValueForJnpfKey('f_money', 'inputNumber')).toBe(99.99)
- expect(sampleValueForJnpfKey('f_price', 'inputNumber')).toBe(99.99)
- expect(sampleValueForJnpfKey('f_total', 'inputNumber')).toBe(99.99)
- expect(sampleValueForJnpfKey('f_sum', 'inputNumber')).toBe(99.99)
- expect(sampleValueForJnpfKey('f_cost', 'inputNumber')).toBe(99.99)
- expect(sampleValueForJnpfKey('f_fee', 'inputNumber')).toBe(99.99)
- })
-
- it('inputNumber 含 amount/money/price/total/sum/cost/fee 关键词才走 decimal, 其它走整数', () => {
- expect(sampleValueForJnpfKey('f_qty', 'inputNumber')).toBe(18)
- expect(sampleValueForJnpfKey('f_score', 'inputNumber')).toBe(18)
- })
-
- it('textarea 多行文本 → string', () => {
- expect(sampleValueForJnpfKey('f_remark', 'textarea')).toMatch(/^test-/)
- })
-
- it('datePicker → YYYY-MM-DD', () => {
- expect(sampleValueForJnpfKey('f_date', 'datePicker')).toMatch(/^\d{4}-\d{2}-\d{2}$/)
- })
-
- it('editor 富文本 → HTML', () => {
- expect(sampleValueForJnpfKey('f_content', 'editor')).toMatch(/^
test-/)
- })
-
- it('switch/rate/slider/colorPicker 静态', () => {
- expect(sampleValueForJnpfKey('f_on', 'switch')).toBe(true)
- expect(sampleValueForJnpfKey('f_star', 'rate')).toBe(5)
- expect(sampleValueForJnpfKey('f_pct', 'slider')).toBe(50)
- expect(sampleValueForJnpfKey('f_color', 'colorPicker')).toBe('#1890ff')
- })
-})
-
-describe('select/radio/checkbox 静态 enum (无网络)', () => {
- it('select 有 options → 选第 1 项 value', async () => {
- const cfg: FieldConfig = {
- jnpfKey: 'select',
- label: '车头型号',
- required: false,
- fieldKey: 'f_type',
- options: [
- { value: '1', label: '奔驰' },
- { value: '2', label: '宝马' },
- ],
- }
- const samples = await buildSamples({ fields: [cfg] }, { skipNetwork: true })
- expect(samples[0].value).toBe('1')
- expect(samples[0].skip).toBe(false)
- })
-
- it('radio 有 options → 选第 1 项', async () => {
- const cfg: FieldConfig = {
- jnpfKey: 'radio',
- label: '性别',
- required: true,
- fieldKey: 'f_gender',
- options: [
- { value: '1', label: '男' },
- { value: '2', label: '女' },
- ],
- }
- const samples = await buildSamples({ fields: [cfg] }, { skipNetwork: true })
- expect(samples[0].value).toBe('1')
- })
-
- it('checkbox 多选 → 选第 1 项数组', async () => {
- const cfg: FieldConfig = {
- jnpfKey: 'checkbox',
- label: '增补原因',
- required: false,
- fieldKey: 'f_reason',
- options: [
- { value: 'a', label: 'A' },
- { value: 'b', label: 'B' },
- ],
- }
- const samples = await buildSamples({ fields: [cfg] }, { skipNetwork: true })
- expect(samples[0].value).toEqual(['a'])
- })
-
- it('select 无 options + 必填 → 必填错误', async () => {
- const cfg: FieldConfig = {
- jnpfKey: 'select',
- label: '车头',
- required: true,
- fieldKey: 'f_type',
- }
- await expect(
- buildSamples({ fields: [cfg] }, { skipNetwork: true })
- ).rejects.toThrow(MissingSampleError)
- })
-
- it('select 无 options + 非必填 → skip=true (不抛错)', async () => {
- const cfg: FieldConfig = {
- jnpfKey: 'select',
- label: '可选车头',
- required: false,
- fieldKey: 'f_type',
- }
- const samples = await buildSamples({ fields: [cfg] }, { skipNetwork: true })
- expect(samples[0].skip).toBe(true)
- expect(samples[0].reason).toBe('select 无 options')
- })
-
- it('select 有 dictionaryType 但 skipNetwork=true → 非必填 skip, 必填抛错', async () => {
- const cfg: FieldConfig = {
- jnpfKey: 'select',
- label: '状态',
- required: true,
- fieldKey: 'f_status',
- dictionaryType: 'user_status',
- }
- await expect(
- buildSamples({ fields: [cfg] }, { skipNetwork: true })
- ).rejects.toThrow(MissingSampleError)
- })
-})
-
-describe('skip 类型 (workSystem 13 种)', () => {
- it.each([
- 'billRule',
- 'createUser', 'createTime', 'modifyUser', 'modifyTime',
- 'calculate',
- 'uploadFile',
- 'qrcode',
- 'groupTitle', 'divider', 'row', 'carousel',
- 'popupSelect', 'popupTableSelect', 'popupAttr', 'autoComplete',
- 'tableGrid',
- 'table',
- ])('%s → skip=true', async (jnpfKey) => {
- const samples = await buildSamples(
- { fields: [{ jnpfKey, label: 'X', required: false, fieldKey: 'f_x' }] },
- { skipNetwork: true }
- )
- expect(samples[0].skip).toBe(true)
- expect(samples[0].reason).toBe(jnpfKey)
- })
-})
-
-describe('skip 字段即使 required 也不抛错', () => {
- it('table 必填 → skip=true 不抛 MissingSampleError', async () => {
- const samples = await buildSamples(
- {
- fields: [
- { jnpfKey: 'table', label: '子表', required: true, fieldKey: 'f_sub' },
- ],
- },
- { skipNetwork: true }
- )
- expect(samples[0].skip).toBe(true)
- expect(samples[0].reason).toBe('table')
- })
-})
-
-describe('MissingSampleError', () => {
- it('含 fieldKey + reason 属性', () => {
- const err = new MissingSampleError('f_name', 'no options')
- expect(err.fieldKey).toBe('f_name')
- expect(err.reason).toBe('no options')
- expect(err.message).toContain('f_name')
- expect(err.message).toContain('no options')
- expect(err.name).toBe('MissingSampleError')
- })
-})
-
-// ============================================================
-// Task 1.6: 工作流字段 (leaveApply flowTitle/flowUrgent)
-// ============================================================
-describe('工作流字段 (leaveApply)', () => {
- it('flowTitle → 静态 sample text', async () => {
- const samples = await buildSamples(
- {
- fields: [
- { jnpfKey: 'input', label: '流程标题', required: true, fieldKey: 'flowTitle' },
- ],
- },
- { skipNetwork: true }
- )
- expect(samples[0].value).toMatch(/^test-/)
- expect(samples[0].skip).toBeFalsy()
- })
-
- it('flowUrgent → 静态 sample text', async () => {
- const samples = await buildSamples(
- {
- fields: [
- { jnpfKey: 'input', label: '紧急情况', required: true, fieldKey: 'flowUrgent' },
- ],
- },
- { skipNetwork: true }
- )
- expect(samples[0].value).toMatch(/^test-/)
- })
-})
-
-// ============================================================
-// Task 1.7: 真实 form schema 集成 (workSystem leaveApply + paymentapply)
-// ============================================================
-describe('真实 form schema 集成 (workSystem)', () => {
- it('leaveApply 15 字段 (formId=1589964488616407041)', async () => {
- // 模拟 leaveApply formData 解析后的 fields
- const fields: FieldConfig[] = [
- { jnpfKey: 'input', label: '流程标题', required: true, fieldKey: 'flowTitle' },
- { jnpfKey: 'input', label: '紧急情况', required: true, fieldKey: 'flowUrgent' },
- { jnpfKey: 'userSelect', label: '申请人员', required: false, fieldKey: 'applyUser' },
- { jnpfKey: 'datePicker', label: '申请日期', required: false, fieldKey: 'applyDate' },
- { jnpfKey: 'organizeSelect', label: '申请部门', required: false, fieldKey: 'applyDept' },
- { jnpfKey: 'input', label: '申请职位', required: false, fieldKey: 'applyPost' },
- { jnpfKey: 'select', label: '请假类别', required: true, fieldKey: 'leaveType' }, // 缺 options + skipNetwork
- { jnpfKey: 'textarea', label: '请假原因', required: true, fieldKey: 'leaveReason' },
- { jnpfKey: 'datePicker', label: '起始时间', required: true, fieldKey: 'leaveStartTime' },
- { jnpfKey: 'datePicker', label: '结束时间', required: true, fieldKey: 'leaveEndTime' },
- { jnpfKey: 'inputNumber', label: '请假天数', required: true, fieldKey: 'leaveDayCount' },
- { jnpfKey: 'inputNumber', label: '请假小时', required: true, fieldKey: 'leaveHour' },
- { jnpfKey: 'uploadFile', label: '相关附件', required: false, fieldKey: 'fileJson' },
- { jnpfKey: 'textarea', label: '请假备注', required: false, fieldKey: 'description' },
- { jnpfKey: 'input', label: '流程单据', required: false, fieldKey: 'billNo' },
- ]
- await expect(
- buildSamples({ fields }, { skipNetwork: true })
- ).rejects.toThrow(MissingSampleError) // leaveType 必填 select 缺 options
- })
-
- it('paymentapply 7 字段 (formId=585398402720727621) - 金额字段 decimal 修复', async () => {
- const fields: FieldConfig[] = [
- { jnpfKey: 'datePicker', label: '申请日期', required: true, fieldKey: 'f_date' },
- { jnpfKey: 'organizeSelect', label: '申请部门', required: true, fieldKey: 'f_dept' },
- { jnpfKey: 'userSelect', label: '申请人', required: false, fieldKey: 'f_applicant' },
- { jnpfKey: 'textarea', label: '申请事由', required: false, fieldKey: 'f_reason' },
- { jnpfKey: 'input', label: '开户银行', required: false, fieldKey: 'f_bank' },
- { jnpfKey: 'input', label: '账户', required: true, fieldKey: 'f_account' },
- { jnpfKey: 'inputNumber', label: '款项金额', required: true, fieldKey: 'f_amount' }, // 金额 → 99.99
- ]
- const samples = await buildSamples({ fields }, { skipNetwork: true })
- expect(samples).toHaveLength(7)
- expect(samples[6].value).toBe(99.99) // v12 decimal 修复
- })
-
- it('paymentapply 非 skipNetwork 模式跑通真 JNPF API (用户/组织)', async () => {
- const fields: FieldConfig[] = [
- { jnpfKey: 'userSelect', label: '申请人', required: false, fieldKey: 'f_applicant' },
- { jnpfKey: 'organizeSelect', label: '申请部门', required: true, fieldKey: 'f_dept' },
- ]
- const samples = await buildSamples({ fields })
- // 真实 JNPF 跑, 申请部门应取到 (因为 workSystem 默认有公司)
- expect(samples[0]).toHaveProperty('value') // userSelect 可能 null (无用户), 但不抛
- expect(samples[1].skip).toBeFalsy() // 必填 org 应有值
- }, 30000) // 网络调用 30s timeout
-})
diff --git a/tests/unit/app.test.ts b/tests/unit/app.test.ts
deleted file mode 100644
index 4f3be86..0000000
--- a/tests/unit/app.test.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * app.test.ts — app 父命令烟囱测试
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; stderr?: Buffer | string }
- return ((err.stdout?.toString() || '') + (err.stderr?.toString() || ''))
- }
-}
-
-describe('app command tree (W9-D1)', () => {
- it('app --help 列出 8 个子命令 (v0.9+: 归并 login/status/switch/init + clear)', () => {
- const out = run(['app', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('info')
- expect(out).toContain('init')
- expect(out).toContain('create')
- expect(out).toContain('clear')
- expect(out).toContain('login')
- expect(out).toContain('status')
- expect(out).toContain('switch')
- })
-
- it('app list --ai-help 含 API 路径', () => {
- const out = run(['app', 'list', '--ai-help'])
- expect(out).toContain('/api/system/System')
- })
-
- it('app info --help 包含 --id', () => {
- const out = run(['app', 'info', '--help'])
- expect(out).toContain('--id')
- })
-
- it('app init --help 包含 --appCode 和 --restart (原 initapp, v0.9 简化)', () => {
- const out = run(['app', 'init', '--help'])
- expect(out).toContain('--appCode')
- expect(out).toContain('--restart')
- })
-
- it('顶层 --help 包含 app', () => {
- const out = run(['--help'])
- expect(out).toContain('app')
- })
-})
-
-describe('app clear (移植自 Java 版 ClearAppCommand.java)', () => {
- it('app clear --help 含 5 个 flag', () => {
- const out = run(['app', 'clear', '--help'])
- expect(out).toContain('--appCode')
- expect(out).toContain('--dry-run')
- expect(out).toContain('--skip-db')
- expect(out).toContain('--no-restart')
- expect(out).toContain('--workspace')
- })
-
- it('app clear --ai-help 含完整 purpose/required/optional/example/source/notes', () => {
- const out = run(['app', 'clear', '--ai-help'])
- expect(out).toContain('## 用途')
- expect(out).toContain('## 必传参数')
- expect(out).toContain('## 可选参数')
- expect(out).toContain('## 来源')
- expect(out).toContain('## 例子')
- expect(out).toContain('## 注意')
- expect(out).toContain('history_bak')
- expect(out).toContain('Phase 1/2/3')
- expect(out).toContain('--appCode=tds2')
- })
-
- it('app clear --appCode=BAD_CODE (大写) 报格式不合法 (regex fail)', () => {
- const out = run(['app', 'clear', '--appCode=BAD_CODE'])
- expect(out).toContain('app-code 格式不合法')
- expect(out).toContain('BAD_CODE')
- })
-
- it('app clear --appCode=bad-code!@# (含特殊字符) 报格式不合法', () => {
- const out = run(['app', 'clear', '--appCode=bad-code!@#'])
- expect(out).toContain('app-code 格式不合法')
- })
-
- it('app clear --appCode=neverexist --workspace=/tmp/nonexistent_xyz 报工程根目录不存在', () => {
- const out = run(['app', 'clear', '--appCode=neverexist', '--workspace=/tmp/nonexistent_xyz_2026'])
- expect(out).toContain('工程根目录不存在')
- })
-
- it('app clear --appCode=neverexist --dry-run --workspace= 不报错 (无任何资源时静默退出)', () => {
- // 实际跑在工程根目录, 但 appCode=neverexistxyz123 不存在 → 0 资源 → 静默
- const out = run(['app', 'clear', '--appCode=neverexistxyz123', '--dry-run'])
- expect(out).toContain('没有找到任何需要清理的资源')
- })
-})
diff --git a/tests/unit/cli-help.test.ts b/tests/unit/cli-help.test.ts
deleted file mode 100644
index 0c2f697..0000000
--- a/tests/unit/cli-help.test.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * cli-help.test.ts — CLI --help / --version 烟囱测试
- *
- * 不依赖 JNPF, 只验证 commander 能解析命令树
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- // help/version 可能 exit non-zero, 取 stdout
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('cli help', () => {
- it('--version 输出 0.1.0', () => {
- const out = run(['--version'])
- expect(out).toContain('0.1.0')
- })
-
- it('--help 列出顶层命令 (v0.9 命名规范化: login/status/switchapp/initapp 全部归入 app)', () => {
- const out = run(['--help'])
- // 顶层不再有 login/status/switchapp
- expect(out).toContain('app')
- expect(out).toContain('form')
- // 顶层 --help 不再列 login/status/switchApp/initapp (它们现在在 app 下)
- expect(out).not.toMatch(/^\s+login\s/m)
- expect(out).not.toMatch(/^\s+status\s/m)
- expect(out).not.toMatch(/^\s+switchApp\s/m)
- })
-
- it('form --help 列出子命令', () => {
- const out = run(['form', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('info')
- expect(out).toContain('create')
- expect(out).toContain('release')
- expect(out).toContain('clone')
- expect(out).toContain('export')
- expect(out).toContain('import')
- expect(out).toContain('validate')
- })
-
- it('app login --ai-help 输出 markdown', () => {
- const out = run(['app', 'login', '--ai-help'])
- expect(out).toContain('# dacli app login')
- expect(out).toContain('## 用途')
- expect(out).toContain('admin')
- })
-
- it('form create --example 输出可执行命令', () => {
- const out = run(['form', 'create', '--example'])
- expect(out).toContain('dacli form create')
- })
-})
diff --git a/tests/unit/datasource.test.ts b/tests/unit/datasource.test.ts
deleted file mode 100644
index 6e64e55..0000000
--- a/tests/unit/datasource.test.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * datasource.test.ts — datasource 父命令烟囱测试
- *
- * 不依赖 JNPF, 只验证 commander 能解析命令树 + --ai-help/--example/--source
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('datasource command tree (W8-D1)', () => {
- it('datasource --help 列出 4 个子命令', () => {
- const out = run(['datasource', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('create')
- expect(out).toContain('test')
- expect(out).toContain('delete')
- })
-
- it('datasource list --help 描述正确', () => {
- const out = run(['datasource', 'list', '--help'])
- expect(out).toContain('列出数据源')
- })
-
- it('datasource create --help 包含 required 标记', () => {
- const out = run(['datasource', 'create', '--help'])
- expect(out).toContain('--fullName')
- expect(out).toContain('--enCode')
- expect(out).toContain('--dbType')
- expect(out).toContain('--host')
- expect(out).toContain('--port')
- expect(out).toContain('--user')
- })
-
- it('datasource test --help 包含 --id', () => {
- const out = run(['datasource', 'test', '--help'])
- expect(out).toContain('--id')
- })
-
- it('datasource delete --help 包含 --id 和 --yes', () => {
- const out = run(['datasource', 'delete', '--help'])
- expect(out).toContain('--id')
- expect(out).toContain('--yes')
- })
-
- it('datasource list --ai-help 输出 markdown', () => {
- const out = run(['datasource', 'list', '--ai-help'])
- expect(out).toContain('## 用途')
- expect(out).toContain('## 来源')
- expect(out).toContain('/api/system/DataSource')
- })
-
- it('datasource create --example 输出可执行命令', () => {
- const out = run(['datasource', 'create', '--example'])
- expect(out).toContain('dacli datasource create')
- expect(out).toContain('--dbType=MySQL')
- })
-
- it('datasource list --source 链接 web 源码', () => {
- const out = run(['datasource', 'list', '--source'])
- expect(out).toContain('web:')
- expect(out).toContain('api:')
- })
-
- it('顶层 --help 包含 datasource', () => {
- const out = run(['--help'])
- expect(out).toContain('datasource')
- })
-})
diff --git a/tests/unit/p2-monitor-log-integration.test.ts b/tests/unit/p2-monitor-log-integration.test.ts
deleted file mode 100644
index 20fdffc..0000000
--- a/tests/unit/p2-monitor-log-integration.test.ts
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * p2-monitor-log-integration.test.ts — P2 3 父命令烟囱测试
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('monitor command tree (W12-D1)', () => {
- it('monitor --help 列出 3 个子命令', () => {
- const out = run(['monitor', '--help'])
- expect(out).toContain('online')
- expect(out).toContain('sql')
- expect(out).toContain('flow')
- })
- it('monitor online --ai-help 含 API 路径', () => {
- const out = run(['monitor', 'online', '--ai-help'])
- expect(out).toContain('/api/system/OnlineUser')
- })
- it('monitor sql --help 包含 --id', () => {
- const out = run(['monitor', 'sql', '--help'])
- expect(out).toContain('--id')
- })
- it('monitor flow --ai-help 含 API 路径', () => {
- const out = run(['monitor', 'flow', '--ai-help'])
- expect(out).toContain('/api/workflow/monitor')
- })
- it('顶层 --help 包含 monitor', () => {
- const out = run(['--help'])
- expect(out).toContain('monitor')
- })
-})
-
-describe('log command tree (W12-D2)', () => {
- it('log --help 列出 2 个子命令', () => {
- const out = run(['log', '--help'])
- expect(out).toContain('login')
- expect(out).toContain('operate')
- })
- it('log login --ai-help 含 API 路径', () => {
- const out = run(['log', 'login', '--ai-help'])
- expect(out).toContain('/api/system/Log')
- })
- it('log operate --help 包含 --keyword', () => {
- const out = run(['log', 'operate', '--help'])
- expect(out).toContain('--keyword')
- })
- it('顶层 --help 包含 log', () => {
- const out = run(['--help'])
- expect(out).toContain('log')
- })
-})
-
-describe('integration command tree (W12-D3)', () => {
- it('integration --help 列出 3 个子命令', () => {
- const out = run(['integration', '--help'])
- expect(out).toContain('emailTest')
- expect(out).toContain('smsTest')
- expect(out).toContain('webhookTest')
- })
- it('integration emailtest --ai-help 提示决策 8', () => {
- const out = run(['integration', 'emailTest', '--ai-help'])
- expect(out).toContain('决策 8')
- expect(out).toContain('邮件')
- })
- it('integration smstest --help 包含 --phone', () => {
- const out = run(['integration', 'smsTest', '--help'])
- expect(out).toContain('--phone')
- })
- it('integration webhooktest --help 包含 --url/--payload', () => {
- const out = run(['integration', 'webhookTest', '--help'])
- expect(out).toContain('--url')
- expect(out).toContain('--payload')
- })
- it('顶层 --help 包含 integration', () => {
- const out = run(['--help'])
- expect(out).toContain('integration')
- })
-})
diff --git a/tests/unit/portal.test.ts b/tests/unit/portal.test.ts
deleted file mode 100644
index 03195e1..0000000
--- a/tests/unit/portal.test.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * portal.test.ts — portal 父命令烟囱测试
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('portal command tree (W8-D3)', () => {
- it('portal --help 列出 4 个子命令', () => {
- const out = run(['portal', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('info')
- expect(out).toContain('create')
- expect(out).toContain('release')
- })
-
- it('portal list --help 描述正确', () => {
- const out = run(['portal', 'list', '--help'])
- expect(out).toContain('门户')
- })
-
- it('portal list --ai-help 含 API 路径', () => {
- const out = run(['portal', 'list', '--ai-help'])
- expect(out).toContain('/api/visualdev/Portal')
- expect(out).toContain('web 源码')
- })
-
- it('portal create --ai-help 提示决策 6', () => {
- const out = run(['portal', 'create', '--ai-help'])
- expect(out).toContain('决策 6')
- expect(out).toContain('/api/visualdev/Portal')
- })
-
- it('portal info --help 包含 --id', () => {
- const out = run(['portal', 'info', '--help'])
- expect(out).toContain('--id')
- })
-
- it('portal create --help 包含 required 字段', () => {
- const out = run(['portal', 'create', '--help'])
- expect(out).toContain('--fullName')
- expect(out).toContain('--enCode')
- expect(out).toContain('--category')
- })
-
- it('portal release --help 包含 --id', () => {
- const out = run(['portal', 'release', '--help'])
- expect(out).toContain('--id')
- })
-
- it('顶层 --help 包含 portal', () => {
- const out = run(['--help'])
- expect(out).toContain('portal')
- })
-})
diff --git a/tests/unit/print-bigscreen.test.ts b/tests/unit/print-bigscreen.test.ts
deleted file mode 100644
index dab8d93..0000000
--- a/tests/unit/print-bigscreen.test.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * print-bigscreen.test.ts — print + bigscreen 父命令烟囱测试
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('print command tree (W9-D3)', () => {
- it('print --help 列出 3 个子命令', () => {
- const out = run(['print', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('info')
- expect(out).toContain('create')
- })
-
- it('print list --ai-help 含 API 路径', () => {
- const out = run(['print', 'list', '--ai-help'])
- expect(out).toContain('/api/system/printDev')
- })
-
- it('print info --help 包含 --id', () => {
- const out = run(['print', 'info', '--help'])
- expect(out).toContain('--id')
- })
-
- it('print create --ai-help 提示决策 6', () => {
- const out = run(['print', 'create', '--ai-help'])
- expect(out).toContain('决策 6')
- expect(out).toContain('printDev')
- })
-
- it('顶层 --help 包含 print', () => {
- const out = run(['--help'])
- expect(out).toContain('print')
- })
-})
-
-describe('bigscreen command tree (W9-D2)', () => {
- it('bigscreen --help 列出 4 个子命令', () => {
- const out = run(['bigscreen', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('info')
- expect(out).toContain('create')
- expect(out).toContain('release')
- })
-
- it('bigscreen list --ai-help 含 API 路径', () => {
- const out = run(['bigscreen', 'list', '--ai-help'])
- expect(out).toContain('/api/extend/BigData')
- })
-
- it('bigscreen info --help 提示无 /{id} 端点', () => {
- const out = run(['bigscreen', 'info', '--help'])
- expect(out).toContain('JNPF 大屏无 /{id} 端点')
- })
-
- it('bigscreen create --ai-help 提示决策 6', () => {
- const out = run(['bigscreen', 'create', '--ai-help'])
- expect(out).toContain('决策 6')
- })
-
- it('顶层 --help 包含 bigscreen', () => {
- const out = run(['--help'])
- expect(out).toContain('bigscreen')
- })
-})
diff --git a/tests/unit/report.test.ts b/tests/unit/report.test.ts
deleted file mode 100644
index d175af0..0000000
--- a/tests/unit/report.test.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * report.test.ts — report 父命令烟囱测试
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('report command tree (W8-D2)', () => {
- it('report --help 列出 3 个子命令 (JNPF 报表只读)', () => {
- const out = run(['report', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('info')
- expect(out).toContain('templates')
- })
-
- it('report list --help 描述正确', () => {
- const out = run(['report', 'list', '--help'])
- expect(out).toContain('只读模板')
- })
-
- it('report list --ai-help 输出 markdown 提示决策 6', () => {
- const out = run(['report', 'list', '--ai-help'])
- expect(out).toContain('决策 6')
- expect(out).toContain('ReportManage')
- })
-
- it('report templates --help 列出 5 个模板', () => {
- const out = run(['report', 'templates', '--help'])
- expect(out).toContain('Month')
- expect(out).toContain('Quarter')
- expect(out).toContain('Purchase')
- })
-
- it('report info --help 包含 --id', () => {
- const out = run(['report', 'info', '--help'])
- expect(out).toContain('--id')
- })
-
- it('顶层 --help 包含 report', () => {
- const out = run(['--help'])
- expect(out).toContain('report')
- })
-})
diff --git a/tests/unit/role-user-org.test.ts b/tests/unit/role-user-org.test.ts
deleted file mode 100644
index f2857d5..0000000
--- a/tests/unit/role-user-org.test.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * role-user-org.test.ts — 权限三角 3 父命令烟囱测试
- */
-import { describe, it, expect } from 'vitest'
-import { execFileSync } from 'node:child_process'
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-
-const __dirname = fileURLToPath(new URL('.', import.meta.url))
-const CLI = resolve(__dirname, '../../src/cli.ts')
-
-function run(args: string[]): string {
- try {
- return execFileSync('npx', ['tsx', CLI, ...args], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- timeout: 30_000,
- })
- } catch (e) {
- const err = e as { stdout?: Buffer | string; status?: number }
- return (err.stdout?.toString() || '')
- }
-}
-
-describe('role command tree (W10-D1)', () => {
- it('role --help 列出 4 个子命令', () => {
- const out = run(['role', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('create')
- expect(out).toContain('delete')
- expect(out).toContain('assign')
- })
- it('role list --ai-help 提示决策 7', () => {
- const out = run(['role', 'list', '--ai-help'])
- expect(out).toContain('决策 7')
- expect(out).toContain('/api/permission/Role')
- })
- it('role create --help 包含 --fullName/--enCode', () => {
- const out = run(['role', 'create', '--help'])
- expect(out).toContain('--fullName')
- expect(out).toContain('--enCode')
- })
- it('role delete --help 包含 --yes', () => {
- const out = run(['role', 'delete', '--help'])
- expect(out).toContain('--yes')
- })
- it('role assign --help 包含 --userIds/--action', () => {
- const out = run(['role', 'assign', '--help'])
- expect(out).toContain('--userIds')
- expect(out).toContain('--action')
- })
- it('顶层 --help 包含 role', () => {
- const out = run(['--help'])
- expect(out).toContain('role')
- })
-})
-
-describe('user command tree (W10-D2)', () => {
- it('user --help 列出 4 个子命令', () => {
- const out = run(['user', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('create')
- expect(out).toContain('delete')
- expect(out).toContain('resetPwd')
- })
- it('user list --ai-help 提示决策 7', () => {
- const out = run(['user', 'list', '--ai-help'])
- expect(out).toContain('决策 7')
- expect(out).toContain('/api/permission/Users')
- })
- it('user create --help 包含 --organizeId/--gender', () => {
- const out = run(['user', 'create', '--help'])
- expect(out).toContain('--organizeId')
- expect(out).toContain('--gender')
- })
- it('user resetpwd --help 包含 --password', () => {
- const out = run(['user', 'resetPwd', '--help'])
- expect(out).toContain('--password')
- })
- it('顶层 --help 包含 user', () => {
- const out = run(['--help'])
- expect(out).toContain('user')
- })
-})
-
-describe('org command tree (W10-D3)', () => {
- it('org --help 列出 3 个子命令', () => {
- const out = run(['org', '--help'])
- expect(out).toContain('list')
- expect(out).toContain('tree')
- expect(out).toContain('create')
- })
- it('org list --ai-help 提示决策 7', () => {
- const out = run(['org', 'list', '--ai-help'])
- expect(out).toContain('决策 7')
- expect(out).toContain('/api/permission/Organize/Selector')
- })
- it('org create --help 包含 --parentId/--category', () => {
- const out = run(['org', 'create', '--help'])
- expect(out).toContain('--parentId')
- expect(out).toContain('--category')
- })
- it('顶层 --help 包含 org', () => {
- const out = run(['--help'])
- expect(out).toContain('org')
- })
-})
diff --git a/tests/unit/workflow/create_stale_retry.test.ts b/tests/unit/workflow/create_stale_retry.test.ts
index 2c3993e..7809cf4 100644
--- a/tests/unit/workflow/create_stale_retry.test.ts
+++ b/tests/unit/workflow/create_stale_retry.test.ts
@@ -27,10 +27,27 @@ vi.mock('../../../src/webapi/workflow.ts', () => ({
loadWorkflow: { delFlow: mocks.mockDelFlow },
}))
-vi.mock('../../../src/core/log.ts', () => ({
- log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), ok: vi.fn() },
- printJson: vi.fn(),
-}))
+vi.mock('../../../src/core/log.ts', async () => {
+ // mock 必须覆盖 log 对象全部 9 个方法, 否则 commands/workflow/_output.ts
+ // 里的 setupOutputFilter (log.setQuiet) / printCommandEnd (log.flush/discard)
+ // 会 'log.setQuiet is not a function' 抛错 (2026-07-20 复盘发现).
+ return {
+ log: {
+ info: vi.fn(),
+ warn: vi.fn(),
+ error: vi.fn(),
+ ok: vi.fn(),
+ setQuiet: vi.fn(),
+ isQuiet: vi.fn(),
+ flush: vi.fn(),
+ discard: vi.fn(),
+ dim: vi.fn(),
+ raw: vi.fn(),
+ debug: vi.fn(),
+ },
+ printJson: vi.fn(),
+ }
+})
vi.mock('../../../src/commands/_error_codes.ts', () => ({
enhanceFromBackend: vi.fn(() => ({ bs: 'BS-新43b', message: 'stale' })),