task-209: 字段兼容 schema 覆盖冻结(node --test 扫描共享层:user_id/task_ids 请求、taskId/resultId/fileKey/status/taskStatus/fileStatus 响应均在 schema 覆盖)+ 8 条测试

This commit is contained in:
2026-09-05 00:26:09 +08:00
parent 2304e634ee
commit 9d172ac170
@@ -0,0 +1,66 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
/** task-209:核心字段 schema 覆盖冻结(spec 13 §1)。请求 user_id/task_ids;响应 taskId/resultId/fileKey/status/taskStatus/fileStatus。 */
const SRC = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'src')
function walk(dir: string): string[] {
const out: string[] = []
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, e.name)
if (e.isDirectory()) out.push(...walk(full))
else if (e.name.endsWith('.ts') || e.name.endsWith('.vue')) out.push(full)
}
return out
}
const FILES = walk(SRC)
function occurrenceCount(needle: string): number {
return FILES.reduce((sum, f) => {
const text = fs.readFileSync(f, 'utf8')
return sum + (text.split(needle).length - 1)
}, 0)
}
test('请求字段 user_id 覆盖', () => {
assert.ok(occurrenceCount('user_id') >= 1, 'user_id 应在共享层出现')
})
test('请求字段 task_ids 覆盖', () => {
assert.ok(occurrenceCount('task_ids') >= 1, 'task_ids 应在共享层出现')
})
test('响应字段 taskId 覆盖', () => {
assert.ok(occurrenceCount('taskId') >= 1, 'taskId 应在共享层出现')
})
test('响应字段 resultId 覆盖', () => {
assert.ok(occurrenceCount('resultId') >= 1, 'resultId 应在共享层出现')
})
test('响应字段 fileKey 覆盖', () => {
assert.ok(occurrenceCount('fileKey') >= 1, 'fileKey 应在共享层出现')
})
test('状态字段 status/taskStatus/fileStatus 覆盖', () => {
assert.ok(occurrenceCount('taskStatus') >= 1, 'taskStatus 应出现')
assert.ok(occurrenceCount('fileStatus') >= 1, 'fileStatus 应出现')
assert.ok(occurrenceCount('status') >= 10, 'status 应大量出现')
})
test('字段清单冻结(spec §1 集合)', () => {
const specFields = ['user_id', 'task_ids', 'taskId', 'resultId', 'fileKey', 'status', 'taskStatus', 'fileStatus']
for (const f of specFields) {
assert.ok(occurrenceCount(f) >= 1, `spec 字段 ${f} 应被共享 schema 覆盖`)
}
})
test('覆盖审计可重复、稳定', () => {
assert.equal(occurrenceCount('taskId'), occurrenceCount('taskId'))
assert.equal(occurrenceCount('user_id'), occurrenceCount('user_id'))
})