with one click
write-test
// Write tests for Agent Health following project conventions. Use when adding tests for new features, bug fixes, or improving coverage. Covers Jest setup, mocking patterns, path aliases, and coverage thresholds.
// Write tests for Agent Health following project conventions. Use when adding tests for new features, bug fixes, or improving coverage. Covers Jest setup, mocking patterns, path aliases, and coverage thresholds.
| name | write-test |
| description | Write tests for Agent Health following project conventions. Use when adding tests for new features, bug fixes, or improving coverage. Covers Jest setup, mocking patterns, path aliases, and coverage thresholds. |
You are helping the user write tests following Agent Health's conventions.
tests/ mirroring the source directory structurejest.config.cjs@/ path alias — never relative imports// ✅ Correct
import { myFunction } from '@/services/myService';
// ❌ Wrong
import { myFunction } from '../../services/myService';
/* Copyright OpenSearch Contributors
SPDX-License-Identifier: Apache-2.0 */
import { functionUnderTest } from '@/path/to/module';
describe('functionUnderTest', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should handle the happy path', () => {
const result = functionUnderTest(validInput);
expect(result).toEqual(expectedOutput);
});
it('should handle edge case', () => {
// ...
});
});
jest.mock('@/server/adapters/opensearch/StorageModule', () => ({
getStorageModule: () => ({
testCases: {
create: jest.fn().mockResolvedValue({ id: 'test-1', name: 'Test' }),
get: jest.fn().mockResolvedValue(null),
},
}),
}));
const mockFetch = jest.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve({ data: 'result' }),
});
global.fetch = mockFetch;
Test through the public API. Only mock at system boundaries.
If the test creates data in OpenSearch or starts a server:
afterEach(async () => {
// Clean up created resources
await storage.delete(createdId);
});
afterAll(async () => {
// Close connections
await server.close();
});
| Metric | Minimum |
|---|---|
| Lines | 90% |
| Statements | 90% |
| Functions | 80% |
| Branches | 80% |
Run coverage: npm test -- --coverage
npm test # All tests
npm run test:unit # Unit only
npm run test:integration # Integration only
npm test -- path/to/file.test.ts # Single file
npm test -- --watch # Watch mode
Create a pull request for Agent Health following all compliance requirements. Use after implementing a feature or fix. Handles SPDX headers, DCO signoff, CHANGELOG, and the PR template.
Diagnose and fix bugs in Agent Health. Use when a user reports a bug, failing test, or unexpected behavior. Follows a systematic diagnosis → fix → verify workflow.
Guided feature implementation for Agent Health. Use when a user wants to add a new capability, endpoint, CLI command, or UI component to the Agent Health project. Ensures correct architecture layer, coding conventions, test coverage, and PR readiness.
Add OpenTelemetry instrumentation to an AI agent for Agent Health observability. Use when a user wants to make their agent's traces visible in Agent Health dashboards, or when debugging why traces aren't appearing. Covers span structure, Gen AI semantic conventions, required attributes, and OTLP exporter setup.
Set up an OpenTelemetry collector or OSIS pipeline to route traces from an agent to OpenSearch for Agent Health consumption. Covers OSIS, OTel Collector, and direct export configurations.
Use when working on config loading, authentication, AWS profiles, or data source resolution. Explains the two config systems (TS vs JSON), auth priority, and multi-profile setup.