0586df2df0
AC-16(S1-F1/S1-F2) - frontend-vue ensureAuth:清态前先判 isAuthError——弱网/超时/5xx 不再把人踢回登录页; http.ts 的 onResponseRejected 给错误打鉴权标记(HTTP 401 与业务 401/4011 都算), 纯网络错误保留底层文案供调用方区分"断网"与"掉登录";clearLocalSession 导出复用。 - admin 全局错误兜底:main.ts 装 app.config.errorHandler(首屏就崩也接得住), window error / unhandledrejection 由 App.vue setup 调 useGlobalErrorReporting() 接线, 卸载出口在 onBeforeUnmount 摘监听与提示定时器(后管的 timer-cleanup-pairing 尺子要求 "注册点所在文件找得回反注册 + 卸载钩子",故接线必须在组件作用域,不在 main.ts)。 上报体只带 kind/message/stack/route/ts 并过脱敏(Bearer、JWT 三段式、query 里疑似 token/key/secret 的取值一律打码),凭据零容忍;服务端新增 /api/admin/client-errors(requireAdmin,字段截断 2000 后 WARN 落日志,不落库)。 AC-17(S1-F3) - 后端新增分片通道 ChunkedUploadService(init/part/status/complete/abort):8MB/片、 同片重复上传幂等覆盖、流式拼装复算 sha256、超限与缺片直接拒绝、24h 过期回收; FileUploadController 暴露 /api/files/chunk/**,LocalFileStorageService 加 saveTempFileFromFile(同一套扩展名黑名单与 fileKey 索引);三键显式写进 application.yml (不进"只在代码默认值里"的名单)。 - 工作台安装包 93MB:WorkbenchClientPackageService 走同一分片通道转存 client 桶 (objectKey 写进会话 purpose,拼装时逐字匹配,防借分片接口覆盖已发布包), confirm 失败带 cleanupUnconfirmedObject 补偿清理未登记对象;后管 ≤64MB 仍直传预签名 PUT。 - 用户端 upload.ts:大文件分片 + 逐片重试 + 进度回调,超时按体积给(不再固定 120s); 断点探测失败不再静默按"全缺"重传(catch-silence 棘轮因此一格没涨,blocks 300→301 已记名)。 AC-18(P1-F1/P1-F2/P1-F4/S1-F4) - 后管 manualChunks 摘掉 element-plus(按需引入已在 src/plugins/element.ts 生效): 实测构建产物已无 element-plus 独立 chunk,index.html 只 modulepreload vue 块。 - UsersPage/DeviceLogsPage 接 createLatestRequestGate,旧响应不再覆盖新页; 用户端新增 useServerTablePaging(只驻留当前页 + 自带竞态门 + 失败给原因), 挂载用例 3 例钉住"翻页重取/旧响应作废/失败可见"。 - DeliveryVideoWorkspace 两处轮询接 document.visibilityState,隐藏标签页暂停。 激活 Phase 0 预置契约 7 例(用户端 5 + 后管 5,共 12 例;其中 AC-16 后管两支按"接线在组件作用域" 的口径改写并把判据加强到反注册配对 + 根组件接线,见蓝图 §5)。 门禁读数:后端 mvn -o test-compile rc=0,CatchSilenceRatchetTest 9 例绿(total 1034→1045、 notRethrow 585→591、logOnly 182→188 逐处记名,EMPTY 未涨)、ChunkedUploadServiceTest 8 例、 WorkbenchClientPackageServiceTest 21 例、ClientErrorReportControllerTest 4 例;后管 1848 例 + mount 33 例 + vue-tsc + build 全绿;用户端 955 例 + mount 30 例 + vue-tsc + build 全绿。 真机:OssWorkbenchClientLiveVerificationTest 以线上 MinIO 实测 PUT→stat→sha256→presign→删除 全链 1 例绿(凭据只走环境变量,不落任何文件)。 ⚠ 按 pathspec 只圈本轮文件:application.yml 用索引手术只提交分片三键那一格,他人 「PENDING 不再按 2 小时判死」的 StaleTaskRepairService/ClientTaskPullSpi/application.yml 注释件与 useLiveTaskBoard/BrandAppearancePatentTab/task-delete-target 四件在飞改动 原样留在工作树未提交。
88 lines
4.7 KiB
TypeScript
88 lines
4.7 KiB
TypeScript
/**
|
||
* AC-16/AC-17(后管侧,R7/S1-F2、S1-F3):全局错误兜底与可见上报、大文件断点续传。
|
||
*
|
||
* Pending Phase 4 激活(`node --test tests/*.test.ts` 认 `{ skip }`,与 tests/live/** 同一写法)。
|
||
*
|
||
* 现状(`docs/audit/稳定性与性能综合审计-2026-10-28.md` §3.4):
|
||
* - **S1-F2** `src/main.ts` 只有 `createApp → use(pinia/router) → installElement → mount`,
|
||
* 没有 `app.config.errorHandler`、没有 `window.onerror` / `unhandledrejection`:渲染崩了
|
||
* 只剩白屏;用户端那份还有 20 条内存环,后管连一份留痕都没有。
|
||
* - **S1-F3** `src/pages/records/workbench-client-api.ts` 的 93MB 安装包走单次 PUT 预签名,
|
||
* 中断即从 0 重传;confirm 失败的对象清理也在同一条通道上。
|
||
*
|
||
* 组件形状按本树既有惯例用源码尺子钉(对齐用户端
|
||
* `frontend-vue/tests/session-expired-signout.test.ts` 的口径:无挂载测试的组件层用源码判据)。
|
||
*/
|
||
import { test } from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readFileSync } from 'node:fs'
|
||
import { dirname, resolve } from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
const here = dirname(fileURLToPath(import.meta.url))
|
||
const root = resolve(here, '..')
|
||
const read = (rel: string) => readFileSync(resolve(root, rel), 'utf-8')
|
||
|
||
const PENDING_ERROR = 'Pending Phase 4: AC-16 全局错误兜底与脱敏上报'
|
||
const PENDING_UPLOAD = 'Pending Phase 4: AC-17 93MB 包分片续传与孤儿对象清理'
|
||
|
||
test('pending_ac16_admin_渲染异常必须有全局兜底', () => {
|
||
const main = read('src/main.ts')
|
||
assert.match(main, /app\.config\.errorHandler\s*=/,
|
||
'S1-F2:渲染期异常必须被 Vue 全局兜底接住,不能只进 console')
|
||
|
||
// window error / unhandledrejection 两个出口的注册点从入口挪到了入口装的守卫模块:
|
||
// 后管的 timer-cleanup-pairing 尺子要求"注册点所在文件必须找得回反注册 + 卸载钩子",
|
||
// 而 main.ts 没有组件作用域可挂——只定义不接线等于没接,所以接线必须在根组件 setup 里。
|
||
// 判据强度没有降:三类错误照样都要接住,另外多卡"反注册配对"和"根组件真的接了线"。
|
||
const guard = read('src/shared/api/error-report.ts')
|
||
assert.match(guard, /addEventListener\(\s*['"]unhandledrejection['"]/,
|
||
'未捕获 Promise 同样要兜底(后管列表请求都是 promise 链)')
|
||
assert.match(guard, /addEventListener\(\s*['"]error['"]/,
|
||
'脚本级崩溃(window error)必须留痕')
|
||
assert.match(guard, /removeEventListener\(\s*['"]unhandledrejection['"]/,
|
||
'AC-16:注册了就要找得回反注册,否则热更新/宿主拆栈会叠监听')
|
||
assert.match(guard, /removeEventListener\(\s*['"]error['"]/,
|
||
'AC-16:window error 的反注册同样要点名')
|
||
assert.match(guard, /onBeforeUnmount\(/,
|
||
'AC-16:卸载出口必须挂在组件生命周期上(模块里空有一个 dispose 函数不算接上)')
|
||
|
||
const app = read('src/App.vue')
|
||
assert.match(app, /useGlobalErrorReporting\(\)/,
|
||
'AC-16:根组件必须真的调用接线函数')
|
||
assert.ok(main.includes('installGlobalError'), '入口仍须装 Vue 渲染兜底(首屏就崩也不能漏)')
|
||
})
|
||
|
||
test('pending_ac16_admin_上报必须挂在入口且不带凭据', () => {
|
||
const main = read('src/main.ts')
|
||
assert.match(main, /installGlobalError|registerGlobalError|setupGlobalError/,
|
||
'兜底与上报必须挂在入口上(只写在页面里=有些页面崩了没人接)')
|
||
|
||
const candidates = ['src/shared/api/error-report.ts', 'src/shared/telemetry/error-report.ts',
|
||
'src/shared/errors/client-report.ts']
|
||
const source = candidates.map((rel) => {
|
||
try {
|
||
return read(rel)
|
||
} catch {
|
||
return ''
|
||
}
|
||
}).join('\n')
|
||
assert.match(source, /sendBeacon|reportClientError/,
|
||
'崩溃必须能上报服务端,否则线上白屏永远无现场')
|
||
assert.doesNotMatch(source, /aiimage_auth_token|authorization/i,
|
||
'上报里不许带令牌原文(凭据零容忍,与 AC-1 同一把尺)')
|
||
})
|
||
|
||
test('pending_ac17_安装包必须分片续传并可观察进度', () => {
|
||
const api = read('src/pages/records/workbench-client-api.ts')
|
||
assert.match(api, /partSize|uploadPart|createMultipartUpload|chunk/,
|
||
'S1-F3:单次 PUT 一断就从 0 重来,必须改成分片/断点续传')
|
||
assert.match(api, /onProgress|progress/, '93MB 上传必须有可见进度')
|
||
})
|
||
|
||
test('pending_ac17_confirm失败必须清理对象', () => {
|
||
const api = read('src/pages/records/workbench-client-api.ts')
|
||
assert.match(api, /confirm[\s\S]{0,400}(abort|deleteObject|cleanup|remove)/,
|
||
'confirm 失败必须清对象(工作台包凭据零容忍:拒绝新包不等于旧对象已处置)')
|
||
})
|