06-testing-quality

A set of project rules for testing a TypeScript application with Jest, a JavaScript testing tool. It describes how to structure tests, isolate them, and check both successful and failing behavior.

In plain words
What is it for?
Writing unit tests for servers, tools, resources, and utilities; mocking file-system and network access; and checking compliance with the MCP protocol.
Why use it?
It gives developers a consistent testing approach and helps prevent untested public methods, ignored errors, and tests that depend on real files or services.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/gargoyle92/agentify-mcp/06-testing-quality
Clone the repo
git clone --depth 1 https://github.com/gargoyle92/agentify-mcp

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,615 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02615
Opus 5 $0.00000 $0.01307
Sonnet 5 $0.00000 $0.00523
Haiku 4.5 $0.00000 $0.00262

Measured yesterday against content hash 1bfa6ae089c2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

06-testing-quality scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/06-testing-quality.mdc · 371 lines

How it starts

The opening of the file, as written. The whole thing — 371 lines — stays where its author put it; the contents beside it link to each section on GitHub.

06-Testing-Quality

Testing Framework Configuration

The project uses Jest for testing as configured in package.json with TypeScript support via tsx.

Testing Structure

src/
├── __tests__/           # Test files (to be created)
│   ├── server/
│   ├── tools/
│   ├── resources/
│   └── utils/
└── __mocks__/           # Mock implementations

CRITICAL TESTING RULES - MUST FOLLOW

✅ ALWAYS DO:

  1. Test all public methods: Every public method must have corresponding tests
  2. Mock external dependencies: Mock file system, network calls, and external APIs
  3. Test error conditions: Test both success and failure scenarios
  4. Validate MCP compliance: Test that tools and resources conform to MCP protocol
  5. Use descriptive test names: Test names should clearly describe the scenario

❌ NEVER DO:

  1. Skip error testing: Never test only happy path scenarios
  2. Test implementation details: Test behavior, not internal implementation
  3. Use real file system: Always mock chokidar and fs operations
  4. Ignore async behavior: Always properly handle Promise assertions
  5. Share test state: Each test must be independent and isolated

Unit Testing Patterns

✅ PROPER Test Structure:

// src/__tests__/server/session-manager.test.ts
import { SessionManager } from '../../server/session-manager.js';
import { Logger } from '../../utils/logger.js';
import { AgentClient, AgentClientType, AgentStatus } from '../../types/index.js';

describe('SessionManager', () => {
  let sessionManager: SessionManager;
  let mockLogger: jest.Mocked<Logger>;

  beforeEach(() => {
    mockLogger = {
      info: jest.fn(),
      warn: jest.fn(),
      error: jest.fn(),
      debug: jest.fn(),
    } as jest.Mocked<Logger>;
    
    sessionManager = new SessionManager(mockLogger);
  });

  describe('registerClient', () => {
    it('should register a valid client and emit clientConnected event', () => {
      // Arrange
      const mockClient: AgentClient = createMockClient({
        id: 'test-client',
        type: AgentClientType.CLAUDE_CODE,
        name: 'Test Client',
      });
      
      const eventSpy = jest.spyOn(sessionManager, 'emit');

      // Act
      sessionManager.registerClient(mockClient);

      // Assert
      expect(sessionManager.getClient('test-client')).toBeDefined();
      expect(eventSpy).toHaveBeenCalledWith('clientConnected', mockClient);
      expect(mockLogger.info).toHaveBeenCalledWith('Client registered: test-client (claude-code)');
    });

    it('should throw error when registering client with missing required fields', () => {
      // Arrange
      const invalidClient = { id: '', type: AgentClientType.CLAUDE_CODE } as AgentClient;

      // Act & Assert
      expect(() => sessionManager.registerClient(invalidClient))
        .toThrow('Invalid client: missing required fields');
    });
  });

  describe('updateClientStatus', () => {
    it('should update client status and emit statusChanged event', () => {
      // Arrange
      const mockClient = createMockClient({ id: 'test-client' });
      sessionManager.registerClient(mockClient);
      const eventSpy = jest.spyOn(sessionManager, 'emit');

      // Act
      sessionManager.updateClientStatus('test-client', AgentStatus.RUNNING);

      // Assert
      const updatedClient = sessionManager.getClient('test-client');
      expect(updatedClient?.status).toBe(AgentStatus.RUNNING);
      expect(eventSpy).toHaveBeenCalledWith('clientStatusChanged', expect.objectContaining({
        client: updatedClient,
        oldStatus: AgentStatus.CONNECTED,
        newStatus: AgentStatus.RUNNING,
      }));
    });
  });
});

// Test helper functions
function createMockClient(overrides: Partial<AgentClient> = {}): AgentClient {
  return {
    id: 'default-client',
    type: AgentClientType.CUSTOM,
    name: 'Default Client',
    version: '1.0.0',
    capabilities: [],
    connectionInfo: {
      connectedAt: new Date(),
      lastActivity: new Date(),
      transport: 'stdio',
    },
    status: AgentStatus.CONNECTED,
    context: {
      workingDirectory: '/test',
    },
    metrics: {
      requestCount: 0,
      errorCount: 0,
      uptime: 0,
    },
    ...overrides,
  };
}

Read the full file on GitHub · 371 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 371 lines · 0 tokens per session scan A 1bfa6ae089c2

Subscribe to this mod's changes

06-testing-quality is a cursor rule published in the GitHub repository gargoyle92/agentify-mcp (1 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,615 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.