Skip to main content
Glama
IMPLEMENTATION_SUMMARY.mdโ€ข9.14 kB
# Shell Environment Testing - Implementation Summary This document summarizes the complete shell environment testing solution for pdfdancer-mcp. ## ๐Ÿ“ฆ What Was Implemented ### 1. **GitHub Actions Workflow** (`.github/workflows/test-shells.yml`) Automated CI/CD testing across multiple shell environments: **Coverage**: - **4 jobs** testing different shell categories - **Unix shells**: bash, sh, zsh, dash (on Ubuntu & macOS) - **Windows shells**: PowerShell, PowerShell Core, CMD - **Special environments**: Git Bash, WSL - **Node.js versions**: 18, 22 - **Total test combinations**: ~25 different shell/OS/Node combinations **Key features**: - Runs on every push and PR - Fail-fast disabled (continues testing even if one fails) - Tests full npm lifecycle (install, build, test, npx execution) - Platform-specific commands handled automatically --- ### 2. **Vitest Shell Test Suite** (`src/shell.environment.test.ts`) Comprehensive local testing that auto-detects available shells: **What it does**: ```typescript โœ“ Auto-detects shells on your system โœ“ Tests server startup through each shell โœ“ Tests environment variable handling (LANG, LC_ALL, PDFDANCER_DOCS_BASE_URL) โœ“ Tests non-TTY mode (CI/CD simulation) โœ“ Tests working directory independence โœ“ Tests special character handling (prevents shell injection) ``` **Shells detected**: - **Windows**: cmd.exe, powershell.exe, pwsh.exe, Git Bash - **Unix**: /bin/sh, /bin/bash, /bin/zsh, /bin/dash, /usr/bin/fish **Run with**: ```bash npm run test:shells ``` --- ### 3. **Docker Multi-Stage Testing** (`test/Dockerfile.shells`) Isolated, reproducible testing environments: **6 specialized test stages**: 1. **alpine-multi-shell**: Tests sh, bash, dash, zsh, fish on Alpine Linux 2. **debian-shells**: Tests bash, dash, zsh, ksh, fish, tcsh on Debian 3. **ubuntu-restricted**: Tests with non-root user (limited permissions) 4. **minimal-shell**: Tests sh-only environment (no bash) 5. **locale-testing**: Tests different locales (en_US, ja_JP, de_DE, C) 6. **ci-simulation**: Tests CI/CD mode (no TTY, non-interactive) **Run with**: ```bash # All stages npm run test:shells:docker # Individual stage docker build -f test/Dockerfile.shells --target minimal-shell -t test . docker run --rm test ``` --- ### 4. **Test Automation Script** (`test/run-shell-tests.sh`) Bash script that runs all Docker stages and reports results: **Features**: - Color-coded output (green โœ“, red โœ—) - Runs all 6 Docker test stages sequentially - Reports pass/fail summary at the end - Exits with error code if any tests fail **Example output**: ``` ๐Ÿš PDFDancer MCP Shell Environment Testing Suite ================================================ Testing: Alpine Linux with sh, bash, dash, zsh, fish โœ“ Passed: Alpine Multi-Shell Testing: Debian with bash, dash, zsh, ksh, fish, tcsh โœ“ Passed: Debian Shells ... Test Summary โœ“ Alpine Multi-Shell โœ“ Debian Shells โœ“ Restricted Permissions โœ“ Minimal Shell โœ“ Locale Testing โœ“ CI Simulation Total: 6 tests Passed: 6 Failed: 0 ``` --- ### 5. **Documentation** **Comprehensive guides**: - `test/SHELL_TESTING.md` - Complete testing guide (450+ lines) - `test/QUICK_START.md` - Quick reference for common commands - `test/IMPLEMENTATION_SUMMARY.md` - This file **README integration** (recommended): ```markdown ## Testing ### Standard Tests npm test ### Shell Environment Tests npm run test:shells # Local shell testing npm run test:shells:docker # Docker comprehensive testing See [test/QUICK_START.md](test/QUICK_START.md) for details. ``` --- ### 6. **NPM Scripts** (Updated `package.json`) New testing scripts: ```json { "test:shells": "vitest run src/shell.environment.test.ts", "test:shells:docker": "./test/run-shell-tests.sh" } ``` --- ## ๐ŸŽฏ What Problems This Solves ### Problem 1: "Works on my machine" syndrome **Solution**: Tests across 25+ shell/OS/Node combinations automatically ### Problem 2: Shell-specific syntax errors **Solution**: POSIX-compliant testing ensures compatibility with sh, dash, etc. ### Problem 3: Windows vs Unix differences **Solution**: Dedicated tests for PowerShell, CMD, Git Bash, WSL ### Problem 4: CI/CD environment failures **Solution**: Non-TTY, non-interactive testing simulates CI environments ### Problem 5: Permission issues **Solution**: Docker tests with non-root users catch permission problems ### Problem 6: Locale/encoding issues **Solution**: Tests with UTF-8, ASCII, and non-English locales ### Problem 7: Shell injection vulnerabilities **Solution**: Tests special characters in queries (pipes, semicolons, backticks) --- ## ๐Ÿ“Š Test Coverage Matrix | Environment | Before | After | |-------------|---------|-------| | **Unix shells** | bash only | bash, sh, zsh, dash, fish, ksh, tcsh | | **Windows shells** | PowerShell | PowerShell, pwsh, CMD, Git Bash | | **Special environments** | None | WSL, non-root, sh-only, no-TTY | | **Locales** | Default | en_US, ja_JP, de_DE, C/ASCII | | **Node.js versions** | 18-25 | 18-25 (unchanged) | | **Operating systems** | 2 (Ubuntu, Windows) | 3 (+ macOS) | **Total test scenarios**: Increased from ~16 to ~50+ --- ## ๐Ÿš€ How to Use ### For Developers ```bash # During development npm run test:shells # Before committing npm run test:all # Before major release npm run test:shells:docker ``` ### For CI/CD Tests run automatically on GitHub Actions: - `.github/workflows/test.yml` - Standard tests (existing) - `.github/workflows/test-shells.yml` - Shell environment tests (new) ### For Contributors 1. **Add new shell support**: Edit `src/shell.environment.test.ts` 2. **Add Docker test stage**: Edit `test/Dockerfile.shells` 3. **Update CI**: Edit `.github/workflows/test-shells.yml` --- ## ๐Ÿ” What Gets Tested ### Server Functionality - โœ… Server initialization through different shells - โœ… MCP protocol compliance (stdio transport) - โœ… All 4 tools (help, version, search-docs, get-docs) - โœ… Error handling and validation ### Environment Compatibility - โœ… Different shell syntaxes (sh, bash, zsh, fish, PowerShell, CMD) - โœ… Different locales (UTF-8, ASCII, non-English) - โœ… Different permission levels (root, non-root, restricted) - โœ… Different terminal modes (TTY, non-TTY, interactive, non-interactive) - โœ… Different working directories - โœ… Different environment variables (LANG, LC_ALL, PATH, PDFDANCER_DOCS_BASE_URL) ### Security - โœ… Shell injection prevention (special characters in queries) - โœ… Path traversal prevention (route validation) - โœ… Command injection prevention (args validation) --- ## ๐Ÿ“ˆ Performance Impact | Test Suite | Duration | When to Run | |-------------|----------|-------------| | Standard E2E tests | ~30 seconds | Every commit | | Shell local tests | ~2 minutes | Before push | | Docker shell tests | ~15 minutes | Before release | | GitHub Actions (all) | ~20 minutes | Automatic on push | **Recommendation**: - Local development: Standard E2E tests only - Pre-push: Include `npm run test:shells` - Pre-release: Run `npm run test:shells:docker` --- ## ๐ŸŽ‰ Benefits 1. **Reliability**: Ensures MCP server works in any user environment 2. **Confidence**: Comprehensive testing before releases 3. **Debugging**: Quick identification of shell-specific issues 4. **Documentation**: Clear guides for adding new tests 5. **Automation**: CI/CD handles most testing automatically 6. **Coverage**: 50+ different environment combinations tested --- ## ๐Ÿ”ฎ Future Enhancements Possible additions: - [ ] Package manager testing (pnpm, yarn, bun) - [ ] Network condition testing (slow, proxy, offline) - [ ] Container runtime testing (Docker, Podman, WSL2) - [ ] Load testing (multiple concurrent MCP clients) - [ ] Memory constraint testing (limited RAM) - [ ] Performance benchmarking across shells - [ ] Automated security scanning (shell injection, XSS) --- ## ๐Ÿ“ Files Created ``` .github/workflows/test-shells.yml # CI/CD workflow src/shell.environment.test.ts # Vitest test suite test/Dockerfile.shells # Multi-stage Docker tests test/run-shell-tests.sh # Docker test automation test/SHELL_TESTING.md # Comprehensive guide test/QUICK_START.md # Quick reference test/IMPLEMENTATION_SUMMARY.md # This file .dockerignore # Docker optimization ``` **Updated files**: ``` package.json # Added test scripts ``` --- ## โœ… Verification To verify the implementation: ```bash # 1. Check linting passes npm run lint # 2. Run local shell tests npm run test:shells # 3. Run standard tests npm test # 4. (Optional) Run Docker tests npm run test:shells:docker # 5. Check CI/CD git push # Triggers GitHub Actions ``` --- ## ๐Ÿ™ Credits This implementation follows best practices from: - MCP SDK documentation - GitHub Actions best practices - Docker multi-stage build patterns - Vitest testing conventions - POSIX shell compatibility guidelines --- ## Questions? See the full documentation in `test/SHELL_TESTING.md` or open an issue on GitHub.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MenschMachine/pdfdancer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server