refactor(core): consolidate execute() arguments into ExecuteOptions (#25101)

This commit is contained in:
Michael Bleigh
2026-04-10 10:11:17 -07:00
committed by GitHub
parent 1d36309f5f
commit 3b7c17a22c
69 changed files with 849 additions and 527 deletions
+55 -42
View File
@@ -240,9 +240,9 @@ describe('DiscoveredMCPTool', () => {
mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
const invocation = tool.build(params);
const toolResult: ToolResult = await invocation.execute(
new AbortController().signal,
);
const toolResult: ToolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(mockCallTool).toHaveBeenCalledWith([
{ name: serverToolName, args: params },
@@ -262,9 +262,9 @@ describe('DiscoveredMCPTool', () => {
const mockMcpToolResponsePartsEmpty: Part[] = [];
mockCallTool.mockResolvedValue(mockMcpToolResponsePartsEmpty);
const invocation = tool.build(params);
const toolResult: ToolResult = await invocation.execute(
new AbortController().signal,
);
const toolResult: ToolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.returnDisplay).toBe('```json\n[]\n```');
expect(toolResult.llmContent).toEqual([
{ text: '[Error: Could not parse tool response]' },
@@ -278,7 +278,7 @@ describe('DiscoveredMCPTool', () => {
const invocation = tool.build(params);
await expect(
invocation.execute(new AbortController().signal),
invocation.execute({ abortSignal: new AbortController().signal }),
).rejects.toThrow(expectedError);
});
@@ -324,8 +324,9 @@ describe('DiscoveredMCPTool', () => {
functionCall,
)} with response: ${safeJsonStringify(mockMcpToolResponseParts)}`;
const invocation = tool.build(params);
const result = await invocation.execute(new AbortController().signal);
const result = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(result.error?.type).toBe(ToolErrorType.MCP_TOOL_ERROR);
expect(result.llmContent).toBe(expectedErrorMessage);
expect(result.returnDisplay).toContain(
@@ -370,8 +371,9 @@ describe('DiscoveredMCPTool', () => {
functionCall,
)} with response: ${safeJsonStringify(mockMcpToolResponseParts)}`;
const invocation = tool.build(params);
const result = await invocation.execute(new AbortController().signal);
const result = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(result.error?.type).toBe(ToolErrorType.MCP_TOOL_ERROR);
expect(result.llmContent).toBe(expectedErrorMessage);
expect(result.returnDisplay).toContain(
@@ -426,10 +428,9 @@ describe('DiscoveredMCPTool', () => {
mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
const invocation = tool.build(params);
const toolResult = await invocation.execute(
new AbortController().signal,
);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
const stringifiedResponseContent = JSON.stringify(
mockToolSuccessResultObject,
);
@@ -451,8 +452,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
// 1. Assert that the llmContent sent to the scheduler is a clean Part array.
expect(toolResult.llmContent).toEqual([{ text: successMessage }]);
@@ -480,8 +482,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([
{
text: `[Tool '${serverToolName}' provided the following audio data with mime-type: audio/mp3]`,
@@ -512,8 +515,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([
{
text: 'Resource Link: My Resource at file:///path/to/thing',
@@ -542,8 +546,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([
{ text: 'This is the text content.' },
]);
@@ -568,8 +573,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([
{
text: `[Tool '${serverToolName}' provided the following embedded resource with mime-type: application/octet-stream]`,
@@ -603,8 +609,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([
{ text: 'First part.' },
{
@@ -635,8 +642,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([{ text: 'Valid part.' }]);
expect(toolResult.returnDisplay).toBe(
'Valid part.\n[Unknown content type: future_block]',
@@ -673,8 +681,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const toolResult = await invocation.execute(new AbortController().signal);
const toolResult = await invocation.execute({
abortSignal: new AbortController().signal,
});
expect(toolResult.llmContent).toEqual([
{ text: 'Here is a resource.' },
{
@@ -707,9 +716,9 @@ describe('DiscoveredMCPTool', () => {
const invocation = tool.build(params);
await expect(invocation.execute(controller.signal)).rejects.toThrow(
'Tool call aborted',
);
await expect(
invocation.execute({ abortSignal: controller.signal }),
).rejects.toThrow('Tool call aborted');
// Tool should not be called if signal is already aborted
expect(mockCallTool).not.toHaveBeenCalled();
@@ -739,7 +748,7 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const promise = invocation.execute(controller.signal);
const promise = invocation.execute({ abortSignal: controller.signal });
// Abort after a short delay to simulate cancellation during execution
setTimeout(() => controller.abort(), ABORT_DELAY);
@@ -758,7 +767,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const result = await invocation.execute(controller.signal);
const result = await invocation.execute({
abortSignal: controller.signal,
});
expect(result.llmContent).toEqual([{ text: 'Success' }]);
expect(result.returnDisplay).toBe('Success');
@@ -776,7 +787,9 @@ describe('DiscoveredMCPTool', () => {
);
const invocation = tool.build(params);
const result = await invocation.execute(controller.signal);
const result = await invocation.execute({
abortSignal: controller.signal,
});
expect(result.error?.type).toBe(ToolErrorType.MCP_TOOL_ERROR);
expect(result.returnDisplay).toContain(
@@ -793,9 +806,9 @@ describe('DiscoveredMCPTool', () => {
const invocation = tool.build(params);
await expect(invocation.execute(controller.signal)).rejects.toThrow(
expectedError,
);
await expect(
invocation.execute({ abortSignal: controller.signal }),
).rejects.toThrow(expectedError);
});
it.each([
@@ -829,12 +842,12 @@ describe('DiscoveredMCPTool', () => {
if (expectError) {
try {
await invocation.execute(controller.signal);
await invocation.execute({ abortSignal: controller.signal });
} catch {
// Expected error
}
} else {
await invocation.execute(controller.signal);
await invocation.execute({ abortSignal: controller.signal });
}
// Verify cleanup by aborting after execution