Skip to content

fix: PowerQuery load-to state transitions, get-load-config, CLI banner#500

Merged
sbroenne merged 1 commit intomainfrom
fix/powerquery-load-state-transitions
Feb 22, 2026
Merged

fix: PowerQuery load-to state transitions, get-load-config, CLI banner#500
sbroenne merged 1 commit intomainfrom
fix/powerquery-load-state-transitions

Conversation

@sbroenne
Copy link
Owner

Bug Fixes

Fixes three related bugs in PowerQuery and CLI.


Bug #1 — CLI banner written to stdout (#497)

Problem: The startup banner was printed to stdout, polluting JSON output. \�xcelcli powerquery list ... | ConvertFrom-Json\ would fail.

Root Cause: \Console.IsOutputRedirected\ is \ alse\ in the VS Code integrated terminal, bypassing the existing redirect guard.

Fix: \RenderHeader()\ now creates a dedicated stderr-targeted \AnsiConsole\ instance.

File: \src/ExcelMcp.CLI/Program.cs\


Bug #2 — \load-to connection-only\ was a no-op on loaded queries (#498)

Problem: Calling \powerquery load-to --destination connection-only\ on a query already loaded to a worksheet returned \success: true\ but left the ListObject and connection in place.

Root Cause: The \ConnectionOnly\ case returned early without calling \UnloadFromDestinations.

Fix: \LoadTo\ now always calls \UnloadFromDestinations\ before applying any new load mode, covering all state transitions in all directions.

File: \src/ExcelMcp.Core/Commands/PowerQuery/PowerQueryCommands.LoadTo.cs\

Regression tests added (4):

  • \LoadTo_LoadedToTable_ThenConnectionOnly_RemovesTableAndConnection\
  • \LoadTo_LoadedToTable_ThenLoadToDataModel_RemovesTableAddsDataModel\
  • \LoadTo_LoadedToDataModel_ThenLoadToTable_RemovesDataModelAddsTable\
  • \LoadTo_LoadedToBoth_ThenConnectionOnly_RemovesBothDestinations\

Bug #3 — \get-load-config\ threw COMException 0x800A03EC for connection-only queries (#499)

Problem: \GetLoadConfig\ threw a raw COMException for queries in connection-only mode (which have no ListObject/QueryTable).

Root Cause: \GetLoadConfig\ accessed .QueryTable\ without guarding against the COM exception that fires when no QueryTable exists. Every other .QueryTable\ access site already had this guard; this was the one missed location.

Fix: Added the same \catch (COMException ex) when (ex.HResult == unchecked((int)0x800A03EC))\ guard.

File: \src/ExcelMcp.Core/Commands/PowerQuery/PowerQueryCommands.Lifecycle.cs\


Test Coverage

  • Full PowerQuery test suite: 103 passed, 0 failed (\Feature=PowerQuery&RunType!=OnDemand)
  • 4 new state-transition regression tests covering all previously untested load-mode directions
  • All pre-commit checks passed (COM leaks, success flag, CLI workflow, MCP smoke test)

Backwards Compatibility

✅ Fully backwards compatible — no interface changes, no parameter changes.

Fixes three bugs in PowerQuery and CLI:

1. CLI banner to stdout (#497)
   - RenderHeader() created an AnsiConsole targeting stderr so JSON
     output on stdout is never polluted by the banner.
   - Console.IsOutputRedirected is false in VS Code integrated terminal,
     so the previous redirect guard did not protect piped usage.

2. load-to connection-only no-op on loaded queries (#498)
   - LoadTo now calls UnloadFromDestinations before applying any new
     load mode, covering all state transitions in all directions:
     LoadToTable→ConnectionOnly, LoadToBoth→ConnectionOnly,
     LoadToTable→DataModel, DataModel→LoadToTable, etc.
   - Added 4 regression tests covering each previously missing direction.

3. get-load-config threw 0x800A03EC for connection-only queries (#499)
   - Added missing COMException guard on .QueryTable access inside
     GetLoadConfig. Every other .QueryTable access site already had
     this guard; GetLoadConfig was the one missed location.
@github-actions
Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant