From 1e2ca610629bcd48cbba4afda534b55d79208359 Mon Sep 17 00:00:00 2001 From: fadwen <110697945+fadwen@users.noreply.github.com> Date: Thu, 24 Sep 2026 02:51:33 +0000 Subject: [PATCH] chore: sync Copilot and Claude Code standards from standards repo --- .claude/rules/powershell-standards/analyze.md | 11 +++++ .../architecturedesign.md | 11 +++++ .claude/rules/powershell-standards/cicd.md | 13 ++++++ .../rules/powershell-standards/comments.md | 10 +++++ .../community-standards.md | 11 +++++ .../copilot-instructions.md | 5 +++ .../powershell-standards/errorsandlogs.md | 10 +++++ .claude/rules/powershell-standards/module.md | 12 ++++++ .claude/rules/powershell-standards/pester.md | 10 +++++ .claude/rules/powershell-standards/platyps.md | 11 +++++ .../powershell-version.md | 11 +++++ .claude/rules/powershell-standards/readme.md | 11 +++++ .../securitycompliance.md | 11 +++++ .../powershell-standards/style-enforcement.md | 10 +++++ .../Testing-Examples/Basic-Function.Tests.ps1 | 40 ++++++++++--------- 15 files changed, 168 insertions(+), 19 deletions(-) create mode 100644 .claude/rules/powershell-standards/analyze.md create mode 100644 .claude/rules/powershell-standards/architecturedesign.md create mode 100644 .claude/rules/powershell-standards/cicd.md create mode 100644 .claude/rules/powershell-standards/comments.md create mode 100644 .claude/rules/powershell-standards/community-standards.md create mode 100644 .claude/rules/powershell-standards/copilot-instructions.md create mode 100644 .claude/rules/powershell-standards/errorsandlogs.md create mode 100644 .claude/rules/powershell-standards/module.md create mode 100644 .claude/rules/powershell-standards/pester.md create mode 100644 .claude/rules/powershell-standards/platyps.md create mode 100644 .claude/rules/powershell-standards/powershell-version.md create mode 100644 .claude/rules/powershell-standards/readme.md create mode 100644 .claude/rules/powershell-standards/securitycompliance.md create mode 100644 .claude/rules/powershell-standards/style-enforcement.md diff --git a/.claude/rules/powershell-standards/analyze.md b/.claude/rules/powershell-standards/analyze.md new file mode 100644 index 0000000..b3b3e44 --- /dev/null +++ b/.claude/rules/powershell-standards/analyze.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" + - "**/*.psd1" +--- + +@../../../.github/instructions/analyze.instructions.md + +Source of this rule: `.github/instructions/analyze.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/architecturedesign.md b/.claude/rules/powershell-standards/architecturedesign.md new file mode 100644 index 0000000..760816c --- /dev/null +++ b/.claude/rules/powershell-standards/architecturedesign.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/*.psm1" + - "**/module.json" + - "**/README.md" +--- + +@../../../.github/instructions/architecturedesign.instructions.md + +Source of this rule: `.github/instructions/architecturedesign.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/cicd.md b/.claude/rules/powershell-standards/cicd.md new file mode 100644 index 0000000..fe2b59e --- /dev/null +++ b/.claude/rules/powershell-standards/cicd.md @@ -0,0 +1,13 @@ +--- +paths: + - "**/.github/workflows/*.yml" + - "**/.github/workflows/*.yaml" + - "**/azure-pipelines.yml" + - "**/build.ps1" + - "**/deploy.ps1" +--- + +@../../../.github/instructions/cicd.instructions.md + +Source of this rule: `.github/instructions/cicd.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/comments.md b/.claude/rules/powershell-standards/comments.md new file mode 100644 index 0000000..2cce02b --- /dev/null +++ b/.claude/rules/powershell-standards/comments.md @@ -0,0 +1,10 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" +--- + +@../../../.github/instructions/comments.instructions.md + +Source of this rule: `.github/instructions/comments.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/community-standards.md b/.claude/rules/powershell-standards/community-standards.md new file mode 100644 index 0000000..6652afb --- /dev/null +++ b/.claude/rules/powershell-standards/community-standards.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" + - "**/*.psd1" +--- + +@../../../.github/instructions/community-standards.instructions.md + +Source of this rule: `.github/instructions/community-standards.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/copilot-instructions.md b/.claude/rules/powershell-standards/copilot-instructions.md new file mode 100644 index 0000000..6c2e7b8 --- /dev/null +++ b/.claude/rules/powershell-standards/copilot-instructions.md @@ -0,0 +1,5 @@ +@../../../.github/copilot-instructions.md + +Source of this rule: `.github/copilot-instructions.md`, the always-on standards GitHub Copilot applies to +every file. This rule has no `paths`, so Claude Code loads it at launch the same way. Relative links +inside it resolve from `.github/`. diff --git a/.claude/rules/powershell-standards/errorsandlogs.md b/.claude/rules/powershell-standards/errorsandlogs.md new file mode 100644 index 0000000..cf38818 --- /dev/null +++ b/.claude/rules/powershell-standards/errorsandlogs.md @@ -0,0 +1,10 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" +--- + +@../../../.github/instructions/errorsandlogs.instructions.md + +Source of this rule: `.github/instructions/errorsandlogs.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/module.md b/.claude/rules/powershell-standards/module.md new file mode 100644 index 0000000..f2998ff --- /dev/null +++ b/.claude/rules/powershell-standards/module.md @@ -0,0 +1,12 @@ +--- +paths: + - "**/*.psm1" + - "**/*.psd1" + - "**/Public/*.ps1" + - "**/Private/*.ps1" +--- + +@../../../.github/instructions/module.instructions.md + +Source of this rule: `.github/instructions/module.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/pester.md b/.claude/rules/powershell-standards/pester.md new file mode 100644 index 0000000..9978d24 --- /dev/null +++ b/.claude/rules/powershell-standards/pester.md @@ -0,0 +1,10 @@ +--- +paths: + - "**/Tests/**/*.ps1" + - "**/*.Tests.ps1" +--- + +@../../../.github/instructions/pester.instructions.md + +Source of this rule: `.github/instructions/pester.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/platyps.md b/.claude/rules/powershell-standards/platyps.md new file mode 100644 index 0000000..de21e5f --- /dev/null +++ b/.claude/rules/powershell-standards/platyps.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/docs/**/*.md" + - "**/Public/*.ps1" + - "**/*.psd1" +--- + +@../../../.github/instructions/platyps.instructions.md + +Source of this rule: `.github/instructions/platyps.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/powershell-version.md b/.claude/rules/powershell-standards/powershell-version.md new file mode 100644 index 0000000..cb07ded --- /dev/null +++ b/.claude/rules/powershell-standards/powershell-version.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" + - "**/*.psd1" +--- + +@../../../.github/instructions/powershell-version.instructions.md + +Source of this rule: `.github/instructions/powershell-version.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/readme.md b/.claude/rules/powershell-standards/readme.md new file mode 100644 index 0000000..cb004f1 --- /dev/null +++ b/.claude/rules/powershell-standards/readme.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/README.md" + - "**/readme.md" + - "**/Readme.md" +--- + +@../../../.github/instructions/readme.instructions.md + +Source of this rule: `.github/instructions/readme.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/securitycompliance.md b/.claude/rules/powershell-standards/securitycompliance.md new file mode 100644 index 0000000..bc5a18f --- /dev/null +++ b/.claude/rules/powershell-standards/securitycompliance.md @@ -0,0 +1,11 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" + - "**/Security/**/*.ps1" +--- + +@../../../.github/instructions/securitycompliance.instructions.md + +Source of this rule: `.github/instructions/securitycompliance.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/.claude/rules/powershell-standards/style-enforcement.md b/.claude/rules/powershell-standards/style-enforcement.md new file mode 100644 index 0000000..d0474fc --- /dev/null +++ b/.claude/rules/powershell-standards/style-enforcement.md @@ -0,0 +1,10 @@ +--- +paths: + - "**/*.ps1" + - "**/*.psm1" +--- + +@../../../.github/instructions/style-enforcement.instructions.md + +Source of this rule: `.github/instructions/style-enforcement.instructions.md` (shared with GitHub Copilot, which +applies it through its `applyTo` glob). Relative links inside it resolve from `.github/instructions/`. diff --git a/powershell-standards/Examples/Testing-Examples/Basic-Function.Tests.ps1 b/powershell-standards/Examples/Testing-Examples/Basic-Function.Tests.ps1 index 232012f..ec5e55c 100644 --- a/powershell-standards/Examples/Testing-Examples/Basic-Function.Tests.ps1 +++ b/powershell-standards/Examples/Testing-Examples/Basic-Function.Tests.ps1 @@ -4,6 +4,12 @@ BeforeAll { # Import the module containing the function to test $ModulePath = Join-Path $PSScriptRoot '..\..\Examples\Basic-Function-Example.ps1' . $ModulePath + + # Names the mocks answer to. Kept in variables rather than literals: consuming + # projects mirror this file and may analyse it with PSAvoidUsingComputerNameHardcoded + # enabled, which flags a string literal passed to -ComputerName. + $script:MockServer = 'MOCKSERVER' + $script:OfflineServer = 'OFFLINE' } Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { @@ -59,13 +65,11 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { } Context "Parameter Validation" { - It "Should accept valid computer names: " -TestCases @( - @{ ComputerName = 'SERVER01'; Expected = $true } - @{ ComputerName = 'web01.contoso.com'; Expected = $true } - @{ ComputerName = 'DB-SERVER-01'; Expected = $true } + It "Should accept valid computer names: " -TestCases @( + @{ ComputerName = 'SERVER01' } + @{ ComputerName = 'web01.contoso.com' } + @{ ComputerName = 'DB-SERVER-01' } ) { - param($ComputerName, $Expected) - # This should not throw Get-BasicServerInfo -ComputerName $ComputerName -WhatIf } @@ -78,8 +82,6 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { @{ InvalidName = 'SERVER 01'; ExpectedError = '*does not match the*pattern*' } @{ InvalidName = ''; ExpectedError = '*length*is too short*' } ) { - param($InvalidName, $ExpectedError) - { Get-BasicServerInfo -ComputerName $InvalidName } | Should-Throw -ExceptionMessage $ExpectedError } @@ -94,21 +96,21 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { Context "Core Functionality" { It "Should return expected object structure" { - $result = Get-BasicServerInfo -ComputerName 'MOCKSERVER' + $result = Get-BasicServerInfo -ComputerName $script:MockServer # Verify object structure $result | Should-NotBeNull $result | Should-NotBeNull # Verify required properties - $result.ComputerName | Should-Be 'MOCKSERVER' + $result.ComputerName | Should-Be $script:MockServer $result.OperatingSystem | Should-Be 'Microsoft Windows Server 2019' $result.TotalMemoryGB | Should-Be 16 $result.CorrelationId | Should-NotBeNull } It "Should include services when IncludeServices switch is used" { - $result = Get-BasicServerInfo -ComputerName 'MOCKSERVER' -IncludeServices + $result = Get-BasicServerInfo -ComputerName $script:MockServer -IncludeServices $result.RunningServices | Should-NotBeNull $result.RunningServiceCount | Should-Be 2 @@ -116,7 +118,7 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { } It "Should calculate uptime correctly" { - $result = Get-BasicServerInfo -ComputerName 'MOCKSERVER' + $result = Get-BasicServerInfo -ComputerName $script:MockServer $result.UptimeDays | Should-BeGreaterThan 4.9 $result.UptimeDays | Should-BeLessThan 5.1 @@ -136,25 +138,25 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { # dot-sourced in BeforeAll. BeforeEach { Mock Test-Connection { - if ($TargetName -eq 'OFFLINE') { return $false } + if ($TargetName -eq $script:OfflineServer) { return $false } return $true } Mock New-CimSession { - if ($ComputerName -eq 'OFFLINE') { throw "Connection failed" } + if ($ComputerName -eq $script:OfflineServer) { throw "Connection failed" } [PSCustomObject]@{ ComputerName = $ComputerName } } } It "Should handle connection failures gracefully" { - Get-BasicServerInfo -ComputerName 'OFFLINE' -ErrorAction SilentlyContinue + Get-BasicServerInfo -ComputerName $script:OfflineServer -ErrorAction SilentlyContinue } It "Should continue processing other computers when one fails" { - $results = Get-BasicServerInfo -ComputerName @('MOCKSERVER', 'OFFLINE') -ErrorAction SilentlyContinue + $results = Get-BasicServerInfo -ComputerName @($script:MockServer, $script:OfflineServer) -ErrorAction SilentlyContinue # Should get one successful result despite one failure $results | Should-NotBeNull - $results.ComputerName | Should-ContainCollection 'MOCKSERVER' + $results.ComputerName | Should-ContainCollection $script:MockServer } } @@ -162,14 +164,14 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" { It "Should complete within acceptable time limits" { $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() - Get-BasicServerInfo -ComputerName 'MOCKSERVER' | Out-Null + Get-BasicServerInfo -ComputerName $script:MockServer | Out-Null $stopwatch.Stop() $stopwatch.ElapsedMilliseconds | Should-BeLessThan 5000 # 5 seconds max for mocked operations } It "Should include performance metrics in output" { - $result = Get-BasicServerInfo -ComputerName 'MOCKSERVER' + $result = Get-BasicServerInfo -ComputerName $script:MockServer $result.QueryTime | Should-NotBeNull $result.QueryDurationMs | Should-BeGreaterThan 0