From 3ea574364c111786fe0134f30979f22f6fa27494 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:23:39 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 15 +++ README.md | 3 + commands/env-setup.md | 60 +++++++++++ plugin.lock.json | 73 +++++++++++++ skills/test-environment-manager/SKILL.md | 52 +++++++++ .../test-environment-manager/assets/README.md | 7 ++ .../assets/docker-compose-template.yml | 53 ++++++++++ .../assets/example_test_script.py | 100 ++++++++++++++++++ .../assets/test_environment_diagram.png | 35 ++++++ .../references/README.md | 9 ++ .../scripts/README.md | 8 ++ 11 files changed, 415 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/env-setup.md create mode 100644 plugin.lock.json create mode 100644 skills/test-environment-manager/SKILL.md create mode 100644 skills/test-environment-manager/assets/README.md create mode 100644 skills/test-environment-manager/assets/docker-compose-template.yml create mode 100644 skills/test-environment-manager/assets/example_test_script.py create mode 100644 skills/test-environment-manager/assets/test_environment_diagram.png create mode 100644 skills/test-environment-manager/references/README.md create mode 100644 skills/test-environment-manager/scripts/README.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..aaccc2f --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "test-environment-manager", + "description": "Manage test environments with Docker Compose, Testcontainers, and environment isolation", + "version": "1.0.0", + "author": { + "name": "Claude Code Plugin Hub", + "email": "[email protected]" + }, + "skills": [ + "./skills" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b745eae --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# test-environment-manager + +Manage test environments with Docker Compose, Testcontainers, and environment isolation diff --git a/commands/env-setup.md b/commands/env-setup.md new file mode 100644 index 0000000..afe8516 --- /dev/null +++ b/commands/env-setup.md @@ -0,0 +1,60 @@ +--- +description: Set up and manage isolated test environments +shortcut: env +--- + +# Test Environment Manager + +Create and manage isolated test environments using Docker Compose, Testcontainers, and environment variables for consistent, reproducible testing. + +## What You Do + +1. **Environment Setup**: Create isolated test environments with databases, caches, message queues +2. **Docker Compose**: Generate docker-compose files for test infrastructure +3. **Testcontainers**: Set up programmatic container management +4. **Environment Variables**: Manage test-specific configuration +5. **Cleanup**: Ensure proper teardown and resource cleanup + +## Output Example + +```yaml +# docker-compose.test.yml +version: '3.8' +services: + postgres-test: + image: postgres:16 + environment: + POSTGRES_DB: test_db + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_pass + ports: + - "5433:5432" + + redis-test: + image: redis:7-alpine + ports: + - "6380:6379" + + localstack: + image: localstack/localstack + environment: + SERVICES: s3,sqs,dynamodb + ports: + - "4566:4566" +``` + +```javascript +// testcontainers setup +const { PostgreSqlContainer } = require('@testcontainers/postgresql'); + +let container; + +beforeAll(async () => { + container = await new PostgreSqlContainer().start(); + process.env.DATABASE_URL = container.getConnectionUri(); +}); + +afterAll(async () => { + await container.stop(); +}); +``` diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..323a51b --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,73 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/testing/test-environment-manager", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "7e9b45115d44f52e40627f37d842c0e4f9394f19", + "treeHash": "26297a2c575870d76893a8b57149483fb4b9d6bb3101dcca8501900c4449d2cd", + "generatedAt": "2025-11-28T10:18:49.381695Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "test-environment-manager", + "description": "Manage test environments with Docker Compose, Testcontainers, and environment isolation", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "960ee2895080546f99356b66aec3021c786cc56900245fa425e9582197a6ec1b" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "1b2d6ccceb02bdc86cb3cbc864602fa539587f6c295f70135d9fc1f266c7bf84" + }, + { + "path": "commands/env-setup.md", + "sha256": "30a70112209f6d8bba436bc35b2573a2f684950886252a696aa3ad1f20ae3121" + }, + { + "path": "skills/test-environment-manager/SKILL.md", + "sha256": "f23db9c3adcdd31dd0419eefb2aad39ab71c12eb708c7e1f01b259eed34a64bd" + }, + { + "path": "skills/test-environment-manager/references/README.md", + "sha256": "20141881c480aff02ad6472808138682ff7b7749baea143774b28559aa613706" + }, + { + "path": "skills/test-environment-manager/scripts/README.md", + "sha256": "9274854c4b70629423bab184cbceb8e4e451646bf459aba16b2093e150687688" + }, + { + "path": "skills/test-environment-manager/assets/README.md", + "sha256": "e7308ee7305730cb78c8bbea92fa3425f8cd0a1d33b5d70adf871d8864ec838d" + }, + { + "path": "skills/test-environment-manager/assets/docker-compose-template.yml", + "sha256": "9cc3d97cf717ffb6915ef799d3158748bf37913f84e3504c30877d0be2fe6ccf" + }, + { + "path": "skills/test-environment-manager/assets/test_environment_diagram.png", + "sha256": "8a5b754a56e0501c6cf6977043ebde3ef6321425ada6f9b38d74539fe314883d" + }, + { + "path": "skills/test-environment-manager/assets/example_test_script.py", + "sha256": "ef75bc8439430e3a816d67a8fa45fcdc19ff7d34aa9f7f38f267de154c08db37" + } + ], + "dirSha256": "26297a2c575870d76893a8b57149483fb4b9d6bb3101dcca8501900c4449d2cd" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/test-environment-manager/SKILL.md b/skills/test-environment-manager/SKILL.md new file mode 100644 index 0000000..ba19ced --- /dev/null +++ b/skills/test-environment-manager/SKILL.md @@ -0,0 +1,52 @@ +--- +name: managing-test-environments +description: | + This skill enables Claude to manage isolated test environments using Docker Compose, Testcontainers, and environment variables. It is used to create consistent, reproducible testing environments for software projects. Claude should use this skill when the user needs to set up a test environment with specific configurations, manage Docker Compose files for test infrastructure, set up programmatic container management with Testcontainers, manage environment variables for tests, or ensure cleanup after tests. Trigger terms include "test environment", "docker compose", "testcontainers", "environment variables", "isolated environment", "env-setup", and "test setup". +allowed-tools: Read, Write, Edit, Grep, Glob, Bash +version: 1.0.0 +--- + +## Overview + +This skill empowers Claude to orchestrate and manage isolated test environments, ensuring consistent and reproducible testing processes. It simplifies the setup and teardown of complex testing infrastructures by leveraging Docker Compose, Testcontainers, and environment variable management. + +## How It Works + +1. **Environment Creation**: Generates isolated test environments with databases, caches, message queues, and other dependencies. +2. **Docker Compose Management**: Creates and configures `docker-compose.yml` files to define the test infrastructure. +3. **Testcontainers Integration**: Sets up programmatic container management using Testcontainers for dynamic environment configuration. + +## When to Use This Skill + +This skill activates when you need to: +- Create an isolated test environment for a software project. +- Manage Docker Compose files for test infrastructure. +- Set up programmatic container management using Testcontainers. + +## Examples + +### Example 1: Setting up a Database Test Environment + +User request: "Set up a test environment with a PostgreSQL database and a Redis cache using Docker Compose." + +The skill will: +1. Generate a `docker-compose.yml` file defining PostgreSQL and Redis services. +2. Configure environment variables for database connection and cache access. + +### Example 2: Creating a Test Environment with Message Queue + +User request: "Create a test environment with RabbitMQ using Testcontainers." + +The skill will: +1. Programmatically create a RabbitMQ container using Testcontainers. +2. Configure environment variables for message queue connection. + +## Best Practices + +- **Configuration**: Ensure that all necessary environment variables are properly configured for the test environment. +- **Cleanup**: Implement cleanup routines to remove test environments after use. +- **Isolation**: Verify that the test environment is properly isolated from other environments. + +## Integration + +This skill integrates with other Claude Code plugins to manage the deployment and execution of tests within the created environments. It can work with CI/CD tools to automate testing workflows. \ No newline at end of file diff --git a/skills/test-environment-manager/assets/README.md b/skills/test-environment-manager/assets/README.md new file mode 100644 index 0000000..d22ed7c --- /dev/null +++ b/skills/test-environment-manager/assets/README.md @@ -0,0 +1,7 @@ +# Assets + +Bundled resources for test-environment-manager skill + +- [ ] docker-compose-template.yml: Template for creating Docker Compose files. +- [ ] test_environment_diagram.png: Diagram illustrating the architecture of a typical test environment. +- [ ] example_test_script.py: Example Python test script that uses the test environment. diff --git a/skills/test-environment-manager/assets/docker-compose-template.yml b/skills/test-environment-manager/assets/docker-compose-template.yml new file mode 100644 index 0000000..9c29928 --- /dev/null +++ b/skills/test-environment-manager/assets/docker-compose-template.yml @@ -0,0 +1,53 @@ +# docker-compose-template.yml +# Template for defining services and dependencies for test environments. + +version: "3.9" # Specify the Docker Compose file version + +services: + # Database service (e.g., PostgreSQL) + db: + image: postgres:14 # Use a specific PostgreSQL version + container_name: test-db # A descriptive container name + restart: always # Automatically restart the container if it fails + ports: + - "5432:5432" # Map host port 5432 to container port 5432 + environment: + POSTGRES_USER: REPLACE_ME # Replace with your desired username + POSTGRES_PASSWORD: REPLACE_ME # Replace with a strong password + POSTGRES_DB: test_database # The database name + volumes: + - db_data:/var/lib/postgresql/data # Persist data even if the container is stopped + + # Redis service (for caching or messaging) + redis: + image: redis:latest # Use the latest Redis image + container_name: test-redis + restart: always + ports: + - "6379:6379" # Map host port 6379 to container port 6379 + + # Application service (the service you are testing) + app: + build: + context: . # Path to the application's Dockerfile + dockerfile: Dockerfile # Name of the Dockerfile + container_name: test-app + restart: always + ports: + - "8080:8080" # Map host port 8080 to container port 8080 + environment: + DATABASE_URL: "postgresql://REPLACE_ME:REPLACE_ME@db:5432/test_database" # Database connection string + REDIS_URL: "redis://redis:6379" # Redis connection string + YOUR_APP_CONFIG: YOUR_VALUE_HERE # Example: App-specific configuration + depends_on: + - db # Ensure the database is running before starting the application + - redis # Ensure redis is running before starting the application + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"] # Example: Health check endpoint + interval: 30s + timeout: 10s + retries: 3 + +# Define named volumes for data persistence +volumes: + db_data: \ No newline at end of file diff --git a/skills/test-environment-manager/assets/example_test_script.py b/skills/test-environment-manager/assets/example_test_script.py new file mode 100644 index 0000000..39a1c7d --- /dev/null +++ b/skills/test-environment-manager/assets/example_test_script.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 + +""" +Example Python test script that uses the test environment. + +This script demonstrates how to interact with services running in the test environment, +managed by the test-environment-manager plugin. + +It assumes that services like a database or message queue are running within Docker containers. +""" + +import os +import time +import logging + +# Configure logging +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + + +def connect_to_database(host, port, user, password, database): + """ + Attempts to connect to the database. + + Args: + host (str): Database host. + port (int): Database port. + user (str): Database user. + password (str): Database password. + database (str): Database name. + + Returns: + bool: True if connection successful, False otherwise. + """ + try: + import psycopg2 # Example: PostgreSQL + conn = psycopg2.connect(host=host, port=port, user=user, password=password, database=database) + conn.close() + logging.info("Successfully connected to the database.") + return True + except ImportError: + logging.error("psycopg2 (PostgreSQL driver) is not installed. Please install it: pip install psycopg2-binary") + return False + except Exception as e: + logging.error(f"Failed to connect to the database: {e}") + return False + + +def send_message(queue_host, queue_port, message): + """ + Sends a message to a message queue. + + Args: + queue_host (str): Message queue host. + queue_port (int): Message queue port. + message (str): Message to send. + + Returns: + bool: True if message sent successfully, False otherwise. + """ + try: + import redis # Example: Redis + r = redis.Redis(host=queue_host, port=queue_port) + r.publish('test_channel', message) + logging.info(f"Successfully sent message to the queue: {message}") + return True + except ImportError: + logging.error("redis is not installed. Please install it: pip install redis") + return False + except Exception as e: + logging.error(f"Failed to send message to the queue: {e}") + return False + + +def main(): + """ + Main function to demonstrate test environment interaction. + """ + database_host = os.environ.get("DATABASE_HOST", "localhost") + database_port = int(os.environ.get("DATABASE_PORT", "5432")) + database_user = os.environ.get("DATABASE_USER", "test_user") + database_password = os.environ.get("DATABASE_PASSWORD", "test_password") + database_name = os.environ.get("DATABASE_NAME", "test_db") + + queue_host = os.environ.get("QUEUE_HOST", "localhost") + queue_port = int(os.environ.get("QUEUE_PORT", "6379")) + + # Example usage: + if connect_to_database(database_host, database_port, database_user, database_password, database_name): + logging.info("Database connection test passed.") + else: + logging.error("Database connection test failed.") + + if send_message(queue_host, queue_port, "Hello from the test environment!"): + logging.info("Message queue test passed.") + else: + logging.error("Message queue test failed.") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/skills/test-environment-manager/assets/test_environment_diagram.png b/skills/test-environment-manager/assets/test_environment_diagram.png new file mode 100644 index 0000000..86163e0 --- /dev/null +++ b/skills/test-environment-manager/assets/test_environment_diagram.png @@ -0,0 +1,35 @@ +// This is a placeholder image. Replace it with a real diagram illustrating the architecture of a typical test environment. +// +// Consider including the following elements: +// - Client application +// - Test environment manager (the plugin) +// - Docker Compose +// - Testcontainers +// - Databases (e.g., PostgreSQL, MySQL) +// - Message queues (e.g., RabbitMQ, Kafka) +// - Other services (e.g., Redis, Memcached) +// - Environment variables +// - Network connections +// +// The diagram should illustrate how the test environment manager orchestrates these components to create isolated and reproducible test environments. +// +// Example (textual representation, to be visually diagrammed): +// +// [Client Application] --> [Test Environment Manager] +// +// [Test Environment Manager] --> [Docker Compose] --> [Containers (Database, Message Queue, Other Services)] +// +// [Test Environment Manager] --> [Testcontainers] --> [Containers (Database, Message Queue, Other Services)] +// +// [Test Environment Manager] <--> [Environment Variables] +// +// Consider using a diagramming tool like draw.io, Lucidchart, or similar to create the visual representation. +// Ensure the diagram is clear, concise, and easy to understand. +// +// When replacing this placeholder, ensure the filename is "test_environment_diagram.png". +// +// You can use a tool like ImageMagick to optimize the image for web use: +// `convert test_environment_diagram_original.png -strip -interlace Plane -gaussian-blur 0.05 -quality 85% test_environment_diagram.png` +// +// This placeholder image is a 1x1 transparent pixel. It is here to meet the requirement for a .png file. +iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII= \ No newline at end of file diff --git a/skills/test-environment-manager/references/README.md b/skills/test-environment-manager/references/README.md new file mode 100644 index 0000000..1a21e3f --- /dev/null +++ b/skills/test-environment-manager/references/README.md @@ -0,0 +1,9 @@ +# References + +Bundled resources for test-environment-manager skill + +- [ ] docker_compose_best_practices.md: Documentation on best practices for writing Docker Compose files for test environments. +- [ ] testcontainers_integration_guide.md: Guide on integrating Testcontainers for programmatic container management. +- [ ] environment_variable_management.md: Documentation on managing environment variables for test environments. +- [ ] example_docker_compose.yml: Example Docker Compose file for a test environment. +- [ ] troubleshooting.md: Common troubleshooting steps for test environment issues. diff --git a/skills/test-environment-manager/scripts/README.md b/skills/test-environment-manager/scripts/README.md new file mode 100644 index 0000000..8cbdfce --- /dev/null +++ b/skills/test-environment-manager/scripts/README.md @@ -0,0 +1,8 @@ +# Scripts + +Bundled resources for test-environment-manager skill + +- [ ] setup_environment.sh: Script to set up the test environment using Docker Compose and Testcontainers. +- [ ] teardown_environment.sh: Script to tear down the test environment, cleaning up containers and resources. +- [ ] health_check.sh: Script to perform health checks on the services running in the test environment. +- [ ] configure_env_vars.py: Python script to configure environment variables for the test environment.