Files
Genarrative/apps/ai-game-creator-shell/tests/resourceReferences.test.ts
k88936 6664b77142 补充前端用户 Response item 契约测试
覆盖 Lexical 文本与引用交错顺序

验证资源引用只发送稳定 resourceId
2026-09-15 23:37:58 +08:00

72 lines
1.9 KiB
TypeScript

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' },
],
});
});
});