Skip to content

(GH-1655) Allow adapted resources to define the return kind for set and test - #1802

Open
Gijs Reijn (Gijsreyn) wants to merge 2 commits into
PowerShell:mainfrom
Gijsreyn:gh-1655/main/adapted-resource-return-kind
Open

Gijs Reijn (Gijsreyn) wants to merge 2 commits into
PowerShell:mainfrom
Gijsreyn:gh-1655/main/adapted-resource-return-kind

Conversation

@Gijsreyn

Copy link
Copy Markdown
Collaborator

PR Summary

This change:

  • Adds the return property (state or stateAndDiff) to the set and test operations of the adapted resource manifest.
  • Uses that value instead of the one in the adapter's manifest when DSC processes set and test output. Adapted resources that don't define it inherit from the adapter as before.
  • Adds two test resources to the dsctest adapter, nine Pester tests and a changelog entry.
  • Resolves Adapted Resources Set and Test return #1655.

PR Context

An adapter defines return once per method in its own manifest, and every resource it adapts inherited that value. An adapter that fronts resources with different capabilities had no way to express that one resource reports its own diff while another only returns state. The adapted resource manifest already carries per operation settings (requireSecurityContext), so return is added next to it for the two operations the issue asks for.

The lookup follows the pattern validate_security_context already uses: when the command is invoked for an adapted resource (context.target_resource), the adapted manifest is consulted first and the adapter's manifest is the fallback.

Remarks on the design

  • Single instance adapters only. The override applies when the adapter is invoked for one resource instance, which is the case for adapters that set inputKind to single. For adapters that receive the full configuration, the output is the adapter's envelope for all instances and DSC computes the diff per resource itself, so a per resource return has no meaning there and is ignored.
  • What-if. The adapter's whatIfReturns still takes precedence during what-if, with the adapted resource's return as the fallback before the adapter's return. No whatIfReturns is added to the adapted resource manifest, since the issue asks for set and test only. It can be added the same way, if preferred.
  • Adapter must implement the operation. When the adapter's manifest has no test method, DSC performs a synthetic test through get and the adapted return for test isn't used.
  • Invalid values fail at discovery. A value other than state or stateAndDiff fails deserialization, so the adapted resource isn't loaded and DSC reports the unknown variant.
  • Serialization. The property is skipped when it isn't set, so the dsc resource list output for existing adapted resources is unchanged.
  • Schema and docs. The adapted resource manifest schema is generated from the Rust type and picks up the property through the existing ReturnKind definition. There is no reference page for the adapted resource manifest yet, so no docs were changed.
  • Out of scope. Validating the state line of stateAndDiff output against the adapted resource's schema. The existing stateAndDiff branches only validate when the invoked resource isn't an adapter, and this PR leaves that as is.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Legacy whatIf execution incorrectly applies the adapted resource’s set.return override, causing --what-if to fail when it expects stateAndDiff but the adapter emits state.

3 open issues
What changed in this PR

Adds per-resource return kinds for adapted resources, addressing #1655 so a single adapter can support resources with different set/test output formats.

Changes:

  • Adds optional return properties to adapted resource set and test manifests.
  • Resolves adapted return kinds before adapter defaults while retaining fallback behavior.
  • Adds two test resources, nine Pester cases, localized logging, and a changelog entry.
File Description
tools/​dsctest/​src/​adapter.rs Emits state-only and state-and-diff test output.
tools/​dsctest/​dsctest.dsc.manifests.json Defines two adapted return-kind fixtures.
lib/​dsc-lib/​src/​dscresources/​command_resource.rs Resolves return kinds for set and test output processing.
lib/​dsc-lib/​src/​dscresources/​adapted_resource_manifest.rs Adds optional return-kind fields to manifest types.
lib/​dsc-lib/​locales/​en-us.toml Adds the return-kind override diagnostic.
dsc/​tests/​discovery/​dsc_adaptedResource.tests.ps1 Tests overrides, fallback, configuration use, and invalid values.
CHANGELOG.md Documents the feature and links #1655.

Review effort: Balanced


let (exit_code, stdout, stderr) = invoke_command(&set.executable, args, input_desired, resource.directory.as_deref(), env, manifest.exit_codes.as_ref())?;

let returns = resolve_return_kind(context.target_resource.as_ref(), set.returns.as_ref(), &Operation::Set);
Comment on lines +152 to +161
$oldPath = $env:DSC_RESOURCE_PATH
try {
$env:DSC_RESOURCE_PATH = $manifestDir + [System.IO.Path]::PathSeparator + (Split-Path (Get-Command dsctest).Source)
$out = dsc resource list 'Adapted/InvalidReturn' 2>$TestDrive/error.txt
$out | Should -BeNullOrEmpty
Get-Content -Path $TestDrive/error.txt -Raw | Should -BeLike '*unknown variant*diff*'
}
finally {
$env:DSC_RESOURCE_PATH = $oldPath
}
};
debug!("{}", t!("dscresources.commandResource.adaptedReturnKind", resource = &resource.type_name, operation = operation, kind = kind));
}
adapted_return.or(manifest_return)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adapted Resources Set and Test return

2 participants