test(phase-0): 确认基线全绿并预置迭代验收测试契约
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// AC-11(R4):用户端大档上传接线的「行为用例」那一半。
|
||||
//
|
||||
// Pending Phase 4 激活。9MB 视频(跨 8MB 分片阈值)调 uploadImageVideoMedia,
|
||||
// 必须出现 POST /files/chunk/init;今天它只打 POST /files/upload(单次 120s)。
|
||||
//
|
||||
// 本文件走 vitest(tests/mount/**),用 mock 的 http 出口对撞 URL 序列,不出网。
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
post: vi.fn(),
|
||||
get: vi.fn(),
|
||||
put: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
deleteFn: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/http.ts', () => ({
|
||||
http: mocks,
|
||||
post: mocks.post,
|
||||
get: mocks.get,
|
||||
put: mocks.put,
|
||||
del: mocks.deleteFn,
|
||||
unwrapJavaResponse: (value: unknown) => value,
|
||||
}))
|
||||
|
||||
import { uploadImageVideoMedia } from '@/shared/api/types/modules/image-video.ts'
|
||||
|
||||
const SKIP = 'Pending Phase 4: 断点续传大档接线(AC-11)'
|
||||
|
||||
describe.skip('AC-11 用户端大档上传', () => {
|
||||
it('9MB 视频必须走分片 init', async () => {
|
||||
const payload = {
|
||||
success: true,
|
||||
data: {
|
||||
url: 'https://oss.example/evidence.mp4',
|
||||
objectKey: 'image-video/obj.mp4',
|
||||
originalFilename: 'big.mp4',
|
||||
mediaType: 'video',
|
||||
upload_id: 'a'.repeat(32),
|
||||
uploaded_parts: [],
|
||||
},
|
||||
}
|
||||
mocks.post.mockResolvedValue(payload)
|
||||
mocks.get.mockResolvedValue({
|
||||
success: true,
|
||||
data: { upload_id: 'a'.repeat(32), uploaded_parts: [] },
|
||||
})
|
||||
|
||||
const file = new File([new Uint8Array(9 * 1024 * 1024)], 'big.mp4', { type: 'video/mp4' })
|
||||
await uploadImageVideoMedia(file)
|
||||
|
||||
const urls = mocks.post.mock.calls.map(([url]) => String(url))
|
||||
expect(
|
||||
urls.some((url) => url.includes('/files/chunk/init')),
|
||||
`AC-11:9MB 视频仍走单次上传,实际出口:${urls.join(', ')}`,
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
// AC-11(R4):用户端大档上传接线双口径的「源码尺子」那一半。
|
||||
//
|
||||
// Pending Phase 4 激活。今天 `src/shared/api/upload.ts::uploadTempFileToJava` 已实现
|
||||
// init→part→status→complete 全套分片,但**零生产调用方**(蓝图 §1.2 R4 实读);
|
||||
// `image-video.ts:215 uploadImageVideoMedia` 仍是一次 multipart+固定 120s。
|
||||
// 本文件钉两件事:
|
||||
// 1. uploadTempFileToJava 的调用方数从 0 变 ≥1;
|
||||
// 2. 图片视频大档路径接上分片(uploadTempFileToJava 或 /files/chunk)。
|
||||
//
|
||||
// 跑法:npm test(node --test tests/*.test.ts;本文件在顶层,不进 vitest 的 glob)。
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, resolve, relative, sep } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { listSourceFiles } from './helpers/task-terminal-ast-ruler.ts'
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const root = resolve(here, '..')
|
||||
const srcFiles = listSourceFiles(resolve(root, 'src'))
|
||||
const rel = (path: string) => relative(root, path).split(sep).join('/')
|
||||
const SKIP = 'Pending Phase 4: 断点续传大档接线(AC-11)'
|
||||
|
||||
test('uploadTempFileToJava 必须有生产调用方(调用方数 ≥1)', { skip: SKIP }, () => {
|
||||
assert.ok(srcFiles.length > 50, `源码扫描面异常:只扫到 ${srcFiles.length} 个文件`)
|
||||
const callers = srcFiles
|
||||
.map(rel)
|
||||
.filter((file) => file !== 'src/shared/api/upload.ts')
|
||||
.filter((file) => readFileSync(resolve(root, file), 'utf-8').includes('uploadTempFileToJava'))
|
||||
assert.ok(
|
||||
callers.length >= 1,
|
||||
`AC-11:uploadTempFileToJava 仍是零生产调用方(扫过 ${srcFiles.length} 个源码文件)`,
|
||||
)
|
||||
})
|
||||
|
||||
test('图片视频大档上传必须接分片通道', { skip: SKIP }, () => {
|
||||
const file = 'src/shared/api/types/modules/image-video.ts'
|
||||
const source = readFileSync(resolve(root, file), 'utf-8')
|
||||
assert.match(
|
||||
source,
|
||||
/uploadTempFileToJava|files\/chunk/,
|
||||
'AC-11:uploadImageVideoMedia 仍是一次 multipart+固定 120s(大档一断就从 0 重传)',
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user