Files
go-sms-V2/web/tests/role-menu-matrix.spec.ts
T
Tory c5a062570f S3 前端收尾泳道收官(FE-6+结算页面族): 盘点修正=views 31 页 S1-B 已搬零残留(归档仓逐文件比对),实际交付四件——FE-D34 利润分析页(views/stats/profit 双 Tab+汇总条[应收/成本分摊/返点/平台净利]+正负着色+口径诚实标注常驻;路由 /stats/profit roles=后端平台门同口径;api settle.ts +profitUsers/profitChannels;vitest 2 件=api 契约+组件挂载);FE-6 Mock 下线(浏览器通道全链移除:main.ts worker 分支/mocks/browser.ts/mockServiceWorker.js/VITE_API_MODE/LoginView 演示提示/Makefile 口径;msw 移 devDependencies 仅存 vitest 层 138 用例不破;packageManager 钉 pnpm12.18.0+lockfile 同步);FE-6 权限矩阵走查(role-menu-matrix.spec.ts 五角色×33 菜单固化快照,未登记新菜单=红,8 件);FE-6 性能(manualChunks:主包 1.27MB/410KB→业务 entry ~19KB+element-plus 341KB+vue-vendor 62KB 全 gzip 逐 chunk<500KB;LCP 真浏览器实测受阻=本机 chromium newPage 即 Target crashed 3 轮全崩 dmesg 无痕,产物口径代替+诚实标注);FE-6 CI+镜像化(ci.yml +web-test job;web/Dockerfile=dist 产物镜像 nginx1.27——容器内 npm 带宽 22~49KiB/s 全量依赖不可行形态裁决,make web-image=宿主 build+nginx 打包;nginx.conf.template envsubst API_UPSTREAM/gzip/SPA fallback/资产强缓存;容器冒烟 root/SPA/反代401/gzip+immutable 全过 镜像50.2MB;deploy/k8s/web.yaml NodePort 30081 备档 kind 未装随 S5 apply);门禁 eslint0/vue-tsc0/vitest 148 全绿(26 文件;guard 菜单 31→32 显式更)/build 9.64s;真机 dev 重启无 msw 引用+proxy→gw 401 应答;验收单 s3-closeout.md(两项环境受阻如实标注)+CHANGELOG+memory-bank 回填
2026-11-15 00:11:37 +08:00

73 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// role-menu-matrix.spec.ts S3·FE-6:五角色×全菜单权限矩阵走查(自动化快照)。
// 预期矩阵为**人工确认后的固化表**(非 routes.ts 同源推导)——任何人改动路由
// roles 都会在此暴露,走查语义=矩阵变更必须显式过目(与后端 casbin 五角色门对齐)。
// 语义基准:资金/通道/结算页=admin/ops;service=运营执行;group/customer=业务
// 与记录自助,不见平台资金信息(与后端 statsIsPlatform/ordersList/profit 平台门一致)。
import { describe, expect, it } from 'vitest'
import { accessibleRoutes } from '@/router/guard'
type Roles = 'admin' | 'ops' | 'service' | 'group' | 'customer'
const ALL: Roles[] = ['admin', 'ops', 'service', 'group', 'customer']
/** 预期矩阵:菜单 name → 允许角色(S3 固化,含 FE-D34 利润分析)。 */
const MATRIX: Record<string, Roles[]> = {
home: ALL,
notice: ['admin', 'ops', 'service', 'group'],
'account-list': ['admin', 'ops'],
audit: ['admin', 'ops', 'service'],
'sms-home': ALL, 'sms-batch': ALL, 'sms-personal': ALL, 'sms-timer': ALL,
'sms-result': ALL, 'sms-template': ALL, 'sms-downlink-detail': ALL,
video: ['admin', 'ops'], csp: ['admin', 'ops'], nullfilter: ['admin', 'ops'], shortlink: ['admin', 'ops'],
'record-down': ALL, 'record-up': ALL,
'record-repush': ['admin', 'ops', 'service'],
channel: ['admin', 'ops'], 'channel-upstream': ['admin', 'ops'], 'channel-group': ['admin', 'ops'],
policy: ['admin', 'ops'], 'policy-route': ['admin', 'ops'], 'policy-report': ['admin', 'ops'],
contacts: ALL,
'stats-user': ['admin', 'ops', 'service'], 'stats-channel': ['admin', 'ops'],
'stats-profit': ['admin', 'ops', 'service'], settle: ['admin', 'ops'],
logs: ['admin', 'ops', 'service'], system: ['admin'], faq: ALL,
}
/** 实测:某角色经守卫过滤后的可见菜单集合。 */
function visibleMenus(role: Roles): Set<string> {
return new Set(
accessibleRoutes([role])
.flatMap((r) => r.children ?? [])
.filter((c) => c.meta?.menu)
.map((c) => String(c.name)),
)
}
describe('S3·FE-6 五角色×全菜单权限矩阵', () => {
const roles: Roles[] = ['admin', 'ops', 'service', 'group', 'customer']
it.each(roles)('角色 %s 可见菜单与矩阵一致', (role) => {
const visible = visibleMenus(role)
for (const [name, allow] of Object.entries(MATRIX)) {
const want = allow.includes(role)
expect(visible.has(name), `${role} × ${name}:期望${want ? '可见' : '不可见'}`).toBe(want)
}
})
it('矩阵覆盖全部菜单项(新增菜单未登记矩阵=本测试红,走查强制过目)', () => {
const adminVisible = visibleMenus('admin')
for (const name of adminVisible) expect(MATRIX[name], `菜单 ${name} 未登记矩阵`).toBeDefined()
expect(adminVisible.size).toBe(Object.keys(MATRIX).length)
})
it('资金与平台配置页对 group/customer 关闭(语义抽样:settle/stats-profit/channel/system)', () => {
for (const role of ['group', 'customer'] as Roles[]) {
const visible = visibleMenus(role)
for (const denied of ['settle', 'stats-profit', 'stats-channel', 'channel', 'channel-upstream', 'system', 'account-list', 'audit']) {
expect(visible.has(denied), `${role} 不应见 ${denied}`).toBe(false)
}
}
})
it('system 配置仅 admin', () => {
for (const role of ['ops', 'service', 'group', 'customer'] as Roles[]) {
expect(visibleMenus(role).has('system')).toBe(false)
}
})
})