Skip to content
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build:watch": "npm run build:watch --workspaces --if-present",
"clean": "npm run clean --workspaces --if-present && rimraf node_modules",
"test": "npm run test --workspaces --if-present -- --testPathIgnorePatterns=/integration/",
"test:coverage": "jest --config=tests/jest.config.cjs --coverage",
"test:watch": "npm run test:watch --workspaces --if-present",
"test:integration": "jest --config jest.integration.config.cjs",
"test:integration:watch": "jest --config jest.integration.config.cjs --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/agents-a365-observability-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"clean": "npx rimraf dist",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
"test": "jest --config ../../tests/jest.config.json --passWithNoTests",
Comment thread
mrunalhirve128 marked this conversation as resolved.
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"pack": "npm pack --pack-destination=../"
Expand Down
27 changes: 27 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Microsoft Agent 365 SDK Tests

Unit and integration tests for the Microsoft Agent 365 SDK - Node.js/TypeScript. This test suite ensures reliability, maintainability, and quality across all modules including runtime, tooling, notifications, and observability extensions.

## Usage

For detailed instructions on running tests and generating coverage reports, see:

- **[Test Plan](TEST_PLAN.md)** - Comprehensive testing strategy and implementation roadmap
- **[Running Tests](RUNNING_TESTS.md)** - Complete guide for installation, running tests, generating coverage reports, and troubleshooting

## Support

For issues, questions, or feedback:

- File issues in the [GitHub Issues](https://github.com/microsoft/Agent365-nodejs/issues) section
- See the [main documentation](../README.md) for more information

## Trademarks

*Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at <http://go.microsoft.com/fwlink/?LinkID=254653>.*

## License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License - see the [LICENSE](../LICENSE.md) file for details.
108 changes: 108 additions & 0 deletions tests/RUNNING_TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Running Unit Tests for Agent365-nodejs SDK

---

## Prerequisites

1. **Node.js 18+**: `node --version`
2. **pnpm**: `npm install -g pnpm`
3. **Dependencies**: `pnpm install` (from repository root)
4. **Build packages**: `pnpm build` (required before running tests)

---

## Test Structure

```plaintext
tests/
├── runtime/ # Runtime tests
├── observability/ # Observability tests
├── tooling/ # Tooling tests
├── notifications/ # Notifications tests
└── all-packages-coverage.test.ts # Ensures all packages appear in coverage reports
```

---

## Running Tests

### Command Line

```powershell
# From repository root
pnpm test

# From tests directory
cd tests
pnpm test # All tests
pnpm test:verbose # Verbose output
pnpm test:watch # Watch mode

# Run specific test file
pnpm test -- runtime/power-platform-api-discovery.test.ts

# Additional options
pnpm test -- --testPathPattern=observability
pnpm test -- --testNamePattern="should return"
pnpm test -- --bail # Stop on first failure
pnpm test -- --onlyFailures # Re-run failed tests only
```

### VS Code Test Explorer (Optional)

1. Install Jest extension (Orta.vscode-jest)
2. Click beaker icon or `Ctrl+Shift+P` → "Test: Focus on Test Explorer View"
3. Click play button to run tests or right-click → "Debug Test"

---

## Coverage Reports

```powershell
cd tests

# Generate coverage reports
pnpm test:coverage # All formats (HTML, LCOV, Cobertura)
pnpm test:ci # CI mode (coverage + optimized for CI)

# View HTML report
start coverage\index.html # Windows
open coverage/index.html # Mac/Linux
```

**Report Formats**: HTML (`coverage/index.html`), LCOV (`lcov.info`), Cobertura (`cobertura-coverage.xml`)

---

## Troubleshooting

### Quick Fixes

| Issue | Solution |
|-------|----------|
| Test loading failed | `pnpm install && pnpm build`, restart VS Code |
| Cannot find module | `pnpm build` from repository root |
| Tests not discovered | Check `.vscode/settings.json`, reload window |

### Complete Reset

```powershell
# From repository root
pnpm install
pnpm build
pnpm test -- --clearCache

# Restart VS Code: Ctrl+Shift+P → "Developer: Reload Window"
```

### VS Code Configuration

Create `.vscode/settings.json` if Test Explorer doesn't work:

```json
{
"jest.rootPath": "tests",
"jest.jestCommandLine": "pnpm test",
"jest.autoRun": "off"
}
```
151 changes: 151 additions & 0 deletions tests/TEST_PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Test Plan for Agent365-nodejs SDK

> **Note:** This plan is under active development. Keep updating as testing progresses.

**Version:** 1.0
**Date:** December 4, 2025
**Status:** Draft

---

## Overview

### Current State
- ✅ Unit tests complete for `runtime` module
- ✅ Unit tests complete for `observability` modules
- ❌ Missing tests for `tooling` and `notifications` modules
- ✅ Coverage reporting includes all 9 packages
- ❌ No integration tests or CI/CD automation

### Goals
- Achieve **80%+ code coverage** across all modules
- Implement unit tests for tooling and notifications modules
- Implement integration tests for cross-module functionality
- Integrate testing into CI/CD pipeline with coverage enforcement

---

## Testing Strategy

**Framework:** `Jest` with `ts-jest`
**Coverage:** `Jest Coverage`
**Mocking:** `jest.mock`
**Async:** Native async/await

**Test Pattern:** AAA (Arrange → Act → Assert)
**Test File Naming:** `<filename>.test.ts` (e.g., `power-platform-api-discovery.test.ts`)
**Test Naming Convention:** `'should <expected_result> when <condition>'`

---

## Implementation Roadmap

| Phase | Deliverables | Priority | Status |
|-------|-------------|----------|--------|
| 1.1 | Runtime unit tests | HIGH | ✅ Complete |
| 1.2 | Tooling unit tests | HIGH | ❌ Missing |
| 1.3 | Notifications unit tests | HIGH | ❌ Missing |
| 1.4 | Expand observability tests | MEDIUM | ✅ Complete |
| 1.5 | Tooling extension tests | LOW | ❌ Missing |
| 2 | Integration tests | MEDIUM | ❌ Missing |
| 3 | CI/CD automation | HIGH | ❌ Missing |

---

## Phase 1: Unit Tests

### 1.1 Runtime Module

**Priority:** HIGH

| Module | Test File | Status |
|--------|-----------|--------|
| `power-platform-api-discovery.ts` | `power-platform-api-discovery.test.ts` | ✅ Complete |
| `utility.ts` | `utility.test.ts` | ✅ Complete |
| `environment-utils.ts` | `environment-utils.test.ts` | ✅ Complete |
| `agentic-authorization-service.ts` | `agentic-authorization-service.test.ts` | ✅ Complete |

---

### 1.2 Tooling Module

**Priority:** HIGH

| Module | Test File | Status |
|--------|-----------|--------|
| `Utility.ts` | `Utility.test.ts` | ❌ Missing |
| `McpToolServerConfigurationService.ts` | `McpToolServerConfigurationService.test.ts` | ❌ Missing |

---

### 1.3 Notifications Module

**Priority:** HIGH

| Module | Test File | Status |
|--------|-----------|--------|
| `agent-notification.ts` | `agent-notification.test.ts` | ❌ Missing |
| `models/*` | Model tests | ❌ Missing |
| `extensions/*` | Extension tests | ❌ Missing |

---

### 1.4 Observability Extensions

**Priority:** MEDIUM

| Extension | Status |
|-----------|--------|
| `openai` | ✅ Expand existing |
| `tokencache` | ✅ Expand existing |

---

### 1.5 Tooling Extensions

**Priority:** LOW

| Extension | Status |
|-----------|--------|
| Claude | ❌ Missing |
| LangChain | ❌ Missing |
| OpenAI | ❌ Missing |

---

## Phase 2: Integration Tests

**Priority:** MEDIUM

| Integration | Status |
|-------------|--------|
| Runtime + Observability | ❌ Missing |
| Tooling + Runtime | ❌ Missing |
| Notifications + Runtime | ❌ Missing |
| OpenAI full flow | ✅ Complete |
| Claude full flow | ❌ Missing |
| LangChain full flow | ❌ Missing |

---

## Phase 3: CI/CD Integration

**Priority:** HIGH

| Component | Status |
|-----------|--------|
| GitHub Actions workflow | ❌ Missing |
| Node.js matrix (18.x, 20.x, 22.x) | ❌ Missing |
| Coverage enforcement (80%+) | ❌ Missing |
| Codecov integration | ❌ Missing |
| PR blocking on failures | ❌ Missing |

---

## Success Criteria

- ✅ 80%+ code coverage for all modules
- ✅ All tests pass independently
- ✅ Full suite completes in < 30 seconds (unit) / < 5 minutes (full)
- ✅ Automated test execution on all PRs
- ✅ Coverage reports visible and enforced
46 changes: 46 additions & 0 deletions tests/all-packages-coverage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* This test ensures all packages are loaded for coverage instrumentation.
* Packages without dedicated tests will show their actual coverage (likely 0%).
*/

const fs = require('fs');
const path = require('path');

// Dynamically load all packages for coverage instrumentation
const packagesDir = path.join(__dirname, '../packages');
const packages = fs.readdirSync(packagesDir).filter((dir: string) => {
const fullPath = path.join(packagesDir, dir);
return fs.statSync(fullPath).isDirectory();
});

// Temporarily skip packages that cause Jest test failures
// TODO: Investigate and enable tooling packages in coverage collection
// Error: "A dynamic import callback was invoked without --experimental-vm-modules"
const skipPackages = [
'agents-a365-tooling',
'agents-a365-tooling-extensions-claude',
'agents-a365-tooling-extensions-langchain',
'agents-a365-tooling-extensions-openai',
];

packages.forEach((pkg: string) => {
if (skipPackages.includes(pkg)) {
return; // Skip packages with dynamic import issues
}
try {
require(`../packages/${pkg}/src/index`);
} catch (error: any) {
// Silently ignore loading errors - package will not appear in coverage
console.warn(`Warning: Could not load package ${pkg}: ${error?.message || error}`);
}
});

describe('All Packages Coverage', () => {
it('should load all packages for coverage reporting', () => {
// Packages are loaded dynamically above
expect(packages.length).toBeGreaterThan(0);
});
});
Loading