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.35k stars 1.45k forks source link

Fix for Source Argument Validation in SourceWorkflow for Default Source Type #4891

Closed Madhusudhan-MSFT closed 1 month ago

Madhusudhan-MSFT commented 1 month ago

Fix for Source Argument Validation in SourceWorkflow for Default Source Type

[Issues:] The current validation in the source flow correctly detects duplicate source names. However, when the source argument is validated along with the source type, it allows different source names with the same arguments for the empty source type. This happens because, during source type comparison, if the source type is not provided, it defaults to an empty string, which is compared against the default type (Microsoft.PreIndexed). This allows multiple different source names with the same argument to be considered valid sources. For an empty source type, the default source type is assigned during the source add operation, not beforehand. Consequently, after the source add operation is finished, the source will have some source arguments, but only the name will differ.

[Fix:]

For an empty source type, we should compare against the default source to prevent different source names with the same arguments for the default types. During validation, we obtain the default type to replace the empty source type and use it for comparison to validate argument duplication.

[How Validated:]

[Manual validation:]

Before fix: image

After fix:

image


Microsoft Reviewers: Open in CodeFlow
github-actions[bot] commented 1 month ago

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.

Unrecognized words (1)

testsource

Previously acknowledged words that are now absent AKV Asn azcopy clsid cobertura notmatch Peet REINSTALLMODE sas SASURL similarissues similaritytolerance templating typeparam 🫥
Some files were automatically ignored :see_no_evil: These sample patterns would exclude them: ``` ^src/AppInstallerCLIE2ETests/TestData/empty$ ``` You should consider adding them to: ``` .github/actions/spelling/excludes.txt ``` File matching is via Perl regular expressions. To check these files, more of their words need to be in the dictionary than not. You can use `patterns.txt` to exclude portions, add items to the dictionary (e.g. by adding them to `allow.txt`), or fix typos.
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words and update file exclusions, you could run the following commands ... in a clone of the [git@github.com:Madhusudhan-MSFT/winget-cli.git](https://github.com/Madhusudhan-MSFT/winget-cli.git) repository on the `user/masudars/SourceCLI_DefaultSourceType_ValidationFix` branch ([:information_source: how do I use this?]( https://github.com/check-spelling/check-spelling/wiki/Accepting-Suggestions)): ``` sh curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' | perl - 'https://github.com/microsoft/winget-cli/actions/runs/11415559540/attempts/1' ```
Warnings (1) See the [:open_file_folder: files](https://github.com/microsoft/winget-cli/pull/4891/files/) view, the [:scroll:action log](https://github.com/microsoft/winget-cli/actions/runs/11415559540/job/31765748961#step:4:1), or [:memo: job summary](https://github.com/microsoft/winget-cli/actions/runs/11415559540/attempts/1#summary-31765748961) for details. [:information_source: Warnings](https://github.com/check-spelling/check-spelling/wiki/Event-descriptions) | Count -|- [:information_source: binary-file](https://github.com/check-spelling/check-spelling/wiki/Event-descriptions#binary-file) | 1 See [:information_source: Event descriptions](https://github.com/check-spelling/check-spelling/wiki/Event-descriptions) for more information.
If the flagged items are :exploding_head: false positives If items relate to a ... * binary file (or some other file you wouldn't want to check at all). Please add a file path to the `excludes.txt` file matching the containing file. File paths are Perl 5 Regular Expressions - you can [test]( https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your files. `^` refers to the file's path from the root of the repository, so `^README\.md$` would exclude [README.md]( ../tree/HEAD/README.md) (on whichever branch you're using). * well-formed pattern. If you can write a [pattern]( https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns ) that would match it, try adding it to the `patterns.txt` file. Patterns are Perl 5 Regular Expressions - you can [test]( https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your lines. Note that patterns can't match multiline strings.