fix(contracts): 守卫收紧必填字段类型与对象形状;修复包级 test 脚本;补齐守卫测试与 REQUIRED 类型锁

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-10-20 18:26:42 +08:00
parent 857389e68b
commit 31cd7ed7f4
3 changed files with 41 additions and 7 deletions
@@ -25,3 +25,33 @@ describe('UniversalRow 契约', () => {
expect(isUniversalRow(bad)).toBe(false)
})
})
const REQUIRED_KEYS = [
'sourceType', 'sourceId', 'status', 'locale',
'taxonomyRefs', 'attachmentRefs', 'seo', 'knownFields', 'extras', 'rawLocation',
] as const
describe('UniversalRow 守卫拒绝路径', () => {
it.each(REQUIRED_KEYS)('缺必填字段 %s 拒绝', (key) => {
const clone: Record<string, unknown> = { ...valid }
delete clone[key]
expect(isUniversalRow(clone)).toBe(false)
})
it('非对象输入拒绝(null / number)', () => {
expect(isUniversalRow(null)).toBe(false)
expect(isUniversalRow(42)).toBe(false)
})
it('taxonomyRefs 非数组拒绝', () => {
expect(isUniversalRow({ ...valid, taxonomyRefs: 'oops' })).toBe(false)
})
it('必填字符串字段非字符串拒绝(sourceId 数字)', () => {
expect(isUniversalRow({ ...valid, sourceId: 101 })).toBe(false)
})
it('seo 为数组拒绝(数组伪装对象)', () => {
expect(isUniversalRow({ ...valid, seo: [] })).toBe(false)
})
})