Files
T
Stefan Broenner 29eb536e49 fix: CodeQL useless-assignment violation in ExcelRangeTool.SetStyleAsync + scripts cleanup (#120)
* fix: Remove hardc-assignment-to-local violation - Changed from hardcoded anonymous object to returning actual result - Ensures operation failures are properly reported to MCP clients

* docs: cleanup temporary files and add documentation standards

- Added .github/instructions/documentation-structure.instructions.md
  * Comprehensive guide for where to put documentation
  * Prevents future accumulation of temporary files
  * Auto-applies to all .md files via GitHub Copilot

- Updated bug-fixing-checklist.instructions.md
  * Removed requirement for BUG-FIX-*.md, TESTS-*.md, DOCS-*.md
  * Use comprehensive PR descriptions instead
  * Prevents clutter from temporary summary files

- Updated critical-rules.instructions.md
  * Rule 13: Use PR descriptions instead of summary docs
  * Updated example to reflect new standard

- Updated copilot-instructions.md
  * Added documentation-structure to path-specific instructions
  * Added documentation task to common tasks list

- Removed 5 temporary files (41 KB total):
  * CODEQL-FIXES-SUMMARY.md (info in git history)
  * CODEQL-SUPPRESSION-VERIFICATION.md (verification complete)
  * docs/PR_SUMMARY.md (merged into AZURE_SELFHOSTED_RUNNER_SETUP.md)
  * vscode-extension/SUMMARY.md (info already in README.md)
  * tests/.../VBA-TEST-EXCLUSION-SUMMARY.md (merged into tests/README.md)

- Enhanced permanent documentation:
  * docs/AZURE_SELFHOSTED_RUNNER_SETUP.md - Added GitHub CLI token generation troubleshooting
  * tests/README.md - Added comprehensive VBA testing section with rationale and setup

- Added scripts/cleanup-docs.ps1
  * Automated cleanup script for future use
  * Verifies extraction complete before deletion
  * Validates cleanup success

All information preserved in permanent locations or git history.
Prevents future accumulation of temporary documentation files.

* chore: Remove unused scripts - keep only pre-commit dependencies

Removed:
- fix-mcp-exceptions.ps1 (one-time fix script)
- fix-success-flags.ps1 (one-time fix script)
- verify-codeql-suppressions.ps1 (verification helper, not needed for commits)
- cleanup-docs.ps1 (unused)

Kept (required for pre-commit hook):
- pre-commit.ps1 (main hook)
- check-com-leaks.ps1 (COM leak detection)
- audit-core-coverage.ps1 (coverage enforcement)
- check-success-flag.ps1 (Rule 0 validation)

---------

Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm>
2025-11-04 06:33:59 +00:00

5.2 KiB

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.md for 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:

Test Architecture

tests/
├── ExcelMcp.Core.Tests/      # Core business logic (Unit + Integration)
├── ExcelMcp.McpServer.Tests/ # MCP protocol layer (Unit + Integration)
├── ExcelMcp.CLI.Tests/        # CLI wrapper (Unit + Integration)
└── ExcelMcp.ComInterop.Tests/ # COM utilities (Unit + OnDemand)

Test Categories

Category Speed Requirements Run By Default
Unit Fast (2-5 sec) None ✅ Yes (CI/CD)
Integration Medium (10-20 min) Excel + Windows ✅ Yes (local)
OnDemand Slow (3-5 min) Excel + Windows ❌ No (explicit 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"

VBA Testing

Why VBA Tests Are Excluded by Default

VBA tests are excluded from normal test runs because:

  1. Stable codebase - VBA features are mature with minimal changes
  2. Performance - Excluding VBA tests makes integration tests ~25% faster (10-15 min vs 15-20 min)
  3. Special requirements - VBA tests require VBA trust enabled in Excel settings
  4. 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