diff --git a/src/commands/workflow/_approver_resolve.ts b/src/commands/workflow/_approver_resolve.ts index 4b72d54..c11c917 100644 --- a/src/commands/workflow/_approver_resolve.ts +++ b/src/commands/workflow/_approver_resolve.ts @@ -92,9 +92,25 @@ export async function resolveApproverExpr(expr: string, ctx: ResolveCtx): Promis const me = await safeCall(() => ctx.webapi?.getCurrentUser?.()) if (me === undefined) return { candidates: [], reason: 'api error' } if (!me) return { candidates: [], reason: 'no current user' } - // JNPF 用空字符串表 unset (而不是 null), 用 || 链而非 ?? - const id = String(me.userId || me.id || '') - const displayName = String(me.realName || me.userName || me.userAccount || me.account || id) + // 真实 JNPF /api/oauth/CurrentUser 响应结构: {menuList, permissionList, userInfo: {userId, realName, ...}, sysConfigInfo}. + // 历史 BS-新148: 顶层读 me.userId 永远 undefined (顶层无此字段, 在 userInfo 子层). + // → currentUserId 空 → ${currentUser} lint 永远 'no current user'. + // 修复: 优先 me.userInfo.userId, fallback 顶层 me.userId (兼容旧的扁平响应). + const info = (me as { userInfo?: Record }).userInfo ?? me + const id = String( + (info as Record).userId || + (info as Record).id || + (me as Record).userId || + (me as Record).id || + '', + ) + const displayName = String( + (info as Record).realName || + (info as Record).userName || + (info as Record).userAccount || + (info as Record).account || + id, + ) if (!id) return { candidates: [], reason: 'no current user' } return { candidates: [{ id, name: displayName }] } } diff --git a/src/commands/workflow/launch.ts b/src/commands/workflow/launch.ts index 0667a9b..ac7a9d6 100644 --- a/src/commands/workflow/launch.ts +++ b/src/commands/workflow/launch.ts @@ -27,8 +27,12 @@ interface Opts { data: string /** 严格策略: 发起后给当前用户授权, 失败 verify.exitCode=3 */ autoAuthorize?: boolean - /** 跳过 verifyLaunched 回查 (默认 false 严格). 老调用方兼容 */ - noVerify?: boolean + /** + * 跳过 verifyLaunched 回查 (默认 false 严格). 老调用方兼容. + * 注: commander `--no-verify` 映射为 `opts.verify = false`, 不读 `opts.noVerify` (历史 BS-新146: + * 源码读 opts.noVerify 永远 undefined, verify 永远跑). + */ + verify?: boolean json?: boolean /** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */ verbose?: boolean @@ -41,7 +45,9 @@ export function buildWorkflowLaunchCommand(): Command { .requiredOption('--formId ', '绑定的表单 id') .requiredOption('--data ', '表单数据 JSON 字符串 (解析后塞进 formData 字段)') .option('--auto-authorize', '发起后给当前用户授权 (JNPF 后端若返 404 则 verify.exitCode=3)', false) - .option('--no-verify', '跳过 verifyLaunched 回查 (默认关闭, 严格模式默认开)', false) + // commander --no-X 语义: opts.X 默认 true, 传 --no-X 时为 false. + // 不要传 default false, 会强制把默认改为 false, 传 --no-X 时反而 = true (反转反向, 漏 verify). + .option('--no-verify', '跳过 verifyLaunched 回查 (默认走 verify 严格模式)') addOutputOptions(cmd) .action(async (opts: Opts) => { setupOutputFilter(opts) @@ -82,7 +88,8 @@ export function buildWorkflowLaunchCommand(): Command { log.ok(`发起成功: taskId=${taskId || '(unknown)'}`) // ---- 跳过选项: --no-verify (老调用方兼容) ---- - if (opts.noVerify) { + // commander `--no-verify` 映射为 opts.verify = false; opts.verify 缺省 = undefined = 走 verify. + if (opts.verify === false) { if (opts.json) printJson(r.data) return ctx.success({ flowId: opts.flowId, formId: opts.formId, taskId, verifySkipped: true }) } @@ -101,10 +108,18 @@ export function buildWorkflowLaunchCommand(): Command { // 内联 webapi (T6 阶段 webapi 注入契约先稳定; 后续可拆到 webapi/operator.ts) const verifyWebapi: LaunchVerifyWebapi = { getFlowTaskOperatorList: async (input) => { - const ops = await c.get>( + // 镜像 dacli tasks.ts:62-71: JNPF /workflow/operator/List/{category} 返 + // {code, msg, data: {list: [...], pagination: {...}}}, 不是裸数组. + // 历史 BS-新147: ops.data 当数组用 → ops.data 是 {list, pagination} → .find 抛 'is not a function'. + // 注: c.get 已包 {code, msg, data: T}, 所以 T 直接声明内层 (list/pagination) 即可. + const r = await c.get<{ + list?: Array<{ id?: string; taskNodeId?: string; userId?: string }> + pagination?: { total?: number } + }>( `/workflow/operator/List/2?flowId=${encodeURIComponent(input.flowId)}&taskId=${encodeURIComponent(input.taskId)}`, ) - return ops.data || [] + if (r?.code && r.code !== 200) return [] + return r.data?.list || [] }, postAuthorize: async (input) => { return c.postJson('/permission/authorize', { objectType: 'flowtask', flowId: input.flowId, taskId: input.taskId }) diff --git a/tests/unit/workflow_approver_resolve.test.ts b/tests/unit/workflow_approver_resolve.test.ts index a1afd30..4bf82e1 100644 --- a/tests/unit/workflow_approver_resolve.test.ts +++ b/tests/unit/workflow_approver_resolve.test.ts @@ -71,6 +71,33 @@ describe('workflow approver resolve', () => { expect(r.reason).toBe('no current user') }) + it('回归 BS-新148: 变量 ${currentUser} 真实 JNPF CurrentUser 嵌套结构 (userInfo.userId) → 候选人', async () => { + // JNPF /api/oauth/CurrentUser 真实响应: {menuList, permissionList, userInfo: {userId, realName, ...}, sysConfigInfo, ...} + // 历史 bug: 顶层读 me.userId 永远 undefined → lint 'no current user'. + // 修复: 优先 me.userInfo.userId, fallback 顶层 me.userId. + const realCurrentUser = { + menuList: [], + permissionList: [], + userInfo: { userId: '349057407209541', userAccount: 'admin', realName: '管理员', userName: '管理员' }, + sysConfigInfo: {}, + currentSystemId: null, + } + const webapi = { getCurrentUser: vi.fn().mockResolvedValue(realCurrentUser) } + const r = await resolveApproverExpr('${currentUser}', { webapi }) + expect(r.candidates).toEqual([{ id: '349057407209541', name: '管理员' }]) + expect(r.reason).toBeUndefined() + }) + + it('回归 BS-新148: ${currentUser} 嵌套 userInfo 但 userId 字段为空 → no current user', async () => { + // userInfo 存在但 userId 为空字符串 (JNPF 用空字符串表 unset) → 应判 'no current user'. + const webapi = { getCurrentUser: vi.fn().mockResolvedValue({ + userInfo: { userId: '', realName: '', userName: '', userAccount: '', account: '' }, + }) } + const r = await resolveApproverExpr('${currentUser}', { webapi }) + expect(r.candidates).toEqual([]) + expect(r.reason).toBe('no current user') + }) + it('unknown expression → unknown expression', async () => { const r = await resolveApproverExpr('${mystery}', { webapi: {} }) expect(r.candidates).toEqual([]) @@ -202,4 +229,27 @@ describe('workflow semantic lint + real webapi 集成', () => { expect(r.ok).toBe(false) expect(r.errors.some(e => /reserved keyword/.test(e))).toBe(true) }) + + it('回归 BS-新148: lint 真实 nested CurrentUser 响应 → 通过', async () => { + // 模拟 dacli create.ts:391-397 注入的真实 webapi.getCurrentUser 返回值. + const xml = ` + + + + + + + ` + const webapi = { + getCurrentUser: async () => ({ + menuList: [], + userInfo: { userId: '349057407209541', realName: '管理员', userAccount: 'admin' }, + sysConfigInfo: {}, + }), + } + const r = await semanticLint(xml, { webapi: webapi as any }) + expect(r.ok).toBe(true) + expect(r.errors).toEqual([]) + }) }) \ No newline at end of file