From 419e00e10a5f0d1d36661eafa047e83d4021bd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 15 Sep 2026 16:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=89=8D=E7=AB=AF=E7=94=A8?= =?UTF-8?q?=E6=88=B7=20Response=20item=20=E5=A5=91=E7=BA=A6=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 覆盖 Lexical 文本与引用交错顺序 验证资源引用只发送稳定 resourceId --- .../tests/resourceReferences.test.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 apps/ai-game-creator-shell/tests/resourceReferences.test.ts diff --git a/apps/ai-game-creator-shell/tests/resourceReferences.test.ts b/apps/ai-game-creator-shell/tests/resourceReferences.test.ts new file mode 100644 index 000000000..ebcdf8794 --- /dev/null +++ b/apps/ai-game-creator-shell/tests/resourceReferences.test.ts @@ -0,0 +1,71 @@ +import { describe, expect, it } from 'vitest'; + +import { + type ChatComposerDraft, + chatComposerDraftToDirectCodexUserItem, +} from '../src/features/project-workspace/resourceReferences'; + +describe('DirectProject user Response item', () => { + it('保留 Lexical content 的文本与引用交错顺序', () => { + const draft: ChatComposerDraft = { + text: '忽略的扁平摘要', + references: [], + content: [ + { type: 'input_text', text: '先看 ' }, + { type: 'agc_resource_reference', resourceId: 'asset-hero' }, + { type: 'input_text', text: ' 再看 ' }, + { + type: 'agc_runtime_region_reference', + label: '主画面', + runId: 'run-1', + versionId: 'version-1', + elementTag: 'canvas', + elementRole: 'playfield', + text: '可试玩区域', + width: 320, + height: 180, + resourceIds: ['asset-hero'], + }, + ], + }; + + expect( + chatComposerDraftToDirectCodexUserItem(draft, 'turn-1:user'), + ).toEqual({ + type: 'message', + role: 'user', + id: 'turn-1:user', + content: draft.content, + }); + }); + + it('资源引用只投影稳定 resourceId,不携带展示字段', () => { + const draft: ChatComposerDraft = { + text: '请使用素材', + references: [ + { + type: 'resource', + resourceId: 'asset-hero', + kind: 'character', + mediaType: 'image/png', + label: '主角', + category: 'character', + tags: ['hero'], + source: 'asset-picker', + }, + ], + }; + + expect( + chatComposerDraftToDirectCodexUserItem(draft, 'turn-2:user'), + ).toEqual({ + type: 'message', + role: 'user', + id: 'turn-2:user', + content: [ + { type: 'input_text', text: '请使用素材' }, + { type: 'agc_resource_reference', resourceId: 'asset-hero' }, + ], + }); + }); +});