cmk:testcontainers
/cmk:testcontainers
Use when the user asks to "use testcontainers for tests", "start a database container in tests", "testcontainers-rs", "container startup is flaky in CI", or needs to start and share a throwaway service container (Postgres, Redis, MinIO, or similar) from Rust test code via the `testcontainers` crate.
- Author
- commandosslabs ↗
- Repository
- ai-devkit ↗
- Licence
- MIT
- Last repository change
- 20.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 20.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when the user asks to "use testcontainers for tests", "start a database container in tests", "testcontainers-rs", "container startup is flaky in CI", or needs to start and share a throwaway service container (Postgres, Redis, MinIO, or similar) from Rust test code via the `testcontainers` crate.
Triggers from the description
Original author description
Use when the user asks to "use testcontainers for tests", "start a database container in tests", "testcontainers-rs", "container startup is flaky in CI", or needs to start and share a throwaway service container (Postgres, Redis, MinIO, or similar) from Rust test code via the `testcontainers` crate.
How it works
- Modes
- Retry and back off around container startup
- Keep the container guard alive as long as anything uses it
- Read back host and port; never assume a fixed one
- Two shapes, same as cmk:test-resources — testcontainers is only one branch
- CI needs a container runtime available, stated up front
- Verify
SKILL.md preview
---
name: cmk:testcontainers
description: Use when the user asks to "use testcontainers for tests", "start a database container in tests", "testcontainers-rs", "container startup is flaky in CI", or needs to start and share a throwaway service container (Postgres, Redis, MinIO, or similar) from Rust test code via the `testcontainers` crate.
version: 0.1.1
---
# Testcontainers (Rust)
Mechanics for starting and sharing a throwaway service container from Rust test code via the `testcontainers` crate (with `testcontainers-modules` for common services), wired into the sharing shapes `cmk:test-resources` defines and the test-runner wiring `cmk:rust` sets up. This skill is the Rust-crate-specific layer under both — it assumes their principles and adds nothing generic of its own.
## Modes
**Init** (default) — wire a new container-backed test resource: retry/backoff, guard lifetime, host/port readback, and which of `cmk:test-resources`' two shapes applies.
**Update** — add a service module, or migrate an existing container-starting helper onto the retry/backoff idiom.
**Verify** — report-only audit against the checks under `## Verify`; never mutates.
## Retry and back off around container startup
Docker image pulls and container startup are the flakiest part of a test run — a bare `.start()` call with no retry turns a transient pull hiccup into a spurious test failure. Wrap it in a bounded retry with a per-attempt timeout and backoff, and fail loud once attempts are exhausted rather than returning a value that looks like success:
```rust
async fn start_postgres() -> ContainerAsync<Postgres> {
const ATTEMPTS: u32 = 3;
const PER_ATTEMPT: Duration = Duration::from_secs(90);
for attempt in 1..=ATTEMPTS {
match tokio::time::timeout(PER_ATTEMPT, Postgres::default().start()).await {
Ok(Ok(container)) => return container,
Ok(Err(_)) | Err(_) if attempt < ATTEMPTS => {
tokio::time::sleep(Duration::from_secs(2 * u64::from(attempt))).await;
}
Ok(Err(_)) | Err(_) => panic!("start Postgres testcontainer after {ATTEMPTS} attempts"),
}
}
unreachable!()
}
```
## Keep the container guard alive as long as anything uses it
`ContainerAsync` owns the container's lifetime through `Drop` — the container stops the moment its last handle drops. Bundle it inside whatever shared struct carries the connection info, not alongside it as a separate value someone could drop early:
```rust
struct SharedPostgres {
_container: ContainerAsync<Postgres>, // never read directly — its Drop is the point
base_url: String,
}
```
In the lock-across-startup singleton shape (`cmk:test-resources`), the `Arc<SharedPostgres>` — not the bare container — is what every caller holds; the container only stops once every caller has dropped its `Arc`.
## Read back host and port; never assume a fixed one
The runner maps each exposed container port to an ephemeral host port, which differs across runs and across containers running concurrently:
```rust
let host = container.get_host().await.expect("read container host");
let port = container.get_host_port_ipv4(5432).await.expect("read mapped port");
let base_url = format!("postgres://postgres:postgres@{host}:{port}");
```
## Two shapes, same as `cmk:test-resources` — testcontainers is only one branch
Testcontainers implements `cmk:test-resources`' "same process" shape (start once, share via a lock-across-startup singleton) and *replaces itself entirely* for the "same external resource" shape — when a genuinely shared server exists (CI providing one Postgres for the whole job), that path connects to it directly instead of starting a container, selected by the two-flag override guard that skill describes. The two branches are alternatives, not layers: a test process either starts its own throwaway container or connects to the shared external one, never both.
## CI needs a container runtime available, stated up front
A container-backed test suite requires Docker (or an equivalent OCI runtime) on whatever runs it. State that requirement in the CI job definition itself — a runner image without it fails every container-backed test with an opaque connection error, which reads as a flaky suite rather than a missing prerequisite.
## Verify
Report-only — never mutate:
- Every container start is wrapped in a bounded retry with backoff, not a bare, unretried `.start()` call.
- The container guard's lifetime is bundled inside whatever struct carries its connection info, never held or dropped separately.
- Host and mapped port are read back after start, never hardcoded or assumed fixed.
- Exactly one of `cmk:test-resources`' two shapes applies per test path — a test never both starts its own container and connects to a shared external one.
- The CI job definition states its container-runtime prerequisite explicitly, not left to be discovered as a first-run failure.
Versions
The database has no other skills named cmk:testcontainers.
Database snapshot: 13.11.2026 · package version 76611e9c7da7 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 2 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100testcontainers-python
testcontainers-python specialist. Covers all container modules (PostgreSQL, MySQL, MongoDB, Redis, Kafka, RabbitMQ, MinIO, Elasticsearch, LocalStack), GenericContainer, wait strategies, Docker Compose, networks, pytest fixtures, and CI/CD integration. USE WHEN: user mentions… - 100testcontainers
When the user wants to use Docker-backed real infrastructure (Postgres, Kafka, Redis, Mongo, S3, etc.) inside tests via the Testcontainers libraries. Use when the user mentions "Testcontainers," "@Testcontainers," "@Container," "PostgreSQLContainer," "GenericContainer,"… - 100integration-test-setup
Set up integration tests for an ASP.NET Core app using WebApplicationFactory and Testcontainers. Use this skill whenever the user wants integration tests, end-to-end API tests, tests that hit a real database, WebApplicationFactory setup, Testcontainers, test fixtures with a real… - 100testcontainers-integration-testing-configuration
Guides configuring Testcontainers to spin up real dependency containers (Postgres, Kafka, Redis, and similar) for integration tests instead of mocks or hand-maintained shared test environments — container lifecycle management (per-test vs. shared/singleton containers), wait… - 90cmk:rust
Use when the user asks to "set up error handling", "add a feature flag", "structure this crate", "what's our clippy/lint policy", "why is this test flaky under nextest", "add dependency hygiene checks", or needs to apply idiomatic Rust practices — error types, module boundaries,… - 100configure-backend-tests
Use when a backend service needs a test setup or its tests mock the database. Builds the pyramid - pure unit tests, real-Postgres integration via testcontainers, HTTP-level tests, OpenAPI contract tests, factories and CI-ready layout (Vitest, go test, pytest).