fix(phase-5.2): 消项 CR 第二轮 P1/P2/P3(通道/证据链/交付时序/后管证据页)
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
// AC-11(R4):后管版本/教程大档上传接线的「源码尺子」那一半。
|
||||
//
|
||||
// Pending Phase 4 激活。今天 `src/pages/records/version-api.ts` 与 `tutorial-api.ts`
|
||||
// 都是 presign → 一次 PUT 直传(512MB 级也一样,蓝图 §1.2 R4 实读);本文件要求两条
|
||||
// 路径接上既有 `/api/files/chunk/**` 分片通道(断点续传/按片重试)。
|
||||
// Pending Phase 4 激活。本尺子的前身只断言 `files/chunk` 出现在非注释行,而那一句匹配来自
|
||||
// `version-api.ts`/`tutorial-api.ts` 里一对**全仓零引用的死常量**(SOFTWARE_VERSION_CHUNK_ENDPOINT/
|
||||
// TUTORIAL_CHUNK_ENDPOINT)——把真调用 `uploadFileInChunks(…)` 删掉,尺子照样绿(评审 P2-6 假绿形状)。
|
||||
// 现在判据钉在**真调用点**上:被接线的那个函数体里必须出现 `uploadFileInChunks(`,
|
||||
// 且死常量不许回来(`CHUNK_ENDPOINT =` 一出现即红)。删调用必判红,加死常量也判红。
|
||||
//
|
||||
// 行为口径在 tests/pure/pending-phase4-大档上传接线.test.ts(vitest 真调 uploadSoftwareVersion/
|
||||
// uploadTutorialPackage,删掉调用同一刻那一边也红);本文件只补"接线没被搬空"这一层。
|
||||
//
|
||||
// 跑法:npm test(node --test tests/*.test.ts)。
|
||||
import { test } from 'node:test'
|
||||
@@ -14,29 +19,75 @@ import { fileURLToPath } from 'node:url'
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const root = resolve(here, '..')
|
||||
|
||||
const LARGE_UPLOAD_FILES = [
|
||||
'src/pages/records/version-api.ts',
|
||||
'src/pages/records/tutorial-api.ts',
|
||||
]
|
||||
/** 把注释整段涂白(保行数):接线只写在注释里不算数。 */
|
||||
function blankComments(source: string): string {
|
||||
return source
|
||||
.replace(/\/\*[\s\S]*?\*\//g, (block) => block.replace(/[^\n]/g, ' '))
|
||||
.replace(/\/\/[^\n]*/g, (line) => ' '.repeat(line.length))
|
||||
}
|
||||
|
||||
test('后管版本/教程大档必须接分片通道', () => {
|
||||
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 重来,没有分片续传)`,
|
||||
)
|
||||
/** 取 `function <name>(…) {…}` 的函数体:大括号配对,跳过字符串与模板串里的括号。 */
|
||||
function functionBodyOf(source: string, name: string): string {
|
||||
const code = blankComments(source)
|
||||
const head = code.indexOf(`function ${name}(`)
|
||||
assert.notEqual(head, -1, `找不到函数 ${name}()——接线被删了还是改名了?`)
|
||||
const open = code.indexOf('{', head)
|
||||
assert.notEqual(open, -1, `${name}() 没有函数体`)
|
||||
let depth = 0
|
||||
let index = open
|
||||
let quote = ''
|
||||
for (; index < code.length; index += 1) {
|
||||
const char = code[index]
|
||||
if (quote) {
|
||||
if (char === '\\') index += 1
|
||||
else if (char === quote) quote = ''
|
||||
continue
|
||||
}
|
||||
if (char === '"' || char === "'" || char === '`') { quote = char; continue }
|
||||
if (char === '{') depth += 1
|
||||
else if (char === '}') {
|
||||
depth -= 1
|
||||
if (depth === 0) return code.slice(open + 1, index)
|
||||
}
|
||||
}
|
||||
return code.slice(open + 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 两格共同判据(读盘点留在用例体内:把 readFileSync 挪进 helper 是本仓 source-pin 棘轮点名的"搬家不算改进"):
|
||||
* ① 从 @/api/chunk-upload 把分片函数引进来;② 被接线的函数体里真的调它;
|
||||
* ③ 阈值同源;④ 死常量不得回来。
|
||||
*/
|
||||
function assertChunkedWiring(source: string, file: string, wiredFunction: string): void {
|
||||
assert.match(
|
||||
source,
|
||||
/import\s*\{[^}]*uploadFileInChunks[^}]*\}\s*from\s*'@\/api\/chunk-upload'/,
|
||||
`AC-11:${file} 没有从 @/api/chunk-upload 引入分片函数`,
|
||||
)
|
||||
const body = functionBodyOf(source, wiredFunction)
|
||||
assert.match(
|
||||
body,
|
||||
/uploadFileInChunks\s*\(/,
|
||||
`AC-11:${file}::${wiredFunction}() 里没有真调用 uploadFileInChunks(…)(大档仍走一次 PUT 直传,512MB 断网从 0 重来)`,
|
||||
)
|
||||
assert.match(
|
||||
body,
|
||||
/CHUNK_UPLOAD_THRESHOLD/,
|
||||
`AC-11:${wiredFunction}() 的选路阈值必须与 chunk-upload 同源,不得各自写死 8MB`,
|
||||
)
|
||||
assert.doesNotMatch(
|
||||
source,
|
||||
/CHUNK_ENDPOINT\s*=/,
|
||||
`AC-11:${file} 又立了一个没人引用的 CHUNK_ENDPOINT 常量——它会顶掉本尺子的匹配来源,正是 P2-6 的假绿形状`,
|
||||
)
|
||||
}
|
||||
|
||||
test('后管安装包上传必须真的调分片通道', () => {
|
||||
const file = 'src/pages/records/version-api.ts'
|
||||
assertChunkedWiring(readFileSync(resolve(root, file), 'utf-8'), file, 'uploadSoftwareVersion')
|
||||
})
|
||||
|
||||
test('分片接线不得只落注释', () => {
|
||||
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} 的分片引用只出现在注释里`)
|
||||
}
|
||||
test('后管教程包上传必须真的调分片通道', () => {
|
||||
const file = 'src/pages/records/tutorial-api.ts'
|
||||
assertChunkedWiring(readFileSync(resolve(root, file), 'utf-8'), file, 'uploadTutorialPackage')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user