/** * 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_渲染异常必须有全局兜底', { skip: PENDING_ERROR }, () => { const main = read('src/main.ts') assert.match(main, /app\.config\.errorHandler\s*=/, 'S1-F2:渲染期异常必须被 Vue 全局兜底接住,不能只进 console') assert.match(main, /addEventListener\(\s*['"]unhandledrejection['"]/, '未捕获 Promise 同样要兜底(后管列表请求都是 promise 链)') assert.match(main, /addEventListener\(\s*['"]error['"]/, '脚本级崩溃(window error)必须留痕') }) test('pending_ac16_admin_上报必须挂在入口且不带凭据', { skip: PENDING_ERROR }, () => { 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_安装包必须分片续传并可观察进度', { skip: PENDING_UPLOAD }, () => { 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失败必须清理对象', { skip: PENDING_UPLOAD }, () => { const api = read('src/pages/records/workbench-client-api.ts') assert.match(api, /confirm[\s\S]{0,400}(abort|deleteObject|cleanup|remove)/, 'confirm 失败必须清对象(工作台包凭据零容忍:拒绝新包不等于旧对象已处置)') })