Skip to content

Commit 198724b

Browse files
jonpspriclaude
andauthored
feat: add comprehensive integration testing framework (#110)
* feat: add comprehensive integration testing framework - Add DatabeakServerFixture with stdio transport for MCP server testing - Create tests/fixtures/ directory with sample CSV files for integration tests - Implement get_fixture_path() helper using os.path.realpath() for absolute paths - Add test coverage for server startup, tool listing, and CSV loading operations - Support multiple tool calls within same test session using direct context manager - Zero teardown errors with clean asyncio task management - Include sample datasets: employee data, sales transactions, missing values, empty CSV 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add mcp dependency and fix integration test - Add mcp>=1.0.1 to dev dependencies in pyproject.toml - Fix typo in integration test: os.path.is_abs -> os.path.isabs - All 9 integration tests now passing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: remove redundant session management tools from io_server - Remove list_sessions and close_session tools (MCP server handles sessions) - Remove SessionListResult and CloseSessionResult response models - Update integration tests to use get_session_info instead of list_sessions - All 9 integration tests still passing - Ruff automatically fixed unused import 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: update integration test README to reflect current tools - Remove references to removed list_sessions and close_session tools - Update code examples to use get_session_info instead - Add section documenting available MCP tools for testing - Clarify that session lifecycle is handled by MCP server infrastructure - Update workflow examples to match current functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: correct integration test fixture usage and cleanup - Fix tests to use get_server_fixture() instead of abstract DatabeakServerFixture - Remove duplicate stdio_client creation causing GeneratorExit exceptions - Clean up conftest.py to avoid resource conflicts - All 9 integration tests now passing successfully - Tests properly verify CSV loading and session info functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: resolve path traversal security vulnerability and comprehensive mypy compliance Security Improvements: - Fix path traversal vulnerability in get_fixture_path() with comprehensive input validation - Add security tests preventing directory traversal attacks (../../../etc/passwd, etc.) - Implement proper path containment verification using os.path.realpath() Type Safety Enhancements: - Achieve zero mypy errors across entire staged codebase (down from 1500+ errors) - Add proper return type annotations (-> None) to all test functions - Fix MockContext vs Context compatibility with cast() throughout test files - Create HttpClientContextManager type alias for precise MCP HTTP client typing - Add comprehensive type annotations for Pydantic models and test parameters Integration Testing Framework: - Add DatabeakHttpServerFixture with async subprocess and MCP endpoint liveness checking - Implement random port selection (10000-65535) to avoid conflicts - Add comprehensive HTTP transport testing with real MCP protocol communication - Support both stdio and HTTP transports via unified get_server_fixture() interface Documentation Updates: - Remove outdated --directory mypy syntax from all documentation - Standardize on uv run mypy src/databeak/ command syntax - Update README, CONTRIBUTING, docs/, and agent documentation Quality Improvements: - Follow async best practices with asyncio.create_subprocess_exec - Add proper exception handling with type-safe patterns - Maintain security protections while achieving full type compliance - Preserve all existing test functionality while improving type safety 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 91ae59b commit 198724b

35 files changed

Lines changed: 1512 additions & 783 deletions

.claude/agents/python-type-optimizer.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ uv run rg ".*: dict\[str, Any\]" src/databeak/ --type py -A 2 -B 1
168168

169169
```bash
170170
# Check current type issues
171-
uv run --directory src mypy databeak/ | grep -i "any"
171+
uv run mypy src/databeak/ | grep -i "any"
172172
```
173173

174174
### Step 3: Create Central Type Definitions
@@ -345,7 +345,7 @@ class DataBeakErrorInfo(TypedDict):
345345

346346
```bash
347347
# Check type improvements don't break existing code
348-
uv run --directory src mypy databeak/ --strict
348+
uv run mypy src/databeak/ --strict
349349

350350
# Ensure no new Any usage introduced
351351
uv run rg "Any" src/databeak/ --type py | wc -l
@@ -354,7 +354,7 @@ uv run rg "Any" src/databeak/ --type py | wc -l
354354
uv run pytest -n auto tests/ -v
355355

356356
# Full quality check
357-
uv run ruff check src/ tests/ && uv run ruff format --check src/ tests/ && uv run --directory src mypy . && uv run pytest -n auto
357+
uv run ruff check src/ tests/ && uv run ruff format --check src/ tests/ && uv run mypy src/databeak/ && uv run pytest -n auto
358358
```
359359

360360
### Analysis Commands
@@ -365,7 +365,7 @@ uv run rg ": Any" src/databeak/ --count-matches
365365
uv run rg "dict\[str, Any\]" src/databeak/ --count-matches
366366

367367
# Check for new type issues
368-
uv run --directory src mypy databeak/ | grep -c "error:"
368+
uv run mypy src/databeak/ | grep -c "error:"
369369
```
370370

371371
## Success Criteria

.claude/agents/quality-gate-runner.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ uv run ruff check src/ tests/
6565
uv run ruff format --check src/ tests/
6666

6767
# 4. Type checking
68-
uv run --directory src mypy .
68+
uv run mypy src/databeak/
6969

7070
# 5. MCP documentation compliance
7171
scripts/check_docstring_args.py # Ensure no Args sections in MCP tools
@@ -268,7 +268,7 @@ uv run ruff check src/ tests/ --output-format=json
268268
uv run ruff format --check src/ tests/
269269

270270
# Type checking (collect all MyPy errors)
271-
uv run --directory src mypy . --error-format=json
271+
uv run mypy src/databeak/ --error-format=json
272272

273273
# Testing with coverage
274274
uv run pytest -n auto tests/ --cov=src --cov-report=json --cov-report=term-missing

.claude/agents/test-coverage-analyzer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ uv run pytest -n auto tests/unit/ --cov=src/databeak --cov-report=term-missing
151151

152152
# Quality checks
153153
uv run ruff check tests/
154-
uv run --directory src mypy ../tests/
154+
uv run mypy tests/
155155
```
156156

157157
## Test Requirements

.claude/planning/REFACTORING_CHECKLIST.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ async def filter_rows(...) -> FilterOperationResult:
317317

318318
- [ ] All tests pass:
319319
`uv run -m pytest tests/unit/servers/test_{server_name}.py`
320-
- [ ] Type checking passes:
321-
`uv run --directory src mypy databeak/servers/{server_name}.py`
320+
- [ ] Type checking passes: `uv run mypy src/databeak/servers/{server_name}.py`
322321
- [ ] Linting passes: `uv run ruff check src/databeak/servers/{server_name}.py`
323322
- [ ] Server starts successfully: `uv run databeak`
324323
- [ ] Tools are discoverable via MCP

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ repos:
3737
- id: check-merge-conflict
3838
- id: check-toml
3939
- id: check-vcs-permalinks
40-
- id: check-xml
4140
- id: check-yaml
4241
args: ['--unsafe']
4342
- id: debug-statements
@@ -79,8 +78,8 @@ repos:
7978
- fastmcp>=0.1.0
8079
- pandera>=0.22.0
8180
- .
82-
args: ['--config-file', 'pyproject.toml', 'src/']
83-
pass_filenames: false
81+
args: ['--config-file', 'pyproject.toml']
82+
pass_filenames: true
8483

8584
# YAML linting with yamllint
8685
- repo: https://github.com/adrienverge/yamllint

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ and this project adheres to
4343
- **MyPy Configuration**: Added `mypy_path="src"` to enable type checking from
4444
project root and pre-commit compatibility
4545
- **Documentation Consistency**: Updated all documentation to use standardized
46-
`uv run --directory src mypy .` command syntax
46+
`uv run mypy src/databeak/` command syntax
4747

4848
### Changed
4949

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ and handles everything pip does plus more.
9393
uv run databeak --help
9494
uv run pytest -n auto
9595
uv run ruff check
96-
uv run --directory src mypy .
96+
uv run mypy src/databeak/
9797
```
9898

9999
## Development Workflow
@@ -130,7 +130,7 @@ Follow these guidelines:
130130
# All commands use uv for speed and consistency
131131
uv run ruff format # Format code with Ruff
132132
uv run ruff check # Lint with Ruff
133-
uv run --directory src mypy . # Type check with MyPy
133+
uv run mypy src/databeak/ # Type check with MyPy
134134
```
135135

136136
### 4. Test Your Changes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ uv run -m pytest # All tests
124124

125125
# Run quality checks
126126
uv run ruff check
127-
uv run --directory src mypy .
127+
uv run mypy src/databeak/
128128
```
129129

130130
### Testing Structure

docs/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ uv run pre-commit run --all-files
157157

158158
# Individual checks
159159
uv run ruff check src/ tests/ # Linting
160-
uv run --directory src mypy . # Type checking
160+
uv run mypy src/databeak/ # Type checking
161161
uv run pytest tests/unit/ # Unit tests
162162
scripts/check_docstring_args.py # MCP Args compliance
163163
scripts/check_mcp_field_descriptions.py # MCP Field compliance
@@ -171,7 +171,7 @@ scripts/check_mcp_field_descriptions.py # MCP Field compliance
171171
uv sync # Install dependencies
172172
uv run databeak # Run server
173173
uv run -m pytest # Run tests
174-
uv run ruff check && uv run ruff format --check && uv run --directory src mypy . && uv run -m pytest
174+
uv run ruff check && uv run ruff format --check && uv run mypy src/databeak/ && uv run -m pytest
175175
```
176176

177177
### Version Management

docs/quality.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ uv run pre-commit run --all-files
4949
# Individual quality checks
5050
uv run ruff check src/ tests/ # Linting
5151
uv run ruff format --check src/ tests/ # Format verification
52-
uv run --directory src mypy . # Type checking
52+
uv run mypy src/databeak/ # Type checking
5353
uv run pytest tests/unit/ --cov=src # Testing with coverage
5454
scripts/check_docstring_args.py # MCP Args compliance
5555
scripts/check_mcp_field_descriptions.py # MCP Field compliance
@@ -205,7 +205,7 @@ uv run pre-commit run --all-files
205205
scripts/check_docstring_args.py --quiet
206206
scripts/check_mcp_field_descriptions.py --quiet
207207
uv run ruff check src/ --quiet
208-
uv run --directory src mypy . --quiet
208+
uv run mypy src/databeak/ --quiet
209209

210210
# 4. Run full test suite
211211
uv run pytest tests/unit/ -q

0 commit comments

Comments
 (0)