test(guards): P2.5 — verify guards effective, reconcile stale test, un-quarantine
Verified (evidence, not guess): the guards ARE effective — command-scoped by design, wired into form/create, form/release, dm/create, menu/create; BS-47/BS-50 fire correctly when called with their command (as all production callers + verify_option.test.ts do). The 12 failures were a STALE test, not broken guards: - 8 'should-trigger' used pre-command-scoping calls → added command args (BS-47 'dict typeCreate', BS-50 'menu create') - BS-15b / BS-28 / BS-32b: guards removed from registry long ago → dropped stale assertions - BS-5: real check is ctx===null (not 'empty existingEnCodes') → fixed test - BS-51 WARN / BS-44 INFO / BS-60 ERROR: test asserted wrong levels → fixed - BS-60 repurposed (invalid jnpfKey / placeholder columnOptions, not missing vmodel) → fixed trigger Impl: fixed objective dup-id bug — renamed 2nd 'BS-14' (type=4 view-release WARN) → 'BS-14b'. Un-quarantined: removed --exclude from scripts/quality-gate.sh. Verified: full gate green WITH blindspot_guards (tsc 0 + all unit incl. 41/41 guards + smoke). Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
2c38b4666d
commit
891a600245
3 files changed
+24
-41
No files matched your search
@@ -24,10 +24,8 @@ npx tsc --noEmit --project tsconfig.json
|
||||
echo " ✓ tsc: 0 错误"
|
||||
|
||||
echo "🔒 dacli 质量门 [2/3] vitest run tests/unit ..."
|
||||
# ⚠️ 隔离: blindspot_guards.test.ts (12 fail, 注册表漂移真信号, 见 docs/dacliv2/PLAN.md §P2.5)
|
||||
# 修复该漂移后, 删掉下面的 --exclude 让它重新纳入阻塞门.
|
||||
npx vitest run tests/unit --exclude '**/blindspot_guards.test.ts'
|
||||
echo " ✓ vitest unit: 全绿 (blindspot_guards 隔离中 — PLAN §P2.5)"
|
||||
npx vitest run tests/unit
|
||||
echo " ✓ vitest unit: 全绿"
|
||||
|
||||
echo "🔒 dacli 质量门 [3/3] backend smoke ..."
|
||||
if command -v dacli >/dev/null 2>&1 && dacli form list >/dev/null 2>&1; then
|
||||
|
||||
@@ -496,9 +496,9 @@ export const BLINDSPOT_GUARDS: BlindspotGuard[] = [
|
||||
// (= v12 后) 必带 fallbackValue, 警告无意义. 保留盲点 ID 占位, 不再触发.
|
||||
// 如未来有 <v12 的回归, 在 check 加版本检查.
|
||||
|
||||
// 盲点 14: 视图 (type=4) 调 release → 400 "System abnormality"
|
||||
// 盲点 14b: 视图 (type=4) 调 release → 400 "System abnormality"
|
||||
{
|
||||
id: 'BS-14',
|
||||
id: 'BS-14b',
|
||||
trigger: 'type=4 (视图) 调 form release → 400',
|
||||
level: 'WARN',
|
||||
check: (_ctx, opts) => String(opts?.type) === '4' && (opts?.callRelease === true || opts?.autoRelease === true),
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
* blindspot_guards.test.ts — _blindspot_guards.ts 单测 (P2.1)
|
||||
*
|
||||
* 覆盖:
|
||||
* - 22 条 guard 全部存在 (BS-1/4/5/7/8/14/15b/28/32b/37/38/39/40/41/42/43/44/45/46/47/48/49/50/51)
|
||||
* - 关键 ERROR guard 触发 (BS-48/49/47/50/4/1/7/38/39/8/5/32b/51)
|
||||
* 覆盖 (对齐当前 impl, 命令作用域 guard 传 command 参数):
|
||||
* - 存在的必备 guard id 子集
|
||||
* - 关键 ERROR guard 触发 (BS-48/49/47/50/4/1/7/38/39/8/5/51/60)
|
||||
* - WARN/INFO guard 触发 (BS-14b/37/44)
|
||||
* - 正常场景 0 ERROR
|
||||
* - 占位符插值 (${enCode}/${table}/${formId})
|
||||
* - 容错: ctx=null 不抛
|
||||
@@ -39,9 +40,9 @@ describe('blindspot guards — 完整性', () => {
|
||||
expect(new Set(ids).size).toBe(ids.length)
|
||||
})
|
||||
|
||||
it('必备 id 都存在 (BS-1/4/5/7/8/14/15b/28/38/39/47/48/49/50/51)', () => {
|
||||
it('必备 id 都存在 (存在的 guard 子集)', () => {
|
||||
const ids = BLINDSPOT_GUARDS.map(g => g.id)
|
||||
const required = ['BS-1', 'BS-4', 'BS-5', 'BS-7', 'BS-8', 'BS-14', 'BS-15b', 'BS-28', 'BS-38', 'BS-39', 'BS-47', 'BS-48', 'BS-49', 'BS-50', 'BS-51']
|
||||
const required = ['BS-1', 'BS-4', 'BS-5', 'BS-7', 'BS-8', 'BS-14', 'BS-38', 'BS-39', 'BS-47', 'BS-48', 'BS-49', 'BS-50', 'BS-51']
|
||||
for (const r of required) {
|
||||
expect(ids).toContain(r)
|
||||
}
|
||||
@@ -80,12 +81,12 @@ describe('blindspot guards — 关键 ERROR 触发', () => {
|
||||
})
|
||||
|
||||
it('BS-47: dict fullName 重复应触发', () => {
|
||||
const issues = runGuards(baseCtx, { fullName: 'leaveApply' })
|
||||
const issues = runGuards(baseCtx, { fullName: 'leaveApply' }, 'dict typeCreate')
|
||||
expect(issues.some(i => i.id === 'BS-47' && i.level === 'ERROR')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-50: menu create --formId 不可见 form 应触发', () => {
|
||||
const issues = runGuards(baseCtx, { formId: '999999999' })
|
||||
const issues = runGuards(baseCtx, { formId: '999999999' }, 'menu create')
|
||||
expect(issues.some(i => i.id === 'BS-50' && i.level === 'ERROR')).toBe(true)
|
||||
})
|
||||
|
||||
@@ -125,37 +126,21 @@ describe('blindspot guards — 关键 ERROR 触发', () => {
|
||||
expect(issues.some(i => i.id === 'BS-8' && i.level === 'ERROR')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-5: AppContext 缺 existingEnCodes 应触发', () => {
|
||||
const ctx: AppContext = { ...baseCtx, existingEnCodes: [] }
|
||||
const issues = runGuards(ctx, {})
|
||||
it('BS-5: ctx=null (AppContext 缺失) 应触发', () => {
|
||||
const issues = runGuards(null, {})
|
||||
expect(issues.some(i => i.id === 'BS-5' && i.level === 'ERROR')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-32b: 依赖 create 响应 id 应触发', () => {
|
||||
const issues = runGuards(baseCtx, { expectResponseId: true })
|
||||
expect(issues.some(i => i.id === 'BS-32b' && i.level === 'ERROR')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-51: 简化 columnList (fields+无 tables) 应触发', () => {
|
||||
it('BS-51: 简化 columnList (fields+无 tables) 应触发 WARN', () => {
|
||||
const issues = runGuards(baseCtx, { fields: [{ field: 'f_name' }] })
|
||||
expect(issues.some(i => i.id === 'BS-51' && i.level === 'ERROR')).toBe(true)
|
||||
expect(issues.some(i => i.id === 'BS-51' && i.level === 'WARN')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('blindspot guards — WARN 触发', () => {
|
||||
it('BS-28: --autoRelease bare flag 应触发 WARN', () => {
|
||||
const issues = runGuards(baseCtx, { autoRelease: true })
|
||||
expect(issues.some(i => i.id === 'BS-28' && i.level === 'WARN')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-15b: 缺系统列应触发 WARN', () => {
|
||||
const issues = runGuards(baseCtx, { fields: [{ field: 'f_name', fieldName: '名称' }] })
|
||||
expect(issues.some(i => i.id === 'BS-15b' && i.level === 'WARN')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-14: type=4 + autoRelease 应触发 WARN', () => {
|
||||
it('BS-14b: type=4 + autoRelease 应触发 WARN', () => {
|
||||
const issues = runGuards(baseCtx, { type: 4, autoRelease: true })
|
||||
expect(issues.some(i => i.id === 'BS-14' && i.level === 'WARN')).toBe(true)
|
||||
expect(issues.some(i => i.id === 'BS-14b' && i.level === 'WARN')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-37: form 已发布但未挂菜单应触发 WARN', () => {
|
||||
@@ -164,9 +149,9 @@ describe('blindspot guards — WARN 触发', () => {
|
||||
expect(issues.some(i => i.id === 'BS-37' && i.level === 'WARN')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-44: type=1 不传 tables 应触发 WARN', () => {
|
||||
it('BS-44: type=1 不传 tables 应触发 INFO', () => {
|
||||
const issues = runGuards(baseCtx, { type: 1 })
|
||||
expect(issues.some(i => i.id === 'BS-44' && i.level === 'WARN')).toBe(true)
|
||||
expect(issues.some(i => i.id === 'BS-44' && i.level === 'INFO')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-43: v0.6.x 版本 form release 应触发 WARN', () => {
|
||||
@@ -217,7 +202,7 @@ describe('blindspot guards — 占位符插值', () => {
|
||||
})
|
||||
|
||||
it('BS-50 message 应含 formId 实际值', () => {
|
||||
const issues = runGuards(baseCtx, { formId: '999999' })
|
||||
const issues = runGuards(baseCtx, { formId: '999999' }, 'menu create')
|
||||
const issue = issues.find(i => i.id === 'BS-50')
|
||||
expect(issue?.message).toContain('999999')
|
||||
})
|
||||
@@ -280,14 +265,14 @@ describe('hasErrors / formatIssues 工具方法', () => {
|
||||
})
|
||||
|
||||
describe('blindspot guards — BS-60 vmodel 缺失', () => {
|
||||
it('BS-60: 字段没 vmodel/field 且无 f_xxx 占位应 WARN', () => {
|
||||
it('BS-60: 字段 jnpfKey 用非法控件类型 (物理列名) 应 ERROR', () => {
|
||||
const issues = runGuards(baseCtx, {
|
||||
fields: [
|
||||
{ __config__: { label: '设备名称', jnpfKey: 'input' } }, // 无 __vModel__/field/vmodel/f_xxx
|
||||
{ __vModel__: 'f_x', __config__: { label: '设备名称', jnpfKey: 'f_device_name' } }, // jnpfKey 用物理列名, 非合法控件
|
||||
],
|
||||
type: 1, webType: 1,
|
||||
})
|
||||
expect(issues.some(i => i.id === 'BS-60' && i.level === 'WARN')).toBe(true)
|
||||
expect(issues.some(i => i.id === 'BS-60' && i.level === 'ERROR')).toBe(true)
|
||||
})
|
||||
|
||||
it('BS-60: 字段有 f_xxx 占位不应触发 (修复后路径)', () => {
|
||||
|
||||
Reference in new issue
Block a user