Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/analyze.md
Original file line number Diff line number Diff line change
@@ -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/`.
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/architecturedesign.md
Original file line number Diff line number Diff line change
@@ -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/`.
13 changes: 13 additions & 0 deletions .claude/rules/powershell-standards/cicd.md
Original file line number Diff line number Diff line change
@@ -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/`.
10 changes: 10 additions & 0 deletions .claude/rules/powershell-standards/comments.md
Original file line number Diff line number Diff line change
@@ -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/`.
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/community-standards.md
Original file line number Diff line number Diff line change
@@ -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/`.
5 changes: 5 additions & 0 deletions .claude/rules/powershell-standards/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -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/`.
10 changes: 10 additions & 0 deletions .claude/rules/powershell-standards/errorsandlogs.md
Original file line number Diff line number Diff line change
@@ -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/`.
12 changes: 12 additions & 0 deletions .claude/rules/powershell-standards/module.md
Original file line number Diff line number Diff line change
@@ -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/`.
10 changes: 10 additions & 0 deletions .claude/rules/powershell-standards/pester.md
Original file line number Diff line number Diff line change
@@ -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/`.
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/platyps.md
Original file line number Diff line number Diff line change
@@ -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/`.
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/powershell-version.md
Original file line number Diff line number Diff line change
@@ -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/`.
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/readme.md
Original file line number Diff line number Diff line change
@@ -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/`.
11 changes: 11 additions & 0 deletions .claude/rules/powershell-standards/securitycompliance.md
Original file line number Diff line number Diff line change
@@ -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/`.
10 changes: 10 additions & 0 deletions .claude/rules/powershell-standards/style-enforcement.md
Original file line number Diff line number Diff line change
@@ -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/`.
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -59,13 +65,11 @@ Describe "Get-BasicServerInfo" -Tag "Unit", "Example" {
}

Context "Parameter Validation" {
It "Should accept valid computer names: <TestCase>" -TestCases @(
@{ ComputerName = 'SERVER01'; Expected = $true }
@{ ComputerName = 'web01.contoso.com'; Expected = $true }
@{ ComputerName = 'DB-SERVER-01'; Expected = $true }
It "Should accept valid computer names: <ComputerName>" -TestCases @(
@{ ComputerName = 'SERVER01' }
@{ ComputerName = 'web01.contoso.com' }
@{ ComputerName = 'DB-SERVER-01' }
) {
param($ComputerName, $Expected)

# This should not throw
Get-BasicServerInfo -ComputerName $ComputerName -WhatIf
}
Expand All @@ -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
}

Expand All @@ -94,29 +96,29 @@ 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
$result.RunningServices[0].Name | Should-Be 'Spooler'
}

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
Expand All @@ -136,40 +138,40 @@ 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
}
}

Context "Performance Requirements" {
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
Expand Down
Loading