后管(四面9分批次): 裸提示 92→0、裸 confirm 24→0 且逐处 await、失败态可见并真能重试

- ElMessage.error 全收进 showAdminFeedback(例外清单 CAP=0,唯一保留的裸调用是出口本体);
  window.confirm 24 处全部改成 await 的 openAdminConfirm(逐处核过所在函数本就 async,
  不存在"点了确认不执行"的异步断层)。
- 新增 load-failure-model + LoadFailureBar:22/23 个取数页有失败态与真重试
  (只有"知道了"清条不算过),例外仅登录页。
- DedupeRegistryPage / DuplicateCheckPage 补 onUnmounted,并加全树定时器/监听配对判据。
- 去重页那处"能点但后端 403":读侧认 wholeCompany、写侧只认 groupIds/userIds 的不对称
  本轮没动后端(前端拿不到与写侧同集合的 groupIds,按它置灰会误伤同事名下真能改的行=静默删功能);
  先修更实在的一半——403 的中文原因此前整段丢失,现在走统一文案到界面。
- 验收:node --test 1,818 例 0 红、npx vue-tsc --noEmit rc=0;5 支新判据 26 例。
This commit is contained in:
2026-10-09 23:09:37 +08:00
parent 15094309cf
commit 8776a9bf1e
37 changed files with 1181 additions and 136 deletions
@@ -0,0 +1,118 @@
/**
* 去重库「前端能点、后端按范围拒」这一处(四面9分口径 · 后管「交互 6.0:1 处能点但后端 403」)。
*
* 判据来自后端 `DedupeTotalDataService`,两条谓词不是同一个口径:
* 读侧 `applyGroupScope`:`scope.wholeCompany()`(公司超管)走 **`company_id = 本公司`**,整家公司的行全给看;
* 写侧 `ensureRecordAccess` / `resolveAccessibleGroup`:只认 **`scope.groupIds()`**(本公司成员当组长的分组)
* 与 `group_id IS NULL && uploaderUserId ∈ scope.userIds()`。
* 于是「代导入行」(平台超管在 A 公司 tab 里把行挂到 B 公司的分组上)与「上传账号已被硬删的行」这两族
* 会**看得见、改不了**:点编辑/删除直接被 403 拒。
*
* 这一支钉三件事:
* ① 403 的中文原因(`无权操作该总数据`)必须真的到达界面——此前写路径取的是
* `error instanceof Error ? error.message`,而 HTTP-403 是 axios 抛的,那句 message 是
* `Request failed with status code 403`(英文、且把响应体里后端写的原因整段丢掉);
* ② 前后端文案不许各说各话:后端那两句拒绝理由改字,本用例红;
* ③ 不许用「客户端猜一个条件把按钮禁用」来糊:客户端拿不到 companyGroupIds,
* 按 `groups` 下拉收窄会误伤同事名下**真能改**的行(假阴性=静默删功能)。
* 要把这个入口收窄,得先让后端把可写标志随列表下发(现成的先例:用户菜单授权树的 `grantable`)。
*/
import test from 'node:test'
import assert from 'node:assert/strict'
import { existsSync } from 'node:fs'
import { readSource } from './helpers.ts'
import { failureDetail, loadFailureMessage, scopeRefusalNote } from '../src/components/load-failure-model.ts'
const PAGE = 'src/pages/asin/DedupeRegistryPage.vue'
const BACKEND = '../backend-java/src/main/java/com/nanri/aiimage/modules/dedupe/service/DedupeTotalDataService.java'
/** 后端按范围拒人时写进响应的原话(HTTP 403 + 响应体 message)。 */
const BACKEND_REFUSALS = ['无权操作该总数据', '无权操作该分组数据']
function fnBody(src: string, name: string): string {
const at = src.search(new RegExp(`(?:async\\s+)?function\\s+${name}\\s*\\(`))
assert.ok(at >= 0, `${name} 不在了:入口被改名或删掉,本用例得重看`)
const open = src.indexOf('{', at)
let depth = 0
for (let i = open; i < src.length; i++) {
if (src[i] === '{') depth += 1
else if (src[i] === '}') {
depth -= 1
if (depth === 0) return src.slice(open + 1, i)
}
}
throw new Error(`${name} 括号不配对`)
}
/** 模拟后端 GlobalExceptionHandler 对 ResponseStatusException 的产物:HTTP 403 + 中文 reason 在响应体里。 */
function http403(reason: string): unknown {
return Object.assign(new Error(`Request failed with status code 403`), {
isAxiosError: true,
response: { status: 403, data: { success: false, code: 403, message: reason } },
})
}
test('后端源码仍在(跨树判据的前提:文件不在了要红,不能静默跳过)', () => {
assert.ok(existsSync(BACKEND), `找不到后端判据源文件 ${BACKEND}:整条跨树对账失去依据`)
})
test('403 的中文原因必须到达界面,而不是 axios 那句英文', () => {
const err = http403('无权操作该总数据')
// 收口前各写路径的写法:英文原文上屏,后端原因整段丢失
const before = err instanceof Error ? err.message : '删除失败'
assert.equal(before, 'Request failed with status code 403')
assert.equal(/[\u4e00-\u9fff]/.test(before), false, '对照本体必须是"界面上一个中文都没有"的那种')
// 收口后:本页兜底 + 后端原因 + 出路
const after = loadFailureMessage(err, '删除失败')
assert.match(after, /删除失败:无权操作该总数据/)
assert.match(after, /平台超级管理员/, '按范围拒人要把出路一起说清楚')
assert.equal(failureDetail(err), '无权操作该总数据')
})
test('去重页四条写路径都把错误交给 loadFailureMessage,不再直接取 error.message', () => {
const src = readSource(PAGE)
for (const name of ['saveEdit', 'removeRow', 'submitImport', 'doExport']) {
const body = fnBody(src, name)
assert.match(body, /loadFailureMessage\(error,/, `${name} 的失败提示没有带出后端原因`)
assert.equal(/error instanceof Error \? error\.message/.test(body), false,
`${name} 还留着 error.message 那套写法:HTTP 403 时会把英文原文弹给用户`)
}
assert.match(src, /import \{ loadFailureMessage \} from '@\/components\/load-failure-model'/)
})
test('前后端拒绝文案对账:后端改字,这条要红', () => {
const backend = readSource(BACKEND)
for (const reason of BACKEND_REFUSALS) {
assert.ok(backend.includes(`"${reason}"`), `后端已不再用「${reason}」这句话拒人:前端那句补充说明要跟着改`)
assert.match(scopeRefusalNote(reason), /平台超级管理员/, `「${reason}」没被识别成范围拒绝`)
}
// 业务校验类的中文(本公司已存在该数据)不许被套上越权说明
assert.equal(scopeRefusalNote('本公司已存在该数据'), '')
})
test('读写两条谓词确实不同口径(不对称仍在=这条台账还没到可关闭的时候)', () => {
const backend = readSource(BACKEND)
// 取 4 参那一条真身:3 参重载只是 `applyGroupScope(query, scope, groupId, false)` 的转发壳,
// 用懒匹配会停在壳上,把"整家公司都放行"那半边看漏。
const readSide = /private void applyGroupScope\(LambdaQueryWrapper<DedupeTotalDataEntity> query,\s*\n?\s*AccessScope scope, Long groupId, boolean groupPrevalidated\)\s*\{[\s\S]*?\n \}/
.exec(backend)
assert.ok(readSide, 'applyGroupScope 不在了:读侧裁剪改写法了,本用例要重读')
assert.match(readSide[0], /scope\.wholeCompany\(\)/, '读侧不再有 wholeCompany 分支:这条不对称可能已被收口')
assert.match(readSide[0], /getCompanyId, scope\.companyId\(\)/,
'读侧已不按 company_id 给整家公司放行:请重判前端入口是否还需要收窄')
const writeSide = /private void ensureRecordAccess\([\s\S]*?\n \}/.exec(backend)
assert.ok(writeSide, 'ensureRecordAccess 不在了:写侧改判据了,本用例要重读')
assert.match(writeSide[0], /scope\.groupIds\(\)\.contains/, '写侧不再按 groupIds 拒人')
assert.equal(/scope\.wholeCompany\(\)/.test(writeSide[0]), false,
'写侧也开始认 wholeCompany:读写字面口径一致了,可以把"能点但拒"这条台账关掉')
})
test('不许用客户端猜测禁用行内入口:那会误伤真能改的行', () => {
const src = readSource(PAGE)
const opsCell = /<td class="ops-cell">[\s\S]*?<\/td>/.exec(src)
assert.ok(opsCell, '行内操作列结构变了:这条判据要重写')
assert.equal(/:disabled=|v-if=/.test(opsCell[0]), false,
'行内编辑/删除上加了客户端权限闸——但前端拿不到后端写侧的 companyGroupIds,'
+ '按分组下拉收窄会把同事名下"看得见也改得动"的行一起禁掉(静默删功能)。'
+ '要收窄请先让后端在列表响应里下发可写标志(先例:用户菜单授权树的 grantable)。')
assert.match(opsCell[0], /@click="removeRow\(row\)"/, '删除入口本身不在了:本用例失效')
})