feat: 完善图像工作区与创作工具体验
This commit is contained in:
@@ -6,6 +6,7 @@ import { Readable, Writable } from 'node:stream';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { handleImageWorkspaceRoutes } from '@electron/api/routes/image-workspace';
|
||||
import type { HostApiContext } from '@electron/api/context';
|
||||
import { DesignWorkspaceModuleError } from '@electron/image-workspace/module';
|
||||
|
||||
const electronMocks = vi.hoisted(() => ({
|
||||
getPath: vi.fn(),
|
||||
@@ -130,11 +131,13 @@ describe('AI design Main route boundary', () => {
|
||||
const workspace = {
|
||||
bootstrap: vi.fn().mockResolvedValue(bootstrap),
|
||||
createWorkspace: vi.fn().mockResolvedValue({ workspaceId: 'workspace-one' }),
|
||||
deleteWorkspace: vi.fn().mockResolvedValue({ workspaceId: 'workspace/one', deleted: true }),
|
||||
createConversation: vi.fn().mockResolvedValue({ conversationId: 'conversation-one' }),
|
||||
getConversation: vi.fn().mockResolvedValue({ conversationId: 'conversation/one' }),
|
||||
renameWorkspace: vi.fn(),
|
||||
getWorkspace: vi.fn(),
|
||||
submitMessage: vi.fn().mockResolvedValue({ workspaceId: 'workspace/one' }),
|
||||
updateGenerationQuote: vi.fn().mockResolvedValue({ quoteId: 'quote/one', quotedDesignPoints: 15 }),
|
||||
confirmGeneration: vi.fn().mockResolvedValue({ workspaceId: 'workspace/one' }),
|
||||
listTasks: vi.fn().mockResolvedValue([]),
|
||||
uploadAsset: vi.fn().mockResolvedValue({ assetId: 'asset-uploaded' }),
|
||||
@@ -168,6 +171,22 @@ describe('AI design Main route boundary', () => {
|
||||
title: '角色设计',
|
||||
});
|
||||
|
||||
const deleteResponse = createResponse();
|
||||
await handleImageWorkspaceRoutes(
|
||||
createRequest('DELETE'),
|
||||
deleteResponse.res,
|
||||
new URL(
|
||||
'http://127.0.0.1/api/works/image-workspace/workspaces/workspace%2Fone',
|
||||
),
|
||||
ctx,
|
||||
);
|
||||
expect(workspace.deleteWorkspace).toHaveBeenCalledWith('workspace/one');
|
||||
expect(deleteResponse.json()).toMatchObject({
|
||||
success: true,
|
||||
status: 200,
|
||||
data: { workspaceId: 'workspace/one', deleted: true },
|
||||
});
|
||||
|
||||
const createConversationResponse = createResponse();
|
||||
await handleImageWorkspaceRoutes(
|
||||
createRequest('POST', {
|
||||
@@ -205,6 +224,33 @@ describe('AI design Main route boundary', () => {
|
||||
data: { conversationId: 'conversation/one' },
|
||||
});
|
||||
|
||||
const updateQuoteResponse = createResponse();
|
||||
await handleImageWorkspaceRoutes(
|
||||
createRequest('PATCH', {
|
||||
finalPrompt: '最新的完整提示词',
|
||||
model: 'wan2.7-i2v-2026-04-25',
|
||||
resolution: '720P',
|
||||
aspectRatio: '16:9',
|
||||
durationSeconds: 6,
|
||||
}),
|
||||
updateQuoteResponse.res,
|
||||
new URL(
|
||||
'http://127.0.0.1/api/works/image-workspace/workspaces/workspace%2Fone/generation-quotes/quote%2Fone',
|
||||
),
|
||||
ctx,
|
||||
);
|
||||
expect(workspace.updateGenerationQuote).toHaveBeenCalledWith({
|
||||
workspaceId: 'workspace/one',
|
||||
quoteId: 'quote/one',
|
||||
finalPrompt: '最新的完整提示词',
|
||||
generationParameters: {
|
||||
model: 'wan2.7-i2v-2026-04-25',
|
||||
resolution: '720P',
|
||||
aspectRatio: '16:9',
|
||||
durationSeconds: 6,
|
||||
},
|
||||
});
|
||||
|
||||
const messageResponse = createResponse();
|
||||
await handleImageWorkspaceRoutes(
|
||||
createRequest('POST', {
|
||||
@@ -258,6 +304,13 @@ describe('AI design Main route boundary', () => {
|
||||
createRequest('POST', {
|
||||
clientTurnId: 'turn-two',
|
||||
expectedTurnRevision: 4,
|
||||
finalPrompt: '最终提示词',
|
||||
generationParameters: {
|
||||
model: 'image-model-one',
|
||||
resolution: '1024x1024',
|
||||
aspectRatio: '1:1',
|
||||
durationSeconds: null,
|
||||
},
|
||||
}),
|
||||
confirmResponse.res,
|
||||
new URL(
|
||||
@@ -271,6 +324,40 @@ describe('AI design Main route boundary', () => {
|
||||
quoteId: 'quote/one',
|
||||
clientTurnId: 'turn-two',
|
||||
expectedTurnRevision: 4,
|
||||
finalPrompt: '最终提示词',
|
||||
generationParameters: {
|
||||
model: 'image-model-one',
|
||||
resolution: '1024x1024',
|
||||
aspectRatio: '1:1',
|
||||
durationSeconds: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps deletion errors structured at the Host boundary', async () => {
|
||||
const deleteWorkspace = vi.fn().mockRejectedValue(new DesignWorkspaceModuleError(
|
||||
503,
|
||||
'workspace_unavailable',
|
||||
'设计项目暂时无法删除,请稍后重试',
|
||||
));
|
||||
const response = createResponse();
|
||||
|
||||
await handleImageWorkspaceRoutes(
|
||||
createRequest('DELETE'),
|
||||
response.res,
|
||||
new URL(
|
||||
'http://127.0.0.1/api/works/image-workspace/workspaces/workspace-one',
|
||||
),
|
||||
{ imageWorkspace: { deleteWorkspace } } as unknown as HostApiContext,
|
||||
);
|
||||
|
||||
expect(deleteWorkspace).toHaveBeenCalledWith('workspace-one');
|
||||
expect(response.statusCode).toBe(503);
|
||||
expect(response.json()).toEqual({
|
||||
success: false,
|
||||
status: 503,
|
||||
code: 'workspace_unavailable',
|
||||
error: '设计项目暂时无法删除,请稍后重试',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user