本仓 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,未来以本仓历史为主
110 lines
3.8 KiB
TypeScript
110 lines
3.8 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 工作流必读)
|
|
* - 字段映射: full.currentSystemId → summary.systemId, full.currentUser → summary.user
|
|
*
|
|
* 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'
|
|
import type { AppContext } from '../../src/core/types.ts'
|
|
|
|
describe('app context --summary (Task 9a)', () => {
|
|
it('摘要模式不含完整 menuList/permissionTree', () => {
|
|
const full = {
|
|
appCode: 'tdd5',
|
|
currentSystemId: '847',
|
|
dbLinkId: '208',
|
|
tokenStatus: 'valid',
|
|
currentUser: { 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('valid')
|
|
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',
|
|
currentSystemId: 'y',
|
|
dbLinkId: 'z',
|
|
tokenStatus: 'valid',
|
|
currentUser: { id: '1', account: 'a' },
|
|
} as any
|
|
const s = buildContextSummary(full)
|
|
expect(s.warnings.length).toBeLessThanOrEqual(5)
|
|
})
|
|
|
|
// Integration-style: 构造真实 AppContext literal (src/core/types.ts), 验证字段映射
|
|
// 修复前 symptom: plan 假设 full.systemId / full.user / full.resourceCounts, 实际 AppContext
|
|
// 字段名是 currentSystemId / currentUser / 无 resourceCounts (要从数组派生)
|
|
it('buildContextSummary 真实 AppContext 字段映射正确', () => {
|
|
const full: AppContext = {
|
|
appCode: 'tdd5',
|
|
currentSystemId: '847134936094737349',
|
|
dbLinkId: '2081671840002990080',
|
|
tokenStatus: 'valid',
|
|
currentUser: { id: 'u1', account: 'admin', realName: 'Admin' },
|
|
existingEnCodes: ['f1'],
|
|
unreleasedForms: [],
|
|
releasedForms: ['f1'],
|
|
modifiedAfterPublishForms: [],
|
|
workflowList: ['w1'],
|
|
existingTables: ['t1'],
|
|
menus: ['m1'],
|
|
topLevelMenus: [],
|
|
currentVersion: '0.1.0',
|
|
warnings: [],
|
|
}
|
|
const s = buildContextSummary(full)
|
|
expect(s.systemId).toBe('847134936094737349')
|
|
expect(s.user.account).toBe('admin')
|
|
expect(s.user.realName).toBe('Admin')
|
|
expect(s.tokenStatus).toBe('valid')
|
|
expect(s.resourceCounts).toEqual({
|
|
forms: 1, // unreleased 0 + released 1 + modified 0
|
|
flows: 1, // workflowList
|
|
menus: 1, // menus
|
|
tables: 1, // existingTables
|
|
dicts: 0,
|
|
})
|
|
})
|
|
|
|
it('currentUser 缺省 → user 默认空对象', () => {
|
|
const full: AppContext = {
|
|
appCode: 'tdd5',
|
|
dbLinkId: '',
|
|
tokenStatus: 'expired',
|
|
existingEnCodes: [],
|
|
unreleasedForms: [],
|
|
releasedForms: [],
|
|
modifiedAfterPublishForms: [],
|
|
workflowList: [],
|
|
existingTables: [],
|
|
menus: [],
|
|
topLevelMenus: [],
|
|
currentSystemId: '',
|
|
currentVersion: '0.1.0',
|
|
warnings: [],
|
|
// currentUser: undefined
|
|
}
|
|
const s = buildContextSummary(full)
|
|
expect(s.user).toEqual({ id: '', account: '' })
|
|
})
|
|
}) |