Skip to content

Latest commit

Β 

History

History

__tests__

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

README.md

Error in user YAML: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
---
title: "Agent Test Suite"
description: "Comprehensive Jest tests for all LightSpeed agents"
version: "v1.0"
last_updated: "2026-09-22""
file_type: "documentation"
---

πŸ§ͺ Agent Test Suite

This directory contains comprehensive Jest tests for all LightSpeed agents, ensuring reliability, correctness, and consistent behavior across automation workflows.

Validation Status

Last Updated: 2025-11-25
Status: βœ… All agent files validated

Validation Results

All agent specification files pass frontmatter validation:

node scripts/validation/validate-agent-frontmatter.js

Result: βœ… 14/14 files passing

Agent File Status
badges.agent.md βœ… Valid
meta.agent.md βœ… Valid
header-footer.agent.md βœ… Valid
issue-type.agent.md βœ… Valid
jsdoc-review.agent.md βœ… Valid
label-standardization.agent.md βœ… Valid
labeling.agent.md βœ… Valid
linting.agent.md βœ… Valid
manage-readmes.agent.md βœ… Valid
metrics.agent.md βœ… Valid
planner.agent.md βœ… Valid
release.agent.md βœ… Valid
reviewer.agent.md βœ… Valid
template.agent.md βœ… Valid

See Validation Report for full details.


Test Organization

Core Agent Tests

File Agent Tested Purpose
template.agent.test.js template.agent.js Tests basic agent structure and initialization
issue-type.agent.test.js issue-type.agent.js Tests issue type detection and assignment
label-standardization.agent.test.js label-standardization.agent.js Tests label normalization and migration
labeling.agent.test.js labeling.agent.js Tests unified labeling workflow
labeling.agent.integration.test.js labeling.agent.js Integration tests with GitHub API mocks
reviewer.agent.test.js reviewer.agent.js Tests PR review automation
planner.agent.test.js planner.agent.js Tests PR checklist generation

Specialized Tests

File Purpose
agent-performance.test.js Performance benchmarks for agents
agent-workflows.test.js Tests agent integration with GitHub workflows
test-mock-validation.test.js Validates test mocks and helpers

πŸš€ Running Tests

Run All Agent Tests

npm test -- .github/agents/__tests__/

Run Specific Test File

npm test -- .github/agents/__tests__/labeling.agent.test.js

Run Tests with Coverage

npm test -- .github/agents/__tests__/ --coverage

Watch Mode (auto-rerun on changes)

npm test -- .github/agents/__tests__/ --watch

Run Specific Test Suite

npm test -- .github/agents/__tests__/labeling.agent.test.js -t "applies default status"

πŸ“Š Coverage Requirements

  • Overall Coverage: β‰₯85%
  • Statements: β‰₯85%
  • Branches: β‰₯80%
  • Functions: β‰₯85%
  • Lines: β‰₯85%

View current coverage:

npm test -- .github/agents/__tests__/ --coverage
open coverage/lcov-report/index.html

βœ… Test Categories

Unit Tests

  • Individual function logic
  • Error handling and edge cases
  • Parameter validation
  • Return value correctness

Integration Tests

  • Multiple functions working together
  • API mocking with octokit
  • GitHub Actions context simulation
  • Real workflow scenarios

Performance Tests

  • Agent execution time benchmarks
  • Memory usage optimization
  • Concurrent operation handling
  • Large dataset processing

πŸ› οΈ Test Utilities & Helpers

Common Test Helpers

Located in test-helpers.js (parent directory):

import {
  mockOctokit,
  mockContext,
  mockPrPayload,
  mockIssuePayload,
  setTestEnv,
  resetTestEnv,
  expectCommentPosted,
  expectDryRun,
} from "../../test-helpers.js";

Mock Functions

mockOctokit()

Creates a mocked GitHub API client with standard REST endpoints.

const octokit = mockOctokit();
octokit.rest.issues.addLabels.mockResolvedValue({ data: {} });

mockContext(payload)

Creates a GitHub Actions context object.

const context = mockContext(
  mockPrPayload({
    labels: [{ name: "type:feature" }],
  }),
);

mockPrPayload(overrides)

Generates a pull request event payload.

const payload = mockPrPayload({
  number: 123,
  title: "Test PR",
});

mockIssuePayload(overrides)

Generates an issue event payload.

const payload = mockIssuePayload({
  number: 456,
  title: "Test Issue",
});

setTestEnv(vars)

Sets environment variables for tests.

setTestEnv({ GITHUB_TOKEN: "test-token" });

resetTestEnv(keys)

Clears specific environment variables after tests.

afterEach(() => resetTestEnv(["GITHUB_TOKEN"]));

πŸ“ Writing New Agent Tests

Test Structure Template

const { mockOctokit, mockContext } = require("../../test-helpers");
const { run } = require("../your-agent.js");

describe("Your Agent", () => {
  beforeAll(() => {
    // Setup before all tests
  });

  afterAll(() => {
    // Cleanup after all tests
  });

  beforeEach(() => {
    // Setup before each test
  });

  afterEach(() => {
    // Cleanup after each test
  });

  test("should perform expected action", async () => {
    // Arrange
    const octokit = mockOctokit();
    const context = mockContext(mockPrPayload());

    // Act
    await run(context);

    // Assert
    expect(octokit.rest.issues.addLabels).toHaveBeenCalled();
  });
});

Best Practices

  1. Clear Test Names: Describe what the test validates, not how

    // βœ… Good
    test("should add default status label when missing", async () => {});
    
    // ❌ Avoid
    test("tests status labels", async () => {});
  2. Arrange-Act-Assert Pattern: Organize test logic clearly

    // Arrange - set up test data
    const input = { labels: [] };
    
    // Act - perform the action
    const result = await runAgent(input);
    
    // Assert - verify the result
    expect(result.labels).toContain("status:needs-review");
  3. Mock External Dependencies: Don't make real API calls

    // βœ… Good
    const octokit = mockOctokit();
    
    // ❌ Avoid
    const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
  4. Test Both Success and Failure Paths

    test("should handle successful case", async () => {
      /* ... */
    });
    test("should throw error when input invalid", async () => {
      /* ... */
    });
  5. Use Meaningful Assertions

    // βœ… Good
    expect(result.labels).toHaveLength(1);
    expect(result.labels[0]).toBe("status:needs-review");
    
    // ❌ Avoid
    expect(result.labels.length).toBe(1);

πŸ” Debugging Tests

Run Tests with Debugging

node --inspect-brk ./node_modules/.bin/jest .github/agents/__tests__/ --runInBand

Log Output During Tests

test("debug test", async () => {
  const result = await runAgent(input);
  console.log("DEBUG:", JSON.stringify(result, null, 2));
  expect(result).toBeDefined();
});

View Detailed Test Output

npm test -- .github/agents/__tests__/ --verbose

πŸ“š Related Documentation

✨ Continuous Integration

All agent tests run automatically on:

  • Pull Requests: All tests must pass before merge
  • Pushes to develop: Validates code quality
  • Pre-commit: Local hook runs affected tests

View CI status in GitHub Actions: .github/workflows/jest-test-audit.yml


Maintained by: LightSpeed Automation Team
Last Updated: 2025-11-24
Version: v1.0

Need help? Say hiβ€”work with us.