fix: stabilize rpg publish and launch

This commit is contained in:
kdletters
2026-05-21 20:20:06 +08:00
parent 224a26d318
commit a9d23a8a44
14 changed files with 614 additions and 82 deletions
@@ -79,6 +79,72 @@ describe('rpgEntryLibraryClient world library routes', () => {
);
});
it('normalizes detail profiles before runtime launch consumes them', async () => {
requestJsonMock.mockResolvedValueOnce({
entry: {
ownerUserId: 'owner-1',
profileId: 'profile-1',
publicWorkCode: 'CW-1',
authorPublicUserCode: 'U-1',
profile: {
id: 'profile-1',
name: '旧数据世界',
summary: '只有摘要字段的旧 profile。',
},
visibility: 'published',
publishedAt: '2026-05-21T00:00:00.000Z',
updatedAt: '2026-05-21T00:00:00.000Z',
authorDisplayName: '作者',
worldName: '旧数据世界',
subtitle: '旧数据',
summaryText: '只有摘要字段的旧 profile。',
coverImageSrc: null,
themeMode: 'martial',
playableNpcCount: 0,
landmarkCount: 0,
},
});
const entry = await getRpgEntryWorldGalleryDetail('owner-1', 'profile-1');
expect(Array.isArray(entry.profile.playableNpcs)).toBe(true);
expect(Array.isArray(entry.profile.storyNpcs)).toBe(true);
expect(Array.isArray(entry.profile.landmarks)).toBe(true);
expect(entry.profile.attributeSchema.schemaVersion).toBe(1);
});
it('falls back to entry summary when old detail profile cannot be normalized', async () => {
requestJsonMock.mockResolvedValueOnce({
entry: {
ownerUserId: 'owner-1',
profileId: 'profile-1',
publicWorkCode: 'CW-1',
authorPublicUserCode: 'U-1',
profile: {
id: 'profile-1',
summary: '缺少 name 的旧 profile。',
},
visibility: 'published',
publishedAt: '2026-05-21T00:00:00.000Z',
updatedAt: '2026-05-21T00:00:00.000Z',
authorDisplayName: '作者',
worldName: '摘要兜底世界',
subtitle: '旧数据',
summaryText: '缺少 name 的旧 profile。',
coverImageSrc: null,
themeMode: 'martial',
playableNpcCount: 0,
landmarkCount: 0,
},
});
const entry = await getRpgEntryWorldGalleryDetail('owner-1', 'profile-1');
expect(entry.profile.id).toBe('profile-1');
expect(entry.profile.name).toBe('摘要兜底世界');
expect(Array.isArray(entry.profile.playableNpcs)).toBe(true);
});
it('reads owned library detail from the runtime entry route', async () => {
requestJsonMock.mockResolvedValueOnce({
entry: {