Skip to content

Node JS Unit tests - #58

Closed
abdulanu0 wants to merge 5 commits into
mainfrom
users/anabdul/Unittest_JS
Closed

abdulanu0 wants to merge 5 commits into
mainfrom
users/anabdul/Unittest_JS

Conversation

@abdulanu0

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings November 13, 2025 22:54
@abdulanu0
abdulanu0 requested a review from a team as a code owner November 13, 2025 22:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive test coverage for multiple packages in the Agent365-nodejs repository, including tooling services, notification models, and various framework extensions.

Key Changes:

  • Added test suites for MCP (Model Context Protocol) tool server configuration and registration services across OpenAI, LangChain, and Claude extensions
  • Added test coverage for notification models and handlers including email references, WPX comments, and agent lifecycle events
  • Added utility and contract tests for the agents-a365-tooling package

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/agents-a365-tooling/src/mcp-tool-server-configuration-service.test.ts Tests for the MCP tool server configuration service with method signature validation
tests/agents-a365-tooling/src/contracts.test.ts Contract tests for MCPServerConfig, InputSchema, and McpClientTool interfaces
tests/agents-a365-tooling/src/Utility.test.ts Tests for utility methods including tools mode, MCP base URLs, and environment configurations
tests/agents-a365-tooling-extensions-openai/src/mcp-tool-registration-service.test.ts Tests for OpenAI-specific MCP tool registration with Agent integration
tests/agents-a365-tooling-extensions-langchain/src/mcp-tool-registration-service.test.ts Tests for LangChain-specific MCP tool registration with MultiServerMCPClient
tests/agents-a365-tooling-extensions-claude/src/mcp-tool-registration-service.test.ts Tests for Claude-specific MCP tool registration with agent options configuration
tests/agents-a365-notifications/models/wpx-comment.test.ts Tests for WPX comment model including factory functions and type guards
tests/agents-a365-notifications/models/notification-type.test.ts Tests for NotificationType enum values and reverse lookups
tests/agents-a365-notifications/models/email-reference.test.ts Tests for email reference model with HTML content handling
tests/agents-a365-notifications/models/agent-notification-activity.test.ts Tests for agent notification activity creation and property mapping
tests/agents-a365-notifications/extensions/email-response.test.ts Tests for email response entity with HTML body handling
tests/agents-a365-notifications/extensions/agent-notification.test.ts Tests for agent notification extension methods on AgentApplication
tests/agents-a365-notifications/extensions/agent-notification-utilities.test.ts Tests for notification utility functions including channel and lifecycle validation
tests/agents-a365-notifications/extensions/agent-notification-handler.test.ts Tests for AgentNotificationHandler type and implementation patterns
tests/agents-a365-notifications/constants.test.ts Tests for notification channel and lifecycle event constants

// Assert
expect(AgenticAuthenticationService.GetAgenticUserToken).toHaveBeenCalledWith(mockAuthorization, mockTurnContext);
expect(Utility.ValidateAuthToken).toHaveBeenCalledWith(serviceToken);
expect(mockConfigService.listToolServers).toHaveBeenCalledWith('agent-123', serviceToken);

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls listToolServers with only 2 parameters ('agent-123', serviceToken), but according to line 35 of the test file in agents-a365-tooling package, the method signature expects 3 parameters (agentUserId, environmentId, authToken). This test appears to be missing the environmentId parameter.

Copilot uses AI. Check for mistakes.
// Assert
expect(Utility.ValidateAuthToken).toHaveBeenCalledWith(authToken);
expect(AgenticAuthenticationService.GetAgenticUserToken).not.toHaveBeenCalled();
expect(mockConfigService.listToolServers).toHaveBeenCalledWith('agent-123', authToken);

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls listToolServers with only 2 parameters ('agent-123', authToken), but according to line 35, the method signature expects 3 parameters (agentUserId, environmentId, authToken). This test appears to be missing the environmentId parameter.

Copilot uses AI. Check for mistakes.
// Assert
expect(AgenticAuthenticationService.GetAgenticUserToken).toHaveBeenCalledWith(mockAuthorization, mockTurnContext);
expect(Utility.ValidateAuthToken).toHaveBeenCalledWith(serviceToken);
expect(mockConfigService.listToolServers).toHaveBeenCalledWith('agent-123', serviceToken);

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls listToolServers with only 2 parameters ('agent-123', serviceToken), but according to line 35 of the test file in this package, the method signature expects 3 parameters (agentUserId, environmentId, authToken). This test appears to be missing the environmentId parameter.

Copilot uses AI. Check for mistakes.
// Assert
expect(Utility.ValidateAuthToken).toHaveBeenCalledWith(authToken);
expect(AgenticAuthenticationService.GetAgenticUserToken).not.toHaveBeenCalled();
expect(mockConfigService.listToolServers).toHaveBeenCalledWith('agent-123', authToken);

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls listToolServers with only 2 parameters ('agent-123', authToken), but according to line 35 of the test file in this package, the method signature expects 3 parameters (agentUserId, environmentId, authToken). This test appears to be missing the environmentId parameter.

Copilot uses AI. Check for mistakes.
// Assert
expect(AgenticAuthenticationService.GetAgenticUserToken).toHaveBeenCalledWith(mockAuthorization, mockTurnContext);
expect(Utility.ValidateAuthToken).toHaveBeenCalledWith(serviceToken);
expect(mockConfigService.listToolServers).toHaveBeenCalledWith('agent-123', serviceToken);

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls listToolServers with only 2 parameters ('agent-123', serviceToken), but according to line 35 of the test file in agents-a365-tooling, the method signature expects 3 parameters (agentUserId, environmentId, authToken). This test appears to be missing the environmentId parameter.

Copilot uses AI. Check for mistakes.
// Assert
expect(Utility.ValidateAuthToken).toHaveBeenCalledWith(authToken);
expect(AgenticAuthenticationService.GetAgenticUserToken).not.toHaveBeenCalled();
expect(mockConfigService.listToolServers).toHaveBeenCalledWith('agent-123', authToken);

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls listToolServers with only 2 parameters ('agent-123', authToken), but according to line 35 of the test file in agents-a365-tooling package, the method signature expects 3 parameters (agentUserId, environmentId, authToken). This test appears to be missing the environmentId parameter.

Copilot uses AI. Check for mistakes.
createEmailReference,
createWpxComment
} from '@microsoft/agents-a365-notifications';
import { Activity, ConversationAccount, ChannelAccount } from '@microsoft/agents-activity';

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import ChannelAccount.

Suggested change
import { Activity, ConversationAccount, ChannelAccount } from '@microsoft/agents-activity';
import { Activity, ConversationAccount } from '@microsoft/agents-activity';

Copilot uses AI. Check for mistakes.
// Licensed under the MIT License.

import { McpToolRegistrationService } from '@microsoft/agents-a365-tooling-extensions-claude';
import { McpToolServerConfigurationService, McpClientTool, Utility, MCPServerConfig } from '@microsoft/agents-a365-tooling';

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import MCPServerConfig.

Suggested change
import { McpToolServerConfigurationService, McpClientTool, Utility, MCPServerConfig } from '@microsoft/agents-a365-tooling';
import { McpToolServerConfigurationService, McpClientTool, Utility } from '@microsoft/agents-a365-tooling';

Copilot uses AI. Check for mistakes.
import { AgenticAuthenticationService } from '@microsoft/agents-a365-runtime';
import { TurnContext, Authorization } from '@microsoft/agents-hosting';
import { createAgent, ReactAgent } from 'langchain';
import { ClientConfig, Connection, MultiServerMCPClient } from '@langchain/mcp-adapters';

Copilot AI Nov 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused imports ClientConfig, Connection.

Suggested change
import { ClientConfig, Connection, MultiServerMCPClient } from '@langchain/mcp-adapters';
import { MultiServerMCPClient } from '@langchain/mcp-adapters';

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings November 14, 2025 04:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

@@ -84,7 +84,7 @@ describe('OpenAIAgentsTraceInstrumentor', () => {
expect((instrumentor as any)._config.enabled).toBe(false);
});

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has been skipped using it.skip(). Consider adding a comment explaining why this test is being skipped and when it should be re-enabled. If the test is no longer needed, it should be removed entirely rather than skipped.

Suggested change
// Skipped due to flakiness in CI environment; see issue #1234. Re-enable when OpenAI Agents SDK mocking is stable.

Copilot uses AI. Check for mistakes.
@pontemonti

Copy link
Copy Markdown
Contributor

Please update at least the title of the PR so that it's clear what these changes are for

@abdulanu0 abdulanu0 changed the title new pr other pr had issues Node JS Unit tests Dec 2, 2025
Copilot AI review requested due to automatic review settings December 2, 2025 16:44
@abdulanu0
abdulanu0 requested a review from a team as a code owner December 2, 2025 16:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.


// Mock utility methods
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock assignment (AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn() uses assignment instead of proper mock setup. Consider using jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken') instead, which is the recommended approach and provides better type safety and test reliability.

Suggested change
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();
jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken').mockImplementation(jest.fn());

Copilot uses AI. Check for mistakes.
Comment on lines +181 to +183
expect(() => {
(WPX_COMMENT_TYPE as any) = 'modified';
}).toThrow();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test attempts to verify immutability by reassigning a constant, which will throw in strict mode but may not work as expected in all contexts. A better approach would be to use Object.isFrozen() or check Object.getOwnPropertyDescriptor() to verify the property is not writable: expect(Object.getOwnPropertyDescriptor(module, 'WPX_COMMENT_TYPE')?.writable).toBe(false).

Suggested change
expect(() => {
(WPX_COMMENT_TYPE as any) = 'modified';
}).toThrow();
// Check that the property is not writable
const descriptor = Object.getOwnPropertyDescriptor(
require('@microsoft/agents-a365-notifications'),
'WPX_COMMENT_TYPE'
);
expect(descriptor?.writable).toBe(false);

Copilot uses AI. Check for mistakes.
});

it('should auto-enable when enabled: true is passed', () => {
it.skip('should auto-enable when enabled: true is passed', () => {

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is being skipped with it.skip. Consider either removing the test if it's no longer needed, or fixing the underlying issue so the test can run. Skipped tests can accumulate technical debt and may indicate unresolved problems in the code.

Copilot uses AI. Check for mistakes.

// Mock utility methods
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock assignment (AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn() uses assignment instead of proper mock setup. Consider using jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken') instead, which is the recommended approach and provides better type safety and test reliability.

Suggested change
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();
jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken').mockImplementation(jest.fn());

Copilot uses AI. Check for mistakes.

// Mock utility methods
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock assignment (AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn() uses assignment instead of proper mock setup. Consider using jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken') instead, which is the recommended approach and provides better type safety and test reliability.

Suggested change
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();
jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken').mockImplementation(jest.fn());

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +175
expect(() => {
(EMAIL_NOTIFICATION_TYPE as any) = 'modified';
}).toThrow();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test attempts to verify immutability by reassigning a constant, which will throw in strict mode but may not work as expected in all contexts. A better approach would be to use Object.isFrozen() or check Object.getOwnPropertyDescriptor() to verify the property is not writable: expect(Object.getOwnPropertyDescriptor(module, 'EMAIL_NOTIFICATION_TYPE')?.writable).toBe(false).

Suggested change
expect(() => {
(EMAIL_NOTIFICATION_TYPE as any) = 'modified';
}).toThrow();
// Check that the EMAIL_NOTIFICATION_TYPE export is not writable
const moduleDescriptor = Object.getOwnPropertyDescriptor(
require('@microsoft/agents-a365-notifications'),
'EMAIL_NOTIFICATION_TYPE'
);
expect(moduleDescriptor?.writable).toBe(false);

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +11
jest.mock('@microsoft/agents-a365-notifications');

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mocking pattern jest.mock('@microsoft/agents-a365-notifications') at line 10 mocks the entire module, but then the test imports and uses actual implementations from the same module (lines 5-7). This creates a conflict where the module is both mocked and used for real types/functions. Consider either removing the mock or being more specific about what needs to be mocked using jest.mock with a factory function, or use jest.spyOn for specific functions instead.

Suggested change
jest.mock('@microsoft/agents-a365-notifications');

Copilot uses AI. Check for mistakes.

// Mock utility methods
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock assignment (Utility.ValidateAuthToken as jest.Mock) = jest.fn() uses a non-standard pattern. This should be jest.spyOn(Utility, 'ValidateAuthToken').mockImplementation(...) or properly configured through the mock definition. The current pattern may not work as expected and could cause test failures.

Suggested change
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();
jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken').mockImplementation(jest.fn());

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +41
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock assignment (Utility.ValidateAuthToken as jest.Mock) = jest.fn() uses a non-standard pattern. This should be jest.spyOn(Utility, 'ValidateAuthToken').mockImplementation(...) or properly configured through the mock definition. The current pattern may not work as expected and could cause test failures.

Suggested change
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();
jest.spyOn(Utility, 'ValidateAuthToken').mockImplementation(jest.fn());
jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken').mockImplementation(jest.fn());

Copilot uses AI. Check for mistakes.

// Mock utility methods
(Utility.ValidateAuthToken as jest.Mock) = jest.fn();
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock assignment (Utility.ValidateAuthToken as jest.Mock) = jest.fn() uses a non-standard pattern. This should be jest.spyOn(Utility, 'ValidateAuthToken').mockImplementation(...) or properly configured through the mock definition. The current pattern may not work as expected and could cause test failures.

Suggested change
(AgenticAuthenticationService.GetAgenticUserToken as jest.Mock) = jest.fn();
jest.spyOn(AgenticAuthenticationService, 'GetAgenticUserToken').mockImplementation(jest.fn());

Copilot uses AI. Check for mistakes.
@abdulanu0 abdulanu0 closed this Dec 4, 2025
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.

3 participants