microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.02k stars 1.43k forks source link

Configuration history support #4552

Closed JohnMcPMS closed 3 months ago

JohnMcPMS commented 3 months ago

Change

This change adds basic configuration history support. This is stored in an SQLite database that is shared by all of the configuration code (so both winget.exe and PowerShell modules will use the same database).

The database currently holds a representation of every configuration set that has been applied (or at least attempted to be applied). Basic fields are stored directly, while more complex data is stored by serializing to YAML. While the database currently has only basic data, it will eventually contain status information for configuration units and other information used during synchronization of multiple configuration users.

[!Note] The dev build (based on AICLI_DISABLE_TEST_HOOKS) uses a different location for history to prevent local tests runs from adversely affecting the configuration usage experience for us.

winget.exe interface changes

A new command is added under the configure top level command, list. This shows details about items in the history.

> wingetdev configure list
Identifier                             Name      First Applied           Origin
----------------------------------------------------------------------------------
{9C8386B3-6C06-46D8-A0B1-83F3C73D86CE} Test Name 2024-06-13 11:43:20.000 Test Path
{F9DB9D25-92F3-4FBC-AD34-BEEEE53F08A0} Test Name 2024-06-13 11:43:21.000 Test Path
{49B3FDDA-9ABA-475C-A9FE-296CE3D7ED48} Test Name 2024-06-13 11:43:21.000 Test Path
{436B929A-E717-4F3B-B16E-BD268D5916D6} Test Name 2024-06-13 11:43:21.000 Test Path
> wingetdev configure list -h "{9C8386B3-6C06-46D8-A0B1-83F3C73D86CE}"
Field         Value
----------------------------------------------------
Identifier    {9C8386B3-6C06-46D8-A0B1-83F3C73D86CE}
Name          Test Name
First Applied 2024-06-13 11:43:20.000
Origin        Test Origin
Path          Test Path

In addition to listing everything, one can provide the listed name of the configuration or any unique starting sequence of the identifier to select a single item to view. The selection options apply to all other commands that take in the history item parameter, and completion has been added for the parameter so that substrings of either identifier or name can be expanded.

The configure, configure show, and configure test commands have all had the history parameter added so that one can operate directly against a historical set.

In addition to displaying information about history, the configure list command also allows for removing items from history with --remove and creating a YAML file for the set with --output.

PowerShell interface changes

The existing cmdlet Get-WinGetConfiguration was updated to include parameter set options -All to get all set from history and -InstanceIdentifier to get a single one (these are exclusive with -File and each other). Remove-WinGetConfigurationHistory was added to allow removing sets from history, and ConvertTo-WinGetConfigurationYaml was added to enable serializing a set to a string.

Validation

Many new tests are added for the interface implementations, as well as unit tests for the internals. The entire existing test base is also exercising writing to history.

Microsoft Reviewers: Open in CodeFlow