# Shell Test Scripts

Comprehensive test suite for the Skraak MCP Server.

## Quick Start

```bash
cd shell_scripts

# Run all tests (recommended)
./test_time.sh && ./test_sql.sh && ./test_resources.sh && ./test_prompts.sh && \
./test_write_tools.sh && ./test_import.sh && ./test_bulk_import.sh && ./test_db_state.sh && ./test_sql_limit.sh && ./test_export.sh && ./test_event_log.sh

# Or run individually
./test_time.sh          # Time tool (no DB needed)
./test_sql.sh           # SQL queries
./test_resources.sh     # Schema resources
./test_prompts.sh       # All 6 prompts
./test_write_tools.sh   # Create/update tools (fresh DB)
./test_import.sh        # Import tools validation (fresh DB)
./test_bulk_import.sh   # Bulk import CLI validation
./test_db_state.sh      # Database integrity check
```

## Test Categories

### Read-Only Tests (Safe, Repeatable)

These tests read from the database and don't modify it. Run as many times as you want.

| Script | Description | Default DB |
|--------|-------------|------------|
| `test_time.sh` | Test `get_current_time` tool | None |
| `test_sql.sh` | Test `execute_sql` queries, security | test.duckdb |
| `test_resources.sh` | Test schema resources | test.duckdb |
| `test_prompts.sh` | Test all 6 MCP prompts | test.duckdb |
| `test_db_state.sh` | Verify database integrity | test.duckdb |

### Write Tests (Fresh DB Each Run)

These tests modify the database. They automatically create a fresh copy of the production database in `/tmp` and clean up afterward.

| Script | Description | DB Handling |
|--------|-------------|-------------|
| `test_write_tools.sh` | Test `create_or_update_*` tools | Fresh DB in /tmp |
| `test_import.sh` | Test import tools validation | Fresh DB in /tmp |
| `test_bulk_import.sh` | Test bulk import CLI command | test.duckdb |

## Database Safety

- **Read-only tests**: Use `test.duckdb` (default) or specify path
- **Write tests**: Automatically create fresh DB from `skraak.duckdb``/tmp/skraak_test_$$.duckdb`
- **Never touches production**: Write tests are isolated

## Test Library

All scripts source `test_lib.sh` which provides:

- `send_request` - Send MCP request and get response
- `run_test` - Run test with pass/fail tracking
- `print_summary` - Print test results
- `fresh_test_db` - Create fresh test database
- `cleanup_test_db` - Clean up test database

## Running Individual Tests

```bash
# With default test database
./test_sql.sh

# With specific database
./test_sql.sh /path/to/database.duckdb

# Write tests always use fresh DB (no argument needed)
./test_write_tools.sh
```

## Expected Output

Each test prints:
- Test names with ✓ (pass) or ✗ (fail)
- Summary with counts
- Exit code 0 on success, 1 on failure

```
=== Testing execute_sql Tool ===
✓ Simple SELECT
✓ SELECT with limit
✓ Parameterized query
✓ JOIN query
✓ Aggregate query
✓ CTE query
✓ INSERT blocked (correctly rejected)
✓ SQL injection blocked (correctly rejected)
✓ DELETE blocked (correctly rejected)

=== Summary ===
Tests run: 9
Passed: 9
Failed: 0
```

## See Also

- `TESTING.md` - Comprehensive testing documentation
- `test_lib.sh` - Shared test functions