diff --git a/apps/ai-game-creator-shell/src/contracts/assetKind.ts b/apps/ai-game-creator-shell/src/contracts/assetKind.ts index 58ce50634..439cc65df 100644 --- a/apps/ai-game-creator-shell/src/contracts/assetKind.ts +++ b/apps/ai-game-creator-shell/src/contracts/assetKind.ts @@ -52,10 +52,17 @@ export function parseGameCreationAppAssetKind( return raw; } - const rawValue = typeof raw === 'string' ? raw : String(raw); - if (rawValue !== 'unknown') { + if (typeof raw !== 'string') { + console.warn('GameCreationApp 资源 kind 不是字符串,已收口为 unknown', { + rawType: typeof raw, + sourceContext: context, + }); + return 'unknown'; + } + + if (raw !== 'unknown') { console.warn('未知的 GameCreationApp 资源 kind,已收口为 unknown', { - rawKind: rawValue, + rawKind: raw, sourceContext: context, }); } diff --git a/apps/ai-game-creator-shell/tests/assetKind.test.ts b/apps/ai-game-creator-shell/tests/assetKind.test.ts index 1d1445d88..14251469d 100644 --- a/apps/ai-game-creator-shell/tests/assetKind.test.ts +++ b/apps/ai-game-creator-shell/tests/assetKind.test.ts @@ -25,4 +25,16 @@ describe('shell generated asset kind boundary', () => { ); warn.mockRestore(); }); + + it('records the input type instead of stringifying non-string input', () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined); + expect(parseGameCreationAppAssetKind(null, 'manifest.asset.kind')).toBe( + 'unknown', + ); + expect(warn).toHaveBeenCalledWith( + 'GameCreationApp 资源 kind 不是字符串,已收口为 unknown', + { rawType: 'object', sourceContext: 'manifest.asset.kind' }, + ); + warn.mockRestore(); + }); });