Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
393 changes: 173 additions & 220 deletions packages/a2a-server/src/http/app.test.ts

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions packages/cli/src/ui/hooks/useToolScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ describe('useReactToolScheduler', () => {
| undefined;

const advanceAndSettle = async () => {
await act(async () => {
await vi.advanceTimersByTimeAsync(0);
});
for (let i = 0; i < 7; i++) {
await act(async () => {
await vi.advanceTimersByTimeAsync(0);
});
}
};

const scheduleAndWaitForExecution = async (
Expand All @@ -237,8 +239,6 @@ describe('useReactToolScheduler', () => {
});

await advanceAndSettle();
await advanceAndSettle();
await advanceAndSettle();
};

beforeEach(() => {
Expand Down Expand Up @@ -350,6 +350,12 @@ describe('useReactToolScheduler', () => {
schedule(newRequest, new AbortController().signal);
});

// Wait for the async schedule operation to update state
for (let i = 0; i < 50; i++) {
if (result.current[0].length === 1) break;
await advanceAndSettle();
}

// After scheduling, the old call should be gone,
// and the new one should be in the display in its initial state.
expect(result.current[0].length).toBe(1);
Expand Down Expand Up @@ -481,6 +487,12 @@ describe('useReactToolScheduler', () => {

await scheduleAndWaitForExecution(result.current[1], request);

// Poll for completion
for (let i = 0; i < 50; i++) {
if (completedToolCalls.length === 1) break;
await advanceAndSettle();
}

expect(completedToolCalls).toHaveLength(1);
expect(completedToolCalls[0].status).toBe('error');
expect(completedToolCalls[0].request).toBe(request);
Expand Down
28 changes: 24 additions & 4 deletions packages/core/src/core/coreToolScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,17 @@ describe('CoreToolScheduler with payload', () => {
);
}

// After internal update, the tool should be awaiting approval again with the NEW content.
const updatedAwaitingCall = (await waitForStatus(
onToolCallsUpdate,
'awaiting_approval',
)) as WaitingToolCall;

// Now confirm for real to execute.
await updatedAwaitingCall.confirmationDetails.onConfirm(
ToolConfirmationOutcome.ProceedOnce,
);

// Wait for the tool execution to complete
await vi.waitFor(() => {
expect(onAllToolCallsComplete).toHaveBeenCalled();
Expand Down Expand Up @@ -979,7 +990,11 @@ describe('CoreToolScheduler YOLO mode', () => {
.map((call) => (call[0][0] as ToolCall)?.status)
.filter(Boolean);
expect(statusUpdates).not.toContain('awaiting_approval');
expect(statusUpdates).toEqual([
// Expect the sequence of states, ignoring duplicates
const uniqueStatusUpdates = statusUpdates.filter(
(status, index, self) => index === 0 || status !== self[index - 1],
);
expect(uniqueStatusUpdates).toEqual([
'validating',
'scheduled',
'executing',
Expand Down Expand Up @@ -1196,7 +1211,11 @@ describe('CoreToolScheduler request queueing', () => {
.map((call) => (call[0][0] as ToolCall)?.status)
.filter(Boolean);
expect(statusUpdates).not.toContain('awaiting_approval');
expect(statusUpdates).toEqual([
// Expect the sequence of states, ignoring duplicates
const uniqueStatusUpdates = statusUpdates.filter(
(status, index, self) => index === 0 || status !== self[index - 1],
);
expect(uniqueStatusUpdates).toEqual([
'validating',
'scheduled',
'executing',
Expand Down Expand Up @@ -1799,8 +1818,9 @@ describe('CoreToolScheduler Sequential Execution', () => {
abortController.signal,
);

const toolCall = (scheduler as unknown as { toolCalls: ToolCall[] })
.toolCalls[0] as WaitingToolCall;
const toolCall = (
scheduler as unknown as { state: { getSnapshot: () => ToolCall[] } }
).state.getSnapshot()[0] as WaitingToolCall;
expect(toolCall.status).toBe('awaiting_approval');

const confirmationSignal = new AbortController().signal;
Expand Down
Loading