本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
108 lines
3.6 KiB
TypeScript
108 lines
3.6 KiB
TypeScript
/**
|
|
* tests/unit/checkpoint_k_semantics.test.ts
|
|
*
|
|
* 覆盖 src/commands/_gates/_checkpoint_k.ts
|
|
* (webapi hardening: K 关卡 phase 感知 + designResources 落地校验)
|
|
*
|
|
* 设计:
|
|
* - phase='design': summaryResources 为空 → not-applicable (退出 0)
|
|
* - phase='summary': summaryResources 全部 lookup 成功 → ok
|
|
* - phase='summary': 某资源 lookup 失败 → failure + 列出 missing (reason='no longer exists')
|
|
* - phase='summary': designResources 未落地 → failure + 列出 missing (reason='designed but not delivered')
|
|
* - phase='summary': designResources ⊆ summaryResources + 全部 lookup 成功 → ok
|
|
*
|
|
* v0.23+ (Task 9, webapi hardening): K 关卡 phase 语义修复, 防止总结阶段引用已删资源或漏交付
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { checkKCheckpoint } from '../../src/commands/_gates/_checkpoint_k.ts'
|
|
|
|
describe('K 关卡语义 (Task 9b)', () => {
|
|
it('设计阶段 (resources=[]) → not-applicable', async () => {
|
|
const r = await checkKCheckpoint({
|
|
phase: 'design',
|
|
appCode: 'tdd5',
|
|
designResources: [],
|
|
summaryResources: [],
|
|
})
|
|
expect(r.status).toBe('not-applicable')
|
|
expect(r.exitCode).toBe(0)
|
|
})
|
|
|
|
it('总结阶段有 summaryResources → 校验每个资源仍在', async () => {
|
|
const r = await checkKCheckpoint({
|
|
phase: 'summary',
|
|
appCode: 'tdd5',
|
|
designResources: [],
|
|
summaryResources: [
|
|
{ kind: 'form', id: 'F1' },
|
|
{ kind: 'flow', id: 'W1' },
|
|
{ kind: 'menu', id: 'M1' },
|
|
],
|
|
liveLookup: async (res) => res.id, // 模拟 lookup
|
|
})
|
|
expect(r.status).toBe('ok')
|
|
expect(r.exitCode).toBe(0)
|
|
})
|
|
|
|
it('总结阶段某资源 lookup 失败 → failure + 列出 missing (no longer exists)', async () => {
|
|
const r = await checkKCheckpoint({
|
|
phase: 'summary',
|
|
appCode: 'tdd5',
|
|
designResources: [],
|
|
summaryResources: [
|
|
{ kind: 'form', id: 'F1' },
|
|
{ kind: 'flow', id: 'MISSING' },
|
|
],
|
|
liveLookup: async (res) => (res.id === 'F1' ? 'F1' : null),
|
|
})
|
|
expect(r.status).toBe('failure')
|
|
expect(r.exitCode).toBe(1)
|
|
expect(r.missing).toEqual([
|
|
{ kind: 'flow', id: 'MISSING', reason: 'no longer exists' },
|
|
])
|
|
})
|
|
|
|
// 设计资源落地校验: designResources ⊆ summaryResources (设计阶段说要做的事, 总结必须看到交付)
|
|
it('设计阶段说有 3 form, 总结阶段只交 2 个 → missing F3 (designed but not delivered)', async () => {
|
|
const r = await checkKCheckpoint({
|
|
phase: 'summary',
|
|
appCode: 'tdd5',
|
|
designResources: [
|
|
{ kind: 'form', id: 'F1' },
|
|
{ kind: 'form', id: 'F2' },
|
|
{ kind: 'form', id: 'F3' },
|
|
],
|
|
summaryResources: [
|
|
{ kind: 'form', id: 'F1' },
|
|
{ kind: 'form', id: 'F2' },
|
|
],
|
|
liveLookup: async (res) => res.id,
|
|
})
|
|
expect(r.status).toBe('failure')
|
|
expect(r.exitCode).toBe(1)
|
|
expect(r.missing).toEqual([
|
|
{ kind: 'form', id: 'F3', reason: 'designed but not delivered' },
|
|
])
|
|
})
|
|
|
|
// 完整通过: 设计资源全部交付 + 全部存活
|
|
it('设计阶段 3 form + 总结阶段 3 form 全部 lookup 成功 → ok', async () => {
|
|
const r = await checkKCheckpoint({
|
|
phase: 'summary',
|
|
appCode: 'tdd5',
|
|
designResources: [
|
|
{ kind: 'form', id: 'F1' },
|
|
{ kind: 'form', id: 'F2' },
|
|
{ kind: 'form', id: 'F3' },
|
|
],
|
|
summaryResources: [
|
|
{ kind: 'form', id: 'F1' },
|
|
{ kind: 'form', id: 'F2' },
|
|
{ kind: 'form', id: 'F3' },
|
|
],
|
|
liveLookup: async (res) => res.id,
|
|
})
|
|
expect(r.status).toBe('ok')
|
|
expect(r.exitCode).toBe(0)
|
|
})
|
|
}) |