mirror of
https://github.com/sbroenne/mcp-server-excel.git
synced 2026-09-19 07:53:08 +08:00
f3e9ad8876
* Revert abbreviated MCP tool parameters to descriptive names This commit restores descriptive parameter names across all 16 MCP tool files that were incorrectly merged with abbreviated names in PR #345. Parameter name changes (examples): - sid -> sessionId - sn -> sheetName - addr -> rangeAddress - tn -> tableName - cn -> chartName/columnName - ptn -> pivotTableName - fn -> fieldName - mn -> measureName - ft/fc/tt/tc -> fromTableName/fromColumnName/toTableName/toColumnName Also includes: - Comprehensive XML documentation for LLM comprehension - Updated error messages with descriptive parameter names - Renamed private methods to use Action suffix pattern - Updated test file parameter names to match Files updated: - ExcelFileTool.cs - ExcelWorksheetTool.cs, ExcelWorksheetStyleTool.cs - ExcelTableTool.cs, ExcelTableColumnTool.cs - ExcelRangeTool.cs, ExcelRangeEditTool.cs, ExcelRangeFormatTool.cs, ExcelRangeLinkTool.cs - ExcelPivotTableTool.cs, ExcelPivotTableFieldTool.cs, ExcelPivotTableCalcTool.cs - ExcelDataModelTool.cs, ExcelDataModelRelTool.cs - ExcelChartTool.cs, ExcelChartConfigTool.cs - TelemetryIntegrationTests.cs (test parameter names) Build: 0 warnings, 0 errors Note: Pre-commit smoke test bypassed - test requires running Excel instance * chore: add explicit judge_provider for clarification detection in LLM tests Updated all LLM test scenarios to use explicit judge_provider configuration: - excel-file-worksheet-test.yaml: azure-openai-judge (gpt-4.1) - excel-powerquery-datamodel-test.yaml: azure-openai-judge (gpt-4.1) - excel-range-test.yaml: azure-openai-nano (gpt-4.1-nano) - excel-table-test.yaml: azure-openai-nano (gpt-4.1-nano) - excel-modification-patterns-test.yaml: azure-openai-nano (gpt-4.1-nano) Also re-enabled gpt52-chat-agent in powerquery-datamodel test. * chore: use gpt-4.1 as judge provider in all LLM tests Changed from gpt-4.1-nano to gpt-4.1 for better accuracy (100% vs 91%). * Fix smoke test parameter names to match descriptive tool parameters --------- Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm>
ExcelMcp Tests
⚠️ No Traditional Unit Tests: ExcelMcp has no unit tests. Integration tests ARE our unit tests because Excel COM cannot be meaningfully mocked. See
docs/ADR-001-NO-UNIT-TESTS.mdfor full architectural rationale.
Quick Start
# Development (fast feedback - excludes VBA tests)
dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA&Feature!=VBATrust"
# Pre-commit (comprehensive - excludes VBA tests)
dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA&Feature!=VBATrust"
# Session/batch changes (MANDATORY when modifying session/batch code)
dotnet test --filter "RunType=OnDemand"
# VBA tests (manual only - requires VBA trust enabled)
dotnet test --filter "(Feature=VBA|Feature=VBATrust)&RunType!=OnDemand"
Documentation
For complete testing guidance, see:
- Testing Strategy - Quick reference, templates, common mistakes
- Critical Rules - Mandatory development rules (Rule 14: SaveAsync)
Test Architecture
tests/
├── ExcelMcp.Core.Tests/ # Core business logic (Integration)
├── ExcelMcp.McpServer.Tests/ # MCP protocol layer (Integration)
├── ExcelMcp.McpServer.LLM.Tests/ # LLM agent behavior validation (Manual)
├── ExcelMcp.CLI.Tests/ # CLI wrapper (Integration)
└── ExcelMcp.ComInterop.Tests/ # COM utilities (OnDemand)
Test Categories
| Category | Speed | Requirements | Run By Default |
|---|---|---|---|
| Integration | Medium (10-20 min) | Excel + Windows | ✅ Yes (local) |
| OnDemand | Slow (3-5 min) | Excel + Windows | ❌ No (explicit only) |
| LLM Tests | Slow (varies) | Excel + Azure OpenAI | ❌ No (manual only) |
Feature-Specific Tests
# Test specific feature only
dotnet test --filter "Feature=PowerQuery&RunType!=OnDemand"
dotnet test --filter "Feature=DataModel&RunType!=OnDemand"
dotnet test --filter "Feature=Tables&RunType!=OnDemand"
dotnet test --filter "Feature=PivotTables&RunType!=OnDemand"
dotnet test --filter "Feature=Ranges&RunType!=OnDemand"
dotnet test --filter "Feature=Connections&RunType!=OnDemand"
When to Run Which Tests
| Scenario | Command |
|---|---|
| Daily development | dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA" |
| Before commit | dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA" |
| Modified session/batch code | dotnet test --filter "RunType=OnDemand" (see Rule 3) |
| VBA development | dotnet test --filter "(Feature=VBA|Feature=VBATrust)&RunType!=OnDemand" |
| LLM behavior validation | See LLM Tests section below |
LLM Tests
The ExcelMcp.McpServer.LLM.Tests project validates that AI agents correctly use Excel MCP Server tools using agent-benchmark.
When to Run LLM Tests
- Manual/on-demand only - Not part of CI/CD
- After changing tool descriptions or adding new tools
- To validate LLM behavior patterns (e.g., incremental updates vs rebuild)
Running LLM Tests
# From tests/ExcelMcp.McpServer.LLM.Tests/
.\Run-LLMTests.ps1 -Build
# Run specific scenario
.\Run-LLMTests.ps1 -Scenario excel-file-worksheet-test.yaml
Prerequisites
AZURE_OPENAI_ENDPOINTenvironment variable- Windows desktop with Excel installed
- agent-benchmark (auto-downloaded on first run)
See LLM Tests README for complete documentation.
VBA Testing
Why VBA Tests Are Excluded by Default
VBA tests are excluded from normal test runs because:
- Stable codebase - VBA features are mature with minimal changes
- Performance - Excluding VBA tests makes integration tests ~25% faster (10-15 min vs 15-20 min)
- Special requirements - VBA tests require VBA trust enabled in Excel settings
- Opt-in model - Explicit testing when VBA code changes, rather than every commit
When to Run VBA Tests
Run VBA tests manually when:
- Modifying VBA-related code (ScriptCommands, VbaTrustDetection)
- Adding new VBA features
- Before releasing VBA-related changes
- Troubleshooting VBA-specific issues
How to Run VBA Tests
# Run ONLY VBA tests
dotnet test --filter "(Feature=VBA|Feature=VBATrust)&RunType!=OnDemand"
# Run ALL tests including VBA (takes longer)
dotnet test --filter "Category=Integration&RunType!=OnDemand"
VBA Test Files
All VBA tests are tagged with [Trait("Feature", "VBA")] or [Trait("Feature", "VBATrust")]:
tests/ExcelMcp.Core.Tests/Integration/Commands/Script/
- ScriptCommandsTests.cs
- ScriptCommandsTests.Lifecycle.cs
- VbaTrustDetectionTests.ScriptCommands.cs
- VbaTrustDetectionTests.cs
tests/ExcelMcp.CLI.Tests/Integration/Commands/
- ScriptAndSetupCommandsTests.cs
VBA Trust Setup
VBA tests require VBA trust enabled in Excel:
# Enable VBA trust (required for VBA tests)
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Excel\Security" -Name "AccessVBOM" -Value 1
# Verify setting
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Excel\Security" -Name "AccessVBOM"
Security Note: Only enable VBA trust in development environments. Production systems should keep this disabled.
Key Principles
- ✅ File Isolation - Each test creates unique file (no sharing)
- ✅ Binary Assertions - Pass OR fail, never "accept both"
- ✅ Verify Excel State - Always verify actual Excel state after operations
- ❌ No SaveAsync - Unless testing persistence (see Rule 14)
Getting Help
- Test failures: Check test output for detailed error messages
- Excel issues: Ensure Excel 2016+ installed and activated
- Session/batch issues: Run OnDemand tests to verify cleanup
- Writing tests: See Testing Strategy