test(phase-0): 确认基线全绿并预置迭代验收测试契约
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||
"totals": {
|
||||
"files": 250,
|
||||
"cases": 1748,
|
||||
"pins": 451,
|
||||
"reads": 644
|
||||
"files": 251,
|
||||
"cases": 1750,
|
||||
"pins": 453,
|
||||
"reads": 646
|
||||
},
|
||||
"files": {
|
||||
"admin-scaffold.test.ts": {
|
||||
@@ -337,6 +337,11 @@
|
||||
"pins": 0,
|
||||
"reads": 1
|
||||
},
|
||||
"pending-phase4-大档上传接线.test.ts": {
|
||||
"cases": 2,
|
||||
"pins": 2,
|
||||
"reads": 2
|
||||
},
|
||||
"pending-phase4-错误兜底与大文件上传.test.ts": {
|
||||
"cases": 1,
|
||||
"pins": 0,
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// AC-11(R4):后管版本/教程大档上传接线的「源码尺子」那一半。
|
||||
//
|
||||
// Pending Phase 4 激活。今天 `src/pages/records/version-api.ts` 与 `tutorial-api.ts`
|
||||
// 都是 presign → 一次 PUT 直传(512MB 级也一样,蓝图 §1.2 R4 实读);本文件要求两条
|
||||
// 路径接上既有 `/api/files/chunk/**` 分片通道(断点续传/按片重试)。
|
||||
//
|
||||
// 跑法:npm test(node --test tests/*.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 SKIP = 'Pending Phase 4: 断点续传大档接线(AC-11)'
|
||||
|
||||
const LARGE_UPLOAD_FILES = [
|
||||
'src/pages/records/version-api.ts',
|
||||
'src/pages/records/tutorial-api.ts',
|
||||
]
|
||||
|
||||
test('后管版本/教程大档必须接分片通道', { skip: SKIP }, () => {
|
||||
for (const file of LARGE_UPLOAD_FILES) {
|
||||
const source = readFileSync(resolve(root, file), 'utf-8')
|
||||
assert.match(
|
||||
source,
|
||||
/files\/chunk/,
|
||||
`AC-11:${file} 仍是 presign 直传(512MB 断网从 0 重来,没有分片续传)`,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test('分片接线不得只落注释', { skip: SKIP }, () => {
|
||||
for (const file of LARGE_UPLOAD_FILES) {
|
||||
const source = readFileSync(resolve(root, file), 'utf-8')
|
||||
const codeLines = source
|
||||
.split('\n')
|
||||
.filter((line) => !line.trim().startsWith('//') && !line.trim().startsWith('*'))
|
||||
.join('\n')
|
||||
assert.match(codeLines, /files\/chunk/, `AC-11:${file} 的分片引用只出现在注释里`)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,73 @@
|
||||
// AC-11(R4):后管大档上传接线的「行为用例」那一半。
|
||||
//
|
||||
// Pending Phase 4 激活。9MB 安装包(跨分片阈值)调 uploadSoftwareVersion,
|
||||
// 必须出现 POST /files/chunk/init;今天它走 presign → 一次 PUT 直传,
|
||||
// 512MB 断网只能从 0 重来。本文件不出网,mock 掉 http 与 axios 直传实例。
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
post: vi.fn(),
|
||||
get: vi.fn(),
|
||||
put: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
directPut: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('axios', () => ({
|
||||
default: {
|
||||
create: () => ({ put: mocks.directPut }),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/api/http', () => ({
|
||||
http: { post: mocks.post, get: mocks.get, put: mocks.put, delete: mocks.delete },
|
||||
unwrap: (value: unknown) => {
|
||||
const envelope = value as { success?: boolean; data?: unknown; message?: string }
|
||||
if (envelope && typeof envelope === 'object' && 'success' in envelope) {
|
||||
if (!envelope.success) {
|
||||
throw new Error(envelope.message || '请求失败')
|
||||
}
|
||||
return envelope.data
|
||||
}
|
||||
return value
|
||||
},
|
||||
}))
|
||||
|
||||
import { uploadSoftwareVersion } from '@/pages/records/version-api.ts'
|
||||
|
||||
const SKIP = 'Pending Phase 4: 断点续传大档接线(AC-11)'
|
||||
|
||||
describe.skip('AC-11 后管大档上传', () => {
|
||||
it('9MB 安装包必须走分片 init', async () => {
|
||||
// 预签名与分片两套响应揉成一个超集:哪条实现路径先走都能拿到自己要的字段。
|
||||
mocks.post.mockResolvedValue({
|
||||
data: {
|
||||
success: true,
|
||||
data: {
|
||||
upload_url: 'https://oss.example/put',
|
||||
file_url: 'https://oss.example/pkg.zip',
|
||||
version: '9.9.9',
|
||||
object_key: 'client/versions/pkg.zip',
|
||||
upload_id: 'a'.repeat(32),
|
||||
uploaded_parts: [],
|
||||
item: null,
|
||||
},
|
||||
},
|
||||
})
|
||||
mocks.get.mockResolvedValue({
|
||||
data: { success: true, data: { upload_id: 'a'.repeat(32), uploaded_parts: [] } },
|
||||
})
|
||||
mocks.directPut.mockResolvedValue({})
|
||||
|
||||
const file = new Blob([new Uint8Array(9 * 1024 * 1024)], {
|
||||
type: 'application/octet-stream',
|
||||
})
|
||||
await uploadSoftwareVersion('9.9.9', file)
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user