Skip to content

feat: add docker-sandbox skill and fix strategic-compact session-start-hook - #216

Merged
baleen37 merged 15 commits into
mainfrom
feat/strategic-compact-session-start-hook
Jan 31, 2026
Merged

feat: add docker-sandbox skill and fix strategic-compact session-start-hook#216
baleen37 merged 15 commits into
mainfrom
feat/strategic-compact-session-start-hook

Conversation

@baleen37

@baleen37 baleen37 commented Jan 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add docker-sandbox skill for testing Claude Code components in isolated Docker environments
  • Fix strategic-compact session-start-hook to properly create session environment file
  • Add tmux-testing skill for terminal-based testing workflows

docker-sandbox Skill

New skill for reproducible Docker-based testing with:

  • Helper libraries for Docker lifecycle management (docker-helpers.sh, test-helpers.sh)
  • YAML-based test definitions (no external dependencies)
  • OAuth token integration with macOS Keychain
  • Automatic container cleanup with trap-based safety
  • Example test files for commands, hooks, and skills
  • Comprehensive BATS tests

Strategic Compact SessionStart Hook Fix

Fixed session-start-hook.sh to properly:

  • Generate unique session ID
  • Create session environment file at ~/.claude/strategic-compact/session-{session_id}.env
  • Export session environment variables

Test Plan

  • All BATS tests pass (bats tests/docker-sandbox.bats)
  • Docker image builds successfully
  • Container cleanup verified
  • Shellcheck passes on all shell scripts
  • YAML/JSON validation passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced Docker-based sandbox environment for testing Claude Code components (SKILLs, Commands, Hooks)
  • Documentation

    • Added comprehensive guide with testing patterns, examples, and best practices
  • Tests

    • Added test suite and example test definitions for Docker-based testing workflows

✏️ Tip: You can customize this high-level summary in your review settings.

baleen37 and others added 14 commits January 30, 2026 11:33
Co-Authored-By: Claude <noreply@anthropic.com>
- Based on Ubuntu 24.04
- Installs Node.js 20.x from NodeSource
- Installs Claude Code CLI globally via npm
- Creates non-root 'claude' user for security
- Includes essential tools: git, jq, bash, tmux

Co-Authored-By: Claude <noreply@anthropic.com>
Add main test runner script that orchestrates Docker container
creation, test execution, and result verification.

Features:
- Loads test definitions from YAML files
- Manages Docker container lifecycle with cleanup traps
- Retrieves OAuth tokens from environment or macOS Keychain
- Executes Claude Code prompts in isolated containers
- Verifies output against expected results
- Reports test results with duration

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive SKILL.md documentation for docker-sandbox testing.
Includes critical requirements, helper library patterns, anti-patterns,
CI/CD considerations, and comparison with tmux-testing.

Co-Authored-By: Claude <noreply@anthropic.com>
Add Docker lifecycle management functions for Claude Code testing.
Provides container creation, execution, and cleanup utilities.

Co-Authored-By: Claude <noreply@anthropic.com>
Add test execution and verification functions library for the
docker-sandbox skill testing framework.

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace standard BATS assertions with project-compatible patterns:
  - assert_success → [ "$status" -eq 0 ]
  - assert_failure → [ "$status" -ne 0 ]
  - assert_file_exists → [ -f "$file" ]
  - assert_file_executable → [ -x "$file" ]
  - assert_output --partial → [[ "$output" == *"text"* ]]
- Fix trap quoting to defer variable expansion:
  - trap "cleanup_container '$CONTAINER_NAME'" EXIT
  - + trap 'cleanup_container "$CONTAINER_NAME"' EXIT

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unused TEST_EXPECTED_NOT_CONTAINS variable
- Fix SC2155 warnings by declaring local variables separately from assignment
- Add shellcheck disable directive for TEST_PROMPT (used by run-docker-test.sh)

Co-Authored-By: Claude <noreply@anthropic.com>
Mock docker function instead of PATH manipulation, which didn't
reliably make docker unavailable on macOS.
- Remove ENTRYPOINT from Dockerfile that breaks binary execution as non-root
- Fix YAML parsing in test-helpers.sh (grep -A1 to -A2)

The ENTRYPOINT directive was causing all binary commands to fail with
"cannot execute binary file" error when running as non-root user.
Container creation script already provides the command (sleep infinity).

The YAML parsing was only capturing one line after test_target:, but
YAML has two lines (type and name), so grep needed -A2 instead of -A1.

Co-Authored-By: Claude <noreply@anthropic.com>
The 'command' is a bash builtin, not accessible via docker exec directly.
Must use 'bash -c "command -v claude"' to check if claude exists.
@coderabbitai

coderabbitai Bot commented Jan 31, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces a complete Docker-based testing infrastructure for Claude Code components. It adds configuration updates, comprehensive documentation, a Dockerfile for an Ubuntu 24.04 test environment with Node.js and Claude Code CLI, helper libraries for Docker operations and test execution, a test orchestration script, example test definitions in YAML format, and a BATS test suite validating the infrastructure itself.

Changes

Cohort / File(s) Summary
Configuration & Documentation
.gitignore, skills/docker-sandbox/SKILL.md
Updated .gitignore to include skills script libraries. Added 430-line SKILL.md guide covering Docker sandbox testing requirements, implementation patterns, helper libraries, test workflows, test definitions, anti-patterns, and CLI references.
Docker Infrastructure
skills/docker-sandbox/docker/Dockerfile, skills/docker-sandbox/scripts/lib/docker-helpers.sh
Introduced Dockerfile with Ubuntu 24.04, Node.js 20.x, Claude Code CLI, non-root user setup, and workspace directory. Created docker-helpers.sh with 10 functions for image building, container lifecycle, readiness polling, logs retrieval, and cleanup operations.
Test Framework
skills/docker-sandbox/scripts/lib/test-helpers.sh, skills/docker-sandbox/scripts/run-docker-test.sh
Added test-helpers.sh with YAML parsing, output verification, file checks, timing, and result reporting functions. Created run-docker-test.sh orchestration script that loads test definitions, manages containers, executes tests, and verifies results.
Test Examples & Validation
skills/docker-sandbox/tests/*.yaml, tests/docker-sandbox.bats
Added three example YAML test definitions for command, hook, and skill testing. Created comprehensive BATS test suite with 115 lines validating docker-helpers.sh, test-helpers.sh, and run-docker-test.sh functionality with Docker availability checks and container lifecycle management.

Sequence Diagram(s)

sequenceDiagram
    participant User as Test Runner
    participant TestOrch as run-docker-test.sh
    participant DockerHelper as docker-helpers.sh
    participant Docker as Docker Daemon
    participant Container as Test Container
    participant TestHelper as test-helpers.sh

    User->>TestOrch: Execute with test definition file
    TestOrch->>TestHelper: load_test_definition()
    TestHelper-->>TestOrch: Parsed test config
    TestOrch->>DockerHelper: build_claude_image()
    DockerHelper->>Docker: Build image
    Docker-->>DockerHelper: Image ready
    TestOrch->>DockerHelper: create_container()
    DockerHelper->>Docker: Create/start container
    Docker->>Container: Start with sleep entrypoint
    DockerHelper->>TestOrch: Container name
    TestOrch->>DockerHelper: wait_for_claude_ready()
    DockerHelper->>Container: Poll for claude CLI
    Container-->>DockerHelper: Claude ready
    TestOrch->>DockerHelper: exec_in_container_capture()
    DockerHelper->>Container: Execute test prompt
    Container->>Container: Run test
    Container-->>DockerHelper: Captured output
    DockerHelper-->>TestOrch: Output
    TestOrch->>TestHelper: verify_contains()
    TestHelper-->>TestOrch: Verification result
    TestOrch->>DockerHelper: cleanup_container()
    DockerHelper->>Docker: Stop/remove container
    Docker-->>DockerHelper: Container cleaned
    TestOrch-->>User: Test result (pass/fail)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 A Docker sandbox springs to life,
With tests that hop without the strife,
Containers dance, helpers align,
BATS validate each perfect line,
Claude Code tested, crisp and fine! 🐳

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/strategic-compact-session-start-hook

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@baleen37
baleen37 merged commit 32ea212 into main Jan 31, 2026
1 check passed
@baleen37
baleen37 deleted the feat/strategic-compact-session-start-hook branch January 31, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant