修正资源 kind 解析边界对非字符串输入的日志

- assetKind.ts:非字符串输入不再走 `String(raw)` 字符串化,改为记录 `rawType` 并直接收口为 `unknown`。
- assetKind.test.ts:新增非字符串输入用例,钉住新的日志形状。
This commit is contained in:
2026-09-16 23:00:42 +08:00
parent faab318127
commit d333f783fe
2 changed files with 22 additions and 3 deletions
@@ -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,
});
}
@@ -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();
});
});