铁律 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 关全过
52 lines
2.4 KiB
TypeScript
52 lines
2.4 KiB
TypeScript
/**
|
|
* tests/unit/app_context_version_regression.test.ts — currentVersion='unknown' 回归 (BS-新152)
|
|
*
|
|
* 历史 bug: readCliVersion() 读 src/cli.ts 找 `const VERSION = '...'`,
|
|
* 但 VERSION 实际声明在 src/program.ts (`export const VERSION = '0.1.0'`),
|
|
* 所以 regex 不命中, 函数永远返 'unknown'.
|
|
*
|
|
* 修复: readCliVersion() 改读 src/program.ts, regex 加 `export` 前缀.
|
|
*
|
|
* 测试策略: 用 vitest fs mock 不友好 (读实际文件), 改为直接 grep 源码断言:
|
|
* 1. program.ts 含 `export const VERSION = '<x.y.z>'`
|
|
* 2. context.ts 的 readCliVersion() 读 program.ts 路径 (不是 cli.ts)
|
|
* 3. regex 包含 `export` 关键字
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { readFileSync } from 'fs'
|
|
import { resolve } from 'path'
|
|
|
|
describe('app context --json currentVersion 回归 BS-新152', () => {
|
|
const dacliRoot = resolve(__dirname, '../..')
|
|
const programTs = readFileSync(resolve(dacliRoot, 'src/program.ts'), 'utf-8')
|
|
const contextTs = readFileSync(resolve(dacliRoot, 'src/commands/app/context.ts'), 'utf-8')
|
|
const cliTs = readFileSync(resolve(dacliRoot, 'src/cli.ts'), 'utf-8')
|
|
const packageJson = JSON.parse(readFileSync(resolve(dacliRoot, 'package.json'), 'utf-8'))
|
|
|
|
it('program.ts 含 export const VERSION = <x.y.z>', () => {
|
|
const m = programTs.match(/export\s+const\s+VERSION\s*=\s*['"]([^'"]+)['"]/)
|
|
expect(m, 'program.ts 必须有 export const VERSION').toBeTruthy()
|
|
expect(m?.[1]).toMatch(/^\d+\.\d+\.\d+/)
|
|
})
|
|
|
|
it('readCliVersion() 不再读 cli.ts (BS-新152 修复)', () => {
|
|
// 修复后 readCliVersion 应读 program.ts
|
|
expect(contextTs).not.toMatch(/resolve\([^)]*['"]\.\.\/\.\.\/cli\.ts['"]/)
|
|
expect(contextTs).toMatch(/resolve\([^)]*['"]\.\.\/\.\.\/program\.ts['"]/)
|
|
})
|
|
|
|
it('readCliVersion() regex 含 export 关键字 (匹配 program.ts 的 export 形式)', () => {
|
|
expect(contextTs).toMatch(/export\s+const\s+VERSION/)
|
|
})
|
|
|
|
it('cli.ts 不应再有 const VERSION 声明 (集中到 program.ts)', () => {
|
|
// 历史 cli.ts 没有 VERSION, readCliVersion() 改读 program.ts 后 cli.ts 应保持干净.
|
|
expect(cliTs).not.toMatch(/^const\s+VERSION\s*=/m)
|
|
})
|
|
|
|
it('package.json version 跟 program.ts VERSION 同步', () => {
|
|
const m = programTs.match(/export\s+const\s+VERSION\s*=\s*['"]([^'"]+)['"]/)
|
|
expect(m?.[1]).toBe(packageJson.version)
|
|
})
|
|
})
|