Add test-env setup script and skill for Claude Code cloud sessions#8065
Add test-env setup script and skill for Claude Code cloud sessions#8065phacops wants to merge 1 commit into
Conversation
Add an on-demand setup script (scripts/setup-test-env.sh) plus a companion skill that prepare an ephemeral Linux container (e.g. a Claude Code cloud session) for running the test suite: - install sentry-devenv via the official bash installer - run `uv sync` (builds the venv and compiles the rust_snuba extension) - start the Docker daemon if needed - bring up devservices (clickhouse, redis, kafka) This is a standalone script rather than a session-start hook so the multi-minute cost is only paid when tests are actually needed. Lower the clickhouse `nofile` ulimit in devservices/config.yml to soft 1024 / hard 4096 so the container can start in environments without CAP_SYS_RESOURCE (the previous 262144 cannot be applied there). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CutWwsFwLDtczduJzjvF8Y
| nofile: | ||
| soft: 262144 | ||
| hard: 262144 | ||
| soft: 1024 | ||
| hard: 4096 | ||
| ports: |
There was a problem hiding this comment.
Bug: The nofile ulimit for ClickHouse in devservices/config.yml is reduced to 4096. This low limit is likely to be exhausted during local test runs, causing failures.
Severity: HIGH
Suggested Fix
To avoid impacting all local development environments, consider using separate Docker Compose configurations. Revert the ulimit change in the general-purpose devservices/config.yml and create a new, specialized configuration file (e.g., docker-compose.cloud.yml) with the lower nofile limit specifically for the cloud container environment that requires it. This isolates the restrictive setting to only the environment where it is necessary.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: devservices/config.yml#L52-L55
Potential issue: The `nofile` ulimit for ClickHouse in `devservices/config.yml` has been
reduced to a hard limit of `4096`. This configuration is used by the `devservices` tool
for local development environments. ClickHouse is known to require a high number of file
descriptors, especially under load. The Snuba test suite performs numerous concurrent
operations, which will likely exceed this low limit, causing tests to fail with "Too
many open files" errors. This impacts any developer running the test suite locally.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
This lower limit is intentional. The sandboxed cloud containers these scripts target lack CAP_SYS_RESOURCE, so the daemon's own nofile hard limit is capped at 4096 — runc can't grant a container a higher limit than that, and the original 262144 made the clickhouse container fail to start entirely (error setting rlimit type 7: operation not permitted). Any value ≤ 4096 is the only thing that works there.
The suggested split (a separate docker-compose.cloud.yml) isn't cleanly doable: devservices up invokes docker compose -f devservices/config.yml ... directly and offers no override-file mechanism, so a sibling compose file wouldn't be picked up.
In practice 4096 is sufficient for a dev/test clickhouse — the test suite passes against it. Keeping the single shared value for simplicity per maintainer decision.
Generated by Claude Code
Summary
Adds an on-demand script + skill that prepares an ephemeral Linux container (e.g. a Claude Code cloud session) for running the Snuba test suite, where nothing is installed and the Docker daemon is not running.
This is intentionally a standalone script rather than a session-start hook —
uv syncplus pulling the clickhouse/redis/kafka images takes several minutes, so we only pay that cost on demand when tests are actually needed.Changes
scripts/setup-test-env.sh— idempotent setup script that:sentry-devenvvia the official bash installeruv sync --frozen --active, which creates.venvand compiles the nativerust_snubaextension into it (no separatematurin developneeded);devservicescomes along as a dev dependencysudo dockerd) if it isn't already runningdevservices(clickhouse, redis, kafka).claude/skills/setup-test-env/SKILL.md— companion skill so the environment can be set up on demand, documenting the correct test invocation.devservices/config.yml— lower the clickhousenofileulimit from262144to soft1024/ hard4096so the container can start in environments withoutCAP_SYS_RESOURCE(the previous value cannot be applied there and made clickhouse fail to start).Notes / gotchas
tests/. Invoking it from the repo root loadstest_distributed_migrations/conftest.py, whosepytest_configureconnects to a multi-node clickhouse host (clickhouse-query) that single-node devservices doesn't provide, causing anINTERNALERRORbefore any test runs. Documented in the skill:devenvrefuses to run as root anddevenv syncis Homebrew-based, so in the cloud container the functional path isuv sync+devservices, notdevenv sync. The globaldevenvinstall is included only for parity with local laptop setups.Validation
ruff checkpasses2 passed) using the documented invocation🤖 Generated with Claude Code
https://claude.ai/code/session_01CutWwsFwLDtczduJzjvF8Y
Generated by Claude Code