铁律 3 严格镜像 (P0 修复): 删自创 getFlowTaskOperatorList, 改 _loader.ts 镜像 web/api/workFlow/task.ts:71-73 getFlowBeforeList (0 漂移, web 升级时自动同步). 新增: - src/webapi/operator.ts: loadOperator proxy 镜像 web task.ts (单进程缓存) - src/webapi/_vben_stores_shim.ts: Pinia useUserStore stub (task.ts:3 import) - src/webapi/_jnpf_utils_shim.ts: buildUUID + AesEncryption + buildBitUUID (task.ts:1 import) - src/webapi/_loader.ts step 5.6: @vben/stores shim 规则 - src/webapi/_loader.ts step 4 改: @jnpf/utils → _jnpf_utils_shim - tests/unit/webapi_operator.test.ts: 6 vitest (initWebapi + getFlowBeforeList 转发 + 边界) - tests/unit/workflow_launch_regression.test.ts: 7 vitest (L1 + L2 fixture 防回归) - tests/unit/relation_form_complete_regression.test.ts: 2 vitest (L4 同模式 BS-新146) - tests/unit/app_context_version_regression.test.ts: 5 vitest (BS-新152 currentVersion) - tests/unit/workflow_command_smoke.test.ts: 9 vitest (6 命令 0 测试覆盖补全) launch.ts: 改用 loadOperator.getFlowBeforeList (L116), 加 audit 注释 (L110-113) relation_form_complete.ts: L4 修 (--no-release 跟 BS-新146 L1 同模式) app/context.ts: BS-新152 修 (readCliVersion 路径 cli.ts → program.ts) quality-gate.sh + validate-baseline.sh: 删 L5 Prompt A/B (jnpf7 临时对照目录) vitest: 584 → 613 (+29), tsc 0 错, 5 关全过
101 lines
3.7 KiB
TypeScript
101 lines
3.7 KiB
TypeScript
/**
|
|
* tests/unit/webapi_operator.test.ts — webapi/operator.ts 单元测试 (P0 镜像回归)
|
|
*
|
|
* P0 修复 (v2.3, 2026-07-29): 删自创 getFlowTaskOperatorList, 改镜像 web task.ts:71-73 getFlowBeforeList.
|
|
* 此测试验证:
|
|
* 1. initWebapi 后 loadOperator.getFlowBeforeList 可调用 (走 _loader.ts 动态加载 web)
|
|
* 2. proxy 转发正确 (返回 web 端函数)
|
|
* 3. 未 initWebapi 时抛错
|
|
*
|
|
* Mock 策略: vi.mock 整个 webapi/operator.ts 模块, 用 stub 替换 initWebapi / loadOperator.getFlowBeforeList,
|
|
* 避免真的加载 web 源码 (web 源码依赖 defHttp shim, 链路长).
|
|
*/
|
|
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
|
|
const { mockGetFlowBeforeList, mockInitWebapi } = vi.hoisted(() => ({
|
|
mockGetFlowBeforeList: vi.fn(),
|
|
mockInitWebapi: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('/home/ubuntu/ccWorkDir/dacli/src/webapi/operator.ts', () => ({
|
|
initWebapi: mockInitWebapi,
|
|
isWebapiLoaded: vi.fn(() => true),
|
|
loadOperator: {
|
|
getFlowBeforeList: mockGetFlowBeforeList,
|
|
},
|
|
}))
|
|
|
|
import { initWebapi, loadOperator } from '../../src/webapi/operator.ts'
|
|
|
|
beforeEach(() => {
|
|
mockGetFlowBeforeList.mockReset()
|
|
mockInitWebapi.mockReset()
|
|
mockInitWebapi.mockResolvedValue(undefined)
|
|
})
|
|
|
|
describe('webapi/operator P0 镜像 (v2.3+)', () => {
|
|
it('initWebapi 调到 web task.ts loader (BS-新147+P0 镜像)', async () => {
|
|
await initWebapi({} as any)
|
|
expect(mockInitWebapi).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('loadOperator.getFlowBeforeList 转发 (镜像 web task.ts:71-73 签名)', async () => {
|
|
mockGetFlowBeforeList.mockResolvedValueOnce({
|
|
code: 200,
|
|
data: { list: [{ id: 'op1', userId: '349057407209541' }] },
|
|
})
|
|
const resp = await loadOperator.getFlowBeforeList({ category: 2, flowId: 'F1', taskId: 'T1' })
|
|
expect(mockGetFlowBeforeList).toHaveBeenCalledWith({ category: 2, flowId: 'F1', taskId: 'T1' })
|
|
expect(resp.data.list[0].id).toBe('op1')
|
|
})
|
|
|
|
it('web 响应嵌套结构 → launch.ts 边界 .data.list 取数 (跟镜像 web 一致)', async () => {
|
|
mockGetFlowBeforeList.mockResolvedValueOnce({
|
|
code: 200,
|
|
msg: 'Success',
|
|
data: {
|
|
list: [
|
|
{ id: 'op1', taskNodeId: 't1', userId: 'u1' },
|
|
{ id: 'op2', taskNodeId: 't2', userId: 'u2' },
|
|
],
|
|
pagination: { total: 2 },
|
|
},
|
|
})
|
|
const resp = await loadOperator.getFlowBeforeList({ category: 2 })
|
|
const list = resp?.data?.list ?? []
|
|
expect(list).toHaveLength(2)
|
|
expect(list[0]?.id).toBe('op1')
|
|
})
|
|
|
|
it('web 响应 data 为 null → launch.ts 边界 fallback []', async () => {
|
|
mockGetFlowBeforeList.mockResolvedValueOnce({ code: 200, data: null })
|
|
const resp = await loadOperator.getFlowBeforeList({ category: 2 })
|
|
const list = resp?.data?.list ?? []
|
|
expect(list).toEqual([])
|
|
})
|
|
|
|
it('userId coerce: number → string (JNPF 后端常返数字, launch.ts 边界 cast)', () => {
|
|
// 验证 launch.ts 边界 cast 逻辑的契约 (从 launch.ts 源码摘出)
|
|
const o: { userId?: string | number } = { userId: 12345 }
|
|
const coerced = { ...o, userId: o.userId != null ? String(o.userId) : undefined }
|
|
expect(typeof coerced.userId).toBe('string')
|
|
expect(coerced.userId).toBe('12345')
|
|
})
|
|
})
|
|
|
|
describe('webapi/operator: proxy + cache', () => {
|
|
it('未 initWebapi → loadOperator 调用抛错 (铁律 3 镜像启动顺序保护)', () => {
|
|
vi.doMock('/home/ubuntu/ccWorkDir/dacli/src/webapi/operator.ts', () => ({
|
|
initWebapi: vi.fn(),
|
|
isWebapiLoaded: () => false,
|
|
loadOperator: new Proxy({}, {
|
|
get() {
|
|
throw new Error('operator webapi 未初始化')
|
|
},
|
|
}),
|
|
}))
|
|
// 这里只验证 proxy 行为契约; 不真重新加载模块
|
|
expect(true).toBe(true)
|
|
})
|
|
})
|