Fixed Docker e2e testing failure issue

This commit is contained in:
Prashant Shendre 2026-10-17 10:54:38 +05:30
parent d8324a22ae
commit 739ed361ea
10 changed files with 73 additions and 7 deletions

View File

@ -73,6 +73,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-INFO}
ports:
- "127.0.0.1:8000:8000"
command: ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--log-level", "info"]
depends_on:
postgres:
condition: service_healthy

View File

@ -66,5 +66,5 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://127.0.0.1:8000/health || exit 1
# Default command starts Uvicorn production server
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--log-level", "info"]
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--log-level", "info"]

View File

@ -104,6 +104,27 @@ TEST_PERSONAS: Dict[str, Dict[str, Any]] = {
"roles": ["Tenant Administrator"],
"tenant_id": "tenant-beta"
},
"admin@alpha-agri.com": {
"sub": "usr_admin_alpha",
"email": "admin@alpha-agri.com",
"name": "Alpha Live Admin",
"roles": ["Tenant Administrator"],
"tenant_id": "tenant-alpha"
},
"buyer@alpha-agri.com": {
"sub": "usr_buyer_alpha",
"email": "buyer@alpha-agri.com",
"name": "Alpha Live Buyer",
"roles": ["Mandi Buyer"],
"tenant_id": "tenant-alpha"
},
"admin@beta-commodities.com": {
"sub": "usr_admin_beta",
"email": "admin@beta-commodities.com",
"name": "Beta Live Admin",
"roles": ["Tenant Administrator"],
"tenant_id": "tenant-beta"
},
"multi@trader.com": {
"sub": "usr_01J8K92MLT001",
"email": "multi@trader.com",
@ -248,6 +269,9 @@ TEST_MEMBERSHIPS: List[Dict[str, Any]] = [
{"membership_id": "mem_005", "tenant_id": "tenant-alpha", "user_id": "usr_01J8K92MLT001", "email": "multi@trader.com", "role": "Mandi Buyer", "status": "ACTIVE"},
{"membership_id": "mem_006", "tenant_id": "tenant-beta", "user_id": "usr_01J8K92MLT001", "email": "multi@trader.com", "role": "Partner / MD", "status": "ACTIVE"},
{"membership_id": "mem_007", "tenant_id": "tenant-gamma", "user_id": "usr_01J8K92GAM001", "email": "user@gamma.com", "role": "Mandi Buyer", "status": "ACTIVE"},
{"membership_id": "mem_live_admin_alpha", "tenant_id": "tenant-alpha", "user_id": "usr_admin_alpha", "email": "admin@alpha-agri.com", "role": "Tenant Administrator", "status": "ACTIVE"},
{"membership_id": "mem_live_buyer_alpha", "tenant_id": "tenant-alpha", "user_id": "usr_buyer_alpha", "email": "buyer@alpha-agri.com", "role": "Mandi Buyer", "status": "ACTIVE"},
{"membership_id": "mem_live_admin_beta", "tenant_id": "tenant-beta", "user_id": "usr_admin_beta", "email": "admin@beta-commodities.com", "role": "Tenant Administrator", "status": "ACTIVE"},
{"membership_id": "mem_demo_001", "tenant_id": "demo-malwa-agri", "user_id": "buyer@malwa-agri.demo", "email": "buyer@malwa-agri.demo", "role": "Mandi Buyer", "status": "ACTIVE"},
{"membership_id": "mem_demo_002", "tenant_id": "demo-malwa-agri", "user_id": "pmgr@malwa-agri.demo", "email": "pmgr@malwa-agri.demo", "role": "Purchase Manager", "status": "ACTIVE"},
{"membership_id": "mem_demo_003", "tenant_id": "demo-malwa-agri", "user_id": "yard@malwa-agri.demo", "email": "yard@malwa-agri.demo", "role": "Yard Supervisor", "status": "ACTIVE"},

View File

@ -17,6 +17,7 @@ Executes real HTTP requests against the live running FastAPI container (port 800
"""
from datetime import datetime, date, timezone
from decimal import Decimal
import os
import json
import time
import unittest
@ -28,7 +29,7 @@ from typing import Any, Dict, Optional, Tuple
from sandbox.identity_mock import mock_idp
BASE_URL = "http://127.0.0.1:8000"
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")
def make_request(

View File

@ -17,12 +17,13 @@ import unittest
import urllib.request
import urllib.error
import uuid
import os
from typing import Any, Dict, Optional, Tuple
from sandbox.identity_mock import mock_idp
BASE_URL = "http://127.0.0.1:8000"
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")
def make_request(

View File

@ -17,6 +17,7 @@ verifying the complete financial lifecycle:
"""
from datetime import datetime, date, timezone
from decimal import Decimal
import os
import json
import unittest
import urllib.request
@ -27,7 +28,7 @@ from typing import Any, Dict, Optional, Tuple
from sandbox.identity_mock import mock_idp
BASE_URL = "http://127.0.0.1:8000"
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")
def make_request(

View File

@ -12,6 +12,7 @@ verifying the complete physical grain procurement and inventory minting lifecycl
from datetime import datetime, date, timedelta, timezone
import json
import unittest
import os
import urllib.request
import urllib.error
import uuid
@ -20,7 +21,7 @@ from typing import Any, Dict, Optional, Tuple
from sandbox.identity_mock import mock_idp
BASE_URL = "http://127.0.0.1:8000"
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")
def make_request(

View File

@ -17,6 +17,7 @@ Executes real HTTP requests against the live running FastAPI container (port 800
from datetime import datetime, timezone, timedelta
import json
import time
import os
import unittest
import urllib.request
import urllib.error
@ -26,7 +27,7 @@ from typing import Any, Dict, Optional, Tuple
from sandbox.identity_mock import mock_idp
BASE_URL = "http://127.0.0.1:8000"
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")
def make_request(

View File

@ -12,6 +12,7 @@ verifying the complete stock-to-dispatch, credit exposure, and destination short
from datetime import datetime, date, timezone
from decimal import Decimal
import json
import os
import unittest
import urllib.request
import urllib.error
@ -21,7 +22,7 @@ from typing import Any, Dict, Optional, Tuple
from sandbox.identity_mock import mock_idp
BASE_URL = "http://127.0.0.1:8000"
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")
def make_request(

View File

@ -368,3 +368,38 @@ Resume from `CKPT-035`. First let's start with step 4 (Process & Quality Gate Ha
- Gate 9.1: PASSED (0 Critical, 0 Major, 0 Minor).
- Gate 14.1: PASSED (0 Critical, 0 Major, 0 Minor across all iterations 01–07).
- Authored Checkpoint `CKPT-036` (`checkpoint-036-production-frontend-expansion-and-gate-hardening.md`) and updated `checkpoint_index.md`.
## Turn 11: 2026-10-17T05:25:00Z — GitHub Actions CI Live E2E Integration Test Fix (test_06, test_07, test_08)
### User Request
> In the @[.github/workflows/ci.yml], when running on github, on step 3 - "Migrations & Live Continer E2E", we get the following err :
> FAIL: test_06_bruno_list_tenant_members (AssertionError: 403 != 200)
> FAIL: test_07_bruno_switch_active_tenant (AssertionError: 403 != 200)
> FAIL: test_08_bruno_get_audit_events (AssertionError: 403 != 200)
### Key Decisions & Actions Summary
1. **Root Cause Analysis:**
- Commit `05ea1de` introduced `_seed_fixtures()` into `InMemoryTenantStorage.__init__()` in `project_code/backend/app/db/session.py` to auto-seed baseline tenants (`tenant-alpha`, `tenant-beta`) from `sandbox/identity_mock.py`.
- In `project_code/tests/e2e/test_live_api_endpoints.py`, `setUpClass` minted test JWTs using custom identities:
- `admin_alpha_token`: `subject="usr_admin_alpha"`, `email="admin@alpha-agri.com"`
- `admin_beta_token`: `subject="usr_admin_beta"`, `email="admin@beta-commodities.com"`
- `buyer_alpha_token`: `subject="usr_buyer_alpha"`, `email="buyer@alpha-agri.com"`
- In `test_06_bruno_list_tenant_members`, a provisioning call `POST /api/v1/platform/tenants` with `tenant_id="tenant-alpha"` was made. Because `tenant-alpha` was already pre-seeded in storage, the controller returned `409 Conflict: DUPLICATE_TENANT` and aborted before creating the initial admin membership.
- Consequently, `usr_admin_alpha` / `admin@alpha-agri.com` was never added to `storage.memberships`.
- When `test_06` (`GET /api/v1/tenants/tenant-alpha/memberships`), `test_07` (`POST /api/v1/session/active-tenant`), and `test_08` (`GET /api/v1/audit/events`) executed with `admin_alpha_token`, `context_resolver.resolve_context()` failed to find an active server-side membership in `tenant-alpha`, raising `TenantContextResolutionError(403 Forbidden)`.
- Additionally, `Dockerfile.backend` defaulted to `--workers 4`. When running containerized tests with in-memory storage, round-robin dispatch across worker processes fragmented in-memory state.
2. **Multi-Layer Remediation:**
- **Layer 1 (`project_code/sandbox/identity_mock.py`):** Added live test identities (`admin@alpha-agri.com`, `buyer@alpha-agri.com`, `admin@beta-commodities.com`) to `TEST_PERSONAS` and `TEST_MEMBERSHIPS` with `ACTIVE` status and canonical PRD roles (`Tenant Administrator` and `Mandi Buyer`). Now `_seed_fixtures()` seeds these memberships unconditionally.
- **Layer 2 (`project_code/tests/e2e/*.py`):** Configured `BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:8000")` across all 6 live integration test files to allow flexible target configuration.
- **Layer 3 (`project_code/docker/Dockerfile.backend` & `compose.yaml`):** Set `--workers 1` as the default for development and container testing to maintain single-process memory consistency.
3. **Verification Outcomes:**
- **Live Container E2E Suite:** Executed `python3 -m unittest discover -s tests/e2e -p "test_*.py"` against live server: **17/17 tests passing (100% OK)** including all 3 previously failing tests (`test_06`, `test_07`, `test_08`).
- **Unit Suite & AST Statement Coverage:** Executed `./scripts/run_tests.sh --scope project`: **197/197 tests passing (100%)** with **98.2% statement coverage** (exceeding $\ge 95\%$ target).
- **UP-AI v1.5 Traceability Gates:** Executed `python3 scripts/verify_traceability_gates.py --all`:
- Gate 5.1: PASSED (0 Critical, 0 Major, 0 Minor).
- Gate 9.1: PASSED (0 Critical, 0 Major, 0 Minor).
- Gate 14.1: PASSED across all iterations 01–07 (0 Critical, 0 Major, 0 Minor).