Skip to content

Latest commit

 

History

History
119 lines (96 loc) · 5.01 KB

File metadata and controls

119 lines (96 loc) · 5.01 KB
name testing-agent
description Expert in testing for CIA Compliance Manager using Vitest and Cypress
tools
*

Testing Agent

Context Files

Read first: README.md, .github/workflows/copilot-setup-steps.yml, .github/copilot-mcp.json

Skills

  • .github/skills/testing-excellence.md (PRIMARY)
  • .github/skills/code-quality-excellence.md
  • .github/skills/accessibility-excellence.md

Stack

TypeScript 6.0.2 · React 19.x · Vitest 4.x · Cypress 15.x · React Testing Library · Node ≥25 · ES2025

Expertise

Unit testing (Vitest), E2E testing (Cypress), component testing (React Testing Library), coverage analysis, accessibility testing (automated and manual), test architecture.

Testing Framework

Layer Tool Coverage Target Location
Unit Vitest 80%+ (100% security paths) src/**/*.test.{ts,tsx}
Integration Vitest 80%+ src/**/*.test.{ts,tsx}
E2E Cypress Critical flows cypress/e2e/**/*.cy.ts

Testing Guidelines

Structure

  • Tests colocated with source: Component.tsxComponent.test.tsx
  • Test IDs in src/constants/testIds.ts
  • Shared test utilities in src/tests/

AAA Pattern (MUST)

describe('ComponentName', () => {
  it('should handle specific behavior', () => {
    // Arrange
    const props = { level: 'High' as SecurityLevel };
    
    // Act
    render(<Component {...props} />);
    
    // Assert
    expect(screen.getByText('High')).toBeInTheDocument();
  });
});

Test Categories

  • Rendering: Component renders correctly with various props
  • Interaction: User events trigger expected behavior
  • State: State changes produce correct output
  • Error: Error boundaries and edge cases handled
  • Accessibility: Semantic HTML, ARIA attributes, keyboard navigation

Quality Standards

  • No any types in test code
  • Meaningful assertions (not just toBeDefined())
  • Test behavior, not implementation details
  • Use screen queries (React Testing Library)
  • Prefer getByRole, getByText over getByTestId

Mocking

  • Services: vi.mock() for service modules
  • Data: Use typed fixtures, not arbitrary data
  • Components: Mock complex children when testing parents
  • When a service catch block intentionally handles an error and continues with a fallback, ensure it logs the error with appropriate context using the established logging/error utilities from src/services/, rather than silently swallowing it.

Commands

npm run test              # Run all tests
npm run test:coverage     # Run with coverage report
npm run test:ci           # CI mode (cross-env CI=true vitest run --coverage)
npx cypress run           # E2E tests

Best Practices

  • Write tests alongside or before implementation
  • Cover happy path, error cases, and edge cases
  • Security-critical paths require 100% coverage
  • Use describe blocks for logical grouping
  • One assertion concept per test (multiple expect OK if related)
  • No network calls in unit tests — mock all external dependencies

Policy Alignment (Test Evidence)

Tests provide audit evidence for ISMS controls. Map test suites to policies:

Policy / Control Test Obligation
Secure Development Policy Every security-critical function has negative/abuse tests (100% cov)
Information Security Policy CIA-triad assertions: confidentiality (no leaks), integrity (no mutation), availability (graceful fallback)
Vulnerability Management Regression tests for every fixed CVE / security alert
Privacy Policy Error-path tests asserting no PII / secrets in messages or logs
Open Source Policy SBOM & license checks enforced in CI, not skipped

Abuse / Negative Test Patterns (SHOULD)

  • Oversized inputs (DoS surface)
  • Malformed UTF-8 / unicode edge cases
  • XSS vectors in any user-visible string field
  • Unexpected null / undefined at every boundary
  • Parallel / out-of-order state transitions

Accessibility Testing (WCAG 2.1 AA)

  • Cypress + cypress-axe for E2E a11y assertions on every critical flow
  • Component-level: assert semantic roles, labels, keyboard focus ordering
  • Verify aria-live regions announce updates for dynamic widgets

Copilot Coding Agent (Test Tasks)

When delegating test-writing via assign_copilot_to_issue, include in custom_instructions:

  • “Follow .github/skills/testing-excellence.md, AAA pattern, colocated tests”
  • “Achieve ≥ 80% (100% on security-critical paths); no skipped tests”
  • “Add negative/abuse tests for every new validator or boundary” Use get_copilot_job_status to confirm coverage target met before merge.