gongxiangp2/lib/__tests__/desktop-native-contract.test.ts
WuYongJie 93fc28f1bb feat(client): add native template slots and safe cloud version restore
Support explicit current-output A/B fill, protected edited drafts, scoped cloud update offers and atomic native restore with stale-open CAS. Preserve original unknown requests, improve Pi conversation continuity and native DPI/navigation reads, and publish the authenticated template metadata contract.

Validated: native backend 172 passed/5 environment tests ignored, UI 110, Pi 53, template/rule API 24 and native cloud contract 6; strict Clippy, layering and wasm. Real S01 selected B, edited/undo-redo, PCraft reopen and layered PSD roundtrip pass with exact pixels. Full nine-output generation and Photoshop acceptance remain open.
2026-10-23 21:27:06 +08:00

24 lines
1.9 KiB
TypeScript

/** @jest-environment node */
import { desktopProjectBody } from '@/lib/desktop-client/contract.mjs'
const hash = 'a'.repeat(64)
function fixture() { return { revision: 0, status: 'draft', document: { version: 3, id: 'project', name: '顾家五屏', screens: [{ id: 'one', width: 1440, height: 2200, previewSource: null }], native: { format: 'photocraft', schemaVersion: 1, documentSource: null as string | null, files: [] as any[] } } } }
test('accepts an explicit incomplete draft but never labels it completed', () => {
const value = fixture(); expect(desktopProjectBody(value).document.version).toBe(3)
value.status = 'completed'; expect(() => desktopProjectBody(value)).toThrow('完结项目')
})
test('requires a complete safe manifest and strips unrecognized fields from native metadata', () => {
const value = fixture()
value.document.native.files = ['canvas.pcraft','context.json','session-backup.json'].map(path => ({ path, source: 'native:' + hash, sha256: hash, size: 100 }))
value.document.native.documentSource = 'native:' + hash
expect(desktopProjectBody(value).document.native.files).toHaveLength(3)
value.document.native.files[0].path = '../credentials.json'; expect(() => desktopProjectBody(value)).toThrow('原生工程文件')
})
test('rejects unhashed native sources, missing session backup, duplicate screens and oversized geometry', () => {
const value = fixture()
value.document.native.files = [{ path: 'canvas.pcraft', source: 'native:' + hash, sha256: hash, size: 100 }]
value.document.native.documentSource = 'native:' + hash
expect(() => desktopProjectBody(value)).toThrow('会话恢复文件')
value.document.native.files[0].source = 'native:uuid'; expect(() => desktopProjectBody(value)).toThrow('工程文件无效')
const other = fixture(); other.document.screens[0].height = 30001; expect(() => desktopProjectBody(other)).toThrow('画布超出限制')
})