8750f3dd83
现网取证(Step 4,决定批次 0 顺序,Task 3 开工前必读): 抓 admin-vue 20261004-135428 的整棵产物图(入口 index-cieBmv8-.js 1,129,621 B / HTTP 200 + 由 vite preload manifest 展开全部 34 个 chunk,逐个只读 GET 全 200)。 判据串 /api/admin/companies 命中 3 处,全在 companies-DdzTeTnG.js(GET/POST/PUT 三条); 非零对照 /api/admin/users 命中 2 处(users-CUWUXHVU.js、history-api-DA7YNc4O.js)证明抓到的 是真在跑的产物,不是空文件。入口 chunk 单查两个串都是 0 命中——字面量在共享 api chunk 里, 只按 brief 的"入口 chunk"抓会得到假的"未命中"结论。 决定性一条:UsersPage-Cv8vbewQ.js 静态 import 了 companies chunk,且里面有 `await $e()` ($e 即 fetchCompanies)⇒ 现网的「用户管理」页仍会打 GET /api/admin/companies。 ⇒ 命中:批次 0 的 admin-vue 必须先发,Task 3 的 jar(listVisible 非超管一律 403)才能上, 否则 15 个公司内管理员一开用户管理就撞 403 → 被前端拦截器踢回登录页(2026-10-04 12:3x 形状)。 附带:现网全树 0 处 superAdminOnly ⇒ Task 1 那道入口剪枝尚未上线。 本笔无生产代码改动(Task 1 的注册表就是这半边唯一实现):新增 tests/company-config-entry-super-only.test.ts 三支(注册表认领 / fetchCompanies 消费者 集合恰好两处 / loadCompanies 读路径不许出现 canManage),三支各做一轮注入变异自证 ⇒ 全轮 3/3 咬红、还原后字节一致并复跑回绿;既有两支反向钉只各加一句注释、 未动断言与取样。全量 1704 pass / 0 fail(基线 1701 + 新增 3),vue-tsc 与 build 均 rc=0。
94 lines
4.7 KiB
TypeScript
94 lines
4.7 KiB
TypeScript
import test from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readSource } from './helpers.ts'
|
||
import { normalizeUserPageParams, toUserListQuery } from '../src/api/users-dto.ts'
|
||
import { toAdminUserItem } from '../src/api/users-model.ts'
|
||
import {
|
||
createUserFilterState,
|
||
isFilterActive,
|
||
toUserListParams,
|
||
} from '../src/pages/account/users-filter.ts'
|
||
import { topbarUserOf } from '../src/layout/topbar-model.ts'
|
||
|
||
/**
|
||
* 公司维度不出现在后台前端(2026-10-04 15:4x 定案,推翻一期 §2.3/§5.1 的"列表加公司列 + 筛选 + 顶栏公司名")。
|
||
*
|
||
* <p>不显示 ≠ 不存在:建号请求体不带 company_id,归属由后端
|
||
* `AdminUserService#resolveTargetCompanyId` 落操作者自己的公司;跨公司隔离发生在消费侧与读取侧
|
||
* (二期批次 2/3),不依赖页面把公司名渲染出来。所以这里的断言全部打在"不得回流"上:
|
||
* 任何一处重新渲染公司,本文件就红。</p>
|
||
*/
|
||
|
||
test('公司列不再写进列表项,但其余字段必须照常解析', () => {
|
||
const item = toAdminUserItem({
|
||
id: 7,
|
||
username: '张三',
|
||
role: 'normal',
|
||
company_id: 2,
|
||
company_name: '福州数富',
|
||
created_by_id: 5,
|
||
creator_username: 'admin',
|
||
})
|
||
assert.ok(item, '解析结果不该为 null')
|
||
assert.equal('companyId' in item, false, '后端仍会带 company_id/company_name,前端不再往列表项里写')
|
||
assert.equal('companyName' in item, false)
|
||
// 反向自检:不许靠"整条解析都坏了"变绿
|
||
assert.equal(item.id, 7)
|
||
assert.equal(item.username, '张三')
|
||
assert.equal(item.createdById, 5)
|
||
assert.equal(item.creatorUsername, 'admin')
|
||
})
|
||
|
||
test('筛选状态与查询参数里都没有公司这一维', () => {
|
||
const state = createUserFilterState()
|
||
assert.equal('companyId' in state, false)
|
||
assert.deepEqual(state, { keyword: '', createdByAdminId: null, role: '', page: 1, pageSize: 10 })
|
||
|
||
const params = toUserListParams({ ...state, keyword: ' x ', createdByAdminId: 4 })
|
||
assert.equal('companyId' in params, false)
|
||
assert.equal(isFilterActive({ ...state, keyword: ' ' }), false)
|
||
|
||
const query = toUserListQuery(normalizeUserPageParams({ page: 2, pageSize: 20, keyword: 'x' }))
|
||
assert.equal('company_id' in query, false, '绝不下发 company_id:一旦下发就是"只看这家"的过滤')
|
||
})
|
||
|
||
test('顶栏不再渲染公司名', () => {
|
||
const vm = topbarUserOf({ id: 1, username: 'admin', role: 'admin', companyName: '厦门米椿花' } as never)
|
||
assert.equal('company' in vm, false)
|
||
assert.deepEqual(vm, { username: 'admin', role: '管理员', hasUser: true })
|
||
assert.equal(topbarUserOf(null).hasUser, false)
|
||
})
|
||
|
||
// 反向钉:公司维度不得回流到界面(2026-10-04 定口径)
|
||
test('账号页与顶栏的源码里公司维度已摘干净', () => {
|
||
const page = readSource('src/pages/account/UsersPage.vue')
|
||
assert.equal(/所属公司/.test(page), false, '账号页不该再出现「所属公司」标签')
|
||
assert.equal(/companyId|companyName|companies/.test(page), false, '页面不再持有公司目录或公司筛选状态')
|
||
assert.equal(/fetchCompanies/.test(page), false, '公司目录接口不该再被账号页调用')
|
||
|
||
// 「删了列忘了改占位行 colspan」是这类改动最常留下的残行:按表头列数交叉核对
|
||
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)
|
||
const headers = (page.match(/<th[\s>]/g) || []).length
|
||
const spans = [...page.matchAll(/colspan="(\d+)"/g)].map((m) => Number(m[1]))
|
||
assert.ok(spans.length >= 1, '列表 tbody 没有 colspan 占位行')
|
||
for (const span of spans) assert.equal(span, headers, `占位行 colspan=${span} 与表头列数 ${headers} 不符`)
|
||
|
||
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
|
||
assert.equal(/所属公司|selectableCompanies|initialCompanyId|companyId/.test(dialog), false,
|
||
'建号弹窗不该再有公司选择')
|
||
|
||
const layout = readSource('src/layout/AdminLayout.vue')
|
||
assert.equal(/userVm\.company|admin-user-company/.test(layout), false, '顶栏旁白只剩用户名与角色')
|
||
|
||
// 视图模型只删映射、留着 company 字段="接口说有、运行时永远空",是最难看出来的一种回流
|
||
const topbar = readSource('src/layout/topbar-model.ts')
|
||
assert.equal(/compan/i.test(topbar), false, '顶栏模型里不该再出现公司字段(连类型一起删)')
|
||
|
||
const filter = readSource('src/pages/account/users-filter.ts')
|
||
assert.equal(/companyId/.test(filter), false)
|
||
const dto = readSource('src/api/users-dto.ts')
|
||
assert.equal(/company_id|companyId/.test(dto), false)
|
||
const model = readSource('src/api/users-model.ts')
|
||
assert.equal(/company_id|company_name/.test(model), false)
|
||
})
|