REDCap Sandbox
REDCap Sandbox
Sandbox Docker et tests d’intégration pour valider REDCap avec Atlas.
Ce workspace fournit un environnement REDCap isolé, des scripts d’installation, des tests de contrat, des tests de sécurité et des smoke tests API. Il sert à confronter les spécifications OpenAPI et clients Atlas à une instance REDCap réelle ou locale.
Structure
redcap-sandbox/├── docker/ # Docker environment for REDCap│ ├── docker-compose.yml # Main compose file (MySQL, PHP, phpMyAdmin)│ ├── config/ # PHP and database configuration│ └── init.sql # Database initialization├── scripts/ # Automation scripts│ ├── install-crf.sh # Automated REDCap installation│ ├── test-contract.sh # Run contract tests│ └── test-security.sh # Run security/fuzzing tests├── tests/ # Integration tests│ ├── contract/ # Generic REDCap API contract tests (require Docker)│ ├── contract-amarre/ # Amarre-specific contract tests (run pnpm test:contract:amarre)│ ├── fixtures/ # Test data and setup scripts│ │ ├── redcap-admin.ts # API-only helpers : mint super-token, create project, import dictionary│ │ └── setup-test-projects.ts # Provisions tokens + amarre project via API│ └── api-smoke.ts # Quick API smoke tests├── docker-compose.yaml # Main compose file└── vitest.config.ts # Vitest configurationREDCap source code is located in the sibling package redcap-openapi/upstream/.
Purpose
The development environment serves three main purposes:
- Validation - Verify that extracted OpenAPI specs match actual REDCap behavior
- Contract Testing - Ensure API responses conform to documented schemas
- Security Testing - Fuzz testing with Schemathesis to find edge cases
Quick Start
1. Start Docker Environment
# From packages/redcap-sandbox directorypnpm docker:upThis starts:
- REDCap at http://localhost:8888
- phpMyAdmin at http://localhost:8889
- Mailpit at http://localhost:8025
2. Install REDCap Database
pnpm docker:installThis script:
- Submits the REDCap install form
- Extracts and executes the SQL schema
- Creates an API token for testing
- Saves config to
docker/config/.env.test
3. Run Tests
# Quick API smoke testpnpm test:api
# Full contract tests (26 tests)pnpm test:contract
# Security/fuzzing testspnpm test:securityDocker Services
| Service | URL | Credentials |
|---|---|---|
| REDCap | http://localhost:8888 | site_admin |
| phpMyAdmin | http://localhost:8889 | redcap / redcap_password |
| Mailpit | http://localhost:8025 | - |
| MariaDB | localhost:3306 | redcap / redcap_password |
Multi-Version Testing
The Docker environment supports multiple REDCap versions:
# Start with specific versionREDCAP_VERSION=14.6.0 pnpm docker:up
# Extract spec for that versionREDCAP_VERSION=14.6.0 pnpm extractVersions are stored in ../redcap-openapi/upstream/versions/<version>/.
Commands Reference
# Docker managementpnpm docker:up # Start servicespnpm docker:down # Stop servicespnpm docker:logs # View logspnpm docker:reset # Reset database (destroys data)pnpm docker:install # Automated installation
# Testingpnpm test:setup # Setup test fixtures + provision amarre project (API-only)pnpm test:api # Smoke tests (quick)pnpm test:contract # Contract tests (full — generic REDCap + amarre)pnpm test:contract:amarre # Contract tests scoped to the amarre project onlypnpm test:security # Security/fuzz testsAmarre contract tests
The tests/contract-amarre/ suite exercises the REDCap endpoints used by apps/amarre. It targets a dedicated amarre project provisioned by pnpm test:setup :
- Mint a super-API token for
site_adminvia the Control Center AJAX endpoint (auth=none gives super-user access by default on the sandbox). POST /api/?content=project&action=importwith the super-token to create a fresh project.POST /api/?content=metadata&action=importwith the project’s regular token to loaddata-dictionaries/127-amarre-v1.json.
No SQL is executed (this is a project policy — REDCap is touched exclusively through its HTTP API, web endpoints included). The helpers live in tests/fixtures/redcap-admin.ts and are idempotent across runs: a cached token in .env.test is reused if it still resolves to a project titled amarre.
Test Fixtures
The tests/fixtures/ directory contains:
projects.json- Test project configurationssetup-test-projects.ts- Script to create test projects via API
Test Projects
| Project | Type | Features |
|---|---|---|
| Classic Database | Classic | Basic data entry |
| Longitudinal (1 arm) | Longitudinal | 8 events |
| Basic Demography | Classic | Single form |
| Repeating Instruments | Classic | 4 repeating forms |
Contract Tests
The contract tests validate:
- Version endpoint returns valid version string
- Project info matches expected schema
- Metadata export returns field definitions
- Record export with filters works correctly
- Event endpoint handles longitudinal vs classic
- Error responses follow expected format
- Response formats (JSON, CSV, XML) work
Troubleshooting
Container not starting
# Check logspnpm docker:logs
# Reset and restartpnpm docker:resetAPI token not working
# Regenerate tokenpnpm docker:installTests failing
Ensure REDCap is running and initialized:
curl -X POST http://localhost:8888/api/ \ -d "token=$(cat sandbox/docker/config/.env.test | grep TOKEN | cut -d= -f2)" \ -d "content=version"