修复旧版设计 Brief 媒介兼容
This commit is contained in:
@@ -232,6 +232,30 @@ describe('Works Square AI design adapter', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('normalizes a missing Brief medium to null and rejects invalid non-null values', async () => {
|
||||
const { medium: _medium, ...legacyBrief } = serverConversation.brief;
|
||||
const legacyConversation = {
|
||||
...serverConversation,
|
||||
brief: legacyBrief,
|
||||
};
|
||||
const invalidConversation = {
|
||||
...serverConversation,
|
||||
brief: { ...serverConversation.brief, medium: 'audio' },
|
||||
};
|
||||
const fetchMock = vi.fn<typeof fetch>()
|
||||
.mockResolvedValueOnce(jsonResponse(legacyConversation))
|
||||
.mockResolvedValueOnce(jsonResponse(invalidConversation));
|
||||
const adapter = new WorksSquareDesignWorkspace({
|
||||
apiBaseUrl: 'https://square.example',
|
||||
fetchImpl: fetchMock,
|
||||
});
|
||||
|
||||
await expect(adapter.getConversation('workspace-one', 'conversation-one'))
|
||||
.resolves.toMatchObject({ brief: { medium: null } });
|
||||
await expect(adapter.getConversation('workspace-one', 'conversation-one'))
|
||||
.rejects.toMatchObject({ code: 'DESIGN_WORKSPACE_RESPONSE_INVALID' });
|
||||
});
|
||||
|
||||
it('submits a conversation turn through the persistent Agent Gateway Session', async () => {
|
||||
const fetchMock = vi.fn<typeof fetch>()
|
||||
.mockResolvedValueOnce(jsonResponse(serverConversation))
|
||||
@@ -940,6 +964,11 @@ describe('Works Square AI design adapter', () => {
|
||||
});
|
||||
|
||||
it('reuses one design Agent Session and normalizes matching task events from fresh WebSocket tickets', async () => {
|
||||
const { medium: _medium, ...legacyBrief } = serverConversation.brief;
|
||||
const legacyConversation = {
|
||||
...serverConversation,
|
||||
brief: legacyBrief,
|
||||
};
|
||||
const snapshotTask = {
|
||||
task_id: 'task-snapshot',
|
||||
workspace_id: 'workspace-one',
|
||||
@@ -964,10 +993,21 @@ describe('Works Square AI design adapter', () => {
|
||||
workspace_id: 'workspace-one',
|
||||
conversation_id: 'conversation-one',
|
||||
workspace_view_revision: 2,
|
||||
conversation: serverConversation,
|
||||
conversation: legacyConversation,
|
||||
generation_tasks: [snapshotTask],
|
||||
},
|
||||
};
|
||||
const invalidSnapshotEvent = {
|
||||
...snapshotEvent,
|
||||
sequence: 98,
|
||||
payload: {
|
||||
...snapshotEvent.payload,
|
||||
conversation: {
|
||||
...serverConversation,
|
||||
brief: { ...serverConversation.brief, medium: 'audio' },
|
||||
},
|
||||
},
|
||||
};
|
||||
const assistantDeltaEvent = {
|
||||
session_id: 'session-one',
|
||||
sequence: 2,
|
||||
@@ -1038,6 +1078,7 @@ describe('Works Square AI design adapter', () => {
|
||||
const { sockets, webSocketFactory } = scriptedSockets([
|
||||
{
|
||||
frames: [
|
||||
{ type: 'event', event: invalidSnapshotEvent },
|
||||
{ type: 'event', event: snapshotEvent },
|
||||
{ type: 'event', event: malformedDeltaEvent },
|
||||
{ type: 'event', event: assistantDeltaEvent },
|
||||
@@ -1077,6 +1118,7 @@ describe('Works Square AI design adapter', () => {
|
||||
conversation: expect.objectContaining({
|
||||
conversationId: 'conversation-one',
|
||||
title: serverConversation.title,
|
||||
brief: expect.objectContaining({ medium: null }),
|
||||
messages: [expect.objectContaining({
|
||||
text: serverConversation.messages[0].text,
|
||||
})],
|
||||
|
||||
Reference in New Issue
Block a user