# Test Execution

> Test Execution Skill

- Skill: `masharratt/test-execution` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx get-skill add masharratt/test-execution`
- Raw SKILL.md: https://api.skillmd.com/api/skills/masharratt/test-execution/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: masharratt (https://skillmd.com/u/masharratt)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/masharratt/test-execution

---


# Test Execution Skill

**Pattern:** Coordinator-Cached Test Execution
**Status:** OPERATIONAL - Specialized for multi-agent concurrent testing

## When to Use This Skill

**USE when:**
- 3+ agents need test results simultaneously
- Multi-agent swarms testing in parallel
- Preventing port/resource conflicts is critical
- Distributed testing environments

**DO NOT USE when:**
- Single agent testing → Use `npm test` directly
- Code validation → Use `.claude/hooks/invoke-post-edit.sh`
- Simple test execution → Use `npm test` directly
- Development workflow → Use standard npm scripts

## Problem Statement

Concurrent test execution causes conflicts, resource contention, and flaky results. Multiple agents running tests simultaneously creates:
- Port conflicts (test servers)
- Database/file system race conditions
- Unreliable coverage reports
- Wasted computation from duplicate test runs

## Solution: Coordinator Pattern

**Single Test Execution:** One coordinator agent runs all tests once
**Cached Results:** Results stored in Redis + JSON file
**Worker Reads:** All other agents read cached results (never execute tests)

## Implementation

### Scripts Available

1. **test-coordinator-pattern.sh** - Coordinator runs tests, caches to Redis
2. **test-cache-reader.sh** - Workers read cached results
3. **test-concurrent-conflicts.sh** - Validates coordinator pattern (20 runs)

### Usage

**Coordinator Agent (runs tests):**
```bash
# Run tests once and cache results
./.claude/skills/test-execution/test-coordinator-pattern.sh swarm-123
```

**Worker Agents (read cache):**
```bash
# Read cached test results (waits for coordinator)
./.claude/skills/test-execution/test-cache-reader.sh swarm-123 worker-1
```

**Validate Pattern:**
```bash
# Test concurrent execution (20 cycles)
./.claude/skills/test-execution/test-concurrent-conflicts.sh
```

## Workflow

```
1. Coordinator detects "run tests" signal
2. Coordinator terminates existing test processes
3. Coordinator runs: npm test -- --run --reporter=json
4. Results cached to:
   - Redis: swarm:${SWARM_ID}:tests:metadata
   - File: test-results.json
5. Workers wait for completion signal (max 5min timeout)
6. Workers read cached results
7. All agents use same test results (no conflicts)
```

## Performance Metrics

- Test execution: 1x instead of Nx (N = number of agents)
- Cache read latency: <100ms
- Conflict prevention: 100% (validated with 20 concurrent runs)
- Resource savings: ~90% (no duplicate test processes)

## Integration with Other Skills

- **Post-Edit Hooks:** Use `.claude/hooks/invoke-post-edit.sh` for TypeScript validation (simpler, faster)
- **Redis Coordination:** Uses same Redis pub/sub infrastructure
- **CFN Loop Validation:** Can integrate test results into consensus calculation

## Current Project Status

**Active Tests:** None in `/src` (legacy tests in `/packages`)
**Jest Configuration:** Installed (29.7.0) but not actively used
**Recommendation:** Skill is operational but currently unnecessary. Use `npm test` directly for development.

## Future Use Cases

When multi-agent swarms become active and need concurrent testing:
1. Designate one agent as test coordinator
2. Coordinator uses `test-coordinator-pattern.sh`
3. Workers use `test-cache-reader.sh`
4. Validate with `test-concurrent-conflicts.sh`
