From da43d93af3bd23250e681d4d11bd1d35c5481888 Mon Sep 17 00:00:00 2001 From: ssw Date: Fri, 17 Jul 2026 12:40:30 +0800 Subject: [PATCH] chore(dacli): clean comment violations batch 3 (5 files) Files: app/context.ts, _encode_validator.ts, form/release.ts, di/update.ts, test/browser.ts Co-Authored-By: Claude --- src/commands/_encode_validator.ts | 81 ++++++++---------- src/commands/app/context.ts | 101 +++++++++++------------ src/commands/di/update.ts | 47 +++++------ src/commands/form/release.ts | 39 ++++----- src/commands/test/browser.ts | 133 ++++++++++++++---------------- 5 files changed, 181 insertions(+), 220 deletions(-) diff --git a/src/commands/_encode_validator.ts b/src/commands/_encode_validator.ts index c952c17..f38e6a1 100644 --- a/src/commands/_encode_validator.ts +++ b/src/commands/_encode_validator.ts @@ -1,21 +1,16 @@ /** - * commands/_encode_validator.ts — 共享 enCode 正则校验 (BS-56) - * - * 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28 + * commands/_encode_validator.ts — 共享 enCode 正则校验 ( * 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:24-28 * 适用: form create / dict typeCreate / menu create / role create / workflow create / identity 等 - * - * v0.11h+ (2026-06-28): - * - 统一 ENCODE_REGEXP (BS-56: 禁下划线, 禁首尾小数点) - * - 增强错误信息: 明确指出"enCode 只能含英文/数字/小数点, 不能含下划线/连字符/中文" - * - 自动建议别名: 把 `test_with_underscore` → `testwithunderscore` 让用户复制粘贴 - * - * Why: 历史 22 盲点根因 #B (AI 盲猜 enCode), BS-56 改进后让 AI 看到清晰规则 + 可用别名 + * - 统一 ENCODE_REGEXP (禁下划线, 禁首尾小数点) + * - 增强错误信息: 明确指出"enCode 只能含英文/数字/小数点, 不能含下划线/连字符/中文" + * - 自动建议别名: 把 `test_with_underscore` → `testwithunderscore` 让用户复制粘贴 + * Why: 历史 22 盲点根因 #B (AI 盲猜 enCode), 改进后让 AI 看到清晰规则 + 可用别名 */ export const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i /** 镜像 web packages/jnpf/utils/src/helpers/formValidate.ts:33-36 - * 中文/字母/数字, 禁特殊符号 */ + * 中文/字母/数字, 禁特殊符号 */ export const FULLNAME_REGEXP = /^([一-龥a-z0-9])+$/i export interface EncodeValidationError { @@ -23,16 +18,14 @@ export interface EncodeValidationError { message: string /** 镜像 web formValidate.ts:26-27 '只能输入英文、数字和小数点且小数点不能放在首尾' */ messageVague: string - /** BS-56 增强: 自动建议的合法别名 (去下划线/连字符) */ + /** 增强: 自动建议的合法别名 (去下划线/连字符) */ suggestedAlias?: string code: string } /** * 校验 enCode 是否符合 JNPF formValidate 正则. - * * 失败时返回清晰错误 + 建议别名; 通过返回 null. - * * @param enCode 原始 enCode * @param field 字段名 (默认 'enCode') * @returns 错误对象 或 null (校验通过) @@ -58,7 +51,7 @@ export function validateEnCode(enCode: string | undefined, field = 'enCode'): En if (ENCODE_REGEXP.test(enc)) { return null } - // 校验失败 — BS-56 增强: 清晰说明 + 建议别名 + // 校验失败 — 增强: 清晰说明 + 建议别名 const suggested = suggestEnCode(enc) return { field, @@ -74,11 +67,11 @@ export function validateEnCode(enCode: string | undefined, field = 'enCode'): En /** * 自动建议合法的 enCode 别名: - * - 去 `_` (下划线) - * - 去 `-` (连字符) - * - 去 ` ` (空格) - * - 中文保留 (不主动改, 但 web formValidate 会拒) - * - 小数点保留 (web 允许) + * - 去 `_` (下划线) + * - 去 `-` (连字符) + * - 去 ` ` (空格) + * - 中文保留 (不主动改, 但 web formValidate 会拒) + * - 小数点保留 (web 允许) */ export function suggestEnCode(enCode: string): string { return String(enCode) @@ -87,20 +80,16 @@ export function suggestEnCode(enCode: string): string { } /** - * v0.21+ (Round 12 fix, BS-新38): 自动 strip 的 enCode + log helper. - * + * (Round 12 fix, 自动 strip 的 enCode + log helper. * 用于各 create 命令 action() 入口早期调用: - * - 给 `round12-foo` → `round12foo` (去 `-`) - * - 静默 strip, 但返回 wasStriped=true 让调用方打 WARN log - * - * 原因: Round 12 drift loop 5/8 模块 (form/dict/di/menu/role) 因 enCode 含 `-` 触发 BS-56 fail, - * 必须手动重试. 加这个 helper, AI 一次提交就能跑通, 不用 retry. - * + * - 给 `round12-foo` → `round12foo` (去 `-`) + * - 静默 strip, 但返回 wasStriped=true 让调用方打 WARN log + * 原因: Round 12 drift loop 5/8 模块 (form/dict/di/menu/role) 因 enCode 含 `-` 触发 fail, + * 必须手动重试. 加这个 helper, AI 一次提交就能跑通, 不用 retry. * 注意: - * - workflow 用 `r12.{enCode}` 含 dot (BS-56 允许), 不需要 strip - * - bigscreen construct 没用 enCode, skip - * - 只 strip `_` 和 `-`, 保留 `.` 和中文 (中文走 validateEnCode 拒) - * + * - workflow 用 `r12.{enCode}` 含 dot (允许), 不需要 strip + * - bigscreen construct 没用 enCode, skip + * - 只 strip `_` 和 `-`, 保留 `.` 和中文 (中文走 validateEnCode 拒) * @param enCode 原始 enCode (字符串或 undefined) * @returns { value: 修正后 enCode, wasStriped: 是否做了修正, original: 原始值 } */ @@ -154,22 +143,18 @@ export function validateFullName(fullName: string | undefined, field = 'fullName } /** - * v0.21+ R14 fix (BS-新52): 自动 strip 的 fullName + log helper. - * + * fix (自动 strip 的 fullName + log helper. * 跟 autoStripEnCode 平行: fullName 含 FULLNAME_REGEXP 禁的字符 (空格/半角括号/全角括号/斜杠/引号等) * 自动剥除, 让 AI 一次提交跑通不用 retry. - * - * R13 现象: `round13 客户管理记录表(集成助手)` 含半角空格 + 全角括号 → BS-56 step0 "名称不能含有特殊符号". + * 现象: `round13 客户管理记录表(集成助手)` 含半角空格 + 全角括号 → step0 "名称不能含有特殊符号". * 修法: autoStrip 后 `round13客户管理记录表集成助手` 通过校验, AI retry 减少一次. - * * strip 规则 (按优先级): - * - 去空格 (半角+全角) - * - 去括号 (半角 () + 全角 ()+ [] + 【】 + {} + {}) - * - 去引号 (半角 " ' + 全角 “” ‘’) - * - 去斜杠 (/ \ + 全角 / \) - * - 去连字符 (- _) — 注意保留小数点 (.) 不动 - * - 去其他常见特殊符号 (.,;:!? — 保留句号) - * + * - 去空格 (半角+全角) + * - 去括号 (半角 () + 全角 ()+ [] + 【】 + {} + {}) + * - 去引号 (半角 " ' + 全角 “” ‘’) + * - 去斜杠 (/ \ + 全角 / \) + * - 去连字符 (- _) — 注意保留小数点 (.) 不动 + * - 去其他常见特殊符号 (.,;:!? — 保留句号) * @param fullName 原始 fullName * @returns { value, wasStriped, original } */ @@ -196,7 +181,7 @@ export function autoStripFullName(fullName: string | undefined): { } } -// v0.15+ (P2-5, 2026-07-02): 删 BS-108 adaptEnCodeForScope/detectEnCodeScope dead code -// - 整个 codebase 零引用 (grep 只在自己文件内) -// - BS-56 formValidate 正则已经统一 form/dict/menu/di, 不需要 scope 区分 -// - audit FINDING-S1: '要么接入 form/dict/menu/di 要么删', 选删 (form 走 web 端后端校验) \ No newline at end of file +// (P2-5, 2026-07-02): 删 adaptEnCodeForScope/detectEnCodeScope dead code +// - 整个 codebase 零引用 (grep 只在自己文件内) +// - formValidate 正则已经统一 form/dict/menu/di, 不需要 scope 区分 +// - audit FINDING-S1: '要么接入 form/dict/menu/di 要么删', 选删 (form 走 web 端后端校验) \ No newline at end of file diff --git a/src/commands/app/context.ts b/src/commands/app/context.ts index 449caf9..b97b017 100644 --- a/src/commands/app/context.ts +++ b/src/commands/app/context.ts @@ -1,19 +1,15 @@ /** * commands/app/context.ts — `dacli app context` (v3.0+ 集成 CurrentUser API) - * * AI 环境快照 (P0.1, 详见 doc/ai-optimization-plan.md §2.1 + doc/ai-error-analysis.md §B) - * - * v3.0+ (2026-06-29) 重大升级: 集成 webapi/user.getUserInfoApi - * - 浏览器登录监测: GET /api/oauth/CurrentUser?systemCode=X&isBackend=Y 是关键请求 - * - 服务器端确认 token + appCode + 用户身份 (比读本地 token 更可靠) - * - 用户从 token.json 读 appCode, 调 webapi/user 验证 - * + * v3.0+ 重大升级: 集成 webapi/user.getUserInfoApi + * - 浏览器登录监测: GET /api/oauth/CurrentUser?systemCode=X&isBackend=Y 是关键请求 + * - 服务器端确认 token + appCode + 用户身份 (比读本地 token 更可靠) + * - 用户从 token.json 读 appCode, 调 webapi/user 验证 * 设计要点: - * - 单次调用产出 AI 干活的最小依赖集: dbLinkId / 已有 enCode / 草稿 vs 发布 / 已有表 / 菜单 / token 状态 / **currentUser** - * - 内部走 webapi 镜像 (user/system/menu/form/dict/dm/workflow), 不 shell out 调子命令 - * - 失败容错: form/dm/menu/currentUser 任一 API 失败时不抛错, 仅写入 warnings - * - --json 走单行 JSON (AI 友好, 不带换行缩进) - * + * - 单次调用产出 AI 干活的最小依赖集: dbLinkId / 已有 enCode / 草稿 vs 发布 / 已有表 / 菜单 / token 状态 / **currentUser** + * - 内部走 webapi 镜像 (user/system/menu/form/dict/dm/workflow), 不 shell out 调子命令 + * - 失败容错: form/dm/menu/currentUser 任一 API 失败时不抛错, 仅写入 warnings + * - --json 走单行 JSON (AI 友好, 不带换行缩进) * 输出接口: src/core/types.ts AppContext */ import { Command } from 'commander' @@ -29,9 +25,9 @@ import { import { getUserInfoApi } from '../../webapi/user.ts' // 复用 cli.ts 的 VERSION 常量 — 避免重复硬编码, 也避免外部依赖 (cat package.json) -// 路径相对 src/commands/app/context.ts → ../../../src/cli.ts -// 不直接 import cli.ts 是为避免循环依赖 (cli.ts 启动时 import 各 command) -// 用 fileURL + 文本扫描 + 正则提 VERSION +// 路径相对 src/commands/app/context.ts → ../../../src/cli.ts +// 不直接 import cli.ts 是为避免循环依赖 (cli.ts 启动时 import 各 command) +// 用 fileURL + 文本扫描 + 正则提 VERSION import { existsSync, readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, join, resolve } from 'node:path' @@ -72,7 +68,6 @@ function calcTokenExpiry(loginAt?: string): string | undefined { /** * P1.2: 公开的 AppContext 加载函数 (供 pre-check 等复用) - * * 设计: 拉 token → 构造 client → 拉 form/dm/menu → 组装 AppContext * 失败容错: 任何 API 失败写入 warnings, 不抛错 * 不抛异常, 失败尽量返回部分填充的对象 + warnings @@ -88,22 +83,22 @@ export async function loadAppContext(opts?: { appCode?: string }): Promise f.state === 1) .map((f) => `${f.id}:${f.enCode || '(no-enCode)'}`) - // BS-53 (2026-06-23): 收集 state=2 — 发布后被编辑过, 前端 web 看不到直到 re-release. - // JNPF 后端 VisualdevController#update line 488-491 已发布表单被 PUT 自动 state 1→2. - // dacli form update 等 PUT 类命令触发. 现象: 用户实测表单"空白/无按钮"但 - // summary.html 误写 "Form state=1 ✅" (实际全部 state=2). + // 收集 state=2 — 发布后被编辑过, 前端 web 看不到直到 re-release. + // JNPF 后端 VisualdevController#update line 488-491 已发布表单被 PUT 自动 state 1→2. + // dacli form update 等 PUT 类命令触发. 现象: 用户实测表单"空白/无按钮"但 + // summary.html 误写 "Form state=1 ✅" (实际全部 state=2). const modifiedAfterPublishForms = forms .filter((f) => f.state === 2) .map((f) => `${f.id}:${f.enCode || '(no-enCode)'}`) @@ -251,10 +246,10 @@ async function tryFetchTables( } /** 安全拉 menu list — 失败返回 null + 警告 - * v0.15+ (BS-109, 2026-07-02): 同时返回顶级菜单完整对象 (id+parentId+fullName) - * 用途: portal release 自动检测 pcModuleParentId - * 顶级菜单判定: parentId === '0' || parentId === '-1' || parentId === 0 || parentId === -1 - * 兼容 web 端 menuSelector + 后端 ModuleServiceImpl.listBySystem 两种返回结构 + * 同时返回顶级菜单完整对象 (id+parentId+fullName) + * 用途: portal release 自动检测 pcModuleParentId + * 顶级菜单判定: parentId === '0' || parentId === '-1' || parentId === 0 || parentId === -1 + * 兼容 web 端 menuSelector + 后端 ModuleServiceImpl.listBySystem 两种返回结构 */ async function tryFetchMenus( c: JnpfClient, @@ -285,11 +280,11 @@ async function tryFetchMenus( } } -/** v0.15+ (BS-109, 2026-07-02): 兜底拉 currentSystemId - * 用途: portal release 必填 pcSystemId/appSystemId, category-cache 命中后通常不调 - * API: GET /system/System/list?keyword={appCode} → filter id === enCode 不靠谱, 改用 /system/System/{enCode} - * 镜像源: webapi/system.ts:getInfo (但后端 getInfo 只接 id 不接 enCode, 改用 list 模糊查) - * 注: 若 list 模糊查也找不到, 返空 (portal release 会发警告) +/** : 兜底拉 currentSystemId + * 用途: portal release 必填 pcSystemId/appSystemId, category-cache 命中后通常不调 + * API: GET /system/System/list?keyword={appCode} → filter id === enCode 不靠谱, 改用 /system/System/{enCode} + * 镜像源: webapi/system.ts:getInfo (但后端 getInfo 只接 id 不接 enCode, 改用 list 模糊查) + * 注: 若 list 模糊查也找不到, 返空 (portal release 会发警告) */ async function tryFetchCurrentSystemId( c: JnpfClient, @@ -313,10 +308,10 @@ async function tryFetchCurrentSystemId( } } -/** v0.11h+ (2026-06-28): 安全拉 workflow list — 失败返回空数组 + 警告 - * 用途: BS-EFLOW-NOWF guard 检测 enableFlow=1 但 workflow list=0 时给 WARN - * API: POST /workflow/Engine/list (web 端 workFlow/template.ts getList 端点) - * body: { keyword, currentPage, pageSize } +/** : 安全拉 workflow list — 失败返回空数组 + 警告 + * 用途: guard 检测 enableFlow=1 但 workflow list=0 时给 WARN + * API: POST /workflow/Engine/list (web 端 workFlow/template.ts getList 端点) + * body: { keyword, currentPage, pageSize } */ async function tryFetchWorkflows( c: JnpfClient, @@ -366,8 +361,8 @@ export function buildAppContextCommand(): Command { // P1.2: 复用 loadAppContext 提取的核心采集逻辑 const ctx = await loadAppContext(opts.app ? { appCode: opts.app } : undefined) - // v0.11e+ Phase E: system 缺失时退出码 2 (AI/脚本可据此停下, 不要继续 CRUD) - // 仍输出 JSON 便于消费方诊断 + // Phase E: system 缺失时退出码 2 (AI/脚本可据此停下, 不要继续 CRUD) + // 仍输出 JSON 便于消费方诊断 const exitCode = ctx.systemExists === false ? 2 : 0 // 输出 diff --git a/src/commands/di/update.ts b/src/commands/di/update.ts index 4bf5090..1ccb9b5 100644 --- a/src/commands/di/update.ts +++ b/src/commands/di/update.ts @@ -1,8 +1,7 @@ /** * commands/di/update.ts — 数据接口修改 - * - * v0.11+ Phase 2: webapi 化 (loadDataInterface.getDataInterfaceInfo + updateDataInterface) - * 替代 v0.10 直接 c.get/c.putJson + * Phase 2: webapi 化 (loadDataInterface.getDataInterfaceInfo + updateDataInterface) + * 替代 直接 c.get/c.putJson */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -18,9 +17,9 @@ interface Opts { fullName?: string enCode?: string categoryId?: string - // v0.15+ (R3.1): 字段名修正 — 原 requestMethod (HTTP verb) 跟 action (SQL verb) 错位映射 - // audit 2026-07-02 §role/print/di 报告: update 用 --requestMethod (HTTP) 但映射到 action (SQL 1=增/2=改/3=查/4=删), Number('GET')=NaN - // 修复: 改 --action 跟 create 命令对齐 + // 字段名修正 — 原 requestMethod (HTTP verb) 跟 action (SQL verb) 错位映射 + // audit §role/print/di 报告: update 用 --requestMethod (HTTP) 但映射到 action (SQL 1=增/2=改/3=查/4=删), Number('GET')=NaN + // 改 --action 跟 create 命令对齐 action?: string url?: string expectedEnCode?: string @@ -36,7 +35,7 @@ export function buildDiUpdateCommand(): Command { .option('--fullName ', '中文名') .option('--enCode ', '英文编码') .option('--categoryId ', '分类 id') - // v0.15+ (R3.1): action 是 SQL 动词 (1=增 2=改 3=查 4=删), 跟 create 命令对齐 + // action 是 SQL 动词 (1=增 2=改 3=查 4=删), 跟 create 命令对齐 .option('--action ', '动作 (type=1 必填): 1=增加 2=修改 3=查询 4=删除') .option('--url ', '接口路径/URL') .option('--expected-enCode ', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)') @@ -52,7 +51,7 @@ export function buildDiUpdateCommand(): Command { process.exit(1) } - // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) + // Phase A2: dirty check (防 AI session 长时间保留误覆盖) const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedEnCode, expectedState: opts.expectedState, @@ -71,7 +70,7 @@ export function buildDiUpdateCommand(): Command { log.info(`⚠ dirty check 已 --force 跳过`) } - // v0.11d+ Phase di: step machine 校验 (镜像 web dataInterface/Form.vue + 后端 DataInterfaceController.update) + // Phase di: step machine 校验 (镜像 web dataInterface/Form.vue + 后端 DataInterfaceController.update) // 跑 3 step 校验, 失败 → exit 1 await runDiStepMachine(c, opts, orig) @@ -79,14 +78,14 @@ export function buildDiUpdateCommand(): Command { if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode if (opts.categoryId) body.categoryId = opts.categoryId - // v0.15+ (R3.1): --action 改跟 create 对齐, 删 requestMethod + // --action 改跟 create 对齐, 删 requestMethod if (opts.action !== undefined) body.action = Number(opts.action) if (opts.url) body.url = opts.url log.info(`loadDataInterface.updateDataInterface (id=${opts.id})`) const r = (await loadDataInterface.updateDataInterface(body)) as { code?: number; msg?: string; data?: unknown } if (r.code !== 200 && r.code !== undefined) { log.error(`di update 失败 (code=${r.code}): ${r.msg}`) - // v0.11e+ Phase A1: 后端错误增强 — 自动从 msg 提取 ErrorCode + // Phase A1: 后端错误增强 — 自动从 msg 提取 ErrorCode const enhanced = enhanceFromBackend(r.msg || '', 'di', { entity: 'di' }) log.error(` ${formatErrorLine(enhanced, { step: 2, stepName: '后端API' })}`) if (opts.json) printJson(r) @@ -114,21 +113,19 @@ export function buildDiUpdateCommand(): Command { } /** - * v0.11d+ Phase di: di update step machine 校验 (3 步镜像) + * Phase di: di update step machine 校验 (3 步镜像) * 在发 API 前暴露问题, 聚合错误一次报 - * * 镜像原型: - * - web dataInterface/Form.vue:166-251 schemas (12 字段, ⚠️ enCode 无正则) - * - 后端 DataInterfaceController.java:246-311 (EXIST001/002 + containsSensitive 查 SQL 敏感字) + * - web dataInterface/Form.vue:166-251 schemas (12 字段, ⚠️ enCode 无正则) + * - 后端 DataInterfaceController.java:246-311 (EXIST001/002 + containsSensitive 查 SQL 敏感字) */ async function runDiStepMachine( c: JnpfClient, opts: Opts, orig: Record, ): Promise { - // 1. 拉全 DI 列表 (供 step 2 唯一性预校验, BS-47) - // v0.15+ (P0-8) 走 webapi/getDataInterfaceList, 替代 c.get - // 注: 拉列表可能慢, 用 pageSize=1000 单页拉完 + // 1. 拉全 DI 列表 (供 step 2 唯一性预校验, // (P0-8) 走 webapi/getDataInterfaceList, 替代 c.get + // 注: 拉列表可能慢, 用 pageSize=1000 单页拉完 let existingDIs: Array<{ fullName?: string; enCode?: string; id?: string }> = [] try { const r = (await getDataInterfaceList({ @@ -146,18 +143,18 @@ async function runDiStepMachine( } // 2. 跑 3 step 校验 - // opts 的字段名映射到 di opts: - // opts.fullName → fullName - // opts.enCode → enCode - // opts.categoryId → category - // opts.requestMethod → action (镜像 web, type=1 才有 action) - // opts.url → url (后端字段) + // opts 的字段名映射到 di opts: + // opts.fullName → fullName + // opts.enCode → enCode + // opts.categoryId → category + // opts.requestMethod → action (镜像 web, type=1 才有 action) + // opts.url → url (后端字段) const diOpts: DiOpts = { fullName: opts.fullName, enCode: opts.enCode, category: opts.categoryId, type: orig.type !== undefined ? Number(orig.type) : undefined, - // v0.15+ (R3.1): 字段名 action, 跟 create 对齐, Number(action) 合法 + // 字段名 action, 跟 create 对齐, Number(action) 合法 action: opts.action !== undefined ? Number(opts.action) : (orig.action as number | undefined), enabledMark: orig.enabledMark !== undefined ? Number(orig.enabledMark) : undefined, sortCode: orig.sortCode !== undefined ? Number(orig.sortCode) : undefined, diff --git a/src/commands/form/release.ts b/src/commands/form/release.ts index a481b07..b85ef65 100644 --- a/src/commands/form/release.ts +++ b/src/commands/form/release.ts @@ -1,14 +1,11 @@ /** - * commands/form/release.ts — 发布表单 (v0.11e+ auto-authorize 后置挂菜单) - * - * v0.11e+ Phase B2: auto-authorize (镜像 web 表单发布后 createMenu/Actions/Module 授权给当前角色) - * - * BS-53 (2026-06-23): JNPF 后端 VisualdevController#update line 488-491 - * 自动把已发布表单 state 1→2 (被 PUT 编辑过). 原 release 只支持 0→1, state=2 形式上 - * "已发布" 但前端 web (state==1 才显示"已发布") 看不到. 本命令现在也支持 state=2→1 - * 重新发布场景, 后端 Actions/Release 端点无论 state 0/1/2 都直接覆盖为 1. - * - * v0.11+ Phase 1 (2026-06-25): 用 webapi 调 web 端 release (替代 c.postJson) + * commands/form/release.ts — 发布表单 (auto-authorize 后置挂菜单) + * Phase B2: auto-authorize (镜像 web 表单发布后 createMenu/Actions/Module 授权给当前角色) + * JNPF 后端 VisualdevController#update line 488-491 + * 自动把已发布表单 state 1→2 (被 PUT 编辑过). 原 release 只支持 0→1, state=2 形式上 + * "已发布" 但前端 web (state==1 才显示"已发布") 看不到. 本命令现在也支持 state=2→1 + * 重新发布场景, 后端 Actions/Release 端点无论 state 0/1/2 都直接覆盖为 1. + * Phase 1 : 用 webapi 调 web 端 release (替代 c.postJson) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -25,18 +22,18 @@ export function buildFormReleaseCommand(): Command { .argument('', '表单 id') .option('--soft', '发布失败不退出 (用于 type=4)', false) .action(async (id: string, opts: { soft?: boolean }) => { - // === step 0 blindspot guard + BS-53 检测 === + // === step 0 blindspot guard + 检测 === // P3.1: 第二层防御 — 仅接入 release 适用的 blindspot guard - // - BS-8 (token expired), BS-5 (ctx 空), BS-43 (v0.6 走错端点) - // - BS-37 (form 已发布未挂菜单 → 浏览器 404) — WARN, 提示后续挂菜单 - // - BS-14 (type=4 视图 release) — release 命令本身没传 type, 此处跳过 - // - BS-49 (enCode 重复) 等创建类 guard 不适用, 跳过 - // - BS-53-info: formId 处于 state=2 (待重发布) → WARN 提示会自动重新发布 + // - (token expired), (ctx 空), (走错端点) + // - (form 已发布未挂菜单 → 浏览器 404) — WARN, 提示后续挂菜单 + // - (type=4 视图 release) — release 命令本身没传 type, 此处跳过 + // - (enCode 重复) 等创建类 guard 不适用, 跳过 + // - formId 处于 state=2 (待重发布) → WARN 提示会自动重新发布 const guardCtx = await loadContextSafe(null) if (guardCtx.warning) log.warn(guardCtx.warning) handleGuardResult('form release', runGuards(guardCtx.ctx, { formId: id }, 'form release')) - // v0.15+ (P2-6): preCheckFormRelease (enCode 在当前 app 列表 + table 存在) + // (P2-6): preCheckFormRelease (enCode 在当前 app 列表 + table 存在) // 旧版 release 不走 precheck, 中途 enCode 已被别人占用能过 // 这里从 guardCtx.releasedForms/unreleasedForms 推 enCode const enCode = guardCtx.ctx?.releasedForms @@ -48,21 +45,21 @@ export function buildFormReleaseCommand(): Command { for (const w of pre.warnings) log.warn(` preCheckFormRelease: ${w}`) } - // === step 1 BS-53 state 检测 + 准备 release 调用 === - // BS-53: 检测 state=2 并提示用户, 后端 Actions/Release 直接覆盖为 1 + // === step 1 state 检测 + 准备 release 调用 === + // 检测 state=2 并提示用户, 后端 Actions/Release 直接覆盖为 1 if (guardCtx.ctx?.modifiedAfterPublishForms?.some(f => f.startsWith(`${id}:`))) { log.info(`formId ${id} 当前 state=2 (已发布被编辑过), 将自动重新发布为 state=1`) } const c = await JnpfClient.fromToken() // === step 2 (后端API (Actions/Release) === - // v0.11+ Phase 1: 用 web 端 release (替代 c.postJson('/visualdev/Base/{id}/Actions/Release')) + // Phase 1: 用 web 端 release (替代 c.postJson('/visualdev/Base/{id}/Actions/Release')) await initWebapi(c) const resp = await loadVisualDev.release(id) const r = { code: 200, msg: 'ok', data: resp } as { code: number; msg?: string } if (r.code === 200) { log.ok(`发布成功 id=${id} (state=1)`) - // 发布成功后, 单独跑 BS-37 (form 已发布但未挂菜单 → 浏览器 404) — WARN 不阻断 + // 发布成功后, 单独跑 (form 已发布但未挂菜单 → 浏览器 404) — WARN 不阻断 // 注: releasedForms 格式 = "id:enCode", 这里按 id 拆出 enCode if (guardCtx.ctx) { const matched = guardCtx.ctx.releasedForms.find(f => f.startsWith(`${id}:`)) diff --git a/src/commands/test/browser.ts b/src/commands/test/browser.ts index 178b3f4..e043011 100644 --- a/src/commands/test/browser.ts +++ b/src/commands/test/browser.ts @@ -1,47 +1,38 @@ /** - * test/browser.ts — TC-B 浏览器真实行为验证 (v0.21+, 2026-07-12) - * - * 目的: 镜像 web 端实际渲染, 用 playwright 验证 DOM 真实结构. - * 跟 TC-C (render.ts) 互补: TC-C 静态分析字段完整性, TC-B 验证实际浏览器渲染. - * + * test/browser.ts — TC-B 浏览器真实行为验证 * 目的: 镜像 web 端实际渲染, 用 playwright 验证 DOM 真实结构. + * 跟 TC-C (render.ts) 互补: TC-C 静态分析字段完整性, TC-B 验证实际浏览器渲染. * 思路: 跟 TC-C 一样 webapi 准备 + 浏览器验证, 但 TC-B 强制走真实浏览器 (DOM). - * 复用: - * - `dacli app context --json` 拿 token (dacli 已登录, 不需重新登录) - * - `/api/oauth/CurrentUser` 拿 menuList 含 urlAddress (e.g. model/hesuanjiancedengji8a3aa) - * - storage snapshot 复用 (一次性 login, 后续 form 复用, 避免每次重新登录) - * - chromium 复用 /home/ubuntu/.cache/ms-playwright (playwright 默认路径) - * + * 复用: + * - `dacli app context --json` 拿 token (dacli 已登录, 不需重新登录) + * - `/api/oauth/CurrentUser` 拿 menuList 含 urlAddress (e.g. model/hesuanjiancedengji8a3aa) + * - storage snapshot 复用 (一次性 login, 后续 form 复用, 避免每次重新登录) + * - chromium 复用 /home/ubuntu/.cache/ms-playwright (playwright 默认路径) * 跑法: - * dacli test browser --module=form --formId= [--appCode=workSystem] - * dacli test browser --module=workflow --id= [--appCode=workSystem] - * + * dacli test browser --module=form --formId= [--appCode=reference app] + * dacli test browser --module=workflow --id= [--appCode=reference app] * 集成: vitest 调 subprocess (跟 tc-c-deep.spec.ts 一样) - * * 7 检查 (form module, 实测 5 form 35/35 PASS): - * 1. 页面加载 (Vue 接管, url 正确) - * 2. 列表 table 渲染 - * 3. 新增 button 存在 - * 4. form 编辑页 (新页面 inputIds 数量) - * 5. F_ / auto / snake 命名约定 (跟 baseline 一致) - * 6. dict select 字段可达 (select 渲染) - * 7. formItem label 全部非空 - * - * 7 检查 (workflow module, v0.21+ 运行时 flowTodo 完整闭环, 2026-07-14): - * 1. 页面加载 (Vue 接管, url 正确) - * 2. 任务列表 table 渲染 (8 列: 流程标题/所属流程/发起时间/发起人员/审批节点/紧急程度/流程状态/接收时间) - * 3. 搜索 form + 4 tabs (全部/协办/退回/超时, 镜像 flowTodo L53-58) - * 4. 批量办理 + 任务行 "办理" 按钮 (flowTodo L206/L226) - * 5. FlowParser modal 打开 (点 办理 → 流程详情 modal, 镜像 L131-139 toDetail) - * 6. modal toolbar 流程图 button + 标题 (FlowParser L989-994 icon-ym-flow-node-condition) - * 7. modal 审批操作 button (FlowParser L364-407 todoBtnList: 退签/开始办理) - * - * v0.22+ P1-8 修复 (2026-07-16): autoLoginAndRefreshStorage - * 问题: ~/.dacli-snapshots/.json 缓存了登录态 localStorage/sessionStorage, - * token 过期后 SPA 跳 /login → 7 检查跑在登录页 → 误报 PASS. - * 修复: 浏览器 launch 后检测 URL 含 /login → 自动 login admin/123456 → 刷新 snapshot → 重试 navigation. - * form + workflow 两个 module 都接入. - * - * @author claude (2026-07-12, BS-NCPF-400 followup; 2026-07-14 workflow module; 2026-07-16 P1-8 auto-login) + * 1. 页面加载 (Vue 接管, url 正确) + * 2. 列表 table 渲染 + * 3. 新增 button 存在 + * 4. form 编辑页 (新页面 inputIds 数量) + * 5. F_ / auto / snake 命名约定 (跟 baseline 一致) + * 6. dict select 字段可达 (select 渲染) + * 7. formItem label 全部非空 + * 7 检查 (workflow module, 运行时 flowTodo 完整闭环, 2026-07-14): + * 1. 页面加载 (Vue 接管, url 正确) + * 2. 任务列表 table 渲染 (8 列: 流程标题/所属流程/发起时间/发起人员/审批节点/紧急程度/流程状态/接收时间) + * 3. 搜索 form + 4 tabs (全部/协办/退回/超时, 镜像 flowTodo L53-58) + * 4. 批量办理 + 任务行 "办理" 按钮 (flowTodo L206/L226) + * 5. FlowParser modal 打开 (点 办理 → 流程详情 modal, 镜像 L131-139 toDetail) + * 6. modal toolbar 流程图 button + 标题 (FlowParser L989-994 icon-ym-flow-node-condition) + * 7. modal 审批操作 button (FlowParser L364-407 todoBtnList: 退签/开始办理) + * autoLoginAndRefreshStorage + * 问题: ~/.dacli-snapshots/.json 缓存了登录态 localStorage/sessionStorage, + * token 过期后 SPA 跳 /login → 7 检查跑在登录页 → 误报 PASS. + * 浏览器 launch 后检测 URL 含 /login → 自动 login admin/123456 → 刷新 snapshot → 重试 navigation. + * form + workflow 两个 module 都接入. + * @author claude (2026-07-12, followup; workflow module; P1-8 auto-login) */ import { Command } from 'commander' @@ -57,7 +48,7 @@ import { JnpfClient } from '../../core/client.ts' type DomElement = { textContent: string; id: string } // ============================================================================ -// Storage snapshot 复用 (v0.21+ TC-B 关键加速) +// Storage snapshot 复用 (TC-B 关键加速) // ============================================================================ const SNAPSHOT_DIR = join(homedir(), '.dacli-snapshots') @@ -261,9 +252,9 @@ async function runBrowserChecks(page: Page, schema: FormSchema, menuEnCode?: str // 5. 命名约定 (跟 baseline convention 一致) // 自我适配: 看实际 ID 投票决定 convention - // e.g. testcustomer ID 形如 "form-uuid_F_Username" → f_prefix (matches _F_UpperCamel) - // hesuanjiancedengji ID 形如 "form-uuid_comInputField101" → auto (matches _Field) - // testreceivable ID 形如 "form-uuid_f_real_name" → snake (matches __) + // e.g. testcustomer ID 形如 "form-uuid_F_Username" → f_prefix (matches _F_UpperCamel) + // hesuanjiancedengji ID 形如 "form-uuid_comInputField101" → auto (matches _Field) + // testreceivable ID 形如 "form-uuid_f_real_name" → snake (matches __) // 注意: 直接匹配 inputId (避免 split 切丢 F_), 找 pattern 中关键部分 // 投票: 各 pattern 命中的 inputId 数 const patternF_prefix = /_F_[A-Z][A-Za-z0-9]*$/ // 末段 F_ @@ -317,7 +308,7 @@ async function runBrowserChecks(page: Page, schema: FormSchema, menuEnCode?: str ) if (found.length > labels.length) labels = found } - // 兜底: 任意 form 内的 label 元素 + // 任意 form 内的 label 元素 if (labels.length === 0) { labels = await page.locator('.ant-form label').evaluateAll( (els: DomElement[]) => els.map(l => l.textContent?.trim() || '').filter(Boolean) @@ -335,27 +326,24 @@ async function runBrowserChecks(page: Page, schema: FormSchema, menuEnCode?: str } /** - * TC-B workflow module 7 检查 (v0.21+ 扩展, 2026-07-14) - * + * TC-B workflow module 7 检查 (扩展, 2026-07-14) * 镜像 web 端 flowEngine/{index,Form}.vue 渲染契约 (vs form module 改的 7 检查): - * - index.vue L290-329 模板: + "新增" 下拉 (5 类型) + "AI建流程" button - * - Form.vue L31-105 schemas: fullName/enCode/decisionType/category/icon/showType/sortCode/description (8 字段) - * - Form.vue L37/66/72 required: fullName + category + icon (3 必填) - * - index.vue L32-42 columns: fullName/enCode/category/type/creatorUser/creatorTime/sortCode/enabledMark/status (9 列) - * - 路由 /onlineDev/flowEngine (静态路径, 无后缀 hash, vs form 走 menuList) + * - index.vue L290-329 模板: + "新增" 下拉 (5 类型) + "AI建流程" button + * - Form.vue L31-105 schemas: fullName/enCode/decisionType/category/icon/showType/sortCode/description (8 字段) + * - Form.vue L37/66/72 required: fullName + category + icon (3 必填) + * - index.vue L32-42 columns: fullName/enCode/category/type/creatorUser/creatorTime/sortCode/enabledMark/status (9 列) + * - 路由 /onlineDev/flowEngine (静态路径, 无后缀 hash, vs form 走 menuList) */ /** - * TC-B workflow module 7 检查 (v0.21+ 运行时 flowTodo 完整闭环, 2026-07-14) - * + * TC-B workflow module 7 检查 (运行时 flowTodo 完整闭环, 2026-07-14) * 镜像 web 端 workFlow/flowTodo 运行时页面 + FlowParser modal (vs 旧的 flowEngine 开发页面): - * - flowTodo/index.vue L43-52 columns: 流程标题/所属流程/发起时间/发起人员/审批节点/紧急程度/流程状态/接收时间 (8 列) - * - flowTodo/index.vue L123-129 actions: 办理 (opType=2, 走 FlowParser modal) - * - flowTodo/index.vue L53-58 tabs: 全部/协办/退回/超时 (4) - * - flowTodo/index.vue L65-106 search form: 6 字段 (keyword/pickerVal/flowCategory/templateId/creatorUserId/flowUrgent) - * - FlowParser.vue L364-407 buttons: 同意/拒绝/退回/转审/加签/催办/暂存/提交 (opType=2 走 todoBtnList: 退签/开始办理) - * - FlowParser.vue L989-994 toolbar: 流程图 button (icon-ym icon-ym-flow-node-condition) - * - 路由 /workFlow/flowTodo (静态路径, workSystem 前端菜单默认含此页) - * + * - flowTodo/index.vue L43-52 columns: 流程标题/所属流程/发起时间/发起人员/审批节点/紧急程度/流程状态/接收时间 (8 列) + * - flowTodo/index.vue L123-129 actions: 办理 (opType=2, 走 FlowParser modal) + * - flowTodo/index.vue L53-58 tabs: 全部/协办/退回/超时 (4) + * - flowTodo/index.vue L65-106 search form: 6 字段 (keyword/pickerVal/flowCategory/templateId/creatorUserId/flowUrgent) + * - FlowParser.vue L364-407 buttons: 同意/拒绝/退回/转审/加签/催办/暂存/提交 (opType=2 走 todoBtnList: 退签/开始办理) + * - FlowParser.vue L989-994 toolbar: 流程图 button (icon-ym icon-ym-flow-node-condition) + * - 路由 /workFlow/flowTodo (静态路径, reference app 前端菜单默认含此页) * 与 form module 区别: form 测 form 设计器 + form 模态框, workflow 测 任务列表 + 审批 modal. * 关联命令: `dacli test render --module=workflow` 已覆盖 workflow 静态 schema, TC-B 专攻运行时 DOM. */ @@ -462,12 +450,11 @@ async function runWorkflowBrowserChecks(page: Page, _schema?: WorkflowSchema): P /** * 自动 login + 拿 storage (SSR 容错, 等真实跳转) - * * 原理: JNPF SPA 用 vue-router, login.vue submit 后用 router.push(redirect 优先 fallback home) - * 跳转完成后 localStorage/sessionStorage 才被 jnpf-web-6.2.0-prod-base 写 token. - * v0.22+ P1-8 修复 (P1-7 仅 form create 兜底, 这里补 TC-B 浏览器层): - * session 失效时 snapshot 已缓存会复用 → 跳转 /login → 7 检查全 FALSE PASS 跑在登录页. - * 修复: launch 后先 goto realUrl, 检测到 /login → 自动 login → refresh snapshot → re-navigate. + * 跳转完成后 localStorage/sessionStorage 才被 jnpf-web-6.2.0-prod-base 写 token. + * P1-8 修复 (P1-7 仅 form create 兜底, 这里补 TC-B 浏览器层): + * session 失效时 snapshot 已缓存会复用 → 跳转 /login → 7 检查全 FALSE PASS 跑在登录页. + * launch 后先 goto realUrl, 检测到 /login → 自动 login → refresh snapshot → re-navigate. */ async function autoLoginAndRefreshStorage( browser: Browser, @@ -551,7 +538,7 @@ async function getOrCreateStorageSnapshot( } // ============================================================================ -// 主入口: form module 跑 TC-B (重构自 v0.21+ 原始实现, 入参 formId → id) +// 主入口: form module 跑 TC-B (重构自 原始实现, 入参 formId → id) // ============================================================================ async function runFormBrowserTest(opts: { @@ -615,8 +602,8 @@ async function runFormBrowserTest(opts: { await page.waitForLoadState('networkidle', { timeout: 15000 }) await page.waitForTimeout(3000) - // 4.5 P1-8 修复: 检测 session 失效 (snapshot 缓存的 token 过期 → SPA 跳 /login). - // 若 URL 含 /login, 重新 login 刷 snapshot + 重试 navigation. + // 4.5 检测 session 失效 (snapshot 缓存的 token 过期 → SPA 跳 /login). + // 若 URL 含 /login, 重新 login 刷 snapshot + 重试 navigation. if (isLoginRedirect(page.url())) { log.warn(`[TC-B] session 失效 (snapshot 缓存 token 过期), 自动 login 刷新`) const refreshed = await autoLoginAndRefreshStorage(browser, appCode, baseUrl) @@ -657,7 +644,7 @@ async function runFormBrowserTest(opts: { } // ============================================================================ -// 主入口: workflow module 跑 TC-B (v0.21+ 新增, 2026-07-14) +// 主入口: workflow module 跑 TC-B (新增, 2026-07-14) // ============================================================================ async function runWorkflowBrowserTest(opts: { @@ -705,15 +692,15 @@ async function runWorkflowBrowserTest(opts: { }) } const page: Page = await context.newPage() - // 镜像 web 端 router: flowTodo 路由 = /workFlow/flowTodo (静态路径, workSystem 前端菜单默认含) - // 注: v0.21+ 初版用 flowEngine (设计/开发页), 2026-07-14 改成 flowTodo (运行时/审批) 测真正业务内容 + // 镜像 web 端 router: flowTodo 路由 = /workFlow/flowTodo (静态路径, reference app 前端菜单默认含) + // 注: 初版用 flowEngine (设计/开发页), 改成 flowTodo (运行时/审批) 测真正业务内容 const realUrl = 'workFlow/flowTodo' const fullUrl = `${baseUrl}/jnpf_app_${appCode}/${realUrl}` await page.goto(fullUrl) await page.waitForLoadState('networkidle', { timeout: 15000 }) await page.waitForTimeout(3000) - // 3.5 P1-8 修复: 检测 session 失效 → 自动 login 刷新 + 重试 navigation (form module 同款逻辑) + // 3.5 检测 session 失效 → 自动 login 刷新 + 重试 navigation (form module 同款逻辑) if (isLoginRedirect(page.url())) { log.warn(`[TC-B] session 失效 (workflow module, snapshot 缓存 token 过期), 自动 login 刷新`) const refreshed = await autoLoginAndRefreshStorage(browser, appCode, baseUrl)