Skip to content

Add stateChanged() and restartRequired() functions - #1608

Merged
Mikey Lombardi (He/Him) (michaeltlombardi) merged 5 commits into
PowerShell:mainfrom
SteveL-MSFT:restart-required-function
Jul 7, 2026
Merged

Add stateChanged() and restartRequired() functions#1608
Mikey Lombardi (He/Him) (michaeltlombardi) merged 5 commits into
PowerShell:mainfrom
SteveL-MSFT:restart-required-function

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

PR Summary

  • stateChanged(<resourceId>) function returns a bool whether the specified resource has executed and incurred a state change (determined by changedProperties)
  • restartRequired(<type>,[name]) function returns if there is a restart required indicated for the named process, named service, or the system. You could already get this information from context(), but it's a bit cumbersome so this makes it much easier

PR Context

Preparation for adding Actions as these would be used for conditions

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.

Pull request overview

This PR adds two new DSC expression functions—stateChanged() and restartRequired()—and wires the configuration execution context to track whether each resource’s set operation actually changed state, enabling simpler conditional logic (e.g., for upcoming Actions/conditions support).

Changes:

  • Added restartRequired(<process|service|system>, [name]) and stateChanged(<resourceId>) functions to the dsc-lib function dispatcher with localized help text.
  • Tracked per-resource state-change status during config set execution (based on changedProperties) and exposed it via stateChanged().
  • Added a new Test/Set test resource and expanded Pester coverage to validate both new functions.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/dsctest/src/set.rs Adds a new dsctest resource implementation used to exercise changedProperties/state-change behavior.
tools/dsctest/src/main.rs Wires the new set module into dsctest CLI command handling and schema export.
tools/dsctest/src/args.rs Adds a set subcommand and schema enum entry for dsctest.
tools/dsctest/dsctest.dsc.manifests.json Registers the new Test/Set resource manifest for dsctest.
lib/dsc-lib/src/functions/state_changed.rs Implements the stateChanged() expression function using execution context data.
lib/dsc-lib/src/functions/restart_required.rs Implements the restartRequired() expression function using execution context data.
lib/dsc-lib/src/functions/mod.rs Registers both new functions in the dispatcher and module list.
lib/dsc-lib/src/dscresources/invoke_result.rs Adds SetResult::is_changed() helper to determine state-change from changedProperties.
lib/dsc-lib/src/configure/mod.rs Records state-change results per executed resource into the shared Context.
lib/dsc-lib/src/configure/context.rs Extends Context to store state_changed values by resourceId.
lib/dsc-lib/locales/en-us.toml Adds localized strings for the new functions (description/syntax/errors).
dsc/tests/dsc_restartRequired.tests.ps1 Adds output-based coverage validating restartRequired() behavior.
dsc/tests/dsc_functions.tests.ps1 Adds coverage validating stateChanged() behavior with changed/unchanged states and missing info.
Cargo.lock Updates lockfile entries (registry crates version bump).

Comment thread lib/dsc-lib/src/functions/state_changed.rs
Comment thread tools/dsctest/src/set.rs
Comment thread lib/dsc-lib/locales/en-us.toml Outdated
Comment thread lib/dsc-lib/locales/en-us.toml Outdated
Comment thread tools/dsctest/dsctest.dsc.manifests.json Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The handling for state changed seems pretty elegant to me, these functions definitely make lookup much more ergonomic.

Merged via the queue into PowerShell:main with commit 01f2294 Jul 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants