Fix DashScope env loading for scene image generation
This commit is contained in:
@@ -539,6 +539,70 @@ describe('ai orchestration fallbacks', () => {
|
||||
expect(debugLabels).toContain('custom-world-story-dossier-batch-1');
|
||||
});
|
||||
|
||||
it('reports staged progress while generating a custom world', async () => {
|
||||
requestPlainTextCompletionMock.mockResolvedValue(
|
||||
JSON.stringify(createCustomWorldResponse()),
|
||||
);
|
||||
const onProgress = vi.fn();
|
||||
|
||||
await generateCustomWorldProfile('一个需要展示真实进度的世界', {
|
||||
onProgress,
|
||||
});
|
||||
|
||||
const phaseIds = onProgress.mock.calls.map(
|
||||
(call) =>
|
||||
(call[0] as { phaseId?: string; overallProgress?: number }).phaseId,
|
||||
);
|
||||
const lastProgress = onProgress.mock.calls.at(-1)?.[0] as
|
||||
| { overallProgress?: number; estimatedRemainingMs?: number | null }
|
||||
| undefined;
|
||||
|
||||
expect(phaseIds).toContain('framework');
|
||||
expect(phaseIds).toContain('playable-outline');
|
||||
expect(phaseIds).toContain('story-outline');
|
||||
expect(phaseIds).toContain('landmark-seed');
|
||||
expect(phaseIds).toContain('landmark-network');
|
||||
expect(phaseIds).toContain('playable-narrative');
|
||||
expect(phaseIds).toContain('playable-dossier');
|
||||
expect(phaseIds).toContain('story-narrative');
|
||||
expect(phaseIds).toContain('story-dossier');
|
||||
expect(phaseIds).toContain('finalize');
|
||||
expect(lastProgress?.overallProgress).toBe(100);
|
||||
expect(lastProgress?.estimatedRemainingMs).toBe(0);
|
||||
});
|
||||
|
||||
it('passes abort signals through custom world generation and rejects when interrupted', async () => {
|
||||
requestPlainTextCompletionMock.mockImplementation(
|
||||
(
|
||||
_system: string,
|
||||
_user: string,
|
||||
options?: { signal?: AbortSignal },
|
||||
) =>
|
||||
new Promise((_resolve, reject) => {
|
||||
options?.signal?.addEventListener(
|
||||
'abort',
|
||||
() => reject(options.signal?.reason ?? new Error('世界生成已中断。')),
|
||||
{ once: true },
|
||||
);
|
||||
}),
|
||||
);
|
||||
const abortController = new AbortController();
|
||||
const generation = generateCustomWorldProfile('一个会被中断的世界', {
|
||||
signal: abortController.signal,
|
||||
});
|
||||
|
||||
abortController.abort(new Error('手动中断生成'));
|
||||
|
||||
await expect(generation).rejects.toThrow('手动中断生成');
|
||||
expect(requestPlainTextCompletionMock).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.any(String),
|
||||
expect.objectContaining({
|
||||
signal: abortController.signal,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('retries custom world generation with a longer timeout after the first timeout attempt', async () => {
|
||||
requestPlainTextCompletionMock
|
||||
.mockRejectedValueOnce(timeoutError)
|
||||
|
||||
Reference in New Issue
Block a user