fix: 保证工具调用开始态可见
- 工具开始事件后让出一次有界绘制机会 - 覆盖快速工具调用的状态可见性测试
This commit is contained in:
@@ -24,6 +24,7 @@ function sse(events: unknown[]) {
|
||||
describe('easyFlowAguiClient', () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('trims outbound history, tools, context and state at the transport boundary', async () => {
|
||||
@@ -200,6 +201,81 @@ describe('easyFlowAguiClient', () => {
|
||||
).rejects.toBeInstanceOf(EasyFlowAguiProjectionError);
|
||||
});
|
||||
|
||||
it('yields a paint opportunity before consuming events after tool start', async () => {
|
||||
vi.useFakeTimers();
|
||||
let paintCallback: FrameRequestCallback | undefined;
|
||||
vi.stubGlobal(
|
||||
'requestAnimationFrame',
|
||||
vi.fn((callback: FrameRequestCallback) => {
|
||||
paintCallback = callback;
|
||||
return 1;
|
||||
}),
|
||||
);
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async () =>
|
||||
sse([
|
||||
{ runId: 'run-1', threadId: '101', type: EventType.RUN_STARTED },
|
||||
{
|
||||
runId: 'run-1',
|
||||
threadId: '101',
|
||||
toolCallId: 'tool-1',
|
||||
toolCallName: 'write_text_file',
|
||||
type: EventType.TOOL_CALL_START,
|
||||
},
|
||||
{
|
||||
delta: '{}',
|
||||
runId: 'run-1',
|
||||
threadId: '101',
|
||||
toolCallId: 'tool-1',
|
||||
type: EventType.TOOL_CALL_ARGS,
|
||||
},
|
||||
{
|
||||
runId: 'run-1',
|
||||
threadId: '101',
|
||||
toolCallId: 'tool-1',
|
||||
type: EventType.TOOL_CALL_END,
|
||||
},
|
||||
{
|
||||
content: 'done',
|
||||
messageId: 'tool-result-1',
|
||||
role: 'tool',
|
||||
runId: 'run-1',
|
||||
threadId: '101',
|
||||
toolCallId: 'tool-1',
|
||||
type: EventType.TOOL_CALL_RESULT,
|
||||
},
|
||||
{
|
||||
runId: 'run-1',
|
||||
threadId: '101',
|
||||
type: EventType.RUN_FINISHED,
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
const received: string[] = [];
|
||||
|
||||
const runPromise = new EasyFlowAguiClient().run({
|
||||
onEvent: (event) => {
|
||||
received.push(event.type);
|
||||
},
|
||||
threadId: '101',
|
||||
url: '/api/v1/agent/1/agui/run',
|
||||
userMessage: { content: '生成文件', id: 'user-1', role: 'user' },
|
||||
});
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
|
||||
expect(received).toContain(EventType.TOOL_CALL_START);
|
||||
expect(received).not.toContain(EventType.TOOL_CALL_RESULT);
|
||||
|
||||
paintCallback?.(0);
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await runPromise;
|
||||
|
||||
expect(received).toContain(EventType.TOOL_CALL_RESULT);
|
||||
expect(received.at(-1)).toBe(EventType.RUN_FINISHED);
|
||||
});
|
||||
|
||||
it('replays a completed run from the server journal after refresh', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
|
||||
Reference in New Issue
Block a user