Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Improve synthetic diff array for test operations

Offen
#1,660 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
45/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
powershell, rust
Bereich
devops

Rechercherichtung

Der Issue nennt keine Implementierungsdateien oder Tests. Beginne damit, die Generierung synthetischer Diffs und die Verarbeitung des Ressourcenschemas für DSC-Testoperationen zu lokalisieren, und vergleiche anschließend, wie schreibgeschützte und nur beschreibbare Eigenschaften dargestellt werden. Als erledigt gilt die Aufgabe, wenn Ergebnis-Diffs keine Eigenschaften mehr melden, die nicht angegeben oder zurückgegeben werden können, und die Abdeckung für Ressourcen mit Übergangs-PowerShell-Skripten vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Issue-Enhancement
Summary of the new feature / enhancement

As a system administrator using DSC to manage my infrastructure,
I want the differingProperties and changedProperties fields of results to accurately reflect configurable properties of the resource without substantial noise,
So that I can quickly review result data.

Currently, the synthetic diff array of property names for DSC resource testoperations has insufficient handling for read-only and write-only properties. This problem is most clearly raised for the transitional PowerShell script resources, where you get results like this (tested with 3.4.0-preview.1):

desiredState:
  input:
    configFilePath: ~/foo/bar/config.toml
    settings:
      foo: bar
  getScript: |-
    param($data)

    function Get-Config {
      [CmdletBinding(DefaultParameterSetName = 'ByPath')]
      param(
        [Parameter(Mandatory, ParameterSetName = 'ByPath')]
        [string]$Path,
        [Parameter(Mandatory, ParameterSetName = 'DefaultConfig')]
        [switch]$Default
      )
      # Elided for brevity
    }

    if ([string]::IsNullOrEmpty($data.configFilePath)) {
      Write-Warning "No config file path provided. Using default configuration."
      Get-Config -Default
    } else {
      Get-Config -Path $data.configFilePath
    }
  testScript: |-
    param($data)

    function Get-Config {
      [CmdletBinding(DefaultParameterSetName = 'ByPath')]
      param(
        [Parameter(Mandatory, ParameterSetName = 'ByPath')]
        [string]$Path,
        [Parameter(Mandatory, ParameterSetName = 'DefaultConfig')]
        [switch]$Default
      )
      # Elided for brevity
    }

    function Test-Config {
      [CmdletBinding()]
      param(
        [Parameter(Mandatory)]
        [pscustomobject]$actual,
        [Parameter(Mandatory)]
        [pscustomobject]$desired
      )
      # Elided for brevity
    }

    if ($null -eq $data.settings) {
      throw "Unable to test configuration without specific settings"
    }
    if ($data.settings -isnot [System.Management.Automation.PSCustomObject]) {
      throw "Unable to test configuration; settings input data must be an object but was [$($data.settings.GetType().FullName)]"
    }

    $actualState = if ([string]::IsNullOrEmpty($data.configFilePath)) {
      Write-Warning "No config file path provided. Using default configuration."
      Get-Config -Default
    } else {
      Get-Config -Path $data.configFilePath
    }

    Test-Config -Actual $actualState.settings -Desired $data.settings
actualState:
  _inDesiredState: false
inDesiredState: false
differingProperties:
- input
- getScript
- testScript

Not only is the result object difficult to read, but the actualState tells the user almost nothing (the _inDesiredState field is hoisted to the top level of the result), but the differing properties field is useless - input and *Script properties are write-only, so the resource will never return them, and output/_inDesiredState are read-only, so the user should never supply them.

The result is a substantial amount of noise with very little information for the user. The only way to more clearly indicate result granularity is for a resource to emit trace messages about how the instance is out-of-state.

Reproducing the output

Run the following command to reproduce the full output noted above:

dsc resource test -r Microsoft.DSC.Transitional/PowerShellScript -i @'
input:
  configFilePath: ~/foo/bar/config.toml
  settings:
    foo: bar
getScript: |-
  param($data)

  function Get-Config {
    [CmdletBinding(DefaultParameterSetName = 'ByPath')]
    param(
      [Parameter(Mandatory, ParameterSetName = 'ByPath')]
      [string]$Path,
      [Parameter(Mandatory, ParameterSetName = 'DefaultConfig')]
      [switch]$Default
    )

    if ($Default) {
      $Path = "$HOME/.config/default_config.json"
    }

    [ordered]@{
      Path = $Path
      settings = [ordered]@{
        foo = "baz"
      }
    }
  }

  if ([string]::IsNullOrEmpty($data.configFilePath)) {
    Write-Warning "No config file path provided. Using default configuration."
    Get-Config -Default
  } else {
    Get-Config -Path $data.configFilePath
  }
testScript: |-
  param($data)

  function Get-Config {
    [CmdletBinding(DefaultParameterSetName = 'ByPath')]
    param(
      [Parameter(Mandatory, ParameterSetName = 'ByPath')]
      [string]$Path,
      [Parameter(Mandatory, ParameterSetName = 'DefaultConfig')]
      [switch]$Default
    )

    if ($Default) {
      $Path = "$HOME/.config/default_config.json"
    }

    [pscustomobject]@{
      path = $Path
      settings = [pscustomobject]@{
        foo = "baz"
      }
    }
  }

  function Test-Config {
    [CmdletBinding()]
    param(
      [Parameter(Mandatory)]
      [pscustomobject]$actual,
      [Parameter(Mandatory)]
      [pscustomobject]$desired
    )
    $inDesiredState = $true
    if ($actual.path -ne $desired.path) {
      $inDesiredState = $false
    }
    foreach ($setting in $desired.psobject.Properties.Name) {
      if ($actual.$setting -ne $desired.$setting) {
        $inDesiredState = $false
      }
    }
    return $inDesiredState
  }

  if ($null -eq $data.settings) {
    throw "Unable to test configuration without specific settings"
  }
  if ($data.settings -isnot [System.Management.Automation.PSCustomObject]) {
    throw "Unable to test configuration; settings input data must be an object but was [$($data.settings.GetType().FullName)]"
  }

  $actualState = if ([string]::IsNullOrEmpty($data.configFilePath)) {
    Write-Warning "No config file path provided. Using default configuration."
    Get-Config -Default
  } else {
    Get-Config -Path $data.configFilePath
  }

  Test-Config -Actual $actualState.settings -Desired $data.settings
'@
Proposed technical implementation details (optional)

While I don't have a concrete proposal, this issue made me think of two approaches that could help with this problem:

  1. Introduce special handling for read-only/write-only properties in result data - we probably shouldn't include them in the differingProperties array, because they'll never match both actual and desired state.
  2. Define a helper keyword for resource schema properties like x-dsc-hideFromDesiredState to specifically filter out properties that add a lot of noise to the result object.
Vorherrschende Sprache
Rust
Sterne
541
Forks
78
Ø Merge
2 T. 22 Std.
Gemergte PRs (30 T.)
17

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus PowerShell/DSC

Alle Issues in PowerShell/DSC

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.