test(前端): 补 routeOf meta 抄送与 companyScoped 双向对账(闸门②原来是零约束)

F1 闸门②行为用例: routeOf() 实跑 producer, 取样自 adminPages.superAdminOnly(不写死 menuKey),
   含取样非空自检与"普通页 meta 不许出现 superAdminOnly"的反向自检。
F2 守卫断言从松散 /superAdminOnly/ 收紧为锚在 `if (to.meta.superAdminOnly && !session.isSuperAdmin)`
   真实语句上; 原 /isSuperAdmin/ 那条已被锚定式覆盖且被 index.ts:57 预先满足, 不再单列。
F3 新增 companyScoped ↔ COMPANY_SCOPED_PAGES 双向对账(>=8 页自检)与 17 条声明路径存在性
   (existsSync 作断言不作守卫, >=17 自检)——Task 7 护栏 G1 的分母掉一行不再无人报警。
F4 src/types/vue-router.d.ts 补 superAdminOnly?: boolean, producer/consumer 的键从字符串约定
   变为编译期契约(控制方已追认, 与 task-29.test.ts 那条同批)。
F5 剪枝的角色实参改用 store 自己的 isSuperAdmin getter, 与守卫同一谓词; task-29 正则未受影响。

变异自证 4 轮 + 3 轮加强(注入→红→从原始字节还原并 sha256 复核): routeOf 删抄送行→F1 红;
去一个 companyScoped: true→F3 对账红(含分母保持 8 的方向一/虚增一行的方向二);
清单路径改名→F3 存在性红; 守卫条件改名→F2 红(且"删语句只留注释 token"这一形状旧断言恒绿、新断言红)。
node --test 聚焦 6 文件 37/37; vue-tsc --noEmit rc=0; npm test 1701/1701(基线 1698 + 新增 3 支)。
This commit is contained in:
2026-10-04 18:48:03 +08:00
parent 468fd353f3
commit ca910c582f
3 changed files with 61 additions and 5 deletions
@@ -28,9 +28,10 @@ export const useAdminSessionStore = defineStore('admin-session', {
try {
this.user = await fetchCurrentUser()
// 剪枝是角色内在闸门的第三处(注册表 + 守卫 + 菜单树),必须在 this.user 赋值之后。
// 角色判定用 store 自己的 isSuperAdmin getter:守卫读的就是它,两处各算一次会靠约定对齐。
this.menuTree = pruneSuperAdminOnly(
canonicalizeMenuTree(await fetchAdminMenuTree()),
isSuperAdminRole(this.user?.role),
this.isSuperAdmin,
)
this.initialized = true
} catch (error) {
+2
View File
@@ -6,5 +6,7 @@ declare module 'vue-router' {
title?: string
/** 菜单 key(对应后端菜单节点 key);仅页面级鉴权使用。 */
menuKey?: string
/** 角色内在闸门:由 routeOf() 从注册表抄来,router/index.ts 消费;不声明则两端都只是字符串约定,改名 vue-tsc 认不出。 */
superAdminOnly?: boolean
}
}