# /sdd:story-test-integration Execute comprehensive integration and end-to-end tests for story validation. --- ## Meta **Category**: Testing & Validation **Format**: Imperative (Comprehensive) **Execution Time**: 3-8 minutes **Prerequisites**: Active story in `/docs/stories/development/` or `/docs/stories/review/` **Destructive**: No (read-only with test execution) **Related Commands**: - `/sdd:story-quick-check` - Fast validation before integration tests - `/sdd:story-full-check` - Comprehensive validation suite (includes this + more) - `/sdd:story-validate` - Final story validation (runs after this) **Context Requirements**: - `/docs/project-context/technical-stack.md` (testing tools, frameworks, database) - `/docs/project-context/coding-standards.md` (test patterns, coverage requirements) - `/docs/project-context/development-process.md` (integration testing criteria) --- ## Parameters **Story Parameters**: ```bash # Auto-detect from current active story or specify: --story-id=STORY-XXX-NNN # Specific story ID --scope=api|db|e2e|all # Test scope (default: all) --performance # Include performance profiling ``` **Test Configuration**: ```bash --browser=chrome|firefox|safari # Browser for e2e tests (default: chrome) --parallel=N # Parallel test execution (default: 4) --coverage # Generate coverage report --verbose # Detailed test output ``` --- ## Process ### Phase 1: Test Scope Discovery (30s) **Load Context**: ```bash # Verify project context exists if ! [ -d /docs/project-context/ ]; then echo "⚠️ Missing /docs/project-context/ - run /sdd:project-init first" exit 1 fi # Load testing requirements source /docs/project-context/technical-stack.md # Testing tools source /docs/project-context/coding-standards.md # Test patterns source /docs/project-context/development-process.md # Integration criteria ``` **Identify Test Scope**: 1. Read active story acceptance criteria 2. Extract integration points (API, database, external services) 3. Identify dependent services and components 4. Determine required test types (API, DB, E2E, performance) **Output**: ``` 🎯 INTEGRATION TEST SCOPE ======================== Story: STORY-XXX-NNN - [Title] Integration Points: βœ“ API: POST /api/tasks, GET /api/tasks/{id} βœ“ Database: tasks, categories, task_category pivot βœ“ Livewire: TaskManager component βœ“ Browser: Task creation workflow Test Types: API, Database, E2E, Performance Estimated Duration: ~5 minutes ``` --- ### Phase 2: API Integration Tests (1-2 min) **Execute API Tests**: ```bash # Laravel/Pest example php artisan test --filter=Api --coverage # Check: βœ“ Endpoint functionality (CRUD operations) βœ“ Request/response formats (JSON, validation) βœ“ Authentication/authorization (gates, policies) βœ“ Error responses (422, 404, 403, 500) βœ“ Rate limiting (if configured) ``` **Output**: ``` πŸ”— API INTEGRATION TESTS ======================= βœ… POST /api/tasks creates task (24ms) βœ… GET /api/tasks returns all tasks (18ms) βœ… PUT /api/tasks/{id} updates task (22ms) βœ… DELETE /api/tasks/{id} removes task (19ms) ❌ POST /api/tasks validates input (FAILED) Expected 422, got 500 Error: Column 'order' cannot be null Passed: 4/5 (80%) Failed: 1 Duration: 0.8s ``` --- ### Phase 3: Database Integration Tests (1-2 min) **Execute Database Tests**: ```bash # Test database operations php artisan test --filter=Database # Check: βœ“ CRUD operations (create, read, update, delete) βœ“ Transactions (rollback, commit) βœ“ Data integrity (constraints, foreign keys) βœ“ Migrations (up, down, fresh) βœ“ Relationships (eager loading, N+1 prevention) ``` **Output**: ``` πŸ’Ύ DATABASE INTEGRATION ====================== βœ… Task model creates records (12ms) βœ… Categories relationship loads (8ms) βœ… Soft deletes work correctly (10ms) βœ… Order column maintains sequence (15ms) βœ… Transaction rollback on error (18ms) Passed: 5/5 (100%) Duration: 0.6s Query Performance: Average: 8ms Slowest: Task::with('categories') - 15ms ``` --- ### Phase 4: End-to-End Tests (2-4 min) **Execute Browser Tests**: ```bash # Pest v4 Browser Testing php artisan test --filter=Browser --browser=chrome # Test workflows: βœ“ Complete user workflows (login β†’ create β†’ edit β†’ delete) βœ“ Multi-step processes (task creation with categories) βœ“ Cross-feature interactions (filtering + sorting) βœ“ Data flow validation (form β†’ server β†’ database β†’ UI) ``` **Output**: ``` 🌐 END-TO-END TESTS (Chrome) =========================== βœ… User can create task with category (2.4s) βœ… Task displays in correct order (1.8s) βœ… Drag-and-drop reorders tasks (3.1s) ❌ Mobile touch gestures work (FAILED) Element not found: [wire:sortable] Screenshot: /tmp/mobile-touch-fail.png Passed: 3/4 (75%) Failed: 1 Duration: 8.2s Console Errors: None Network Errors: None ``` --- ### Phase 5: Performance Testing (1-2 min, optional) **Execute Performance Tests** (if `--performance` flag): ```bash # Load testing ab -n 100 -c 10 https://ccs-todo.test/api/tasks # Check: βœ“ API response times (< 200ms p95) βœ“ Database query performance (< 50ms avg) βœ“ Memory usage (< 128MB) βœ“ Stress test critical paths (100 concurrent users) ``` **Output**: ``` ⚑ PERFORMANCE PROFILING ======================= API Endpoints: GET /api/tasks avg: 45ms p95: 120ms βœ“ POST /api/tasks avg: 68ms p95: 180ms βœ“ PUT /api/tasks/{id} avg: 52ms p95: 150ms βœ“ Database Queries: Average: 12ms Slowest: Task::with('categories', 'tags') - 48ms Memory Usage: 64MB (peak: 82MB) βœ“ Bottlenecks: None detected ``` --- ### Phase 6: Test Report Generation (10s) **Generate Comprehensive Report**: ``` πŸ“Š INTEGRATION TEST RESULTS =========================== Story: STORY-XXX-NNN - [Title] Executed: 2025-10-01 14:32:15 Duration: 5m 12s OVERALL: 🟑 PASSING WITH WARNINGS β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Test Suite β”‚ Passed β”‚ Failed β”‚ Skipped β”‚ Coverage β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ API Integration β”‚ 4 β”‚ 1 β”‚ 0 β”‚ 92% β”‚ β”‚ Database Integrationβ”‚ 5 β”‚ 0 β”‚ 0 β”‚ 88% β”‚ β”‚ E2E Browser β”‚ 3 β”‚ 1 β”‚ 0 β”‚ 76% β”‚ β”‚ Performance β”‚ N/A β”‚ N/A β”‚ N/A β”‚ N/A β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ TOTAL β”‚ 12 β”‚ 2 β”‚ 0 β”‚ 85% β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ❌ FAILED TESTS (2): 1. POST /api/tasks validates input Error: Column 'order' cannot be null Fix: Add default value to 'order' column in migration 2. Mobile touch gestures work Error: Element not found: [wire:sortable] Fix: Ensure SortableJS loads on mobile viewport Screenshot: /tmp/mobile-touch-fail.png ⚠️ WARNINGS (1): - Slowest query: Task::with('categories', 'tags') - 48ms Consider adding indexes or reducing eager loading βœ… HIGHLIGHTS: βœ“ All database operations working correctly βœ“ API authentication/authorization passing βœ“ Desktop E2E workflows functional βœ“ Performance within acceptable ranges πŸ“ˆ COVERAGE: 85% (target: 80%+) Lines: 342/402 Branches: 28/35 Functions: 45/48 🎯 NEXT STEPS: 1. Fix: Add default order value in migration 2. Fix: Debug mobile touch gesture handling 3. Re-run: php artisan test --filter="failed" 4. Then run: /sdd:story-validate ``` --- ### Phase 7: Failure Handling & Auto-Fix (if failures) **Interactive Failure Resolution**: ``` ❌ 2 TEST FAILURES DETECTED Would you like me to: [1] Show detailed error logs [2] Suggest fixes for each failure [3] Implement fixes automatically [4] Re-run failed tests only [5] Exit (fix manually) Choose option [1-5]: ``` **If Option 2 (Suggest Fixes)**: ``` πŸ”§ SUGGESTED FIXES ================== Failure 1: POST /api/tasks validates input Problem: Column 'order' has no default value Location: database/migrations/xxx_create_tasks_table.php Fix: $table->integer('order')->default(0); Confidence: HIGH (common pattern) Failure 2: Mobile touch gestures Problem: SortableJS not loading on mobile Location: resources/js/app.js Fix: Check Alpine.js device detection: if (window.isDevice('mobile') || window.isDevice('tablet')) { loadSortable(); } Confidence: MEDIUM (requires investigation) Apply fixes? [y/n]: ``` **If Option 3 (Auto-fix)**: - Apply suggested fixes - Run Pint formatting - Re-run failed tests - Show updated results --- ### Phase 8: Story Update (10s) **Update Story Documentation**: ```bash # Append to story's progress log echo "$(date): Integration tests executed" >> /docs/stories/development/STORY-XXX-NNN.md # Add test results section cat >> /docs/stories/development/STORY-XXX-NNN.md <