Skip to content

Add unit tests #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/ci-executors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: engine-executors Tests

on:
push:
branches: [main]
paths:
- "executors/**"
pull_request:
branches: [main]
paths:
- "executors/**"
workflow_dispatch: # Allow manual triggering for testing (optional)

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: ubuntu-latest

services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Give GitHub Actions access to @thirdweb-dev/vault
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd #@v0.9.1
with:
ssh-private-key: ${{ secrets.VAULT_REPO_DEPLOY_KEY }}

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #checkout@v4

- name: Install CI dependencies
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18
with:
tool: cargo-nextest

- name: Cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build -p engine-executors --verbose

- name: Run tests
run: cargo nextest run -p engine-executors --profile ci

- name: Test Report
uses: dorny/test-reporter@6e6a65b7a0bd2c9197df7d0ae36ac5cee784230c # @v2
if: success() || failure() # run this step even if previous step failed
with:
name: Integration Tests # Name of the check run which will be created
path: target/nextest/ci/junit.xml # Path to test results
reporter: java-junit # Format of test results
75 changes: 75 additions & 0 deletions .github/workflows/coverage-executors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: engine-executors Coverage

on:
push:
branches: [main]
paths:
- "executors/**"
pull_request:
branches: [main]
paths:
- "executors/**"
workflow_dispatch: # Allow manual triggering for testing (optional)

env:
CARGO_TERM_COLOR: always

jobs:
coverage:
runs-on: ubuntu-latest

services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Give GitHub Actions access to @thirdweb-dev/vault
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd #@v0.9.1
with:
ssh-private-key: ${{ secrets.VAULT_REPO_DEPLOY_KEY }}

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #checkout@v4

- name: Install CI dependencies
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18
with:
tool: cargo-tarpaulin

- name: Cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-tarpaulin-${{ hashFiles('**/Cargo.lock') }}

# Run coverage with tarpaulin
- name: Run coverage
run: cargo tarpaulin -p engine-executors --skip-clean --out Xml --out Html --output-dir coverage --exclude-files "aa-core/*" --exclude-files "core/*" --exclude-files "server/*" --exclude-files "thirdweb-core/*" --exclude-files "twmq/*"

# Archive coverage reports as artifacts
- name: Archive code coverage results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # @4.6.2
with:
name: code-coverage-report
path: coverage/

- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # @v1.3.0
with:
filename: coverage/cobertura.xml
format: markdown
output: both

- name: Add Coverage Summary to Job Summary
# This step reads the generated markdown file and appends it to the
# special GITHUB_STEP_SUMMARY file, which populates the job summary page.
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
9 changes: 9 additions & 0 deletions executors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ engine-aa-core = { version = "0.1.0", path = "../aa-core" }
rand = "0.9.1"
uuid = { version = "1.17.0", features = ["v4"] }
chrono = "0.4.41"

[dev-dependencies]
tokio = { version = "1.0", features = ["full"] }
mockall = "0.14.0"
wiremock = "0.6.2"
redis = { version = "0.27.5", features = ["tokio-comp"] }
testcontainers = "0.23.1"
testcontainers-modules = { version = "0.11.4", features = ["redis"] }
tracing-test = "0.2.5"
184 changes: 184 additions & 0 deletions executors/GITHUB_ACTIONS_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# GitHub Actions Workflows - Following Repository Patterns

## ✅ Successfully Implemented Per-Crate Workflow Pattern

Following the established pattern from `twmq` crate, I've created dedicated GitHub Actions workflows for the `engine-executors` crate that exactly match the repository conventions.

## 📋 Pattern Analysis & Implementation

### **Reference Pattern (twmq):**
- `ci-twmq.yaml` - Tests for twmq crate
- `coverage-twmq.yaml` - Coverage for twmq crate

### **Implemented Pattern (engine-executors):**
- `ci-executors.yaml` - Tests for engine-executors crate
- `coverage-executors.yaml` - Coverage for engine-executors crate

## 🔧 Exact Pattern Compliance

### **1. Workflow Naming Convention**
```yaml
# Pattern: {crate-name} Tests / {crate-name} Coverage
name: twmq Tests → name: engine-executors Tests
name: twmq Coverage → name: engine-executors Coverage
```

### **2. Path Triggers (Crate-Specific Only)**
```yaml
# Before (Non-compliant): Multiple paths
paths:
- "executors/**"
- "aa-types/**" # ❌ Dependencies shouldn't trigger
- "core/**" # ❌ Dependencies shouldn't trigger
- "twmq/**" # ❌ Other crates shouldn't trigger

# After (Compliant): Single crate path only
paths:
- "executors/**" # ✅ Only this crate triggers its workflow
```

### **3. Cache Keys (Shared Pattern)**
```yaml
# CI Cache Key (exactly matching twmq)
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

# Coverage Cache Key (exactly matching twmq)
key: ${{ runner.os }}-cargo-tarpaulin-${{ hashFiles('**/Cargo.lock') }}
```

### **4. Build & Test Commands**
```yaml
# Pattern: Always use -p {crate-name}
Build: cargo build -p twmq --verbose → cargo build -p engine-executors --verbose
Test: cargo nextest run -p twmq --profile ci → cargo nextest run -p engine-executors --profile ci
Coverage: cargo tarpaulin -p twmq ... → cargo tarpaulin -p engine-executors ...
```

### **5. Artifact & Report Names**
```yaml
# Test Report Name (exactly matching twmq)
name: Integration Tests # ✅ Same for all crates

# Coverage Artifact Name (exactly matching twmq)
name: code-coverage-report # ✅ Same for all crates
```

## 📁 File Structure

```
.github/workflows/
├── ci-twmq.yaml # ✅ Tests for twmq crate
├── coverage-twmq.yaml # ✅ Coverage for twmq crate
├── ci-executors.yaml # ✅ Tests for engine-executors crate
├── coverage-executors.yaml # ✅ Coverage for engine-executors crate
└── (other workflows...)
```

## 🚀 Workflow Behavior

### **CI Workflow (`ci-executors.yaml`)**
```yaml
Triggers:
- Push to main with changes in executors/**
- PR to main with changes in executors/**
- Manual dispatch

Steps:
1. ✅ Setup Redis service (redis:7-alpine)
2. ✅ Checkout code with SSH agent
3. ✅ Install cargo-nextest
4. ✅ Cache cargo artifacts (shared key)
5. ✅ Build engine-executors package
6. ✅ Run tests with nextest
7. ✅ Generate JUnit XML report
8. ✅ Upload test results for PR visibility
```

### **Coverage Workflow (`coverage-executors.yaml`)**
```yaml
Triggers:
- Push to main with changes in executors/**
- PR to main with changes in executors/**
- Manual dispatch

Steps:
1. ✅ Setup Redis service (redis:7-alpine)
2. ✅ Checkout code with SSH agent
3. ✅ Install cargo-tarpaulin
4. ✅ Cache cargo artifacts (shared key)
5. ✅ Run coverage analysis on engine-executors
6. ✅ Generate HTML & XML coverage reports
7. ✅ Upload coverage artifacts
8. ✅ Add coverage summary to job summary
```

## 🔍 Key Pattern Principles Followed

### **1. Isolation Principle**
- ✅ Each crate has its own dedicated workflows
- ✅ Only triggers on changes to that specific crate
- ✅ No cross-crate triggering to avoid unnecessary runs

### **2. Consistency Principle**
- ✅ Identical workflow structure across all crates
- ✅ Same service configurations (Redis)
- ✅ Same caching strategies
- ✅ Same reporting mechanisms

### **3. Reusability Principle**
- ✅ Shared infrastructure (Redis service, SSH setup)
- ✅ Common artifact names for easy aggregation
- ✅ Standard tool usage (nextest, tarpaulin)

### **4. Efficiency Principle**
- ✅ Only runs when relevant code changes
- ✅ Proper caching to speed up builds
- ✅ Parallel test execution with nextest

## 📊 Comparison Table

| Aspect | twmq Pattern | engine-executors Implementation | Status |
|--------|-------------|--------------------------------|---------|
| **Workflow Names** | `twmq Tests`, `twmq Coverage` | `engine-executors Tests`, `engine-executors Coverage` | ✅ |
| **Path Triggers** | `"twmq/**"` only | `"executors/**"` only | ✅ |
| **Cache Keys** | Shared, no crate suffix | Shared, no crate suffix | ✅ |
| **Build Command** | `cargo build -p twmq` | `cargo build -p engine-executors` | ✅ |
| **Test Command** | `cargo nextest run -p twmq` | `cargo nextest run -p engine-executors` | ✅ |
| **Coverage Command** | `cargo tarpaulin -p twmq` | `cargo tarpaulin -p engine-executors` | ✅ |
| **Test Report Name** | "Integration Tests" | "Integration Tests" | ✅ |
| **Artifact Name** | "code-coverage-report" | "code-coverage-report" | ✅ |
| **Redis Service** | redis:7-alpine | redis:7-alpine | ✅ |
| **SSH Setup** | webfactory/ssh-agent | webfactory/ssh-agent | ✅ |

## 🎯 Benefits of This Pattern

### **For Developers:**
- ✅ **Predictable**: Same workflow structure for every crate
- ✅ **Efficient**: Only runs tests for changed crates
- ✅ **Fast Feedback**: Parallel execution with proper caching
- ✅ **Clear Reports**: Consistent test and coverage reporting

### **For CI/CD:**
- ✅ **Scalable**: Easy to add workflows for new crates
- ✅ **Maintainable**: Identical structure makes updates simple
- ✅ **Resource Efficient**: No unnecessary workflow runs
- ✅ **Reliable**: Proven pattern from existing twmq workflows

### **For Code Quality:**
- ✅ **Comprehensive**: Every crate gets full test & coverage analysis
- ✅ **Isolated**: Issues in one crate don't affect others
- ✅ **Traceable**: Clear mapping between crate changes and test results
- ✅ **Consistent**: Same quality standards across all crates

## 📝 Summary

Successfully implemented GitHub Actions workflows for the `engine-executors` crate that **exactly match** the established repository pattern:

- ✅ **Pattern Compliance**: 100% match with twmq workflow structure
- ✅ **Trigger Isolation**: Only runs on executors/** changes
- ✅ **Tool Consistency**: Uses same CI tools (nextest, tarpaulin)
- ✅ **Cache Efficiency**: Shares cache keys for optimal performance
- ✅ **Report Standards**: Uses standard artifact and report names
- ✅ **Service Integration**: Proper Redis setup for realistic testing

The workflows are now ready to automatically execute on every PR that touches the executors crate, providing immediate feedback on test results and coverage analysis while following the exact patterns established in the repository.
Loading
Loading