This guide describes the comprehensive test suite created for the enhanced apply_diff tool. The tests ensure reliability, performance, and backward compatibility of all new features.
-
ValidationHierarchy Tests (
validation-hierarchy.test.ts)- Tests all three validation levels (strict, permissive, fuzzy)
- Verifies early termination for performance
- Tests line hint disambiguation
- Validates error handling
-
StructuralValidator Tests (
structural-validator.test.ts)- Tests delimiter balance detection (braces, parentheses, brackets)
- Validates quote and comment handling
- Tests JSON structure validation
- Ensures warnings don't block changes
-
Cache and Performance Tests (
cache-performance.test.ts)- Validates file content caching
- Tests partial success mode
- Measures early termination performance
- Tests performance tracking with StructuredLogger
-
Backward Compatibility Tests (
backward-compatibility.test.ts)- Ensures old parameter names (originalContent/newContent) still work
- Tests mixed parameter usage
- Validates existing behavior preservation
- Tests error handling consistency
-
Edge Cases Tests (
edge-cases.test.ts)- Empty file handling
- Single line files
- Files without trailing newlines
- Very long lines (1000+ characters)
- Unicode and special characters
- Different line endings (CRLF vs LF)
-
Full Workflow Tests (
integration.test.ts)- Complete TypeScript refactoring scenarios
- JSON configuration updates
- Multi-file refactoring workflows
- Error recovery with partial success
npm installYou MUST rebuild and reload the extension after ANY code changes:
npm run compile
vsce package
code --install-extension vscode-mcp-server-0.0.4.vsix --force
code -r .This is MANDATORY because:
- VS Code extensions run in a separate host process
- Code changes are NOT reflected until the extension is repackaged
- Running tests without rebuilding will test the OLD code
npm testnpm test -- --grep "ValidationHierarchy Tests"- Open the test file in VS Code
- Set breakpoints as needed
- Press F5 to start debugging
- Select "Extension Tests" configuration
// Create test file
await vscode.workspace.fs.writeFile(testFileUri, Buffer.from(content));
// Read and verify
const result = await vscode.workspace.fs.readFile(testFileUri);
const text = Buffer.from(result).toString('utf8');await vscode.commands.executeCommand('mcp.applyDiff', {
filePath: 'test.ts',
diffs: [{ /* diff config */ }]
});try {
await vscode.commands.executeCommand('mcp.applyDiff', { /* ... */ });
assert.fail('Should have thrown error');
} catch (error) {
assert.ok(error instanceof Error);
assert.ok(error.message.includes('expected text'));
}- ✅ Exact match at hint
- ✅ Exact match with radius search
- ✅ Whitespace normalization
- ✅ Case-insensitive matching
- ✅ Similarity matching (70%, 80%, 90%)
- ✅ Contextual matching
- ✅ File content caching (5-second TTL)
- ✅ Early termination (95% confidence)
- ✅ Partial success mode
- ✅ Performance metrics tracking
- ✅ Progressive error disclosure
- ✅ Diagnostic information
- ✅ Match confidence reporting
- ✅ Structural warnings
- ✅ Empty files
- ✅ Large files
- ✅ Unicode content
- ✅ Special characters
- ✅ Line ending variations
- ✅ Concurrent operations
- Isolation: Each test should be independent and not rely on other tests
- Cleanup: Always clean up test files in
after()hooks - Assertions: Use clear, descriptive assertion messages
- Performance: Keep individual tests under 10 seconds
- Naming: Use descriptive test names that explain what is being tested
-
Timeout Errors
- Increase timeout in Mocha configuration
- Check for async operations not being awaited
-
File Access Errors
- Ensure test files are cleaned up properly
- Check file permissions
-
Command Not Found
- Verify extension is activated
- Check command registration in extension.ts
- Code Coverage: Add nyc for code coverage reporting
- Performance Benchmarks: Create dedicated performance test suite
- Stress Testing: Add tests with very large files (10MB+)
- Concurrent Testing: More comprehensive concurrent operation tests
- Language-Specific Tests: Add tests for more file types (Python, Java, etc.)