# 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.