Skip to content

Add cross-platform process resource and termination action - #1797

Merged
Steve Lee (SteveL-MSFT) merged 3 commits into
mainfrom
stevel-msft-process-resource
Nov 10, 2026
Merged

Steve Lee (SteveL-MSFT) merged 3 commits into
mainfrom
stevel-msft-process-resource

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

The experimental process resource echoes input for state operations and limits export to four processes. Replace it with useful cross-platform process queries, while keeping engine tests deterministic by moving them to existing dsctest resources.

Changes

  • Replace Microsoft/Process with Microsoft.System/Process, supporting real get and export on Windows, Linux, and macOS. Export combines optional PID, name, and command-line filters; process names support * wildcards.
  • Add Microsoft.System.Action/TerminateProcess for configuration set. It accepts either a PID or an exact process name, terminates every name match, and reports missing targets and partial failures. Wildcards are intentionally rejected for termination.
  • Migrate legacy engine tests to existing dsctest fixtures and add coverage for process queries, filtering, and isolated termination targets.
  • Include the executable and both manifests in release packages for all three platforms, with resource/action reference documentation and examples.

Migration considerations

The resource type changes to Microsoft.System/Process. It is read-only and no longer implements set or native test; termination is exposed separately as an action. cmdline now contains an array of individual arguments rather than a debug-formatted string. Get requires a PID or an unambiguous exact name; export returns all matching processes without the previous enumeration limit.

Validation

Validated on Windows using the repository-root build.ps1:

  • Local DSC/resource builds and Clippy passed.
  • All 64 affected Pester tests passed, including the new process resource and action coverage.
  • All 3 process Rust unit tests and the migrated configuration parser test passed.
  • All 42 expression grammar corpus tests passed during the prerequisite build.

Linux and macOS runtime validation was not performed locally.

Replace the experimental process fixture with Microsoft.System/Process get and filtered export operations. Add the TerminateProcess action, migrate engine tests to dsctest, document the new contracts, and include both manifests in release packages.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 22:50

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

Unresolved process-handling bugs can reject valid empty Linux process names, break synthetic command-line tests, and treat threads as independent processes.

3 open issues
What changed in this PR

Replaces the experimental process fixture with a read-only, cross-platform Microsoft.System/Process resource and a separate termination action, while moving engine tests to deterministic fixtures.

Changes:

  • Adds real process queries, filtered export, and termination by PID or exact name.
  • Adds resource tests and migrates engine tests away from live process enumeration.
  • Packages both manifests and the executable for Windows, Linux, and macOS, with reference documentation and examples.
File Description
resources/​process/​tests/​process_terminate.tests.ps1 Tests action discovery, termination, and invalid targets.
resources/​process/​tests/​process_get.tests.ps1 Tests PID queries and input validation.
resources/​process/​tests/​process_export.tests.ps1 Tests enumeration and combined export filters.
resources/​process/​terminateprocess.dsc.action.json Defines the termination action and its schemas.
resources/​process/​src/​process_info.rs Implements process snapshots, filtering, and termination.
resources/​process/​src/​main.rs Dispatches operations and handles JSON input and errors.
resources/​process/​process.dsc.resource.json Defines the renamed, read-only resource.
resources/​process/​locales/​en-us.toml Adds localized diagnostics.
resources/​process/​ExportTest.dsc.yaml Updates the export example to the new resource.
resources/​process/​Cargo.toml Adds regex and localization dependencies.
resources/​process/​.project.data.json Includes the action manifest in build output.
lib/​dsc-lib/​src/​configure/​config_doc.rs Migrates parser test data to Test/Export.
dsc/​tests/​other/​dsc_resource_get.tests.ps1 Uses a deterministic export fixture.
dsc/​tests/​other/​dsc_actions.tests.ps1 Limits discovery assertions to test actions.
dsc/​tests/​config/​dsc_export.tests.ps1 Replaces process-dependent tests with fixtures.
docs/​reference/​resources/​Microsoft/​System/​Process/​index.md Documents query behavior, properties, and migration.
docs/​reference/​resources/​Microsoft/​System/​Process/​examples/​query-processes.md Demonstrates queries and filtered exports.
docs/​reference/​resources/​Microsoft/​System/​Action/​TerminateProcess/​index.md Documents termination behavior and safety constraints.
docs/​reference/​resources/​Microsoft/​System/​Action/​TerminateProcess/​examples/​terminate.config.dsc.yaml Provides a PID-targeted configuration example.
docs/​reference/​resources/​Microsoft/​System/​Action/​TerminateProcess/​examples/​terminate-process.md Explains how to invoke termination.
docs/​reference/​cli/​config/​export.md Updates the process resource type in an example.
docs/​get-started/​index.md Updates the resource listing and capabilities.
docs/​concepts/​resources/​overview.md Updates the resource listing and capabilities.
data.build.json Adds process artifacts to platform packages.
Cargo.lock Records the added process dependencies.

Review effort: Balanced

Comment thread resources/process/src/main.rs Resolved
Comment thread resources/process/src/process_info.rs Resolved
Allow empty operating-system names in returned state, ignore expected command lines during get, and exclude Linux tasks from process snapshots. Add regression coverage and update CI assertions for the new resource and action.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

😁 Code Coverage Report

Changed Code Coverage

95% (90%+ coverage)

Metric Value
Changed lines analyzed 262
Lines covered by tests 249
Coverage percentage 95%

🔵 Full Codebase Coverage

83% (good)

Metric Value
Total executable lines 21263
Lines covered by tests 17723
Coverage percentage 83%

Changed code coverage measures only Rust lines added/modified in this PR.
Full codebase coverage measures all instrumented Rust lines across the project.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

The destructive termination action was validated only on Windows, leaving Linux/macOS target selection, isolation, and permission or partial-failure behavior requiring runtime validation and platform-owner review.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

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.

Ergonomics and schema look good to me!

Comment on lines +21 to +38
pub fn validate(&self) -> Result<(), String> {
if self.name.as_ref().is_some_and(String::is_empty) {
return Err(t!("input.emptyName").to_string());
}
Ok(())
}

pub fn validate_identity(&self) -> Result<(), String> {
self.validate()?;
if self.pid.is_none() && self.name.is_none() {
return Err(t!("input.missingIdentity").to_string());
}
if self.name.as_ref().is_some_and(|name| name.contains('*')) {
return Err(t!("input.wildcardOnlyExport").to_string());
}
Ok(())
}
}

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.

Nit: Generally, prefer to make it impossible to create an invalid instance of the type over implementing validation functions called on an existing instance.

This is a bit tough with the serde model, but maybe if we refactor as validate_value(input: &serde_json::Value) and call the validation prior to deserializing from value?

More realistically, we need a higher level abstraction for this pattern to be able to use across our own types/crates. We do a lot of adhoc validation between JSON Schema, serde, and struct impls.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's think about this more broadly and apply the pattern across the resources later

@SteveL-MSFT
Steve Lee (SteveL-MSFT) added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 6badf51 Nov 10, 2026
32 checks passed
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the stevel-msft-process-resource branch November 10, 2026 20:29
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.

3 participants