From d333f783fe6d81b51f7a0e88fa30cd88f02f4106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Wed, 16 Sep 2026 23:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B5=84=E6=BA=90=20kind=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E8=BE=B9=E7=95=8C=E5=AF=B9=E9=9D=9E=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E8=BE=93=E5=85=A5=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - assetKind.ts:非字符串输入不再走 `String(raw)` 字符串化,改为记录 `rawType` 并直接收口为 `unknown`。 - assetKind.test.ts:新增非字符串输入用例,钉住新的日志形状。 --- .../src/contracts/assetKind.ts | 13 ++++++++++--- apps/ai-game-creator-shell/tests/assetKind.test.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) 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(); + }); });