BS-新147/153/154: workflow launch 镜像 web getFlowBeforeList + shim 补全

铁律 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 关全过
This commit is contained in:
ssw committed 2026-07-29 11:18:13 +08:00
1 parent ee3d4448c9
commit 8762cd0121
8 files changed
+585

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
/**
* _jnpf_utils_shim.ts — @jnpf/utils shim (v2.3+ P0 镜像回归)
*
* 镜像源: web/packages/jnpf/utils (AesEncryption, buildBitUUID, buildUUID 等)
* dacli 没有 browser DOM, 不能真跑部分 web 工具. 提供最小 stub.
*
* 使用方:
* - webapi/operator.ts 通过 _loader.ts 加载 web/api/workFlow/task.ts
* - task.ts:1 import { AesEncryption, buildBitUUID } from '@jnpf/utils'
* - _loader.ts 把 from '@jnpf/utils' 重写到此 shim
*
* 铁律 3 (P0): 保留 web 端函数名 + 签名, 即使部分函数 stub. web 升级 task.ts 时只需更新 shim.
*/
export { buildUUID } from '../../../web/packages/jnpf/utils/src/helpers/uuid.ts'
/** JNPF AES 加密 (web 端 cipher.ts). dacli 端无浏览器 crypto, 提供最小 stub (明文透传) */
export class AesEncryption {
private useHex: boolean
constructor(opts: { useHex?: boolean } = {}) {
this.useHex = opts.useHex ?? false
}
/** @stub — 返回原文 (dacli 不用, 仅满足 ES module 解析 + 启动期 web 端 sync 任务) */
encryptByAES(text: string): string {
return this.useHex ? Buffer.from(text, 'utf-8').toString('hex') : text
}
/** @stub — 返回原文 */
decryptByAES(text: string): string {
return this.useHex ? Buffer.from(text, 'hex').toString('utf-8') : text
}
}
/** buildBitUUID — web 端根据 buildUUID + 业务位生成特定格式 id. dacli 端 stub 返 buildUUID */
export function buildBitUUID(): string {
return crypto.randomUUID()
}
+30
View File
@@ -0,0 +1,30 @@
/**
* _vben_stores_shim.ts — @vben/stores Pinia shim (v2.3+ P0 镜像回归)
*
* 镜像源: web/packages/@vben/stores (Pinia stores)
* dacli 没有 Vue runtime, 不能真跑 Pinia. 提供最小 stub:
* - useUserStore() → 空 store proxy, 任何属性访问返 undefined
*
* 使用方:
* - webapi/operator.ts 通过 _loader.ts 加载 web/api/workFlow/task.ts
* - task.ts:3 import { useUserStore } from '@vben/stores'
* - task.ts:20 useUserStore() 在 getFlowBeforeList 路径不会触发 (它是无状态 HTTP 调用),
* 但 ES module import 必须在顶层解析, 故仍需 stub.
*
* 铁律 3 (P0): 不自创 useUserStore 实现 (web 端是 Pinia reactive store),
* 提供最小 stub 让 task.ts ES module 解析通过; 业务字段 userId 等走真实 API 响应.
*/
export const useUserStore = () => new Proxy({}, {
get(_target, prop) {
if (prop === 'userInfo') return null
return undefined
},
has() {
return true
},
}) as unknown as () => { userInfo?: unknown }
// Stub 其他可能的 store (按需扩展, 不引入 Pinia 依赖)
export const useAppStore = () => ({} as any)
export const useAccessStore = () => ({} as any)
export const useBaseStore = () => ({} as any)
+71
View File
@@ -0,0 +1,71 @@
/**
* webapi/operator.ts — workflow operator/task API 镜像 (v2.3+ P0 严格镜像)
*
* 镜像源: web/apps/jnpf-web-apps-main/src/api/workFlow/task.ts (181 行)
* 关键函数:
* - getFlowBeforeList (line 71-73): GET /api/workflow/operator/List/{category}
* - batchSign (line 75-77), sign (line 79-81)
* - checkInfo (line 151-153): GET /api/workflow/operator/{taskOperatorId}/Info?opType=...
* - audit (line 96-98): POST /api/workflow/operator/Audit/{id}
*
* 镜像机制 (CLAUDE.md §3 铁律 3 镜像架构 0 漂移):
* - loadWebModule 动态 import web src, 自动替换 defHttp → _defhttp_shim
* - defHttp shim 接 JnpfClient, 直接复用 dacli 已登录 token
* - 单进程 cache (跟 webapi/user.ts loadUser 同模式)
*
* 历史 (BS-新147 + P0 镜像回归):
* - v0.22~v2.2: launch.ts inline getFlowTaskOperatorList (我自创), 违反铁律 3
* - v2.3: P0 修复, 镜像 web getFlowBeforeList, launch.ts 改调 loadOperator.getFlowBeforeList
* - 修前漂移: 自创函数名 / 自创 query string / 自创类型, web 升级时无法自动跟上
* - 修后: 0 漂移, web 升级 task.ts 时 loader 自动同步, dacli 端仅需 1 行 initDefHttpShim
*
* 注意 (启动顺序):
* - 必须先 initWebapi(client) (内部会调 initDefHttpShim)
* - initWebapi 由 launch.ts / tasks.ts 入口处 await 一次
* - 调用前可用 isWebapiLoaded() 检查
*/
import { getCcWorkDir } from '../core/paths.ts'
import { JnpfClient } from '../core/client.ts'
import { loadWebModule } from './_loader.ts'
const TASK_API_SRC = `${getCcWorkDir()}/web/apps/jnpf-web-apps-main/src/api/workFlow/task.ts`
let cached: any = null
export async function initWebapi(client: JnpfClient): Promise<void> {
if (cached) return
// defHttp shim 必须先 init (client 注入), 否则 web 端 defHttp.get 无 baseUrl/token
const { initDefHttpShim } = await import('./_defhttp_shim.ts')
initDefHttpShim(client)
cached = await loadWebModule(TASK_API_SRC)
}
export function isWebapiLoaded(): boolean {
return cached !== null
}
/**
* loadOperator 代理 (跟 webapi/user.ts loadUser 同模式).
*
* 镜像 web getFlowBeforeList (task.ts:71-73):
* web signature: getFlowBeforeList({ category, flowId?, keyword?, ... })
* 返回: JnpfResp<ListResp<OperatorInfo>>
*
* 用法:
* const list = await loadOperator.getFlowBeforeList({ category: 2, flowId: 'F1', taskId: 'T1' })
*/
export const loadOperator: any = new Proxy({} as any, {
get(_target, prop) {
if (!cached) {
throw new Error(
'operator webapi 未初始化, 请先 await initWebapi(client). ' +
'通常在 launch.ts / tasks.ts action 入口处调用.',
)
}
const fn = cached[prop]
if (typeof fn !== 'function') {
throw new Error(`loadOperator.${String(prop)} 不是函数 (web 端 task.ts 未导出)`)
}
return fn
},
})