From 001a9c9b38e7ddab1ca3f9fcf5fdb9504a407551 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Oct 2026 23:47:33 +0000 Subject: [PATCH 1/4] Initial plan From 2d122fd485cd4bb09dc4718f9d3f28745f31b460 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Oct 2026 23:51:29 +0000 Subject: [PATCH 2/4] Reject background pipelines as DSC resources Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/AvoidAlias.cs | 2 ++ Tests/Rules/AvoidUsingAlias.tests.ps1 | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Rules/AvoidAlias.cs b/Rules/AvoidAlias.cs index f40d961f1..03c3d7f02 100644 --- a/Rules/AvoidAlias.cs +++ b/Rules/AvoidAlias.cs @@ -318,6 +318,7 @@ private ScriptBlockExpressionAst GetDscResourceBody(CommandAst cmdAst) if (!(cmdAst.Parent is PipelineAst commandPipeline) || commandPipeline.PipelineElements.Count != 1 || commandPipeline.PipelineElements[0] != cmdAst + || commandPipeline.Background || !(commandPipeline.Parent is NamedBlockAst || commandPipeline.Parent is StatementBlockAst)) { return null; @@ -346,6 +347,7 @@ private ScriptBlockExpressionAst GetDscResourceBody(CommandAst cmdAst) if (index >= 0 && index + 1 < statements.Count && statements[index + 1] is PipelineAst bodyPipeline && bodyPipeline.PipelineElements.Count == 1 + && !bodyPipeline.Background && bodyPipeline.PipelineElements[0] is CommandExpressionAst bodyExpression) { if (HasStatementSeparator(cmdAst, bodyPipeline) diff --git a/Tests/Rules/AvoidUsingAlias.tests.ps1 b/Tests/Rules/AvoidUsingAlias.tests.ps1 index 1c2470447..d262c8a6c 100644 --- a/Tests/Rules/AvoidUsingAlias.tests.ps1 +++ b/Tests/Rules/AvoidUsingAlias.tests.ps1 @@ -208,6 +208,7 @@ Configuration PackageTest { Write-Output $(Verb Argument {}) @(Verb Argument {}) Verb Argument {} > $null + Verb Argument {} & if (Verb Argument {}) {} return Verb Argument {} if ($true) { @@ -227,7 +228,7 @@ Configuration PackageTest { $violations = @($rule.AnalyzeScript($configuration, $null)) - $violations.Count | Should -Be 5 + $violations.Count | Should -Be 6 $violations | ForEach-Object { $_.SuggestedCorrections[0].Text | Should -Be 'Get-Verb' } @@ -241,6 +242,8 @@ Configuration PackageTest { gci .; {} gci . & {} + gci . + {} & } '@ $ast = [System.Management.Automation.Language.Parser]::ParseInput($target, [ref]$null, [ref]$null) @@ -252,7 +255,7 @@ Configuration PackageTest { $violations = @($rule.AnalyzeScript($configuration, $null)) - $violations.Count | Should -Be 3 + $violations.Count | Should -Be 4 $violations | ForEach-Object { $_.Extent.Text | Should -Be 'gci' $_.SuggestedCorrections[0].Text | Should -Be 'Get-ChildItem' From eecf49029b72b5dcf0e169e022e03ec86ed36aa8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Oct 2026 00:18:15 +0000 Subject: [PATCH 3/4] Guard background AST API for CoreCLR Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/AvoidAlias.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Rules/AvoidAlias.cs b/Rules/AvoidAlias.cs index 03c3d7f02..fa6f94efa 100644 --- a/Rules/AvoidAlias.cs +++ b/Rules/AvoidAlias.cs @@ -318,7 +318,9 @@ private ScriptBlockExpressionAst GetDscResourceBody(CommandAst cmdAst) if (!(cmdAst.Parent is PipelineAst commandPipeline) || commandPipeline.PipelineElements.Count != 1 || commandPipeline.PipelineElements[0] != cmdAst +#if CORECLR || commandPipeline.Background +#endif || !(commandPipeline.Parent is NamedBlockAst || commandPipeline.Parent is StatementBlockAst)) { return null; @@ -347,7 +349,9 @@ private ScriptBlockExpressionAst GetDscResourceBody(CommandAst cmdAst) if (index >= 0 && index + 1 < statements.Count && statements[index + 1] is PipelineAst bodyPipeline && bodyPipeline.PipelineElements.Count == 1 +#if CORECLR && !bodyPipeline.Background +#endif && bodyPipeline.PipelineElements[0] is CommandExpressionAst bodyExpression) { if (HasStatementSeparator(cmdAst, bodyPipeline) From f852e80e1d002e01e30c8f91b0cf07ae9e5cccab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 Oct 2026 07:18:16 +0000 Subject: [PATCH 4/4] Make background pipeline test expectations version-aware Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Tests/Rules/AvoidUsingAlias.tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/Rules/AvoidUsingAlias.tests.ps1 b/Tests/Rules/AvoidUsingAlias.tests.ps1 index d262c8a6c..7dc377774 100644 --- a/Tests/Rules/AvoidUsingAlias.tests.ps1 +++ b/Tests/Rules/AvoidUsingAlias.tests.ps1 @@ -228,7 +228,8 @@ Configuration PackageTest { $violations = @($rule.AnalyzeScript($configuration, $null)) - $violations.Count | Should -Be 6 + $expectedViolations = if ($PSVersionTable.PSVersion.Major -ge 7) { 6 } else { 5 } + $violations.Count | Should -Be $expectedViolations $violations | ForEach-Object { $_.SuggestedCorrections[0].Text | Should -Be 'Get-Verb' } @@ -255,7 +256,8 @@ Configuration PackageTest { $violations = @($rule.AnalyzeScript($configuration, $null)) - $violations.Count | Should -Be 4 + $expectedViolations = if ($PSVersionTable.PSVersion.Major -ge 7) { 4 } else { 3 } + $violations.Count | Should -Be $expectedViolations $violations | ForEach-Object { $_.Extent.Text | Should -Be 'gci' $_.SuggestedCorrections[0].Text | Should -Be 'Get-ChildItem'