Skip to content

Fix error handling in sendChatHistoryAsync and empty array test expectations#160

Merged
pontemonti merged 3 commits intousers/johanb/RTP_OpenAIfrom
copilot/sub-pr-157
Jan 27, 2026
Merged

Fix error handling in sendChatHistoryAsync and empty array test expectations#160
pontemonti merged 3 commits intousers/johanb/RTP_OpenAIfrom
copilot/sub-pr-157

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 27, 2026

Test failures occurred after recent refactoring: sendChatHistoryAsync threw unhandled exceptions from session.getItems() errors, and test expectations conflicted with the requirement to call the MCP platform even with empty message arrays.

Changes

  • Error handling in sendChatHistoryAsync: Wrapped session.getItems() in try-catch to convert session errors to OperationResult.failed while allowing validation errors from downstream calls to propagate
  • Test expectations: Updated "should return success for empty session" to expect HTTP call with empty chatHistory array, aligning with MCP platform requirements
  • Type safety: Changed catch block error type from any to unknown with proper OperationError wrapping
let items: AgentInputItem[];
try {
  items = await session.getItems(limit);
} catch (err: unknown) {
  const error = err as Error;
  return OperationResult.failed(new OperationError(error));
}

// Validation errors from this method will propagate
return await this.sendChatHistoryMessagesAsync(turnContext, items, toolOptions);

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…st expectations for empty arrays

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
Copilot AI changed the title [WIP] Add chat history API for OpenAI integration Fix error handling in sendChatHistoryAsync and empty array test expectations Jan 27, 2026
Copilot AI requested a review from pontemonti January 27, 2026 17:54
@pontemonti pontemonti marked this pull request as ready for review January 27, 2026 18:03
@pontemonti pontemonti requested a review from a team as a code owner January 27, 2026 18:03
@pontemonti pontemonti merged commit f1c54ae into users/johanb/RTP_OpenAI Jan 27, 2026
@pontemonti pontemonti deleted the copilot/sub-pr-157 branch January 27, 2026 18:03
pontemonti added a commit that referenced this pull request Jan 28, 2026
* Add chat history API for OpenAI

* fix: update uuid and @types/uuid dependencies to use catalog

* fix: correct header formatting in PRD for OpenAI sendChatHistoryAsync API

* refactor: remove unnecessary logging and improve message role validation in McpToolRegistrationService

* refactor: simplify role extraction in McpToolRegistrationService and remove validation

* Add @types/uuid and uuid dependencies

* Remove early return for empty messages in sendChatHistoryMessagesAsync (#158)

* Initial plan

* fix: ensure MCP call is made even when messages array is empty

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

* Remove fragile error handling from sendChatHistory methods (#159)

* Initial plan

* Remove fragile 'is required' check from sendChatHistory methods

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

* Update tests/tooling-extensions-openai/sendChatHistoryAsync.test.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix error handling in sendChatHistoryAsync and empty array test expectations (#160)

* Initial plan

* Fix test failures: wrap session.getItems() in try-catch and update test expectations for empty arrays

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
Co-authored-by: Johan Broberg <johan@pontemonti.net>

* Add error handling for message conversion in sendChatHistoryMessagesAsync (#163)

* Initial plan

* Add error handling for convertToChatHistoryMessages and test

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

* Address code review feedback: safer error handling and remove extra blank line

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: Johan Broberg <johanb@microsoft.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants