fix(phase-5.2): 消项 CR 第二轮 P1/P2/P3(通道/证据链/交付时序/后管证据页)

This commit is contained in:
2026-10-31 21:12:18 +08:00
parent a4e4456b50
commit 91d36327f9
61 changed files with 2833 additions and 311 deletions
@@ -3,7 +3,7 @@
// Pending Phase 4 激活。9MB 安装包(跨分片阈值)调 uploadSoftwareVersion,
// 必须出现 POST /files/chunk/init;今天它走 presign → 一次 PUT 直传,
// 512MB 断网只能从 0 重来。本文件不出网,mock 掉 http 与 axios 直传实例。
import { describe, it, expect, vi } from 'vitest'
import { beforeEach, describe, it, expect, vi } from 'vitest'
const mocks = vi.hoisted(() => ({
post: vi.fn(),
@@ -34,9 +34,16 @@ vi.mock('@/api/http', () => ({
}))
import { uploadSoftwareVersion } from '@/pages/records/version-api.ts'
import { uploadTutorialPackage } from '@/pages/records/tutorial-api.ts'
describe('AC-11 后管大档上传', () => {
// 会话跨尝试复用后,两格之间必须清态:残留的 upload_id 会让第二格跳过本该发生的 init。
beforeEach(() => {
vi.clearAllMocks()
localStorage.clear()
})
it('9MB 安装包必须走分片 init', async () => {
// 预签名与分片两套响应揉成一个超集:哪条实现路径先走都能拿到自己要的字段。
mocks.post.mockResolvedValue({
@@ -68,5 +75,48 @@ describe('AC-11 后管大档上传', () => {
urls.some((url) => url.includes('/files/chunk/init')),
`AC-11:9MB 安装包仍走 presign 直传,实际出口:${urls.join(', ')}`,
).toBe(true)
// P2-6:删掉 uploadFileInChunks(…) 真调用后,这一格必须跟着红——所以还要核对分片片确实发出去了。
expect(
mocks.post.mock.calls.filter(([url]) => /\/files\/chunk\/[^/]+\/part\/\d+$/.test(String(url))).length,
'AC-11:走分片就要真把片 POST 出去',
).toBe(2)
})
// P2-6:教程包那条道过去只有源码尺子覆盖(而尺子当时吃的是死常量),删掉真调用没人判红。
it('9MB 教程包必须走分片 init', async () => {
localStorage.clear()
mocks.post.mockResolvedValue({
data: {
success: true,
data: {
upload_url: 'https://oss.example/put',
file_url: 'https://oss.example/tutorial.zip',
version: '9.9.9',
object_key: 'client/tutorials/tutorial.zip',
upload_id: 'b'.repeat(32),
uploaded_parts: [],
item: null,
},
},
})
mocks.get.mockResolvedValue({
data: { success: true, data: { upload_id: 'b'.repeat(32), uploaded_parts: [] } },
})
mocks.directPut.mockResolvedValue({})
const file = new Blob([new Uint8Array(9 * 1024 * 1024)], {
type: 'application/octet-stream',
})
await uploadTutorialPackage(file, 'tutorial.zip', '9.9.9')
const urls = mocks.post.mock.calls.map(([url]) => String(url))
expect(
urls.some((url) => url.includes('/files/chunk/init')),
`AC-11:9MB 教程包仍走 presign 直传,实际出口:${urls.join(', ')}`,
).toBe(true)
expect(
mocks.directPut.mock.calls.length,
'AC-11:大档不该再走一次 PUT 直传',
).toBe(0)
})
})