JustinGrote / ModuleFast

A "fast and loose" way to install modules from Powershell Gallery quickly. Meant for CICD, not production
Other
77 stars 5 forks source link

`Install-ModuleFast`: Return wrong modules when using `-WhatIf` #35

Closed johlju closed 8 months ago

johlju commented 8 months ago

Here is a strange issue. It returns the wrong modules. It does not return Sampler.GitHubTask but it returns Sampler and Plaster. (Sampler is dependent on Plaster). All of these are installed, so non should be returned.

Problem:

PS> Install-ModuleFast -Specification 'Sampler','Sampler.GitHubtasks' -Destination './output/RequiredModules' -NoProfileUpdate -NoPSModulePathUpdate -Update -Verbose -Debug -Confirm:$false -WhatIf
VERBOSE: Sampler(): Evaluating Module Specification                                                                     
DEBUG: Sampler(): Skipping PSModulePath /Users/johlju/source/Sampler/output/builtModule - Configured but does not exist.
DEBUG: Sampler(): Skipping PSModulePath /Users/johlju/source/Sampler/output/RequiredModules - Does not have this module.
DEBUG: Sampler(): Skipping PSModulePath /Users/johlju/.local/share/powershell/Modules - Does not have this module.      
DEBUG: Sampler(): Skipping PSModulePath /usr/local/share/powershell/Modules - Does not have this module.                
DEBUG: Sampler(): Skipping PSModulePath /usr/local/microsoft/powershell/7/Modules - Does not have this module.          
DEBUG: Sampler(): 🔍 No installed versions matched the spec. Will check remotely.                                       
DEBUG: Sampler: fetch registration index from https://preview.pwsh.gallery/index.json                                   
DEBUG: Sampler: fetch info from https://preview.pwsh.gallery/sampler/index.json                                         
VERBOSE: Sampler.GitHubtasks(): Evaluating Module Specification                                                         
DEBUG: Sampler.GitHubtasks(): Skipping PSModulePath /Users/johlju/source/Sampler/output/builtModule - Configured but does not exist.
DEBUG: Sampler.GitHubtasks(): Skipping 0.3.4 because -Update was specified and the version does not exactly meet the upper bound of the spec or no upper bound was specified at all, meaning there is a possible newer version remotely.
DEBUG: Sampler.GitHubtasks(): New Best Candidate Version 0.3.4                                                          
DEBUG: Sampler.GitHubtasks(): Skipping PSModulePath /Users/johlju/.local/share/powershell/Modules - Does not have this module.
DEBUG: Sampler.GitHubtasks(): Skipping PSModulePath /usr/local/share/powershell/Modules - Does not have this module.    
DEBUG: Sampler.GitHubtasks(): Skipping PSModulePath /usr/local/microsoft/powershell/7/Modules - Does not have this module.
DEBUG: Sampler.GitHubtasks(): 🔍 No installed versions matched the spec. Will check remotely.                           
DEBUG: Sampler.GitHubtasks: fetch registration index from https://preview.pwsh.gallery/index.json                       
DEBUG: Sampler.GitHubtasks: fetch info from https://preview.pwsh.gallery/sampler.githubtasks/index.json                 
DEBUG: Sampler.GitHubtasks(): Processing Response                                                                       
DEBUG: Sampler.GitHubtasks(): Received Response with 3 pages                                                            
DEBUG: Sampler.GitHubtasks(): skipping candidate 0.3.5-preview0002 because it is a prerelease and prerelease was not specified either with the -Prerelease parameter, by specifying a prerelease version in the spec, or adding a ! on the module name spec to indicate prerelease is acceptable.
DEBUG: Sampler.GitHubtasks(): Found satisfying version 0.3.4 in the inlined index.                                      
DEBUG: Sampler.GitHubTasks(0.3.4): ✅ -Update was specified and the best remote candidate matches what is locally installed, so we can skip this module.
DEBUG: Sampler(): Processing Response                                                                                   
DEBUG: Sampler(): Received Response with 4 pages                                                                        
DEBUG: Sampler.GitHubtasks(): Found satisfying version 0.117.0 in the inlined index.                                    
VERBOSE: Sampler(0.117.0): Added to install plan                                                                        
DEBUG: Sampler(): has 1 additional dependencies: Plaster()                                                              
DEBUG: No modules with name Plaster currently exist in the install plan. Resolving dependency...                        
DEBUG: Fetching info on remaining 1 dependencies                                                                        
DEBUG: Plaster(): Skipping PSModulePath /Users/johlju/source/Sampler/output/builtModule - Configured but does not exist.
DEBUG: Plaster(): Skipping 1.1.4 because -Update was specified and the version does not exactly meet the upper bound of the spec or no upper bound was specified at all, meaning there is a possible newer version remotely.
DEBUG: Plaster(): Skipping 1.1.3 because -Update was specified and the version does not exactly meet the upper bound of the spec or no upper bound was specified at all, meaning there is a possible newer version remotely.
DEBUG: Plaster(): Skipping 1.1.4 because -Update was specified and the version does not exactly meet the upper bound of the spec or no upper bound was specified at all, meaning there is a possible newer version remotely.
DEBUG: Plaster(): Skipping PSModulePath /usr/local/share/powershell/Modules - Does not have this module.                
DEBUG: Plaster(): Skipping PSModulePath /usr/local/microsoft/powershell/7/Modules - Does not have this module.          
DEBUG: No local modules that satisfies dependency Plaster(). Checking Remote...                                         
DEBUG: Sampler(): Fetching dependency Plaster()                                                                         
DEBUG: Plaster: fetch registration index from https://preview.pwsh.gallery/index.json                                   
DEBUG: Plaster: fetch info from https://preview.pwsh.gallery/plaster/index.json                                         
DEBUG: Plaster(): Processing Response                                                                                   
DEBUG: Plaster(): Received Response with 2 pages                                                                        
DEBUG: Sampler.GitHubtasks(): Found satisfying version 1.1.4 in the inlined index.                                      
VERBOSE: Plaster(1.1.4): Added to install plan                                                                          
What if: Performing the operation "Install 2 Modules" on target "/Users/johlju/source/Sampler/output/RequiredModules".  

Name    ModuleVersion                                                                                                   
----    -------------                                                                                                   
Sampler 0.117.0                                                                                                         
Plaster 1.1.4    

PS> get-module -Name 'Sampler', 'Sampler.GitHubTasks', 'Plaster' -ListAvailable | ft Name,Version,Path  

Name                Version Path
----                ------- ----
Plaster             1.1.4   /Users/johlju/source/Sampler/output/RequiredModules/Plaster/1.1.4/Plaster.psd1
Sampler.GitHubTasks 0.3.4   /Users/johlju/source/Sampler/output/RequiredModules/Sampler.GitHubTasks/0.3.4/Sampler.GitHubTasks.ps…
Plaster             1.1.4   /Users/johlju/.local/share/powershell/Modules/Plaster/1.1.4/Plaster.psd1
Plaster             1.1.3   /Users/johlju/.local/share/powershell/Modules/Plaster/1.1.3/Plaster.psd1                                                                
JustinGrote commented 8 months ago

EDIT: Disregard, I missed where you said it happens when the package are already installed. I think dependencies are not getting evaluated the same as main packages. I'll investigate. Thanks!

VERBOSE: Plaster(1.1.4): Added to install plan                                                                          
What if: Performing the operation "Install 2 Modules" on target "C:\Users\JGrote\AppData\Local\powershell\Modules".     

Name    ModuleVersion                                                                                                   
----    -------------                                                                                                   
Sampler 0.117.0                                                                                                         
Plaster 1.1.4                                                                                                           
JustinGrote commented 8 months ago

This is what should be happening with Sampler when -Update is specified. I save off the best found candidate and if its already locally installed, skip it, and that evaluation should all happen in the plan but it isn't for some reason for that package even tho the versions match. I think it has something to do with your 0.117.0 version having leading or trailing zeroes and causing it to not match because it's being trimmed somewhere.

DEBUG: Sampler.GitHubTasks(0.3.4): ✅ -Update was specified and the best remote candidate matches what is locally installed, so we can skip this module.

JustinGrote commented 8 months ago

Found the problem, I scoped my $BestCandidate incorrectly. I moved it to a map to a higher level and it will now work as expected, I will close this with the commit when I complete it, it kind of got lumped into other work.