截图槽位空串归一成 null 保留顺序

- normalizeMetadata 不再 filter 掉空串槽位,改为归一成 null(消费草稿本地图)
- 否则后续槽位整体前移,与 .export/taonier.json 的截图顺序错位
- 更新定向测试:空串槽位保留为 null
This commit is contained in:
2026-10-07 10:47:10 +08:00
parent 99d5fd1eaa
commit ab9789d11a
2 changed files with 8 additions and 6 deletions
@@ -175,9 +175,11 @@ function normalizeMetadata(
// 封面校验不在这里:`coverObjectKey === null` 表示用草稿 `coverPath`,只有宿主读到
// `.export/taonier.json` 后才能判断「草稿也没有封面」,所以由原生发布命令按统一文案失败关闭。
const coverObjectKey = (metadata?.coverObjectKey ?? '').trim() || null;
const screenshots = (metadata?.screenshots ?? [])
.map((screenshot) => (screenshot === null ? null : screenshot.trim()))
.filter((screenshot) => screenshot !== '');
// 槽位顺序与最终截图一一对应:空串/纯空白按「没有沿用值」归一成 `null`(消费草稿本地图),
// 不能直接 filter 掉,否则后面的槽位会整体前移,与草稿里的截图顺序错位。
const screenshots = (metadata?.screenshots ?? []).map((screenshot) =>
screenshot === null || screenshot.trim() === '' ? null : screenshot.trim(),
);
if (screenshots.length > MAX_AGC_GAME_SCREENSHOTS) {
throw new Error('游戏截图最多 6 张');
}
@@ -159,7 +159,7 @@ describe('Rust 发布 facade', () => {
});
});
test('截图槽位里的 null 与沿用 objectKey 原样透传', async () => {
test('截图槽位里的 null、沿用 objectKey 与空串按序透传', async () => {
const { invoke, calls } = installNativeInvoke((command) => {
if (command === 'publish_local_project_game') return PUBLISH_RESULT;
throw new Error(`未预期的命令:${command}`);
@@ -172,7 +172,7 @@ describe('Rust 发布 facade', () => {
manifest: MANIFEST,
metadata: {
coverObjectKey: null,
// 第 2 张沿用线上、其余从草稿本地图按序补齐;空串在归一化时被丢弃。
// 第 2 张沿用线上,其余用草稿本地图;空串归一成 `null` 保留槽位顺序,不能被丢掉。
screenshots: [null, 'generated/shot-online.png', null, ' '],
},
versionNumber: 4,
@@ -180,7 +180,7 @@ describe('Rust 发布 facade', () => {
expect(calls[0]?.args).toMatchObject({
metadata: {
screenshots: [null, 'generated/shot-online.png', null],
screenshots: [null, 'generated/shot-online.png', null, null],
},
});
});