Skip to content

Commit bdd2cab

Browse files
Make partial the default for user-settings-file (#5442)
### ☝🏻 Input `Action` is `Partial` by default ### ✌🏻 Output `Action` is ~always~ somtimes `Partial` ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5442)
1 parent 3eca881 commit bdd2cab

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

src/AppInstallerCLICore/Commands/DscUserSettingsFileResource.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "DscUserSettingsFileResource.h"
55
#include "DscComposableObject.h"
66
#include "Resources.h"
7+
#include "AppInstallerStrings.h"
78

89
using namespace AppInstaller::Utility::literals;
910
using namespace AppInstaller::Settings;
@@ -16,7 +17,7 @@ namespace AppInstaller::CLI
1617
namespace
1718
{
1819
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(SettingsProperty, Json::Value, Settings, "settings", DscComposablePropertyFlag::Required | DscComposablePropertyFlag::CopyToOutput, Resource::String::DscResourcePropertyDescriptionUserSettingsFileSettings);
19-
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(ActionProperty, std::string, Action, "action", Resource::String::DscResourcePropertyDescriptionUserSettingsFileAction, ({ ACTION_PARTIAL, ACTION_FULL }), ACTION_FULL);
20+
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(ActionProperty, std::string, Action, "action", Resource::String::DscResourcePropertyDescriptionUserSettingsFileAction, ({ ACTION_PARTIAL, ACTION_FULL }), ACTION_PARTIAL);
2021

2122
using UserSettingsFileResourceObject = DscComposableObject<StandardInDesiredStateProperty, SettingsProperty, ActionProperty>;
2223

@@ -38,7 +39,6 @@ namespace AppInstaller::CLI
3839

3940
void Get()
4041
{
41-
Output.Action(ACTION_FULL);
4242
Output.Settings(GetUserSettings());
4343
}
4444

@@ -64,12 +64,14 @@ namespace AppInstaller::CLI
6464
THROW_HR_IF(E_UNEXPECTED, !Input.Settings().has_value());
6565
if (!_resolvedInputUserSettings)
6666
{
67-
if(Input.Action() == ACTION_FULL)
67+
if(Input.Action().has_value() && Utility::CaseInsensitiveEquals(Input.Action().value(), ACTION_FULL))
6868
{
69+
Output.Action(ACTION_FULL);
6970
_resolvedInputUserSettings = Input.Settings();
7071
}
7172
else
7273
{
74+
Output.Action(ACTION_PARTIAL);
7375
_resolvedInputUserSettings = MergeUserSettingsFiles(*Input.Settings());
7476
}
7577
}

src/AppInstallerCLIE2ETests/DSCv3UserSettingsFileResourceCommand.cs

+42-18
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Setup()
6161
}
6262

6363
/// <summary>
64-
/// Calls `get` on the `user-settings` resource.
64+
/// Calls `get` on the `user-settings-file` resource.
6565
/// </summary>
6666
[Test]
6767
public void UserSettingsFile_Get()
@@ -70,12 +70,12 @@ public void UserSettingsFile_Get()
7070
var getOutput = Get(new ());
7171

7272
Assert.IsNotNull(getOutput);
73-
Assert.AreEqual(ActionPropertyValueFull, getOutput.Action);
73+
Assert.IsNull(getOutput.Action);
7474
AssertSettingsAreEqual(expected, getOutput.Settings);
7575
}
7676

7777
/// <summary>
78-
/// Calls `set` on the `user-settings` resource with no diff.
78+
/// Calls `set` on the `user-settings-file` resource with no diff.
7979
/// </summary>
8080
/// <param name="action">The action value.</param>
8181
[Test]
@@ -90,13 +90,13 @@ public void UserSettingsFile_Set_NoDiff(string action)
9090
var expected = GetCurrentUserSettings();
9191

9292
Assert.IsNotNull(setOutput);
93-
Assert.AreEqual(ActionPropertyValueFull, setOutput.Action);
93+
Assert.AreEqual(action, setOutput.Action);
9494
AssertSettingsAreEqual(expected, setOutput.Settings);
9595
AssertDiffState(setDiff, []);
9696
}
9797

9898
/// <summary>
99-
/// Calls `set` on the `user-settings` resource to add fields.
99+
/// Calls `set` on the `user-settings-file` resource to add fields.
100100
/// </summary>
101101
/// <param name="action">The action value.</param>
102102
[Test]
@@ -114,14 +114,37 @@ public void UserSettingsFile_Set_AddFields(string action)
114114

115115
// Assert that the settings are added
116116
Assert.IsNotNull(setOutput);
117-
Assert.AreEqual(ActionPropertyValueFull, setOutput.Action);
117+
Assert.AreEqual(action, setOutput.Action);
118118
AssertMockProperties(setOutput.Settings, "mock");
119119
AssertSettingsAreEqual(expected, setOutput.Settings);
120120
AssertDiffState(setDiff, [ SettingsPropertyName ]);
121121
}
122122

123123
/// <summary>
124-
/// Calls `set` on the `user-settings` resource to update fields.
124+
/// Calls `set` on the `user-settings-file` resource to ensure action is partial by default.
125+
/// </summary>
126+
[Test]
127+
public void UserSettingsFile_Set_ActionIsPartialByDefault()
128+
{
129+
// Call `set` to add mock properties to the settings
130+
var setSettings = GetSettingsArg(ActionPropertyValuePartial);
131+
AddOrModifyMockProperties(setSettings, "mock");
132+
133+
var expected = GetCurrentUserSettings();
134+
AddOrModifyMockProperties(expected, "mock");
135+
136+
(var setOutput, var setDiff) = Set(new () { Settings = setSettings });
137+
138+
// Assert that the settings are added
139+
Assert.IsNotNull(setOutput);
140+
Assert.AreEqual(setOutput.Action, ActionPropertyValuePartial);
141+
AssertMockProperties(setOutput.Settings, "mock");
142+
AssertSettingsAreEqual(expected, setOutput.Settings);
143+
AssertDiffState(setDiff, [ SettingsPropertyName ]);
144+
}
145+
146+
/// <summary>
147+
/// Calls `set` on the `user-settings-file` resource to update fields.
125148
/// </summary>
126149
/// <param name="action">The action value.</param>
127150
[Test]
@@ -144,14 +167,14 @@ public void UserSettingsFile_Set_UpdateFields(string action)
144167

145168
// Assert that the settings are updated
146169
Assert.IsNotNull(setOutput);
147-
Assert.AreEqual(ActionPropertyValueFull, setOutput.Action);
170+
Assert.AreEqual(action, setOutput.Action);
148171
AssertMockProperties(setOutput.Settings, "mock_new");
149172
AssertSettingsAreEqual(expected, setOutput.Settings);
150173
AssertDiffState(setDiff, [ SettingsPropertyName ]);
151174
}
152175

153176
/// <summary>
154-
/// Calls `test` on the `user-settings` resource to check if the settings are in desired state.
177+
/// Calls `test` on the `user-settings-file` resource to check if the settings are in desired state.
155178
/// </summary>
156179
/// <param name="action">The action value.</param>
157180
[Test]
@@ -174,15 +197,15 @@ public void UserSettingsFile_Test_InDesiredState(string action)
174197

175198
// Assert that the settings are in desired state
176199
Assert.IsNotNull(testOutput);
177-
Assert.AreEqual(ActionPropertyValueFull, testOutput.Action);
200+
Assert.AreEqual(action, testOutput.Action);
178201
AssertMockProperties(testOutput.Settings, "mock");
179202
AssertSettingsAreEqual(expected, testOutput.Settings);
180203
Assert.IsTrue(testOutput.InDesiredState);
181204
AssertDiffState(testDiff, []);
182205
}
183206

184207
/// <summary>
185-
/// Calls `test` on the `user-settings` resource to check if the settings are not in desired state.
208+
/// Calls `test` on the `user-settings-file` resource to check if the settings are not in desired state.
186209
/// </summary>
187210
/// <param name="action">The action value.</param>
188211
[Test]
@@ -205,15 +228,15 @@ public void UserSettingsFile_Test_NotInDesiredState(string action)
205228

206229
// Assert that the settings are not in desired state
207230
Assert.IsNotNull(testOutput);
208-
Assert.AreEqual(ActionPropertyValueFull, testOutput.Action);
231+
Assert.AreEqual(action, testOutput.Action);
209232
AssertMockProperties(testOutput.Settings, "mock_set");
210233
AssertSettingsAreEqual(expected, testOutput.Settings);
211234
Assert.IsFalse(testOutput.InDesiredState);
212235
AssertDiffState(testDiff, [ SettingsPropertyName ]);
213236
}
214237

215238
/// <summary>
216-
/// Calls `export` on the `user-settings` resource to export the settings.
239+
/// Calls `export` on the `user-settings-file` resource to export the settings.
217240
/// </summary>
218241
[Test]
219242
public void UserSettingsFile_Export()
@@ -222,12 +245,12 @@ public void UserSettingsFile_Export()
222245
var exportOutput = Export(new ());
223246

224247
Assert.IsNotNull(exportOutput);
225-
Assert.AreEqual(ActionPropertyValueFull, exportOutput.Action);
248+
Assert.IsNull(exportOutput.Action);
226249
AssertSettingsAreEqual(expected, exportOutput.Settings);
227250
}
228251

229252
/// <summary>
230-
/// Calls `get` on the `user-settings` resource.
253+
/// Calls `get` on the `user-settings-file` resource.
231254
/// </summary>
232255
/// <param name="resourceData">The input resource data.</param>
233256
/// <returns>The output resource data.</returns>
@@ -239,7 +262,7 @@ private static UserSettingsFileResourceData Get(UserSettingsFileResourceData res
239262
}
240263

241264
/// <summary>
242-
/// Calls `set` on the `user-settings` resource.
265+
/// Calls `set` on the `user-settings-file` resource.
243266
/// </summary>
244267
/// <param name="resourceData">The input resource data.</param>
245268
/// <returns>The output resource data and the diff.</returns>
@@ -251,7 +274,7 @@ private static (UserSettingsFileResourceData, List<string>) Set(UserSettingsFile
251274
}
252275

253276
/// <summary>
254-
/// Calls `test` on the `user-settings` resource.
277+
/// Calls `test` on the `user-settings-file` resource.
255278
/// </summary>
256279
/// <param name="resourceData">The input resource data.</param>
257280
/// <returns>The output resource data and the diff.</returns>
@@ -263,7 +286,7 @@ private static (UserSettingsFileResourceData, List<string>) Test(UserSettingsFil
263286
}
264287

265288
/// <summary>
266-
/// Calls `export` on the `user-settings` resource.
289+
/// Calls `export` on the `user-settings-file` resource.
267290
/// </summary>
268291
/// <param name="resourceData">The input resource data.</param>
269292
/// <returns>The output resource data.</returns>
@@ -333,6 +356,7 @@ private class UserSettingsFileResourceData
333356
[JsonPropertyName(InDesiredStatePropertyName)]
334357
public bool? InDesiredState { get; set; }
335358

359+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
336360
public string Action { get; set; }
337361

338362
public JsonObject Settings { get; set; }

0 commit comments

Comments
 (0)