- Add 'dacli app context --summary' for AI-friendly slim context (drops menuList/permissionTree, caps warnings at 5) - Add src/commands/_gates/_checkpoint_k.ts: phase-aware gate (design=not-applicable, summary=live-lookup verify) - 5 new unit tests (2 context summary, 3 K checkpoint)
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
/**
|
|
* tests/unit/app_context_summary.test.ts
|
|
*
|
|
* 覆盖 src/commands/app/_context_summary.ts
|
|
* (webapi hardening: 摘要模式不输出完整 menuList/permissionTree, AI 友好)
|
|
*
|
|
* 设计:
|
|
* - buildContextSummary 接受 full AppContext (含 warnings 数组等)
|
|
* - 返回 ContextSummary: 剔除重字段, warnings 限长 ≤5
|
|
* - 不应包含 menuList/permissionTree (重负载字段)
|
|
* - 必须保留 user / appCode / dbLinkId / tokenStatus (AI 工作流必读)
|
|
*
|
|
* v0.23+ (Task 9, webapi hardening): 加 --summary 模式, 减少 AI context window 占用
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { buildContextSummary } from '../../src/commands/app/_context_summary.ts'
|
|
|
|
describe('app context --summary (Task 9a)', () => {
|
|
it('摘要模式不含完整 menuList/permissionTree', () => {
|
|
const full = {
|
|
appCode: 'tdd5',
|
|
systemId: '847',
|
|
dbLinkId: '208',
|
|
tokenStatus: 'ok',
|
|
user: { id: 'u1', account: 'admin' },
|
|
menuList: Array(50).fill({ enCode: 'm' }),
|
|
permissionTree: { /* huge */ },
|
|
warnings: [],
|
|
}
|
|
const summary = buildContextSummary(full)
|
|
expect(summary.appCode).toBe('tdd5')
|
|
expect(summary.dbLinkId).toBe('208')
|
|
expect(summary.tokenStatus).toBe('ok')
|
|
expect(summary).not.toHaveProperty('menuList')
|
|
expect(summary).not.toHaveProperty('permissionTree')
|
|
expect(summary).toHaveProperty('user')
|
|
})
|
|
|
|
it('warnings 保留 + 不超过 5 条', () => {
|
|
const full = {
|
|
warnings: Array(10).fill({ kind: 'x', message: 'y' }),
|
|
appCode: 'x',
|
|
systemId: 'y',
|
|
dbLinkId: 'z',
|
|
tokenStatus: 'ok',
|
|
user: { id: '1', account: 'a' },
|
|
} as any
|
|
const s = buildContextSummary(full)
|
|
expect(s.warnings.length).toBeLessThanOrEqual(5)
|
|
})
|
|
})
|