diff --git a/.github/workflows/quality-gates.yml b/.github/workflows/quality-gates.yml index 4acf105..ac511db 100644 --- a/.github/workflows/quality-gates.yml +++ b/.github/workflows/quality-gates.yml @@ -116,13 +116,20 @@ jobs: # The log readers on a generated log of 10,000 lines (TST-43), in their declared order and # outside the coverage run, whose instrumentation would slow what they measure. Each test # holds an absolute limit with room for a slow runner and a check that four times the lines - # take less than six times as long; the MEASURE lines in the log are the figures the - # performance gate (#136) will record as baselines. - - name: Performance tests + # take less than six times as long. The suite runs three times and writes each measurement + # to measurements.jsonl, and the performance gate (CIC-13) compares the median of each with + # the baseline recorded for this runner image in Tests/Performance/Baselines.psd1. A new + # image has no baseline: the gate warns, prints the entry to record, and passes. + - name: Performance tests and gate shell: pwsh run: | $ErrorActionPreference = 'Stop' - ./Tests/Invoke-Tests.ps1 -TestType Performance -OutputPath ./reports/performance -Output Detailed -SummaryPath $env:GITHUB_STEP_SUMMARY + $null = New-Item -ItemType Directory -Path ./reports/performance -Force + $env:ISL_PERFORMANCE_RESULTS = Join-Path -Path (Resolve-Path ./reports/performance) -ChildPath 'measurements.jsonl' + foreach ($run in 1..3) { + ./Tests/Invoke-Tests.ps1 -TestType Performance -Output Detailed -OutputPath "./reports/performance/run$run" -SummaryPath $env:GITHUB_STEP_SUMMARY + } + ./Build/Test-PerformanceBaseline.ps1 -ResultPath $env:ISL_PERFORMANCE_RESULTS - name: Upload test results and coverage if: always() diff --git a/Build/Test-PerformanceBaseline.ps1 b/Build/Test-PerformanceBaseline.ps1 new file mode 100644 index 0000000..31cd1d5 --- /dev/null +++ b/Build/Test-PerformanceBaseline.ps1 @@ -0,0 +1,247 @@ +#Requires -Version 5.1 + +<# +.SYNOPSIS + Compares the measurements of the performance tests with their recorded baselines. + +.DESCRIPTION + The performance gate of CIC-13. Tests/Performance writes one JSON line for each measurement + to the file that ISL_PERFORMANCE_RESULTS names: the name of the reader, the lines of the log + it read, the seconds it took and the megabytes its result kept. When the suite has run several + times, the script takes the median of each measurement, so that one slow run does not decide, + and compares it with the baseline recorded for the machine it runs on. + + Baselines are recorded for a runner: the image of a GitHub-hosted runner (the ImageOS variable + it sets, such as win25), its architecture and the PowerShell version, as in win25/X64/7.6. A + measurement fails when its median is more than the margin above its baseline: a margin of 0.5 + lets it be half as large again. A machine with no baseline, a developer's computer or a new + runner image, is reported and not gated, so that a new image does not fail every build; its + medians are printed in the form of a baseline entry, to be recorded with -Record. + +.PARAMETER ResultPath + The file of JSON lines that the performance tests wrote. The tests append to it, so delete it + before a new recording; measurements from more than one PowerShell version are refused. + +.PARAMETER BaselinePath + The baselines. Default: Tests/Performance/Baselines.psd1. + +.PARAMETER Runner + The runner to compare with. Default: ImageOS/architecture/major.minor of PowerShell on a + GitHub-hosted runner, and the computer's name elsewhere. + +.PARAMETER Record + Prints the medians as a baseline entry for the runner and compares nothing. + +.EXAMPLE + ./Build/Test-PerformanceBaseline.ps1 -ResultPath ./reports/performance/measurements.jsonl + + Compares the medians of the measurements with the baselines of this runner. + +.EXAMPLE + ./Build/Test-PerformanceBaseline.ps1 -ResultPath ./measurements.jsonl -Record + + Prints the medians as the baseline entry of this runner. + +.INPUTS + None. + +.OUTPUTS + None. A line for each measurement, as information records. +#> +[CmdletBinding()] +param( + [Parameter(Mandatory)] + [string]$ResultPath, + + [Parameter()] + [string]$BaselinePath, + + [Parameter()] + [string]$Runner, + + [Parameter()] + [switch]$Record +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +# Windows PowerShell 5.1 has no $PSScriptRoot while it binds the parameters, so the defaults are set here +if (-not $BaselinePath) { + $repositoryRoot = Split-Path -Path $PSScriptRoot -Parent + $testsFolder = Join-Path -Path $repositoryRoot -ChildPath 'Tests' + $performanceFolder = Join-Path -Path $testsFolder -ChildPath 'Performance' + $BaselinePath = Join-Path -Path $performanceFolder -ChildPath 'Baselines.psd1' +} +if (-not $Runner) { + $version = '{0}.{1}' -f $PSVersionTable.PSVersion.Major, $PSVersionTable.PSVersion.Minor + $architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture + $machine = if ($env:ImageOS) { $env:ImageOS } else { $env:COMPUTERNAME } + $Runner = '{0}/{1}/{2}' -f $machine, $architecture, $version +} + +function Format-Invariant { + <# + .SYNOPSIS + Formats a string with its numbers written as the invariant culture writes them. + + .DESCRIPTION + The -f operator writes a number in the current culture, 1,06 in German, which a baseline + entry pasted into Baselines.psd1 would then read as an array. This writes 1.06 whatever the + culture. + + .PARAMETER Format + The format string, as for -f. + + .PARAMETER Argument + The values to put into it. + + .EXAMPLE + Format-Invariant -Format '{0} s' -Argument 1.06 + + Returns '1.06 s' in every culture. + + .INPUTS + None. + + .OUTPUTS + System.String. The formatted string. + #> + [CmdletBinding()] + [OutputType([string])] + param( + [Parameter(Mandatory)] + [string]$Format, + + [Parameter(Mandatory)] + [AllowNull()] + [object[]]$Argument + ) + + [string]::Format([System.Globalization.CultureInfo]::InvariantCulture, $Format, $Argument) +} + + +function Get-Median { + <# + .SYNOPSIS + Gets the median of a set of numbers. + + .DESCRIPTION + Sorts the numbers and returns the middle one, or the mean of the two in the middle when + there is an even number of them. + + .PARAMETER Value + The numbers. + + .EXAMPLE + Get-Median -Value 3, 1, 2 + + Returns 2. + + .INPUTS + None. + + .OUTPUTS + System.Double. The median. + #> + [CmdletBinding()] + [OutputType([double])] + param( + [Parameter(Mandatory)] + [double[]]$Value + ) + + $sorted = @($Value | Sort-Object) + $middle = [math]::Floor($sorted.Count / 2) + if ($sorted.Count % 2 -eq 1) { + $sorted[$middle] + } else { + ($sorted[$middle - 1] + $sorted[$middle]) / 2 + } +} + + +$lines = @([System.IO.File]::ReadAllLines((Resolve-Path -LiteralPath $ResultPath).ProviderPath) | + Where-Object { $_.Trim() }) +if ($lines.Count -eq 0) { + throw "No measurements in '$ResultPath': the performance tests wrote nothing." +} +$results = @($lines | ForEach-Object { $_ | ConvertFrom-Json }) +# One recording per file: medians over two PowerShell versions, or two versions of the code, would +# describe neither +$versions = @($results | ForEach-Object { $_.PSObject.Properties['PowerShell'] } | Where-Object { $_ } | + ForEach-Object { "$($_.Value)" } | Sort-Object -Unique) +if ($versions.Count -gt 1) { + throw ("The measurements in '$ResultPath' come from more than one PowerShell version " + + "($($versions -join ', ')). Delete the file and record again.") +} +$medians = @( + foreach ($group in @($results | Group-Object -Property Name, Lines | Sort-Object -Property Name)) { + $first = $group.Group[0] + [pscustomobject]@{ + Key = '{0}/{1}' -f $first.Name, $first.Lines + Runs = $group.Count + Seconds = [math]::Round((Get-Median -Value @($group.Group.Seconds)), 2) + Megabytes = [math]::Round((Get-Median -Value @($group.Group.Megabytes)), 1) + } + } +) + +if ($Record) { + $entry = foreach ($median in $medians) { + $values = $median.Key, $median.Seconds, $median.Megabytes + Format-Invariant -Format " '{0}' = @{{ Seconds = {1}; Megabytes = {2} }}" -Argument $values + } + Write-Information -InformationAction Continue -MessageData ( + "Baseline entry for '$Runner':`n '$Runner' = @{`n$($entry -join "`n")`n }") + return +} + +$baselines = Import-PowerShellDataFile -LiteralPath $BaselinePath +foreach ($key in 'Margin', 'Runners') { + if (-not $baselines.ContainsKey($key)) { + throw "The baselines '$BaselinePath' have no '$key' table." + } +} +if (-not $baselines['Runners'].ContainsKey($Runner)) { + $measured = ($medians | ForEach-Object { + Format-Invariant -Format '{0} {1} s {2} MB' -Argument $_.Key, $_.Seconds, $_.Megabytes + }) -join '; ' + Write-Warning ("No performance baseline for the runner '$Runner', so nothing is gated. Measured " + + "(median of the runs): $measured. Record one with -Record.") + return +} + +$runnerBaselines = $baselines['Runners'][$Runner] +$failures = [System.Collections.Generic.List[string]]::new() +foreach ($median in $medians) { + if (-not $runnerBaselines.ContainsKey($median.Key)) { + Write-Information -InformationAction Continue -MessageData ( + "$($median.Key): $($median.Seconds) s, $($median.Megabytes) MB, no baseline") + continue + } + $baseline = $runnerBaselines[$median.Key] + foreach ($measure in 'Seconds', 'Megabytes') { + $limit = [math]::Round($baseline[$measure] * (1 + $baselines['Margin'][$measure]), 2) + $value = $median.$measure + $verdict = if ($value -gt $limit) { 'over' } else { 'within' } + $values = $median.Key, $value, $measure, $verdict, $limit, $baseline[$measure], $median.Runs + $lineFormat = '{0}: {1} {2}, {3} the limit {4} (baseline {5}, median of {6} runs)' + $line = Format-Invariant -Format $lineFormat -Argument $values + Write-Information -MessageData $line -InformationAction Continue + if ($verdict -eq 'over') { + $failures.Add($line) + } + } +} +foreach ($baselineKey in $runnerBaselines.Keys) { + if ($baselineKey -notin $medians.Key) { + $failures.Add("$($baselineKey): has a baseline, and the performance tests measured nothing for it") + } +} +if ($failures.Count -gt 0) { + throw "The performance gate failed for '$Runner':`n$($failures -join "`n")" +} +Write-Information -InformationAction Continue -MessageData ( + "Performance gate: $($medians.Count) measurement(s) within the baselines of '$Runner'.") diff --git a/CHANGELOG.md b/CHANGELOG.md index 14833e3..5074585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ entries are carried over from the manifest's release notes. ### Added +- A performance gate in CI: the tests job runs the performance tests three times and fails when + the median time of a reader at 10,000 lines is more than twice its baseline for that runner + image, or its memory a quarter more, recorded in `Tests/Performance/Baselines.psd1` (#136). - Performance tests for `Get-IntuneAgentLog` and `Get-IntuneAgentTimeline` on a generated log of 10,000 lines, run with `Tests/Invoke-Tests.ps1 -TestType Performance` and in CI, and security tests, tagged `Security` and run with `-Tag Security`, that a `-Credential` password reaches the diff --git a/CLAUDE.md b/CLAUDE.md index e9a89eb..2a7f7f1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -260,6 +260,7 @@ vault is searched, and the secret stays a `SecureString` until the publish call. ./Tests/Invoke-Tests.ps1 # every suite, shuffled; suites that need elevation, a lab account or PSScriptAnalyzer skip themselves ./Tests/Invoke-Tests.ps1 -CodeCoverage # the same with the 80% coverage gate, as the tests job runs it ./Tests/Invoke-Tests.ps1 -TestType Performance # the log readers on a generated log, not part of the default run +./Build/Test-PerformanceBaseline.ps1 -ResultPath -Record # baselines from ISL_PERFORMANCE_RESULTS, see the tests job ./Tests/Invoke-Tests.ps1 -TestType Unit -Tag Security # where a -Credential password goes, and the checks on input ./Build/Invoke-Analysis.ps1 # PSScriptAnalyzer with the settings file, as the tests job runs it ./Build/Build-Help.ps1 -SkipUpdate # rebuild MAML after editing docs/, the form CI compares diff --git a/Tests/Performance/AgentLogReader.Tests.ps1 b/Tests/Performance/AgentLogReader.Tests.ps1 index 47f8ef9..364ac8b 100644 --- a/Tests/Performance/AgentLogReader.Tests.ps1 +++ b/Tests/Performance/AgentLogReader.Tests.ps1 @@ -8,7 +8,9 @@ memory it holds against a limit with room for a slow runner, and the time at four times the lines against six times the time of the smaller log, which a reader that grows linearly stays well inside and one that grows with the square of the lines does not. Every measurement is - written to the information stream as a MEASURE line, for the baselines of the performance gate. + written to the information stream as a MEASURE line and, when ISL_PERFORMANCE_RESULTS names a + file, as a JSON line to it, which the performance gate (Build/Test-PerformanceBaseline.ps1) + compares with Baselines.psd1. The readers run once on a small log before they are measured, so that the first measurement does not carry the one-time cost of compiling the module's script blocks and expressions. On a @@ -145,6 +147,20 @@ BeforeAll { $line = 'MEASURE {0} lines={1} seconds={2} megabytes={3} powershell={4}' -f $Name, $Lines, $measurement.Seconds, $measurement.Megabytes, $PSVersionTable.PSVersion Write-Information -MessageData $line -InformationAction Continue + # For the performance gate (Build/Test-PerformanceBaseline.ps1): one JSON line for each + # measurement, appended to the file the variable names + if ($env:ISL_PERFORMANCE_RESULTS) { + $record = [ordered]@{ + Name = $Name + Lines = $Lines + Seconds = $measurement.Seconds + Megabytes = $measurement.Megabytes + PowerShell = "$($PSVersionTable.PSVersion)" + } + $json = ($record | ConvertTo-Json -Compress) + "`n" + $utf8 = [System.Text.UTF8Encoding]::new($false) + [System.IO.File]::AppendAllText($env:ISL_PERFORMANCE_RESULTS, $json, $utf8) + } $measurement } diff --git a/Tests/Performance/Baselines.psd1 b/Tests/Performance/Baselines.psd1 new file mode 100644 index 0000000..e83a8fd --- /dev/null +++ b/Tests/Performance/Baselines.psd1 @@ -0,0 +1,25 @@ +# The baselines of the performance gate (CIC-13, Build/Test-PerformanceBaseline.ps1): for each +# runner, the median seconds and the megabytes kept of each reader at 10,000 lines, recorded with +# Test-PerformanceBaseline.ps1 -Record from the hosted runs named in the comment of each runner. +# A median more than the margin above its baseline fails the build. +# +# The margins come from the first recorded runs. Three jobs on win25-vs2026, three runs of the +# suite each: the medians of the jobs were 0.90 to 1.10 seconds for the log reader and 1.24 to +# 1.69 for the timeline, up to a third apart, and the first run of each job took twice as long as +# the other two, which the median leaves out. The memory kept was the same in every run. A median +# twice its baseline, or a quarter more memory, is therefore a change in the code, not the runner. +@{ + Margin = @{ + Seconds = 1.0 + Megabytes = 0.25 + } + + Runners = @{ + # Quality Gates runs 45726300466, 45726303917 and 45726307359, 2026-11-26; the medians of + # the middle one + 'win25-vs2026/X64/7.6' = @{ + 'Get-IntuneAgentLog/10000' = @{ Seconds = 1.06; Megabytes = 25.7 } + 'Get-IntuneAgentTimeline/10000' = @{ Seconds = 1.63; Megabytes = 20.2 } + } + } +} diff --git a/Tests/Unit/Build/Test-PerformanceBaseline.Tests.ps1 b/Tests/Unit/Build/Test-PerformanceBaseline.Tests.ps1 new file mode 100644 index 0000000..5e12e91 --- /dev/null +++ b/Tests/Unit/Build/Test-PerformanceBaseline.Tests.ps1 @@ -0,0 +1,239 @@ +#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '6.2.0' } + +<# + Build/Test-PerformanceBaseline.ps1, the performance gate (CIC-13), run against measurements + and baselines written for each test: it must pass medians within the margin, fail one above + it, take the median so that one slow run does not decide, and leave a runner without a + baseline ungated. The script is called in this process, and what it writes is read from the + information and warning streams. +#> + +BeforeAll { + $repositoryRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent + $buildFolder = Join-Path -Path $repositoryRoot -ChildPath 'Build' + $script:Gate = Join-Path -Path $buildFolder -ChildPath 'Test-PerformanceBaseline.ps1' + + function script:Invoke-Gate { + <# + .SYNOPSIS + Runs the performance gate on measurements and baselines written for one test. + + .DESCRIPTION + Writes the measurements as JSON lines and the baselines as a data file under TestDrive, + runs Build/Test-PerformanceBaseline.ps1 on them for the runner 'test/X64/7.6', and + returns what it wrote, the message of the error it ended with, if any, and whether it + passed. + + .PARAMETER Measurement + Hashtables of Name, Lines, Seconds and Megabytes, one for each measurement. + + .PARAMETER Baseline + The text of the Runners table's entries for 'test/X64/7.6', or $null for no entry. + + .PARAMETER Record + Runs the gate with -Record. + + .PARAMETER DefaultRunner + Leaves -Runner out, so that the gate works out the runner itself. + + .PARAMETER Culture + The culture the gate runs under, such as de-DE. Default: the current one. + + .EXAMPLE + Invoke-Gate -Measurement @{ Name = 'R'; Lines = 10; Seconds = 1; Megabytes = 1 } -Baseline $null + + Runs the gate on one measurement for a runner with no baseline. + + .INPUTS + None. + + .OUTPUTS + IntuneScriptLab.Test.GateRun. Output, Failure and Passed. + #> + [CmdletBinding()] + [OutputType('IntuneScriptLab.Test.GateRun')] + param( + [Parameter()] + [hashtable[]]$Measurement = @(), + + [Parameter()] + [AllowNull()] + [string]$Baseline, + + [Parameter()] + [switch]$Record, + + [Parameter()] + [switch]$DefaultRunner, + + [Parameter()] + [string]$Culture + ) + + $folder = Join-Path -Path $TestDrive -ChildPath ([guid]::NewGuid().ToString('N')) + $null = New-Item -ItemType Directory -Path $folder + $resultPath = Join-Path -Path $folder -ChildPath 'measurements.jsonl' + $json = foreach ($item in $Measurement) { ([pscustomobject]$item | ConvertTo-Json -Compress) } + [System.IO.File]::WriteAllText($resultPath, (@($json) -join "`n"), [System.Text.UTF8Encoding]::new($false)) + $runners = if ($Baseline) { "'test/X64/7.6' = @{ $Baseline }" } else { '' } + $baselinePath = Join-Path -Path $folder -ChildPath 'Baselines.psd1' + $data = "@{ Margin = @{ Seconds = 0.5; Megabytes = 0.5 }; Runners = @{ $runners } }" + [System.IO.File]::WriteAllText($baselinePath, $data, [System.Text.UTF8Encoding]::new($false)) + + $gateSplat = @{ ResultPath = $resultPath; BaselinePath = $baselinePath; Runner = 'test/X64/7.6' } + if ($Record) { + $gateSplat['Record'] = $true + } + if ($DefaultRunner) { + $gateSplat.Remove('Runner') + } + $thread = [System.Threading.Thread]::CurrentThread + $savedCulture = $thread.CurrentCulture + $failure = $null + $output = try { + if ($Culture) { + $thread.CurrentCulture = [System.Globalization.CultureInfo]::new($Culture) + } + & $script:Gate @gateSplat 6>&1 3>&1 + } catch { + $failure = $_.Exception.Message + } finally { + $thread.CurrentCulture = $savedCulture + } + [pscustomobject]@{ + PSTypeName = 'IntuneScriptLab.Test.GateRun' + Output = (@($output) | ForEach-Object { "$_" }) -join "`n" + Failure = $failure + Passed = $null -eq $failure + } + } + + $script:Reader = 'Get-IntuneAgentLog' + $script:Base = "'Get-IntuneAgentLog/10000' = @{ Seconds = 4; Megabytes = 30 }" +} + +Describe 'Build/Test-PerformanceBaseline.ps1' -Tag 'Unit', 'Build' { + + Context 'Measurements within the baselines' { + It 'passes a median within the margin and says so for each measure' { + $result = Invoke-Gate -Baseline $script:Base -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 5.9; Megabytes = 44 } + ) + + $result.Passed | Should-BeTrue + $result.Output | Should-BeLikeString '*Get-IntuneAgentLog/10000: 5.9 Seconds, within the limit 6 *' + $result.Output | Should-BeLikeString '*44 Megabytes, within the limit 45 *' + $result.Output | Should-BeLikeString '*1 measurement(s) within the baselines*' + } + + It 'takes the median of the runs, so that one slow run does not fail the build' { + $result = Invoke-Gate -Baseline $script:Base -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 4.1; Megabytes = 30 } + @{ Name = $script:Reader; Lines = 10000; Seconds = 20; Megabytes = 31 } + @{ Name = $script:Reader; Lines = 10000; Seconds = 3.9; Megabytes = 29 } + ) + + $result.Passed | Should-BeTrue + $result.Output | Should-BeLikeString '*4.1 Seconds, within the limit 6 (baseline 4, median of 3 runs)*' + } + } + + Context 'Measurements above the baselines' { + It 'fails a median above the margin for ' -ForEach @( + @{ Measure = 'Seconds'; Seconds = 6.1; Megabytes = 30 } + @{ Measure = 'Megabytes'; Seconds = 4; Megabytes = 46 } + ) { + $result = Invoke-Gate -Baseline $script:Base -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = $Seconds; Megabytes = $Megabytes } + ) + + $result.Passed | Should-BeFalse + $result.Failure | Should-BeLikeString "*Get-IntuneAgentLog/10000:* $Measure, over the limit*" + } + + It 'fails when a measurement with a baseline was not taken' { + $result = Invoke-Gate -Baseline $script:Base -Measurement @( + @{ Name = 'Get-IntuneAgentTimeline'; Lines = 10000; Seconds = 1; Megabytes = 1 } + ) + + $result.Passed | Should-BeFalse + $result.Failure | Should-BeLikeString '*Get-IntuneAgentLog/10000: has a baseline*measured nothing*' + } + + It 'fails when the tests wrote no measurement' { + $result = Invoke-Gate -Baseline $script:Base + + $result.Passed | Should-BeFalse + $result.Failure | Should-BeLikeString '*No measurements*' + } + } + + Context 'What the gate reads' { + It 'passes a size the baselines do not name, and says it has none' { + $result = Invoke-Gate -Baseline $script:Base -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 4; Megabytes = 30 } + @{ Name = $script:Reader; Lines = 2500; Seconds = 1; Megabytes = 7 } + ) + + $result.Passed | Should-BeTrue + $result.Output | Should-BeLikeString '*Get-IntuneAgentLog/2500: 1 s, 7 MB, no baseline*' + } + + It 'refuses measurements from two PowerShell versions in one file' { + $result = Invoke-Gate -Baseline $script:Base -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 4; Megabytes = 30; PowerShell = '7.6.10' } + @{ Name = $script:Reader; Lines = 10000; Seconds = 4; Megabytes = 30; PowerShell = '5.1.26100' } + ) + + $result.Passed | Should-BeFalse + $result.Failure | Should-BeLikeString '*more than one PowerShell version (5.1.26100, 7.6.10)*' + } + + It 'names the runner by the image, the architecture and the PowerShell version' { + $savedImage = $env:ImageOS + $env:ImageOS = 'win99' + try { + $result = Invoke-Gate -Baseline $script:Base -DefaultRunner -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 4; Megabytes = 30 } + ) + } finally { + $env:ImageOS = $savedImage + } + + $architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture + $version = '{0}.{1}' -f $PSVersionTable.PSVersion.Major, $PSVersionTable.PSVersion.Minor + $result.Output | Should-BeLikeString "*runner 'win99/$architecture/$version'*" + } + + It 'writes numbers with a point under a culture that writes a comma' { + $result = Invoke-Gate -Baseline $null -Record -Culture 'de-DE' -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 1.06; Megabytes = 25.7 } + ) + + $entry = "'Get-IntuneAgentLog/10000' = @{ Seconds = 1.06; Megabytes = 25.7 }" + $result.Output | Should-BeLikeString "*$entry*" + } + } + Context 'A runner without baselines' { + It 'warns, prints what it measured, and passes' { + $result = Invoke-Gate -Baseline $null -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 99; Megabytes = 999 } + ) + + $result.Passed | Should-BeTrue + $result.Output | Should-BeLikeString "*No performance baseline for the runner 'test/X64/7.6'*" + $result.Output | Should-BeLikeString '*Get-IntuneAgentLog/10000 99 s 999 MB*' + } + + It 'prints the medians as a baseline entry with -Record' { + $result = Invoke-Gate -Baseline $null -Record -Measurement @( + @{ Name = $script:Reader; Lines = 10000; Seconds = 3; Megabytes = 20 } + @{ Name = $script:Reader; Lines = 10000; Seconds = 5; Megabytes = 30 } + ) + + $result.Passed | Should-BeTrue + $result.Output | Should-BeLikeString "*'test/X64/7.6' = @{*" + $result.Output | Should-BeLikeString "*'Get-IntuneAgentLog/10000' = @{ Seconds = 4; Megabytes = 25 }*" + } + } +} diff --git a/docs/StandardsDecisions.md b/docs/StandardsDecisions.md index 1769f71..5b3d79d 100644 --- a/docs/StandardsDecisions.md +++ b/docs/StandardsDecisions.md @@ -29,7 +29,7 @@ Each decision is one of three: | MOD-20, static data under `Data` | Build, as [#134](https://github.com/fadwen/IntuneScriptLab/issues/134) | The rule order, the inbox module table, the Windows release builds and the map of agent log events are `.psd1` files under `Data`. The root module reads each into a `$script:` variable when it is imported, and a file that is missing or does not parse fails the import. A data file holds constants only, so an agent log pattern too long for one line is an array of parts that `Get-IslAgentLogEvent` joins. | | MOD-21, a cache with an expiry | Does not fit | The module caches what it fetches within one run, and that run is the expiry that fits. `Get-IslAssignmentFilter` and `Test-IslDeviceGroup` keep a filter and a group's answer in the run's `Cache`, so a filter or group that several policies share is fetched once. Across runs a cache would be wrong: a tenant pre-flight has to read the tenant as it is now. The index of a parsed syntax tree is kept in a `ConditionalWeakTable` for as long as that tree exists. | | TST-43, performance and security tests | Build, as [#135](https://github.com/fadwen/IntuneScriptLab/issues/135) | `Tests/Performance/AgentLogReader.Tests.ps1` measures `Get-IntuneAgentLog` and `Get-IntuneAgentTimeline` on a generated log of 10,000 lines, time and memory against limits and the growth from 2,500 lines, and runs as `-TestType Performance` in the tests job. `Tests/Unit/Module.Credential.Tests.ps1`, tagged `Security`, shows that a `-Credential` password reaches the task registration and no stream, error, result or file; the input-length and pre-flight path tests carry the tag too. | -| CIC-13, performance gate | Build after TST-43, as [#136](https://github.com/fadwen/IntuneScriptLab/issues/136) | It compares with baselines that the performance tests have to record first. | +| CIC-13, performance gate | Build after TST-43, as [#136](https://github.com/fadwen/IntuneScriptLab/issues/136) | `Build/Test-PerformanceBaseline.ps1` compares the median of three runs of `Tests/Performance` with the baselines in `Tests/Performance/Baselines.psd1`, recorded for each hosted runner image, PowerShell version and architecture, and fails a median above its margin. A runner without a baseline, such as a new image, is reported and not gated. | | CIC-14, documentation gate for the README | Build, as [#137](https://github.com/fadwen/IntuneScriptLab/issues/137) | `Build/Test-MarkdownLink.ps1`, run by the `help` job, checks the anchors and relative links of the README and the other Markdown, as `docs/` is checked by `Build-Help.ps1 -ValidateOnly`. | | CIC-12, credential and dependency scanning | Build, as [#127](https://github.com/fadwen/IntuneScriptLab/issues/127) | No workflow scans for credentials. The standards installer adds a scan with `-IncludeCredentialScan`; the module has no dependencies to scan. | | PLT-12, the help build in the normal local build | Build, as [#138](https://github.com/fadwen/IntuneScriptLab/issues/138) | `Build/Invoke-Build.ps1` rebuilds the help and `docs/Rules.md`, checks the links, analyzes and runs the unit suites on 7 and 5.1, and heads the "Checks" in `CLAUDE.md` and `CONTRIBUTING.md`. |