Skip to content

Add test coverage for messageSizeWithinLimit utility function#170

Merged
mattieruth merged 1 commit intomessage-too-large-handlingfrom
copilot/sub-pr-168-again
Jan 14, 2026
Merged

Add test coverage for messageSizeWithinLimit utility function#170
mattieruth merged 1 commit intomessage-too-large-handlingfrom
copilot/sub-pr-168-again

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

The messageSizeWithinLimit utility function lacked test coverage for various message types and edge cases, particularly Unicode characters and nested objects.

Changes

  • tests/utils.spec.ts: Added 18 test cases covering basic types, Unicode/multi-byte characters, nested structures, boundary conditions, and edge cases
  • jest.setup.js: Polyfills TextEncoder/TextDecoder for jsdom environment (not available by default)
  • package.json: Configured Jest to load setup file
  • eslint.config.mjs: Added Node.js globals for Jest setup file

Test Coverage

// Validates accurate UTF-8 byte counting
test("handles Unicode characters correctly", () => {
  const message = "🎉";  // 4-byte UTF-8 emoji
  const size = new TextEncoder().encode(JSON.stringify(message)).length;
  expect(messageSizeWithinLimit(message, size)).toBe(true);
  expect(messageSizeWithinLimit(message, size - 1)).toBe(false);
});

// Validates nested object serialization size
test("handles nested objects", () => {
  const message = { outer: { inner: { deep: "value" } } };
  const size = new TextEncoder().encode(JSON.stringify(message)).length;
  expect(messageSizeWithinLimit(message, size)).toBe(true);
});

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Update error handling for large message payloads Add test coverage for messageSizeWithinLimit utility function Jan 14, 2026
Copilot AI requested a review from mattieruth January 14, 2026 21:26
@mattieruth mattieruth force-pushed the copilot/sub-pr-168-again branch from c0e284b to f618283 Compare January 14, 2026 22:30
@mattieruth mattieruth marked this pull request as ready for review January 14, 2026 22:30
@mattieruth mattieruth merged commit 34888a0 into message-too-large-handling Jan 14, 2026
1 check passed
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