-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Problem
Running \�xcelcli powerquery load-to --destination connection-only\ on a query that was already loaded to a worksheet returned \success: true\ but left the ListObject and connection in place — a silent no-op.
Steps to Reproduce
\\powershell
excelcli powerquery create --file Book.xlsx --query PQ1 --mcode 'let s = 1 in s' --destination worksheet
excelcli powerquery load-to --file Book.xlsx --query PQ1 --destination connection-only
excelcli powerquery get-load-config --file Book.xlsx --query PQ1
Returns loadMode: LoadToTable instead of ConnectionOnly
\\
Root Cause
The ConnectionOnly case in PowerQueryCommands.LoadTo.cs assumed the query was already connection-only and returned early without calling UnloadFromDestinations.
Fix
LoadTo now always calls UnloadFromDestinations before applying any new load mode, covering all state transitions in all directions (LoadToTable→ConnectionOnly, LoadToBoth→ConnectionOnly, LoadToTable→DataModel, DataModel→LoadToTable, etc.).
Regression Tests Added
- LoadTo_LoadedToTable_ThenConnectionOnly_RemovesTableAndConnection
- LoadTo_LoadedToTable_ThenLoadToDataModel_RemovesTableAddsDataModel
- LoadTo_LoadedToDataModel_ThenLoadToTable_RemovesDataModelAddsTable
- LoadTo_LoadedToBoth_ThenConnectionOnly_RemovesBothDestinations