(dsc): `PSResourceList` ignores `scope` when resolving `_exist`

Abierto
#2,054 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp, powershell
Área
cli, tooling

Línea de trabajo

Start with ConvertInputToPSResource and GetPSResourceList, then reproduce the two scope cases from the issue using the shown PSResourceList configurations. Trace how omitted and explicit scope values are represented during resource matching and set operations. Done means explicit scope limits _exist, test, and set to that scope while omitted scope preserves the current any-scope behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Needs-Triage
Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.
Steps to reproduce

As a user, I want scope to act as a filter when it is specified on a PSResourceList resource entry, so that _exist reflects whether the resource is present in that scope and set only touches that scope.

Today ConvertInputToPSResource defaults scope to CurrentUser when it is omitted, and GetPSResourceList collects installed resources from both scopes and matches on name and version only. The script cannot tell "the user asked for CurrentUser" from "the user said nothing", so scope is ignored when resolving the current state.

Two visible consequences:

  1. get reports _exist: true with a scope that differs from the desired one.

    resources:
    - name: PSResourceList scope test
      type: Microsoft.PowerShell.PSResourceGet/PSResourceList
      properties:
        repositoryName: PSGallery
        resources:
        - name: Pester
          version: '5.7.1'
          scope: CurrentUser
    

    With Pester 5.7.1 installed only in AllUsers, dsc resource get returns:

    { "name": "Pester", "version": "5.7.1", "scope": "AllUsers", "_exist": true }
    

    test then reports _inDesiredState: false because the scope differs, and set reinstalls into CurrentUser. The get output and the test result disagree about whether the resource exists.

  2. _exist: false with an explicit scope removes the resource from a different scope.

    resources:
    - name: PSResourceList scope test
      type: Microsoft.PowerShell.PSResourceGet/PSResourceList
      properties:
        repositoryName: PSGallery
        resources:
        - name: Pester
          scope: CurrentUser
          _exist: false
    

    With Pester installed only in AllUsers, dsc resource set runs Uninstall-PSResource -Name Pester -Scope AllUsers. A configuration that only asked about CurrentUser modifies the machine-wide scope and needs elevation to do so.

Expected behavior
When scope is specified, only resources installed in that scope are considered for _exist, test and set. When scope is omitted, the current behaviour (any scope) is kept.
Actual behavior
See the JSON snippet and the Uninstall-PSResource call above.
Error details

Environment data
Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     1.3.0      preview1   Microsoft.PowerShell.PSResourceGet  Core,Desk {Compress-PSResource, Find-PSResource, …
Binary     1.2.0      preview5   Microsoft.PowerShell.PSResourceGet  Core,Desk {Compress-PSResource, Find-PSResource, …

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     1.2.0                 Microsoft.PowerShell.PSResourceGet  Core,Desk {Compress-PSResource, Find-PSResource, …

Key   : PSVersion
Value : 7.6.6
Name  : PSVersion


Key   : PSEdition
Value : Core
Name  : PSEdition


Key   : GitCommitId
Value : 7.6.6
Name  : GitCommitId


Key   : OS
Value : Microsoft Windows 10.0.26200
Name  : OS


Key   : Platform
Value : Win32NT
Name  : Platform


Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions


Key   : PSRemotingProtocolVersion
Value : 2.4
Name  : PSRemotingProtocolVersion


Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion


Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion
Visuals

No response

Lenguaje dominante
C#
Estrellas
576
Forks
114
Merge medio
23 h 17 min
PR fusionados (30 d)
8

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de PowerShell/PSResourceGet

Todos los issues de PowerShell/PSResourceGet

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.