技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
managing-test-environments【数据与研究】Test provision and manage isolated test environments with configuration and data. Use when performing specialized testing. Trigger with phrases like "manage test environment", "provision test env", or "setup test infrastructure".
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: managing-test-environments description: 'Test provision and manage isolated test environments with configuration and data.
Use when performing specialized testing.
Trigger with phrases like "manage test environment", "provision test env", or "setup test infrastructure".
' allowed-tools: Read, Write, Edit, Grep, Glob, Bash(test:env-*) version: 1.25.0 author: Jeremy Longshore jeremy@intentsolutions.io license: MIT tags:
Provision, configure, and manage isolated test environments for reliable test execution. Supports Docker Compose environments, Testcontainers, local service stacks, and ephemeral CI environments.
.env files or secrets managerdocker-compose.yml, .env.test, jest.config.*, pytest.ini) to understand current environment setup.docker-compose.test.yml defining isolated service containers:
.env.test) with connection strings, API keys, and feature flags appropriate for testing.docker-compose.test.yml with all required service definitions.env.test with test-specific configuration valuesseeds/test-data.sql or equivalent)scripts/test-env.sh)| Error | Cause | Solution |
|---|---|---|
| Port already in use | Another process or dev environment occupies the port | Use dynamic port allocation or specify alternate ports in docker-compose.test.yml |
| Container health check timeout | Service takes too long to initialize | Increase health check interval and retries; ensure sufficient memory allocation |
| Database seed failure | Migration conflicts or missing schema | Run migrations before seeds; verify migration order; check for schema drift |
| Environment variable not found | .env.test not loaded or variable misspelled | Verify dotenv loading order; use env-cmd or dotenv-cli to inject variables |
| Stale Docker volumes | Previous test data persists across runs | Add --volumes flag to docker-compose down in teardown; use tmpfs mounts |
Docker Compose test environment with PostgreSQL and Redis:
# docker-compose.test.yml
services:
postgres-test:
image: postgres:16-alpine
environment:
POSTGRES_DB: testdb
POSTGRES_PASSWORD: testpass
ports: ["5433:5432"] # 5432: 5433: PostgreSQL port
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 2s
retries: 10
redis-test:
image: redis:7-alpine
ports: ["6380:6379"] # 6379: 6380: Redis TLS port
healthcheck:
test: ["CMD", "redis-cli", "ping"]
Testcontainers setup in Jest:
import { PostgreSqlContainer } from '@testcontainers/postgresql';
let container;
beforeAll(async () => {
container = await new PostgreSqlContainer().start();
process.env.DATABASE_URL = container.getConnectionUri();
}, 30000); # 30000: 30 seconds in ms
afterAll(async () => { await container.stop(); });