File size: 23,304 Bytes
cc036ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# End-to-End Testing Suite for Atom

Comprehensive E2E tests validating Atom's critical workflows with real service integration (PostgreSQL, Redis, LLM providers).

## Overview

This directory contains end-to-end tests that validate complete user journeys with **real services** (not mocked). E2E tests catch integration issues between components and ensure the system works as users expect.

**Testing Philosophy:**
- **Real Service Integration**: PostgreSQL, Redis, Docker, LLM providers (not mocked)
- **Complete User Journeys**: Test workflows end-to-end, not individual components
- **Production Confidence**: Validate actual behavior, not mocked responses
- **Performance Validation**: Ensure workflows complete within time thresholds
- **Coverage Targets**: 60-70% for MCP service (vs 26.56% with mocks)

### Why E2E Testing Matters

Unit tests validate individual components in isolation. Integration tests validate component interactions. **E2E tests validate complete user journeys** from start to finish, catching integration issues that unit/integration tests miss.

**Example**: Unit test might verify `AgentGovernanceService.can_perform_action()` returns `True`. E2E test verifies that an agent can actually execute a workflow end-to-end, including database writes, audit trails, and canvas presentations.

### Test Categories

| Category | File | Purpose | Tests |
|----------|------|---------|-------|
| **MCP Tools** | `test_mcp_tools_e2e.py` | MCP tool integration with real PostgreSQL | 66 |
| **Database** | `test_database_integration_e2e.py` | PostgreSQL, SQLite, migrations, pooling | 31 |
| **LLM Providers** | `test_llm_providers_e2e.py` | OpenAI, Anthropic, DeepSeek, BYOK | 36 |
| **Critical Workflows** | `test_critical_workflows_e2e.py` | Complete user journey validation | 20 |
| **Governance** | `test_scenario_01_governance.py` | Agent governance & routing | 8 |
| **Streaming** | `test_scenario_02_streaming.py` | Multi-provider LLM streaming | 6 |
| **Canvas** | `test_scenario_03_canvas.py` | Canvas presentations with governance | 5 |
| **Guidance** | `test_scenario_04_guidance.py` | Real-time agent guidance | 7 |
| **Browser** | `test_scenario_05_browser.py` | Browser automation with Playwright | 6 |
| **Episodes** | `test_scenario_06_episodes.py` | Episodic memory & retrieval | 8 |
| **Graduation** | `test_scenario_07_graduation.py` | Agent graduation framework | 7 |
| **Training** | `test_scenario_08_training.py` | Student agent training | 8 |
| **Device** | `test_scenario_09_device.py` | Device capabilities & permissions | 9 |
| **Deeplinks** | `test_scenario_10_deeplinks_feedback.py` | Deep linking & feedback | 8 |

## Setup Instructions

### Prerequisites

```bash

# 1. Install Python dependencies

cd /Users/rushiparikh/projects/atom/backend

pip install -e .



# 2. Install Docker (required for PostgreSQL and Redis)

# Download from: https://www.docker.com/products/docker-desktop



# 3. Install Playwright for browser automation tests (optional)

playwright install chromium

```

### Environment Configuration

```bash

# Required for E2E testing with real services

export E2E_TESTING=true



# Database configuration (default: PostgreSQL on port 5433)

export DATABASE_URL="postgresql://atom:atom@localhost:5433/atom_e2e"

# Or for Personal Edition testing:

# export DATABASE_URL="sqlite:///./atom_e2e.db"



# Redis configuration (default: localhost:6380)

export REDIS_URL="redis://localhost:6380"



# LLM Provider API Keys (optional - tests skip if not set)

export OPENAI_API_KEY="sk-..."

export ANTHROPIC_API_KEY="sk-ant-..."

export DEEPSEEK_API_KEY="sk-..."

export GEMINI_API_KEY="..."



# Feature flags (automatically set by conftest.py)

export STREAMING_GOVERNANCE_ENABLED=true

export CANVAS_GOVERNANCE_ENABLED=true

export BROWSER_AUTOMATION_ENABLED=true

export EPISODIC_MEMORY_ENABLED=true

```

### Docker Service Setup

```bash

# Start PostgreSQL and Redis for E2E testing

cd /Users/rushiparikh/projects/atom

docker-compose -f docker-compose-e2e.yml up -d



# Verify services are running

docker ps



# Stop services when done

docker-compose -f docker-compose-e2e.yml down

```

**Services:**
- **PostgreSQL 16**: `localhost:5433` (user: `atom`, pass: `atom`, db: `atom_e2e`)
- **Valkey 8** (Redis-compatible): `localhost:6380`

## Test Execution Guide

### Running All E2E Tests

```bash

# Run all E2E tests with real services

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v



# Run with timeout enforcement (10 minutes total)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v --timeout=600



# Run with coverage (MCP service target: 60-70%)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v --cov=integrations/mcp_service --cov-report=term-missing

```

### Running Specific Test Suites

```bash

# MCP Tool E2E Tests (PostgreSQL integration)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_mcp_tools_e2e.py -v



# Database Integration E2E Tests (PostgreSQL, SQLite, migrations)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_database_integration_e2e.py -v



# LLM Provider E2E Tests (requires API keys)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_llm_providers_e2e.py -v



# Critical Workflow E2E Tests (complete user journeys)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_critical_workflows_e2e.py -v

```

### Running with Coverage

```bash

# Generate HTML coverage report

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v \

  --cov=integrations/mcp_service \

  --cov=core \

  --cov-report=html \

  --cov-report=term-missing



# View coverage report

open htmlcov/index.html



# Check coverage for specific module

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v \

  --cov=integrations/mcp_service.mcp_service \

  --cov-report=term-missing

```

### Debugging Failed Tests

```bash

# Run with verbose output

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_critical_workflows_e2e.py -v -s



# Drop into debugger on failure

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_critical_workflows_e2e.py -v -s --pdb



# Run last failed tests

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v --lf



# Run until first failure

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v -x

```

## Test Organization

### E2E Test Files

#### 1. MCP Tool E2E Tests (`test_mcp_tools_e2e.py`)

**Purpose**: Validate MCP tool integration with real PostgreSQL operations



**Test Coverage**:

- CRM tools (Salesforce, HubSpot, Pipedrive): 5 tests

- Task management (Asana, Trello, Jira): 6 tests

- Ticketing systems (Zendesk, Freshdesk): 4 tests

- Knowledge base (Notion, Confluence): 6 tests

- Canvas presentations: 5 tests

- Finance tools (QuickBooks, Xero): 3 tests

- WhatsApp integration: 3 tests

- Shopify integration: 4 tests

- Error handling (404, 500, timeout): 8 tests

- Concurrency (parallel operations): 4 tests

- Performance (bulk operations): 4 tests

- Data validation (SQL injection, XSS): 10 tests



**Key Fixtures**:

- `e2e_docker_compose`: Start/stop Docker services

- `e2e_postgres_db`: PostgreSQL database connection

- `mcp_service`: MCP service instance with DB
- `crm_data_factory`: Create test CRM records

#### 2. Database Integration E2E Tests (`test_database_integration_e2e.py`)

**Purpose**: Validate database operations across PostgreSQL and SQLite



**Test Coverage**:

- PostgreSQL CRUD operations: 4 tests

- PostgreSQL transactions: 3 tests

- PostgreSQL foreign keys: 3 tests

- SQLite Personal Edition: 2 tests

- SQLite WAL mode: 1 test

- Connection pooling: 3 tests

- Alembic migrations: 4 tests

- Backup/restore: 3 tests

- Performance benchmarks: 3 tests



**Key Fixtures**:

- `e2e_postgres_db`: PostgreSQL database

- `e2e_sqlite_db`: SQLite in-memory database

- `migration_runner`: Run Alembic migrations
- `database_backup`: Backup/restore utilities

#### 3. LLM Provider E2E Tests (`test_llm_providers_e2e.py`)

**Purpose**: Validate multi-provider LLM integration with real API calls



**Test Coverage**:

- OpenAI integration: 6 tests

- Anthropic integration: 6 tests

- DeepSeek integration: 5 tests

- BYOK handler: 7 tests

- Context management: 3 tests

- Cross-provider comparison: 2 tests

- Error handling: 3 tests

- Performance benchmarks: 2 tests



**Key Fixtures**:

- `llm_api_keys`: Detect available API keys

- `openai_client`: OpenAI client (skips if no key)
- `anthropic_client`: Anthropic client (skips if no key)
- `byok_handler`: BYOK handler with multiple providers

**Note**: Tests gracefully skip when API keys not configured (CI-friendly)

#### 4. Critical Workflow E2E Tests (`test_critical_workflows_e2e.py`)

**Purpose**: Validate complete user journeys end-to-end



**Test Coverage**:

- **Agent Execution Workflow** (3 tests):

  - Complete agent lifecycle (creation, execution, monitoring, results)

  - Failure scenarios with error handling

  - Multi-agent coordination



- **Skill Loading Workflow** (3 tests):

  - Skill import, security scanning, storage, execution

  - Package dependency detection

  - Invalid SKILL.md handling



- **Package Installation Workflow** (3 tests):

  - Governance approval, vulnerability scanning, installation

  - Dependency resolution

  - Graceful failure handling



- **Multi-Provider LLM Workflow** (3 tests):

  - Provider failure and fallback

  - Cost optimization

  - Budget enforcement



- **Canvas Presentation Workflow** (3 tests):

  - Canvas creation, LLM content generation, presentation

  - LLM-generated content on canvas

  - Feedback loop and linkage



- **End-to-End Smoke Tests** (5 tests):

  - Complete agent-to-canvas journey

  - Skill-to-package integration

  - Performance threshold validation

  - Data integrity checks

  - Error recovery and audit trail validation



**Key Fixtures**:

- `agent_workflow`: Agent execution workflow setup
- `skill_workflow`: Skill loading workflow setup
- `package_workflow`: Package installation workflow setup
- `llm_workflow`: Multi-provider LLM workflow setup
- `canvas_workflow`: Canvas presentation workflow setup
- `composite_workflow`: All workflows combined
- `workflow_performance_thresholds`: Performance validation

### Fixture Modules

#### `conftest.py` - Root E2E Configuration
- Docker Compose lifecycle management
- PostgreSQL and Redis fixtures
- LLM API key detection
- Test data factories
- Performance monitoring

#### `fixtures/workflow_fixtures.py` - Workflow-Specific Fixtures

- Agent workflow fixture

- Skill workflow fixture

- Package workflow fixture

- LLM workflow fixture

- Canvas workflow fixture

- Composite workflow fixture

- Performance threshold fixture

- Audit trail helper



#### `fixtures/database_fixtures.py` - Database Fixtures
- PostgreSQL engine fixture
- SQLite engine fixture
- Migration runner fixture
- Backup/restore fixture
- Connection pool fixture

#### `fixtures/llm_fixtures.py` - LLM Provider Fixtures

- API key detection

- OpenAI client fixture

- Anthropic client fixture

- BYOK handler fixture

- Mock response fixture



#### `fixtures/test_data_factory.py` - Test Data Generation

- CRM data factory

- Task data factory

- Ticket data factory

- Knowledge base factory

- Canvas data factory

- Finance data factory



## CI/CD Integration



### GitHub Actions Configuration



```yaml

name: E2E Tests



on:

  push:

    branches: [main, develop]

  pull_request:
    branches: [main, develop]

  schedule:

    # Run daily at 2 AM UTC

    - cron: '0 2 * * *'


jobs:
  e2e-tests:
    runs-on: ubuntu-latest

    timeout-minutes: 15


    services:

      postgres:

        image: postgres:16-alpine

        env:

          POSTGRES_USER: atom

          POSTGRES_PASSWORD: atom

          POSTGRES_DB: atom_e2e

        ports:

          - 5433:5432

        options: >-

          --health-cmd pg_isready

          --health-interval 10s

          --health-timeout 5s

          --health-retries 5


      redis:

        image: valkey/valkey:8

        ports:

          - 6380:6379

        options: >-

          --health-cmd "redis-cli ping"

          --health-interval 10s

          --health-timeout 5s

          --health-retries 5


    steps:

      - uses: actions/checkout@v3


      - name: Set up Python
        uses: actions/setup-python@v4

        with:

          python-version: '3.11'


      - name: Install dependencies
        run: |

          cd backend

          pip install -e .

          pip install pytest pytest-timeout pytest-cov


      - name: Run E2E tests
        env:

          E2E_TESTING: true

          DATABASE_URL: postgresql://atom:atom@localhost:5433/atom_e2e

          REDIS_URL: redis://localhost:6380

          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

        run: |

          PYTHONPATH=./backend pytest backend/tests/e2e/ -v \

            --timeout=600 \

            --cov=integrations/mcp_service \

            --cov-report=xml \

            --cov-report=term-missing


      - name: Check coverage threshold
        run: |

          coverage=$(coverage report | grep integrations/mcp_service | awk '{print $4}' | sed 's/%//')

          if (( $(echo "$coverage < 60" | bc -l) )); then

            echo "Coverage $coverage% below 60% threshold"

            exit 1

          fi

          echo "Coverage $coverage% meets threshold"


      - name: Upload coverage
        uses: codecov/codecov-action@v3

        with:

          files: ./coverage.xml

          flags: e2e

          name: e2e-coverage


      - name: Upload test results
        if: always()

        uses: actions/upload-artifact@v3

        with:

          name: e2e-test-results

          path: |

            backend/htmlcov/

            backend/.coverage*

```


### Parallel Execution

```bash

# Run E2E tests in parallel (faster on CI)

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v -n auto



# Run specific suites in parallel

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest \

  backend/tests/e2e/test_mcp_tools_e2e.py \

  backend/tests/e2e/test_database_integration_e2e.py \

  -v -n auto

```

## Performance Benchmarks

### Expected Execution Times

| Test Suite | Tests | Target | Notes |
|------------|-------|--------|-------|
| MCP Tools E2E | 66 | 2-3 min | PostgreSQL operations |
| Database Integration | 31 | 1-2 min | PostgreSQL + SQLite |
| LLM Providers | 36 | 2-4 min | API calls (if keys set) |
| Critical Workflows | 20 | 1-2 min | Workflow validation |
| Scenarios (01-10) | 64 | 3-5 min | Feature scenarios |
| **TOTAL** | **217+** | **<10 min** | **Full suite target** |

### Performance Targets

| Workflow | Target | Validation |
|----------|--------|------------|
| Agent creation | <1s | `test_workflow_performance_within_thresholds` |
| Agent execution | <10s | `test_agent_execution_workflow` |
| Skill import | <5s | `test_skill_loading_workflow` |
| Package install | <60s | `test_python_package_installation` |
| LLM streaming | <5s | `test_multi_provider_fallback` |
| Canvas presentation | <2s | `test_canvas_presentation_workflow` |
| **Total workflow** | **<2 min** | `test_complete_agent_to_canvas_workflow` |

### Timeout Enforcement

```bash

# Set 10-minute timeout for entire suite

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v --timeout=600



# Set per-test timeout

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v --timeout=30

```

## Coverage Targets

### Current Baseline (Phase 62)

| Module | Coverage | Target | Gap |
|--------|----------|--------|-----|
| MCP Service | 26.56% | 60-70% | **-33% to -43%** |
| Core Services | 24.4% | 50-60% | -26% to -36% |
| API Routes | 38.2% | 70-80% | -32% to -42% |

### E2E Test Contribution

E2E tests with real services should improve MCP service coverage from **26.56% to 60-70%**:

**Why E2E Improves Coverage**:
- Unit tests mock external dependencies (database, APIs)
- E2E tests use real PostgreSQL, Redis, LLM providers
- Real service integration covers actual code paths
- No mocking = actual code execution = better coverage

**Validation**:
```bash

# Run E2E tests with coverage

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v \

  --cov=integrations/mcp_service \

  --cov-report=term-missing



# Check MCP service coverage

# Target: 60-70% (vs 26.56% baseline)

```

## Troubleshooting

### Docker Issues

**Issue**: Docker services not starting
```bash

# Check Docker is running

docker ps



# Restart Docker Desktop (macOS/Windows)

# Or restart Docker daemon (Linux)

sudo systemctl restart docker



# Re-create services

docker-compose -f docker-compose-e2e.yml down

docker-compose -f docker-compose-e2e.yml up -d

```

**Issue**: PostgreSQL connection refused
```bash

# Check PostgreSQL is running

docker ps | grep postgres



# Check PostgreSQL logs

docker-compose -f docker-compose-e2e.yml logs postgres



# Verify connection

psql -h localhost -p 5433 -U atom -d atom_e2e

```

**Issue**: Redis connection refused
```bash

# Check Redis is running

docker ps | grep redis



# Check Redis logs

docker-compose -f docker-compose-e2e.yml logs redis



# Verify connection

redis-cli -p 6380 ping

```

### Database Issues

**Issue**: "Database is locked" (SQLite)
```bash

# Remove stale database files

rm -f atom_e2e.db atom_e2e.db-wal atom_e2e.db-shm



# Re-run tests

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v

```

**Issue**: Migration failures
```bash

# Reset database

docker-compose -f docker-compose-e2e.yml down

docker volume rm atom_postgres_data

docker-compose -f docker-compose-e2e.yml up -d



# Run migrations manually

cd backend

alembic upgrade head

```

### API Key Issues

**Issue**: "API key required" (LLM tests)
```bash

# Option 1: Set API keys

export OPENAI_API_KEY="sk-..."

export ANTHROPIC_API_KEY="sk-ant-..."



# Option 2: Skip LLM tests

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v -k "not llm"

```

### Test Timeout Issues

**Issue**: Tests exceed timeout
```bash

# Increase timeout

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v --timeout=900



# Run tests individually

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/test_critical_workflows_e2e.py -v -s



# Run slow tests last

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v -m "not slow"

```

### Import Errors

**Issue**: "No module named 'core'"
```bash

# Set PYTHONPATH

export PYTHONPATH=/Users/rushiparikh/projects/atom/backend



# Or use inline

PYTHONPATH=/Users/rushiparikh/projects/atom/backend pytest backend/tests/e2e/ -v

```

**Issue**: "No module named 'pytest'"
```bash

# Install pytest

cd /Users/rushiparikh/projects/atom/backend

pip install pytest pytest-timeout pytest-cov

```

## Best Practices

### Writing E2E Tests

1. **Test Complete Workflows**: Don't test individual functions - test user journeys
2. **Use Real Services**: PostgreSQL, Redis, Docker (not mocks)
3. **Validate Audit Trails**: Check database records, logs, metrics
4. **Test Failure Scenarios**: Not just happy path - error handling too
5. **Assert Performance**: Use `workflow_performance_thresholds` fixture
6. **Clean Up Test Data**: Use fixtures with proper teardown

### Example E2E Test

```python

def test_complete_user_workflow(composite_workflow):

    """Test complete workflow from user request to result."""

    agent = composite_workflow["agent"]

    canvas = composite_workflow["canvas"]



    # Step 1: Execute agent

    execution = AgentExecution(

        agent_id=agent["agent"].id,

        user_id=canvas["user_id"],

        task="Generate insights",

        status="in_progress"

    )

    agent["session"].add(execution)

    agent["session"].commit()



    # Step 2: Complete execution

    execution.status = "completed"

    execution.output_data = {"insights": ["insight1", "insight2"]}

    agent["session"].commit()



    # Step 3: Create canvas

    audit = CanvasAudit(

        canvas_id=canvas["canvas_id"],

        user_id=canvas["user_id"],

        action="present",

        canvas_data=execution.output_data

    )

    canvas["session"].add(audit)

    canvas["session"].commit()



    # Step 4: Verify workflow complete

    assert execution.status == "completed"

    assert audit.action == "present"

```

## Contributing

When adding new E2E tests:

1. **Create Test File**: `tests/e2e/test_new_feature_e2e.py`
2. **Use E2E Fixtures**: Leverage existing fixtures from `fixtures/`
3. **Test Real Services**: Use PostgreSQL, Redis, Docker (not mocks)
4. **Validate Workflows**: Test complete user journeys
5. **Add Performance Assertions**: Use `workflow_performance_thresholds`
6. **Update README**: Document new tests in this file
7. **Update conftest.py**: Add new fixtures if needed
8. **Verify Coverage**: Run with `--cov` to check coverage contribution

## Resources

### Documentation
- **Main Documentation**: `/Users/rushiparikh/projects/atom/CLAUDE.md`
- **API Documentation**: `/Users/rushiparikh/projects/atom/backend/docs/API_DOCUMENTATION.md`
- **Deployment Guide**: `/Users/rushiparikh/projects/atom/docs/DEPLOYMENT/DEPLOYMENT_RUNBOOK.md`
- **Operations Guide**: `/Users/rushiparikh/projects/atom/backend/docs/OPERATIONS_GUIDE.md`

### Source Code
- **Core Services**: `/Users/rushiparikh/projects/atom/backend/core/`
- **API Routes**: `/Users/rushiparikh/projects/atom/backend/api/`
- **Integrations**: `/Users/rushiparikh/projects/atom/backend/integrations/`
- **Tools**: `/Users/rushiparikh/projects/atom/backend/tools/`

### Test Infrastructure
- **E2E Fixtures**: `/Users/rushiparikh/projects/atom/backend/tests/e2e/fixtures/`
- **Unit Tests**: `/Users/rushiparikh/projects/atom/backend/tests/unit/`
- **Integration Tests**: `/Users/rushiparikh/projects/atom/backend/tests/integration/`

## Support

For issues or questions about E2E testing:
1. Check test docstrings for details
2. Review fixture definitions in `tests/e2e/fixtures/`
3. Inspect service implementations in `core/`
4. Check API route implementations in `api/`
5. Review CI/CD logs for environment-specific issues
6. Check Docker logs: `docker-compose -f docker-compose-e2e.yml logs`

---

**Last Updated**: 2025-02-20
**E2E Test Count**: 217+ tests across 14 test files
**Coverage Target**: 60-70% for MCP service (vs 26.56% baseline)
**Performance Target**: <10 minutes for full suite execution