This document describes the diagnostic testing approach for the MCP Tree-sitter Server project.
The diagnostics suite consists of targeted pytest tests that isolate and document specific issues in the codebase. These tests are designed to:
- Document current behavior with proper pass/fail results
- Isolate failure points to specific functions or modules
- Provide detailed error information and stack traces
- Create a foundation for developing targeted fixes
The diagnostic framework combines standard pytest behavior with enhanced diagnostic capabilities:
- Tests properly pass or fail based on assertions
- Comprehensive diagnostic data is captured for debugging
- Diagnostic information is saved to JSON for further analysis
The Makefile includes several targets for running diagnostics:
# Run all diagnostic tests
make test-diagnostics
# CI-friendly version (won't fail the build on diagnostic issues)
make test-diagnostics-ciFor running diagnostics alongside regular tests:
# Run both regular tests and diagnostics
make test-allimport pytest
from mcp_server_tree_sitter.testing import diagnostic
@pytest.mark.diagnostic # Mark the test as producing diagnostic data
def test_some_feature(diagnostic): # Use the diagnostic fixture
# Add details to diagnostic data
diagnostic.add_detail("key", "value")
try:
# Test your functionality
result = some_functionality()
# Use standard assertions - the test will fail if they don't pass
assert result is not None, "Result should not be None"
except Exception as e:
# Record the error in diagnostic data
diagnostic.add_error("ErrorType", str(e))
# Add any artifacts you want to save
diagnostic.add_artifact("error_artifact", {"error": str(e)})
# Re-raise to fail the test
raiseThe diagnostic fixture provides several methods:
add_detail(key, value): Add a key-value pair to diagnostic detailsadd_error(error_type, message, traceback=None): Add an erroradd_artifact(name, content): Add an artifact (e.g., JSON data)finalize(status="completed"): Mark the diagnostic as complete
The following issues were identified during the diagnostic process and have since been fixed in the current implementation:
list_languages()previously returned empty lists despite languages being available- Language detection through
install_language()worked, but languages didn't appear in available lists
get_ast()previously failed with errors when attempting to build the tree- Core AST parsing functionality is now operational with efficient cursor-based traversal
- Several analysis functions failed with "too many values to unpack (expected 2)"
- Affected
get_symbols(),get_dependencies(), andanalyze_complexity() - These issues were resolved by fixing query captures handling
- Integration with tree-sitter-language-pack is now complete and stable
- All supported languages are correctly recognized and available for analysis
The diagnostic tests generate detailed JSON result files in the diagnostic_results directory with timestamps. These files contain valuable information for debugging:
- Error messages and stack traces
- Current behavior documentation
- Environment and configuration details
- Detailed information about tree-sitter integration
In addition, the test output includes a diagnostic summary:
============================== Diagnostic Summary ==============================
Collected 4 diagnostics, 2 with errors
-------------------------------- Error Details ---------------------------------
- /path/to/test.py::test_function
Error 1: ErrorType: Error message
-
Run the diagnostic tests to verify current issues
make test-diagnostics -
Examine the diagnostic results in the terminal output and the
diagnostic_resultsdirectory -
Review specific error patterns to identify the root cause:
- For unpacking errors, check the query capture processing code
- For AST parsing, examine the tree-sitter integration layer
- For language registry issues, check the initialization sequence
-
Make targeted fixes to address specific issues, using the diagnostic tests to verify repairs
-
After fixes, run both diagnostics and regular tests to ensure no regressions
make test-all
The following priority was used to address the previously identified issues, which have all been resolved:
- ✅ Language Registry Issues - Fixed language listing to enable proper language detection
- ✅ AST Parsing - Fixed core parsing functionality with efficient cursor-based traversal
- ✅ Query Handling - Resolved unpacking errors in query captures to enable analysis tools
- ✅ Incremental Improvements - Core functionality is working correctly and ready for further refinement
All 90 tests are now passing, including the diagnostic tests.
Diagnostics should be run:
- After any significant changes to core tree-sitter integration code
- Before submitting pull requests that touch language or AST handling
- When investigating specific failures in higher-level functionality
- As part of debugging for issues reported by users
For CI environments, the diagnostic tests have special considerations:
The Makefile includes CI-friendly targets that won't fail the build due to known issues:
make test-diagnostics-ci: Runs diagnostics but always returns success
-
Primary CI Pipeline: Use
make testfor regression testing of working functionalitytest: script: - make test
-
Diagnostic Job: Add a separate, optional job for diagnostics
diagnostics: script: - make test-diagnostics-ci artifacts: paths: - diagnostic_results/ allow_failure: true
The pytest-based diagnostic framework offers significant advantages:
- Unified framework: All tests use pytest with consistent behavior
- Clear pass/fail: Tests fail when they should, making issues obvious
- Rich diagnostics: Detailed diagnostic information is still collected
- Standard integration: Works with pytest's fixtures, plugins, and reporting
In the future, we plan to:
- Enhance the diagnostic plugin with more features
- Integrate with CI/CD pipelines for better reporting
- Add automatic visualization of diagnostic data
- Improve the organization of diagnostic tests