[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71Q3VW4NJD2BT6CV1S5W5V6":3,"skill-same:01M71Q3VW4NJD2BT6CV1S5W5V6":79},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":48,"commitSha":49,"skillDirectory":50,"forksCount":14,"repositoryHtmlUrl":51,"repositoryHomepageUrl":52,"ownerHtmlUrl":53,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":54,"install":55,"resources":68},"01M71Q3VW4NJD2BT6CV1S5W5V6","test-environments",null,"Design environment strategy for testing across dev, CI, preview, staging, and production — Docker Compose test infrastructure, multi-stage Dockerfiles, seed-data lifecycle, per-PR preview environments, production parity, and external-dependency stubbing at the HTTP boundary. Use when: \"set up test environment,\" \"docker-compose for tests,\" \"per-PR preview environment,\" \"staging parity,\" \"spin up test infra,\" \"environment tiers.\" Not for: choosing mock-vs-stub-vs-fake per dependency — use service-virtualization; factory and fixture data patterns — use test-data-management; pipeline\u002FActions config — use ci-cd-integration. Related: test-data-management, ci-cd-integration, contract-testing, service-virtualization.","pattanation\u002FNorvik","pattanation","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235419268?v=4","01M71M5THHYYB15ME8R2E4FCZG","Patta","01M71M5TJM1NDM992M8PDKYR2K",0,"MIT","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Ftest-environments\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"test","test environments","environments","config","virtualization","at","dependency","across","preview","when","seed-data","design","ci","up","testing","docker compose","actions","pipeline","fixture","SET","2026-11-10 13:02:02",false,"---\nname: test-environments\ndescription: >-\n  Design environment strategy for testing across dev, CI, preview, staging, and production —\n  Docker Compose test infrastructure, multi-stage Dockerfiles, seed-data lifecycle, per-PR\n  preview environments, production parity, and external-dependency stubbing at the HTTP boundary.\n  Use when: \"set up test environment,\" \"docker-compose for tests,\" \"per-PR preview environment,\"\n  \"staging parity,\" \"spin up test infra,\" \"environment tiers.\"\n  Not for: choosing mock-vs-stub-vs-fake per dependency — use service-virtualization; factory and\n  fixture data patterns — use test-data-management; pipeline\u002FActions config — use ci-cd-integration.\n  Related: test-data-management, ci-cd-integration, contract-testing, service-virtualization.\nlicense: MIT\nmetadata:\n  author: kindlmann\n  version: \"2.0\"\n  category: infrastructure\n---\n\n\u003Cobjective>\nStaging on SQLite passes tests that break on prod Postgres; a shared staging box becomes a\nqueue where one broken deploy blocks the whole team; an unmocked Stripe call flakes CI at\nrandom. This skill prevents those by designing environment tiers that mirror production where\nit matters, isolate per-PR, and stub external dependencies at the HTTP boundary. It delivers a\nworking `docker compose up` local\u002FCI stack, a parity checklist, and a stubbing strategy keyed\nto dependency type.\n\u003C\u002Fobjective>\n\n## Discovery Questions\n\nCheck `.agents\u002Fqa-project-context.md` first — if it exists, use it and skip anything already\nanswered there. Then:\n\n1. **How many environments exist today?** Local dev, CI, staging, preview, production? Map what you have before designing what you need.\n2. **Is the app containerized?** Check for `Dockerfile`, `docker-compose.yml`, or `compose.yaml`. If yes, multi-stage targets and compose come for free; if not, that is the first deliverable.\n3. **How is test data seeded?** Manual SQL, migration-based, factory libraries, or production snapshots? This decides whether seed scripts are a quick win or a rewrite.\n4. **How close is staging to production?** Same DB engine, queue, cache, auth provider, orchestration? Each mismatch is a class of bugs staging can never catch.\n5. **External dependencies:** How many third-party APIs does the system call, and are they stubbed in non-prod? Unstubbed third parties are the top source of CI flake.\n\n---\n\n## Core Principles\n\n**1. Staging must mirror production where bugs hide.** If staging uses SQLite and production\nuses PostgreSQL, staging tests prove nothing about prod behavior. Match the database engine\n*and version*, the queue system, the cache layer, and the auth provider — those are where\nenvironment-specific bugs live.\n\n**2. Ephemeral environments beat long-lived ones.** A shared staging environment becomes a\nbottleneck where one broken deploy blocks the entire team. Per-PR preview environments give\nisolation and parallel testing; keep staging only for final pre-release validation.\n\n**3. Deterministic seed data, not production copies.** Production snapshots carry PII, stale\nreferences, and non-reproducible state. Build seed data from factories that generate\nconsistent, valid, minimal datasets. (For factory patterns, see `test-data-management`.)\n\n**4. Stub external dependencies at the boundary, not deep inside.** Third-party APIs are\nunreliable, rate-limited, and expensive. Stub them at the HTTP boundary with MSW or WireMock —\nnever by mocking internal service classes, which hides integration bugs between your own code.\n\n**5. Environment config is code.** Every environment difference (URLs, flags, credentials,\nresource limits) must be version-controlled and reviewable. No manual setup that cannot be\nreproduced from the repo.\n\n---\n\n## Environment Strategy\n\n### Environment Tiers\n\n| Environment | Purpose | Data | External Deps | Lifecycle |\n|-------------|---------|------|---------------|-----------|\n| **Local dev** | Fast inner loop | Seeded fixtures, minimal | Stubbed (MSW\u002FWireMock) | Developer-managed |\n| **CI** | Automated validation | Seeded per-run, ephemeral | Stubbed or containerized | Created\u002Fdestroyed per pipeline |\n| **Preview** | PR-level review & E2E | Seeded from factories | Stubbed or sandbox | Created on PR, destroyed on close |\n| **Staging** | Pre-production validation | Anonymized production-like | Real integrations (sandbox accounts) | Long-lived, regularly reset |\n| **Production** | Live users | Real | Real | Permanent |\n\n### Local Development\n\nFast feedback, zero shared state. Developers must be able to run the full stack locally in\nunder two minutes:\n\n```bash\ndocker compose -f docker-compose.test.yml up -d\nnpm run db:seed\nnpm run dev\n```\n\nUse Docker Compose for infrastructure deps (database, cache, queue) but run the application\nnatively for fast reload. External APIs are stubbed with MSW handlers loaded in dev mode.\n\n### CI Environment\n\nFully containerized, created fresh per pipeline run, destroyed after. The block below is the\n**`services:` fragment** of a job — nest it under `jobs.\u003Cid>.services` alongside `runs-on`\nand `steps`; on its own it is not a valid workflow file.\n\n```yaml\n# .github\u002Fworkflows\u002Ftest.yml — fragment: nest under jobs.test.services\nservices:\n  postgres:\n    image: postgres:18-alpine\n    env:\n      POSTGRES_DB: testdb\n      POSTGRES_USER: test\n      POSTGRES_PASSWORD: test\n    ports: ['5432:5432']\n    options: >-\n      --health-cmd=\"pg_isready -U test\"\n      --health-interval=5s\n      --health-timeout=3s\n      --health-retries=5\n  redis:\n    image: redis:8-alpine\n    ports: ['6379:6379']\n    options: >-\n      --health-cmd=\"redis-cli ping\"\n      --health-interval=5s\n      --health-timeout=3s\n      --health-retries=5\n```\n\n### Docker Compose vs Testcontainers\n\nTwo ways to give tests real infrastructure. Pick by where the lifecycle should live:\n\n- **Docker Compose** — declarative stack you bring up before the suite (`docker compose up\n  --wait`) and tear down after, usually via a `trap`-guarded script. Best for local dev, a\n  shared CI stack, and E2E where many tests share one set of services.\n- **Testcontainers** (Node \u002F JVM \u002F Python \u002F Go) — containers spun up *from test code* and\n  auto-torn-down per suite or per test, with no compose file or `trap` to maintain. Best for\n  integration tests that need isolated, programmatic infra (a throwaway Postgres per test\n  class). The 2026 default for \"ephemeral infra owned by the test,\" and a strong alternative\n  to hand-rolled compose + trap scripts.\n\nReach for Compose when humans and many tests share the stack; reach for Testcontainers when\neach test (or suite) wants its own disposable copy.\n\n### Preview Environments (Per-PR)\n\nEach pull request gets its own isolated environment; reviewers click a link and test the exact\nchanges without interfering with other PRs.\n\nHosting options (2026), pick by stack:\n\n- **Vercel** preview deployments — Next.js \u002F static \u002F serverless; per-PR URL automatically.\n- **Cloudflare Pages** preview — git-integrated, generous free tier.\n- **Render** \u002F **Railway** preview environments — full-stack including databases.\n- **Northflank**, **Qovery**, **Bunnyshell**, **Uffizzi** — full ephemeral-environment\n  platforms (Kubernetes-backed) when previews need the whole stack, not just a frontend.\n\nFor each preview, pair the env lifecycle with a **database branch** (Neon, Supabase,\nPlanetScale-style): create a branch on PR open, drop it on close. That gives every preview a\ncheap, instant, isolated DB copy instead of a shared staging DB. (See `test-data-management`.)\n\nFor local-dev parity with CI:\n\n- **Devcontainers** (`.devcontainer\u002Fdevcontainer.json`) — VS Code, Codespaces, JetBrains. The\n  standard for \"everyone gets the same Docker-backed dev env.\"\n- **Tilt** (`Tiltfile`) — Kubernetes-first local dev with hot reload and multi-service\n  orchestration. Pick when staging itself is K8s.\n\nA frontend preview with E2E against the generated URL is a few lines:\n\n```yaml\n- name: Run E2E against preview\n  env:\n    BASE_URL: ${{ steps.deploy.outputs.preview-url }}\n  run: npx playwright test --project=chromium\n```\n\nA custom Docker preview keyed to a per-PR namespace, auto-torn-down on close:\n\n```yaml\n- name: Deploy preview\n  run: |\n    NAMESPACE=\"pr-${{ github.event.number }}\"\n    docker compose -f docker-compose.preview.yml -p \"$NAMESPACE\" up -d\n    echo \"preview-url=https:\u002F\u002F${NAMESPACE}.preview.example.com\" >> \"$GITHUB_OUTPUT\"\n\n- name: Teardown preview\n  if: github.event.action == 'closed'\n  run: |\n    NAMESPACE=\"pr-${{ github.event.number }}\"\n    docker compose -p \"$NAMESPACE\" down -v\n```\n\n### Staging\n\nLong-lived environment that mirrors production infrastructure. Reset weekly or on-demand to\nprevent drift:\n\n```bash\n#!\u002Fbin\u002Fbash\n# scripts\u002Freset-staging.sh\nset -euo pipefail\n\necho \"Resetting staging database...\"\npsql \"$STAGING_DATABASE_URL\" -c \"DROP SCHEMA public CASCADE; CREATE SCHEMA public;\"\n\necho \"Running migrations...\"   # migrations MUST recreate extensions + grants (see caveat below)\nnpm run db:migrate -- --env staging\n\necho \"Seeding anonymized data...\"\nnpm run db:seed -- --env staging --dataset production-anonymized\n\necho \"Verifying staging health...\"\ncurl -sf https:\u002F\u002Fstaging.example.com\u002Fhealth || exit 1\necho \"Staging reset complete.\"\n```\n\n**Caveat:** `DROP SCHEMA public CASCADE` also drops the schema's default privileges and any\ninstalled extensions (`uuid-ossp`, `pgcrypto`, …). Your migration pipeline must recreate them\n(`CREATE EXTENSION IF NOT EXISTS …`, re-grant defaults) or the migrate step fails. Don't assume\na bare `CREATE SCHEMA public` restores the prior grants — it does not.\n\n---\n\n## Docker Compose for Testing\n\nA production-quality `docker-compose.test.yml` spins up the full stack (app, Postgres, Redis,\na one-shot seed container, Mailpit) for integration and E2E tests. Two details that matter:\n\n- **Health checks gate `depends_on`.** Without a `healthcheck` + `condition: service_healthy`,\n  `depends_on` only waits for the container to *start*, not for the service to accept\n  connections — tests then race the database and fail with connection errors.\n- **Seed is a one-shot container, not a long-running service.** It uses `depends_on:\n  condition: service_completed_successfully`, so the app starts only after seeding *exits 0*.\n  Teams that model seed as a long-running service get a race where the app boots mid-seed.\n\nSee `references\u002Fdocker-compose.md` for the full `docker-compose.test.yml`, the\n`trap`-guarded integration test runner, the multi-stage Dockerfile (with the `production`\ntarget), and the MinIO block.\n\n### Multi-Stage Dockerfile\n\nOne `base` layer installs deps once; `development`, `test`, and `seed` stages reuse it; and a\nslim `production` stage runs prod deps only (`npm ci --omit=dev`) with build artifacts copied\nfrom the `test` stage. The split keeps test dependencies and source out of the shipped image\nwhile giving each environment its own entrypoint. Use `npm ci --include=dev` in `base` — the\nmodern flag; `--production=false` is legacy `--omit`\u002F`--include` syntax. Full Dockerfile in\n`references\u002Fdocker-compose.md`.\n\n---\n\n## External Dependency Management\n\n### Stubbing Strategy by Dependency Type\n\n| Dependency Type | Local\u002FCI Strategy | Staging Strategy |\n|----------------|-------------------|------------------|\n| Payment (Stripe) | MSW handler returning mock responses | Stripe test mode with `sk_test_` keys |\n| Email (SendGrid) | **Mailpit** capturing SMTP (web UI on :8025, SMTP on :1025) | SendGrid sandbox mode |\n| Auth (Auth0) | Local JWT issuer with test keys | Auth0 dev tenant |\n| Storage (S3) | MinIO container (S3-compatible) | Dedicated test bucket with lifecycle policy |\n| Search (Elasticsearch) | Testcontainers Elasticsearch | Dedicated test index with reset script |\n| SMS (Twilio) | MSW handler | Twilio test credentials |\n\n**Avoid: MailHog** — unmaintained, last release 2020. Use Mailpit (`axllent\u002Fmailpit`); it is a\ndrop-in on the same ports (1025 SMTP \u002F 8025 UI).\n\n### MSW for HTTP Stubs\n\nStub external APIs at the HTTP boundary with MSW 2.x: `http` + `HttpResponse` from `msw`,\n`setupServer` from `msw\u002Fnode`, lifecycle wired through `beforeAll`\u002F`afterEach`\u002F`afterAll`. Set\n`onUnhandledRequest: \"error\"` so an unmocked external call fails the test loudly instead of\nleaking a real network request. See `references\u002Fstubbing.md` for the Stripe\u002FSendGrid\u002Fgeocoding\nhandlers and the server lifecycle.\n\n### MinIO as an S3 Substitute\n\nRun S3-compatible storage in a container instead of hitting real AWS in local\u002FCI tests. Point\nthe AWS SDK `S3Client` at it with `endpoint`, env-var credentials, and `forcePathStyle: true`\n(required for MinIO). Compose service + client config in `references\u002Fdocker-compose.md`.\n\n### Contract Testing as Stub Validation\n\nStubs drift from reality. Pair every stub with a contract test that verifies the stub matches\nthe real API shape. For details, see `contract-testing`.\n\n---\n\n## Environment Parity Checklist\n\nRun this when setting up or auditing a non-production environment.\n\n| Dimension | Question | Red Flag |\n|-----------|----------|----------|\n| **Database engine** | Same engine and version as production? | SQLite in test, PostgreSQL in prod |\n| **Database schema** | Same migration pipeline applied? | Manual schema changes in staging |\n| **Data shape** | Seed data covers all entity states? | Only \"happy path\" records, no edge cases |\n| **Infrastructure** | Same container orchestration? | Docker Compose in CI, Kubernetes in prod |\n| **Network** | Same internal service topology? | Monolith in test, microservices in prod |\n| **Config** | Env vars documented and version-controlled? | Undocumented env vars, manual setup |\n| **Auth** | Same auth provider\u002Fflow? | Bypassed auth in test with hardcoded tokens |\n| **Feature flags** | Same flag evaluation engine? | Hardcoded flags in test, LaunchDarkly in prod |\n| **TLS\u002FHTTPS** | Same certificate handling? | HTTP in staging, HTTPS in prod |\n| **Timeouts\u002FLimits** | Same rate limits, pools, timeouts? | Infinite timeouts in test hide perf issues |\n\nFor factory-based seed data patterns, see `test-data-management`.\n\n---\n\n## Anti-Patterns\n\n**Shared staging as the only test environment.** One developer's broken deploy blocks everyone.\nUse ephemeral per-PR environments for isolation and keep staging for final pre-release\nvalidation only.\n\n**Production database copies for test data.** PII risk, non-reproducible state, massive\ndatasets that slow tests. Build minimal seed data from factories with deterministic values.\n\n**Environment-specific code paths.** `if (process.env.NODE_ENV === \"test\") { skipAuth(); }`\nmeans you are not testing the real auth flow. Swap implementations via dependency injection or\nconfig, not environment conditionals.\n\n**Manual environment setup.** If setup needs a 15-step wiki page, it will be wrong within a\nweek. Script everything: `docker compose up -d && npm run db:seed` should be the only steps.\n\n**Stubbing internal services instead of external ones.** Stub at the HTTP boundary where your\nsystem talks to the outside world. Stubbing internal modules hides integration bugs between\nyour own services.\n\n**No health checks in Docker Compose.** `depends_on` without a healthcheck waits only for the\ncontainer to start, not for the service to be ready — tests race the database and fail with\nconnection errors.\n\n**Long-lived preview environments.** Previews that persist after merge waste resources and\naccumulate stale state. Automate teardown on PR close (`if: github.event.action == 'closed'`).\n\n---\n\n## Verification\n\nRun these against the artifacts you produce, smallest check first:\n\n1. **Compose file is valid** — `docker compose -f docker-compose.test.yml config -q` exits 0\n   (catches YAML and schema errors before you ever pull an image).\n2. **Stack comes up healthy** — `docker compose -f docker-compose.test.yml up -d --wait\n   --wait-timeout 60` exits 0; a non-zero exit means a healthcheck never went green.\n3. **Database accepts connections** — `docker compose exec postgres pg_isready -U test -d\n   testdb` reports `accepting connections`.\n4. **Dockerfile builds the production target** — `docker build --target production -t app:prod\n   .` succeeds, and `docker run --rm app:prod npm ls --omit=dev --depth=0` shows no dev deps.\n5. **Stubs fail loud** — run the suite with `onUnhandledRequest: \"error\"`; any real outbound\n   call should error the test, not pass silently.\n\n---\n\n## Done When\n\n- Environment inventory documented (dev, CI, preview, staging, production) with characteristics and access notes per tier.\n- `docker compose -f docker-compose.test.yml config -q` exits 0 and `docker compose up -d --wait` brings every service to a passing healthcheck (exit 0).\n- Multi-stage Dockerfile builds the `production` target with `--omit=dev` (no dev dependencies in the shipped image).\n- Seed scripts are idempotent (running twice exits 0, no duplicate-key errors) and checked into the repository.\n- External dependencies are stubbed at the HTTP boundary with `onUnhandledRequest: \"error\"`; no real third-party credentials in non-prod.\n- Environment parity gaps documented (e.g. SQLite in CI vs PostgreSQL in prod) with mitigations in place or tracked as issues.\n- Preview environments auto-created for PRs and auto-torn-down on close (`if: github.event.action == 'closed'`).\n\n---\n\n## Reference Files (in `references\u002F`)\n\n- **docker-compose.md** — full `docker-compose.test.yml` (Postgres 18, Redis 8, one-shot seed, Mailpit), the `trap`-guarded integration test runner, the multi-stage Dockerfile (base\u002Fdevelopment\u002Ftest\u002Fseed\u002Fproduction), and the MinIO service + S3 client config.\n- **stubbing.md** — MSW 2.x handlers for Stripe\u002FSendGrid\u002Fgeocoding and the `setupServer` lifecycle with `onUnhandledRequest: \"error\"`.\n\n---\n\n## Related Skills\n\n- **service-virtualization** — Decision framework for choosing mock vs stub vs fake vs real per dependency, and WireMock\u002FMSW depth. Go there to *decide* the stubbing approach; this skill wires the chosen stub into the environment.\n- **test-data-management** — Factory patterns, synthetic data, database seeding, and DB branching (Neon\u002FSupabase\u002FPlanetScale) for per-PR DB copies.\n- **ci-cd-integration** — Pipeline config, GitHub Actions services, artifact management, sharding, and self-hosted runners. Go there for the surrounding workflow; this skill defines the services it runs against.\n- **contract-testing** — Consumer-driven contracts that verify your stubs match real APIs.\n","\u003Cobjective>\nStaging on SQLite passes tests that break on prod Postgres; a shared staging box becomes a\nqueue where one broken deploy blocks the whole team; an unmocked Stripe call flakes CI at\nrandom. This skill prevents those by designing environment tiers that mirror production where\nit matters, isolate per-PR, and stub external dependencies at the HTTP boundary. It delivers a\nworking `docker compose up` local\u002FCI stack, a parity checklist, and a stubbing strategy keyed\nto dependency type.\n\u003C\u002Fobjective>\n\n## Discovery Questions\n\nCheck `.agents\u002Fqa-project-context.md` first — if it exists, use it and skip anything already\nanswered there. Then:\n\n1. **How many environments exist today?** Local dev, CI, staging, preview, production? Map what you have before designing what you need.\n2. **Is the app containerized?** Check for `Dockerfile`, `docker-compose.yml`, or `compose.yaml`. If yes, multi-stage targets and compose come for free; if not, that is the first deliverable.\n3. **How is test data seeded?** Manual SQL, migration-based, factory libraries, or production snapshots? This decides whether seed scripts are a quick win or a rewrite.\n4. **How close is staging to production?** Same DB engine, queue, cache, auth provider, orchestration? Each mismatch is a class of bugs staging can never catch.\n5. **External dependencies:** How many third-party APIs does the system call, and are they stubbed in non-prod? Unstubbed third parties are the top source of CI flake.\n\n---\n\n## Core Principles\n\n**1. Staging must mirror production where bugs hide.** If staging uses SQLite and production\nuses PostgreSQL, staging tests prove nothing about prod behavior. Match the database engine\n*and version*, the queue system, the cache layer, and the auth provider — those are where\nenvironment-specific bugs live.\n\n**2. Ephemeral environments beat long-lived ones.** A shared staging environment becomes a\nbottleneck where one broken deploy blocks the entire team. Per-PR preview environments give\nisolation and parallel testing; keep staging only for final pre-release validation.\n\n**3. Deterministic seed data, not production copies.** Production snapshots carry PII, stale\nreferences, and non-reproducible state. Build seed data from factories that generate\nconsistent, valid, minimal datasets. (For factory patterns, see `test-data-management`.)\n\n**4. Stub external dependencies at the boundary, not deep inside.** Third-party APIs are\nunreliable, rate-limited, and expensive. Stub them at the HTTP boundary with MSW or WireMock —\nnever by mocking internal service classes, which hides integration bugs between your own code.\n\n**5. Environment config is code.** Every environment difference (URLs, flags, credentials,\nresource limits) must be version-controlled and reviewable. No manual setup that cannot be\nreproduced from the repo.\n\n---\n\n## Environment Strategy\n\n### Environment Tiers\n\n| Environment | Purpose | Data | External Deps | Lifecycle |\n|-------------|---------|------|---------------|-----------|\n| **Local dev** | Fast inner loop | Seeded fixtures, minimal | Stubbed (MSW\u002FWireMock) | Developer-managed |\n| **CI** | Automated validation | Seeded per-run, ephemeral | Stubbed or containerized | Created\u002Fdestroyed per pipeline |\n| **Preview** | PR-level review & E2E | Seeded from factories | Stubbed or sandbox | Created on PR, destroyed on close |\n| **Staging** | Pre-production validation | Anonymized production-like | Real integrations (sandbox accounts) | Long-lived, regularly reset |\n| **Production** | Live users | Real | Real | Permanent |\n\n### Local Development\n\nFast feedback, zero shared state. Developers must be able to run the full stack locally in\nunder two minutes:\n\n```bash\ndocker compose -f docker-compose.test.yml up -d\nnpm run db:seed\nnpm run dev\n```\n\nUse Docker Compose for infrastructure deps (database, cache, queue) but run the application\nnatively for fast reload. External APIs are stubbed with MSW handlers loaded in dev mode.\n\n### CI Environment\n\nFully containerized, created fresh per pipeline run, destroyed after. The block below is the\n**`services:` fragment** of a job — nest it under `jobs.\u003Cid>.services` alongside `runs-on`\nand `steps`; on its own it is not a valid workflow file.\n\n```yaml\n# .github\u002Fworkflows\u002Ftest.yml — fragment: nest under jobs.test.services\nservices:\n  postgres:\n    image: postgres:18-alpine\n    env:\n      POSTGRES_DB: testdb\n      POSTGRES_USER: test\n      POSTGRES_PASSWORD: test\n    ports: ['5432:5432']\n    options: >-\n      --health-cmd=\"pg_isready -U test\"\n      --health-interval=5s\n      --health-timeout=3s\n      --health-retries=5\n  redis:\n    image: redis:8-alpine\n    ports: ['6379:6379']\n    options: >-\n      --health-cmd=\"redis-cli ping\"\n      --health-interval=5s\n      --health-timeout=3s\n      --health-retries=5\n```\n\n### Docker Compose vs Testcontainers\n\nTwo ways to give tests real infrastructure. Pick by where the lifecycle should live:\n\n- **Docker Compose** — declarative stack you bring up before the suite (`docker compose up\n  --wait`) and tear down after, usually via a `trap`-guarded script. Best for local dev, a\n  shared CI stack, and E2E where many tests share one set of services.\n- **Testcontainers** (Node \u002F JVM \u002F Python \u002F Go) — containers spun up *from test code* and\n  auto-torn-down per suite or per test, with no compose file or `trap` to maintain. Best for\n  integration tests that need isolated, programmatic infra (a throwaway Postgres per test\n  class). The 2026 default for \"ephemeral infra owned by the test,\" and a strong alternative\n  to hand-rolled compose + trap scripts.\n\nReach for Compose when humans and many tests share the stack; reach for Testcontainers when\neach test (or suite) wants its own disposable copy.\n\n### Preview Environments (Per-PR)\n\nEach pull request gets its own isolated environment; reviewers click a link and test the exact\nchanges without interfering with other PRs.\n\nHosting options (2026), pick by stack:\n\n- **Vercel** preview deployments — Next.js \u002F static \u002F serverless; per-PR URL automatically.\n- **Cloudflare Pages** preview — git-integrated, generous free tier.\n- **Render** \u002F **Railway** preview environments — full-stack including databases.\n- **Northflank**, **Qovery**, **Bunnyshell**, **Uffizzi** — full ephemeral-environment\n  platforms (Kubernetes-backed) when previews need the whole stack, not just a frontend.\n\nFor each preview, pair the env lifecycle with a **database branch** (Neon, Supabase,\nPlanetScale-style): create a branch on PR open, drop it on close. That gives every preview a\ncheap, instant, isolated DB copy instead of a shared staging DB. (See `test-data-management`.)\n\nFor local-dev parity with CI:\n\n- **Devcontainers** (`.devcontainer\u002Fdevcontainer.json`) — VS Code, Codespaces, JetBrains. The\n  standard for \"everyone gets the same Docker-backed dev env.\"\n- **Tilt** (`Tiltfile`) — Kubernetes-first local dev with hot reload and multi-service\n  orchestration. Pick when staging itself is K8s.\n\nA frontend preview with E2E against the generated URL is a few lines:\n\n```yaml\n- name: Run E2E against preview\n  env:\n    BASE_URL: ${{ steps.deploy.outputs.preview-url }}\n  run: npx playwright test --project=chromium\n```\n\nA custom Docker preview keyed to a per-PR namespace, auto-torn-down on close:\n\n```yaml\n- name: Deploy preview\n  run: |\n    NAMESPACE=\"pr-${{ github.event.number }}\"\n    docker compose -f docker-compose.preview.yml -p \"$NAMESPACE\" up -d\n    echo \"preview-url=https:\u002F\u002F${NAMESPACE}.preview.example.com\" >> \"$GITHUB_OUTPUT\"\n\n- name: Teardown preview\n  if: github.event.action == 'closed'\n  run: |\n    NAMESPACE=\"pr-${{ github.event.number }}\"\n    docker compose -p \"$NAMESPACE\" down -v\n```\n\n### Staging\n\nLong-lived environment that mirrors production infrastructure. Reset weekly or on-demand to\nprevent drift:\n\n```bash\n#!\u002Fbin\u002Fbash\n# scripts\u002Freset-staging.sh\nset -euo pipefail\n\necho \"Resetting staging database...\"\npsql \"$STAGING_DATABASE_URL\" -c \"DROP SCHEMA public CASCADE; CREATE SCHEMA public;\"\n\necho \"Running migrations...\"   # migrations MUST recreate extensions + grants (see caveat below)\nnpm run db:migrate -- --env staging\n\necho \"Seeding anonymized data...\"\nnpm run db:seed -- --env staging --dataset production-anonymized\n\necho \"Verifying staging health...\"\ncurl -sf https:\u002F\u002Fstaging.example.com\u002Fhealth || exit 1\necho \"Staging reset complete.\"\n```\n\n**Caveat:** `DROP SCHEMA public CASCADE` also drops the schema's default privileges and any\ninstalled extensions (`uuid-ossp`, `pgcrypto`, …). Your migration pipeline must recreate them\n(`CREATE EXTENSION IF NOT EXISTS …`, re-grant defaults) or the migrate step fails. Don't assume\na bare `CREATE SCHEMA public` restores the prior grants — it does not.\n\n---\n\n## Docker Compose for Testing\n\nA production-quality `docker-compose.test.yml` spins up the full stack (app, Postgres, Redis,\na one-shot seed container, Mailpit) for integration and E2E tests. Two details that matter:\n\n- **Health checks gate `depends_on`.** Without a `healthcheck` + `condition: service_healthy`,\n  `depends_on` only waits for the container to *start*, not for the service to accept\n  connections — tests then race the database and fail with connection errors.\n- **Seed is a one-shot container, not a long-running service.** It uses `depends_on:\n  condition: service_completed_successfully`, so the app starts only after seeding *exits 0*.\n  Teams that model seed as a long-running service get a race where the app boots mid-seed.\n\nSee `references\u002Fdocker-compose.md` for the full `docker-compose.test.yml`, the\n`trap`-guarded integration test runner, the multi-stage Dockerfile (with the `production`\ntarget), and the MinIO block.\n\n### Multi-Stage Dockerfile\n\nOne `base` layer installs deps once; `development`, `test`, and `seed` stages reuse it; and a\nslim `production` stage runs prod deps only (`npm ci --omit=dev`) with build artifacts copied\nfrom the `test` stage. The split keeps test dependencies and source out of the shipped image\nwhile giving each environment its own entrypoint. Use `npm ci --include=dev` in `base` — the\nmodern flag; `--production=false` is legacy `--omit`\u002F`--include` syntax. Full Dockerfile in\n`references\u002Fdocker-compose.md`.\n\n---\n\n## External Dependency Management\n\n### Stubbing Strategy by Dependency Type\n\n| Dependency Type | Local\u002FCI Strategy | Staging Strategy |\n|----------------|-------------------|------------------|\n| Payment (Stripe) | MSW handler returning mock responses | Stripe test mode with `sk_test_` keys |\n| Email (SendGrid) | **Mailpit** capturing SMTP (web UI on :8025, SMTP on :1025) | SendGrid sandbox mode |\n| Auth (Auth0) | Local JWT issuer with test keys | Auth0 dev tenant |\n| Storage (S3) | MinIO container (S3-compatible) | Dedicated test bucket with lifecycle policy |\n| Search (Elasticsearch) | Testcontainers Elasticsearch | Dedicated test index with reset script |\n| SMS (Twilio) | MSW handler | Twilio test credentials |\n\n**Avoid: MailHog** — unmaintained, last release 2020. Use Mailpit (`axllent\u002Fmailpit`); it is a\ndrop-in on the same ports (1025 SMTP \u002F 8025 UI).\n\n### MSW for HTTP Stubs\n\nStub external APIs at the HTTP boundary with MSW 2.x: `http` + `HttpResponse` from `msw`,\n`setupServer` from `msw\u002Fnode`, lifecycle wired through `beforeAll`\u002F`afterEach`\u002F`afterAll`. Set\n`onUnhandledRequest: \"error\"` so an unmocked external call fails the test loudly instead of\nleaking a real network request. See `references\u002Fstubbing.md` for the Stripe\u002FSendGrid\u002Fgeocoding\nhandlers and the server lifecycle.\n\n### MinIO as an S3 Substitute\n\nRun S3-compatible storage in a container instead of hitting real AWS in local\u002FCI tests. Point\nthe AWS SDK `S3Client` at it with `endpoint`, env-var credentials, and `forcePathStyle: true`\n(required for MinIO). Compose service + client config in `references\u002Fdocker-compose.md`.\n\n### Contract Testing as Stub Validation\n\nStubs drift from reality. Pair every stub with a contract test that verifies the stub matches\nthe real API shape. For details, see `contract-testing`.\n\n---\n\n## Environment Parity Checklist\n\nRun this when setting up or auditing a non-production environment.\n\n| Dimension | Question | Red Flag |\n|-----------|----------|----------|\n| **Database engine** | Same engine and version as production? | SQLite in test, PostgreSQL in prod |\n| **Database schema** | Same migration pipeline applied? | Manual schema changes in staging |\n| **Data shape** | Seed data covers all entity states? | Only \"happy path\" records, no edge cases |\n| **Infrastructure** | Same container orchestration? | Docker Compose in CI, Kubernetes in prod |\n| **Network** | Same internal service topology? | Monolith in test, microservices in prod |\n| **Config** | Env vars documented and version-controlled? | Undocumented env vars, manual setup |\n| **Auth** | Same auth provider\u002Fflow? | Bypassed auth in test with hardcoded tokens |\n| **Feature flags** | Same flag evaluation engine? | Hardcoded flags in test, LaunchDarkly in prod |\n| **TLS\u002FHTTPS** | Same certificate handling? | HTTP in staging, HTTPS in prod |\n| **Timeouts\u002FLimits** | Same rate limits, pools, timeouts? | Infinite timeouts in test hide perf issues |\n\nFor factory-based seed data patterns, see `test-data-management`.\n\n---\n\n## Anti-Patterns\n\n**Shared staging as the only test environment.** One developer's broken deploy blocks everyone.\nUse ephemeral per-PR environments for isolation and keep staging for final pre-release\nvalidation only.\n\n**Production database copies for test data.** PII risk, non-reproducible state, massive\ndatasets that slow tests. Build minimal seed data from factories with deterministic values.\n\n**Environment-specific code paths.** `if (process.env.NODE_ENV === \"test\") { skipAuth(); }`\nmeans you are not testing the real auth flow. Swap implementations via dependency injection or\nconfig, not environment conditionals.\n\n**Manual environment setup.** If setup needs a 15-step wiki page, it will be wrong within a\nweek. Script everything: `docker compose up -d && npm run db:seed` should be the only steps.\n\n**Stubbing internal services instead of external ones.** Stub at the HTTP boundary where your\nsystem talks to the outside world. Stubbing internal modules hides integration bugs between\nyour own services.\n\n**No health checks in Docker Compose.** `depends_on` without a healthcheck waits only for the\ncontainer to start, not for the service to be ready — tests race the database and fail with\nconnection errors.\n\n**Long-lived preview environments.** Previews that persist after merge waste resources and\naccumulate stale state. Automate teardown on PR close (`if: github.event.action == 'closed'`).\n\n---\n\n## Verification\n\nRun these against the artifacts you produce, smallest check first:\n\n1. **Compose file is valid** — `docker compose -f docker-compose.test.yml config -q` exits 0\n   (catches YAML and schema errors before you ever pull an image).\n2. **Stack comes up healthy** — `docker compose -f docker-compose.test.yml up -d --wait\n   --wait-timeout 60` exits 0; a non-zero exit means a healthcheck never went green.\n3. **Database accepts connections** — `docker compose exec postgres pg_isready -U test -d\n   testdb` reports `accepting connections`.\n4. **Dockerfile builds the production target** — `docker build --target production -t app:prod\n   .` succeeds, and `docker run --rm app:prod npm ls --omit=dev --depth=0` shows no dev deps.\n5. **Stubs fail loud** — run the suite with `onUnhandledRequest: \"error\"`; any real outbound\n   call should error the test, not pass silently.\n\n---\n\n## Done When\n\n- Environment inventory documented (dev, CI, preview, staging, production) with characteristics and access notes per tier.\n- `docker compose -f docker-compose.test.yml config -q` exits 0 and `docker compose up -d --wait` brings every service to a passing healthcheck (exit 0).\n- Multi-stage Dockerfile builds the `production` target with `--omit=dev` (no dev dependencies in the shipped image).\n- Seed scripts are idempotent (running twice exits 0, no duplicate-key errors) and checked into the repository.\n- External dependencies are stubbed at the HTTP boundary with `onUnhandledRequest: \"error\"`; no real third-party credentials in non-prod.\n- Environment parity gaps documented (e.g. SQLite in CI vs PostgreSQL in prod) with mitigations in place or tracked as issues.\n- Preview environments auto-created for PRs and auto-torn-down on close (`if: github.event.action == 'closed'`).\n\n---\n\n## Reference Files (in `references\u002F`)\n\n- **docker-compose.md** — full `docker-compose.test.yml` (Postgres 18, Redis 8, one-shot seed, Mailpit), the `trap`-guarded integration test runner, the multi-stage Dockerfile (base\u002Fdevelopment\u002Ftest\u002Fseed\u002Fproduction), and the MinIO service + S3 client config.\n- **stubbing.md** — MSW 2.x handlers for Stripe\u002FSendGrid\u002Fgeocoding and the `setupServer` lifecycle with `onUnhandledRequest: \"error\"`.\n\n---\n\n## Related Skills\n\n- **service-virtualization** — Decision framework for choosing mock vs stub vs fake vs real per dependency, and WireMock\u002FMSW depth. Go there to *decide* the stubbing approach; this skill wires the chosen stub into the environment.\n- **test-data-management** — Factory patterns, synthetic data, database seeding, and DB branching (Neon\u002FSupabase\u002FPlanetScale) for per-PR DB copies.\n- **ci-cd-integration** — Pipeline config, GitHub Actions services, artifact management, sharding, and self-hosted runners. Go there for the surrounding workflow; this skill defines the services it runs against.\n- **contract-testing** — Consumer-driven contracts that verify your stubs match real APIs.\n",{"name":5,"license":15,"metadata":44,"description":7},{"author":45,"version":46,"category":47},"kindlmann","2.0","infrastructure","claude\u002Finstall-gsd-build-foQdV","d86cd127f527124b5fd0fd0bc679a4d79b7d01d7",".agents\u002Fskills\u002Ftest-environments","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik","https:\u002F\u002Fnorvik-orpin.vercel.app","https:\u002F\u002Fgithub.com\u002Fpattanation","2026-07-17 11:17:04",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add pattanation\u002FNorvik --skill test-environments",{"tool":61,"command":62},"bunx","bunx skills add pattanation\u002FNorvik --skill test-environments",{"tool":64,"command":65},"pnpm","pnpm dlx skills add pattanation\u002FNorvik --skill test-environments","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Ftest-environments\u002FSKILL.md",true,[69,75],{"path":70,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fdocker-compose.md","REFERENCE","参考文档",5084,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Ftest-environments\u002Freferences\u002Fdocker-compose.md",{"path":76,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Fstubbing.md",2426,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Ftest-environments\u002Freferences\u002Fstubbing.md",[80,89,96,103,127,152],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":84,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":88},"01M73Z1NPMJ667E0DSPBS9FH0B","jetson-set-target","Switch the active Jetson target-platform pointer to an existing profile YAML. Use before customize\u002Fbuild\u002Fflash to change target; not for authoring profiles — use jetson-init-target instead.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fjetson-set-target\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":84,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":88},"01M73YC29YWGCW521P7B0NM3HQ","earth2studio-data-fetch","Fetch weather\u002Fclimate data via Earth2Studio data sources for specific variables and times. Do NOT use for inference pipelines, model discovery, or installation.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fearth2studio-data-fetch\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":84,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":88},"01M73YBNHMHFDFP83MAVGQQ92N","earth2studio-create-datasource","Create and validate Earth2Studio data source wrappers (DataSource, ForecastSource, DataFrameSource, ForecastFrameSource) from remote stores. Do NOT use for fetching data with existing sources, model inference, or installation tasks.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fearth2studio-create-datasource\u002FSKILL.md",[],[],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":84,"licenseFileUrl":107,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":39},"01M71QDV4DM8T19HEHWATEF1K4","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[111,33,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126],"webapp","webapp testing","local","screenshots","for","applications","browser","ui","behavior","web","playwright","with","frontend","debugging","toolkit","logs",{"skillNo":128,"name":129,"nameZh":6,"description":130,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":84,"licenseFileUrl":131,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":39},"01M71QDH2GGMXGA9105C9W1N7B","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[135,120,136,137,138,139,140,141,142,143,144,145,115,146,147,123,148,149,150,151],"web artifacts builder","artifacts","artifacts builder","builder","multi","state","routing","state management","react","single-file","css","Tailwind","ui components","single","use","file","components",{"skillNo":153,"name":154,"nameZh":6,"description":155,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":156,"sourceHtmlUrl":157,"categories":158,"keywords":159,"publishedAt":39},"01M71QD9T2XC3EWMQNN9ACNWQ1","vueuse-functions","Apply VueUse composables where appropriate to build concise, maintainable Vue.js \u002F Nuxt features.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fvueuse-functions\u002FLICENSE.md","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fvueuse-functions\u002FSKILL.md",[],[160,161,162,163,164,165,166,167,168,169,170,171,172,173],"vueuse","vueuse functions","functions","composables","project","nuxt","apply","github","concise","build","https","features","vue","js"]