Skip to content

Commit 22dfa9a

Browse files
fix: migrate Pester tests to v5 syntax for CI compatibility
- BeforeAll at script root (Pester 5 requirement) - Should -Be instead of Should Be (legacy v3 syntax removed) - Should -Not -Throw instead of Should Not Throw - $PSScriptRoot instead of $MyInvocation.MyCommand.Path - Cross-platform absolute path test (Windows vs Linux) - validate.yml: explicit Pester 5 install + New-PesterConfiguration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3a2b59d commit 22dfa9a

File tree

3 files changed

+73
-57
lines changed

3 files changed

+73
-57
lines changed

.github/workflows/validate.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ jobs:
2525
- name: Checkout
2626
uses: actions/checkout@v6
2727

28+
- name: Install Pester 5
29+
shell: pwsh
30+
run: |
31+
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser -SkipPublisherCheck
32+
2833
- name: Run Pester tests
2934
shell: pwsh
3035
run: |
31-
$results = Invoke-Pester tests/ -PassThru
36+
Import-Module Pester -MinimumVersion 5.0
37+
$config = New-PesterConfiguration
38+
$config.Run.Path = "tests/"
39+
$config.Run.PassThru = $true
40+
$config.Output.Verbosity = "Detailed"
41+
$results = Invoke-Pester -Configuration $config
3242
if ($results.FailedCount -gt 0) { exit 1 }
3343
3444
test-cli:

tests/common.Tests.ps1

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
2-
. (Join-Path (Join-Path (Join-Path $here "..") "scripts") "common.ps1")
1+
BeforeAll {
2+
. (Join-Path $PSScriptRoot ".." "scripts" "common.ps1")
3+
}
34

45
Describe "New-GitHubHeaders" {
56

67
It "returns User-Agent header without token" {
78
$env:GITHUB_TOKEN = ""
89
$h = New-GitHubHeaders
9-
$h["User-Agent"] | Should Be "dusan-maintains-oss-log"
10-
$h.ContainsKey("Authorization") | Should Be $false
10+
$h["User-Agent"] | Should -Be "dusan-maintains-oss-log"
11+
$h.ContainsKey("Authorization") | Should -Be $false
1112
}
1213

1314
It "includes Authorization when GITHUB_TOKEN is set" {
1415
$env:GITHUB_TOKEN = "test-token-123"
1516
try {
1617
$h = New-GitHubHeaders
17-
$h["Authorization"] | Should Be "Bearer test-token-123"
18-
$h["X-GitHub-Api-Version"] | Should Be "2022-11-28"
18+
$h["Authorization"] | Should -Be "Bearer test-token-123"
19+
$h["X-GitHub-Api-Version"] | Should -Be "2022-11-28"
1920
} finally {
2021
$env:GITHUB_TOKEN = ""
2122
}
@@ -26,21 +27,25 @@ Describe "Get-RepoRoot" {
2627

2728
It "returns the parent of scripts directory" {
2829
$root = Get-RepoRoot
29-
$root | Should Not BeNullOrEmpty
30-
(Test-Path (Join-Path $root "scripts")) | Should Be $true
30+
$root | Should -Not -BeNullOrEmpty
31+
(Test-Path (Join-Path $root "scripts")) | Should -Be $true
3132
}
3233
}
3334

3435
Describe "Resolve-RepoPath" {
3536

3637
It "resolves a relative path to repo root" {
3738
$resolved = Resolve-RepoPath -Path "config/tracked-repositories.json"
38-
$resolved | Should Match "tracked-repositories\.json$"
39+
$resolved | Should -Match "tracked-repositories\.json$"
3940
}
4041

4142
It "returns absolute paths unchanged" {
42-
$abs = "C:\absolute\path.json"
43-
(Resolve-RepoPath -Path $abs) | Should Be $abs
43+
if ($IsWindows -or $env:OS -match "Windows") {
44+
$abs = "C:\absolute\path.json"
45+
} else {
46+
$abs = "/absolute/path.json"
47+
}
48+
(Resolve-RepoPath -Path $abs) | Should -Be $abs
4449
}
4550
}
4651

@@ -49,9 +54,9 @@ Describe "Ensure-Directory" {
4954
It "creates a directory if it does not exist" {
5055
$testDir = Join-Path ([System.IO.Path]::GetTempPath()) "oss-test-$(Get-Random)"
5156
try {
52-
(Test-Path $testDir) | Should Be $false
57+
(Test-Path $testDir) | Should -Be $false
5358
Ensure-Directory -Path $testDir
54-
(Test-Path $testDir) | Should Be $true
59+
(Test-Path $testDir) | Should -Be $true
5560
} finally {
5661
if (Test-Path $testDir) { Remove-Item $testDir -Recurse -Force }
5762
}
@@ -61,7 +66,7 @@ Describe "Ensure-Directory" {
6166
$testDir = Join-Path ([System.IO.Path]::GetTempPath()) "oss-test-$(Get-Random)"
6267
New-Item -ItemType Directory -Path $testDir | Out-Null
6368
try {
64-
{ Ensure-Directory -Path $testDir } | Should Not Throw
69+
{ Ensure-Directory -Path $testDir } | Should -Not -Throw
6570
} finally {
6671
Remove-Item $testDir -Recurse -Force
6772
}
@@ -72,18 +77,18 @@ Describe "Get-TrackedConfig" {
7277

7378
It "parses the default config file" {
7479
$cfg = Get-TrackedConfig
75-
$cfg.version | Should Be 1
76-
$cfg.contributor | Should Be "dusan-maintains"
77-
$cfg.repositories.Count | Should BeGreaterThan 4
80+
$cfg.version | Should -Be 1
81+
$cfg.contributor | Should -Be "dusan-maintains"
82+
$cfg.repositories.Count | Should -BeGreaterThan 4
7883
}
7984

8085
It "each repository has required fields" {
8186
$cfg = Get-TrackedConfig
8287
foreach ($repo in $cfg.repositories) {
83-
$repo.owner | Should Not BeNullOrEmpty
84-
$repo.repo | Should Not BeNullOrEmpty
85-
$repo.tracked_pr_numbers | Should Not BeNullOrEmpty
86-
$repo.review_sla_base_name | Should Not BeNullOrEmpty
88+
$repo.owner | Should -Not -BeNullOrEmpty
89+
$repo.repo | Should -Not -BeNullOrEmpty
90+
$repo.tracked_pr_numbers | Should -Not -BeNullOrEmpty
91+
$repo.review_sla_base_name | Should -Not -BeNullOrEmpty
8792
}
8893
}
8994
}
@@ -92,14 +97,14 @@ Describe "Convert-StringToUtcDateTime" {
9297

9398
It "parses ISO 8601 strings" {
9499
$dt = Convert-StringToUtcDateTime -Value "2026-03-15T12:30:00Z"
95-
$dt.Year | Should Be 2026
96-
$dt.Month | Should Be 3
97-
$dt.Day | Should Be 15
98-
$dt.Hour | Should Be 12
99-
$dt.Minute | Should Be 30
100+
$dt.Year | Should -Be 2026
101+
$dt.Month | Should -Be 3
102+
$dt.Day | Should -Be 15
103+
$dt.Hour | Should -Be 12
104+
$dt.Minute | Should -Be 30
100105
}
101106

102107
It "throws on invalid input" {
103-
{ Convert-StringToUtcDateTime -Value "not-a-date" } | Should Throw
108+
{ Convert-StringToUtcDateTime -Value "not-a-date" } | Should -Throw
104109
}
105110
}

tests/health-score.Tests.ps1

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,72 @@
1-
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
2-
. (Join-Path (Join-Path (Join-Path $here "..") "scripts") "common.ps1")
1+
BeforeAll {
2+
. (Join-Path $PSScriptRoot ".." "scripts" "common.ps1")
33

4-
function Get-LogScore {
5-
param([double]$Value, [double]$Scale = 1000)
6-
if ($Value -le 0) { return 0 }
7-
$raw = [Math]::Log10($Value + 1) / [Math]::Log10($Scale + 1) * 10
8-
return [Math]::Min([Math]::Round($raw, 2), 10)
9-
}
4+
function Get-LogScore {
5+
param([double]$Value, [double]$Scale = 1000)
6+
if ($Value -le 0) { return 0 }
7+
$raw = [Math]::Log10($Value + 1) / [Math]::Log10($Scale + 1) * 10
8+
return [Math]::Min([Math]::Round($raw, 2), 10)
9+
}
1010

11-
function Get-DecayScore {
12-
param([double]$DaysSinceEvent, [double]$HalfLifeDays = 180)
13-
if ($DaysSinceEvent -le 0) { return 10 }
14-
$score = 10 * [Math]::Exp(-0.693 * $DaysSinceEvent / $HalfLifeDays)
15-
return [Math]::Round([Math]::Max($score, 0), 2)
11+
function Get-DecayScore {
12+
param([double]$DaysSinceEvent, [double]$HalfLifeDays = 180)
13+
if ($DaysSinceEvent -le 0) { return 10 }
14+
$score = 10 * [Math]::Exp(-0.693 * $DaysSinceEvent / $HalfLifeDays)
15+
return [Math]::Round([Math]::Max($score, 0), 2)
16+
}
1617
}
1718

1819
Describe "Get-LogScore" {
1920

2021
It "returns 0 for zero input" {
21-
(Get-LogScore -Value 0) | Should Be 0
22+
(Get-LogScore -Value 0) | Should -Be 0
2223
}
2324

2425
It "returns 0 for negative input" {
25-
(Get-LogScore -Value -5) | Should Be 0
26+
(Get-LogScore -Value -5) | Should -Be 0
2627
}
2728

2829
It "returns score between 0 and 10 for positive values" {
2930
$score = Get-LogScore -Value 500 -Scale 1000
30-
$score | Should BeGreaterThan 0
31-
$score | Should Not BeGreaterThan 10
31+
$score | Should -BeGreaterThan 0
32+
$score | Should -Not -BeGreaterThan 10
3233
}
3334

3435
It "scales logarithmically - 1M scores higher than 1k" {
3536
$low = Get-LogScore -Value 1000 -Scale 1000000
3637
$high = Get-LogScore -Value 1000000 -Scale 1000000
37-
$high | Should BeGreaterThan $low
38+
$high | Should -BeGreaterThan $low
3839
}
3940

4041
It "caps at 10" {
4142
$score = Get-LogScore -Value 999999999 -Scale 1000
42-
$score | Should Be 10
43+
$score | Should -Be 10
4344
}
4445
}
4546

4647
Describe "Get-DecayScore" {
4748

4849
It "returns 10 for 0 days" {
49-
(Get-DecayScore -DaysSinceEvent 0) | Should Be 10
50+
(Get-DecayScore -DaysSinceEvent 0) | Should -Be 10
5051
}
5152

5253
It "returns approximately 5 at half-life" {
5354
$score = Get-DecayScore -DaysSinceEvent 180 -HalfLifeDays 180
54-
$score | Should BeGreaterThan 4
55-
$score | Should BeLessThan 6
55+
$score | Should -BeGreaterThan 4
56+
$score | Should -BeLessThan 6
5657
}
5758

5859
It "scores decrease over time" {
5960
$fresh = Get-DecayScore -DaysSinceEvent 30
6061
$old = Get-DecayScore -DaysSinceEvent 365
6162
$ancient = Get-DecayScore -DaysSinceEvent 730
62-
$fresh | Should BeGreaterThan $old
63-
$old | Should BeGreaterThan $ancient
63+
$fresh | Should -BeGreaterThan $old
64+
$old | Should -BeGreaterThan $ancient
6465
}
6566

6667
It "never goes below 0" {
6768
$score = Get-DecayScore -DaysSinceEvent 99999
68-
$score | Should Not BeLessThan 0
69+
$score | Should -BeGreaterOrEqual 0
6970
}
7071
}
7172

@@ -75,11 +76,11 @@ Describe "Health Score JSON Schema" {
7576
$jsonPath = Join-Path (Join-Path (Get-RepoRoot) "evidence") "health-scores.json"
7677
if (Test-Path $jsonPath) {
7778
$data = Get-Content $jsonPath -Raw | ConvertFrom-Json
78-
$data.generated_at_utc | Should Not BeNullOrEmpty
79-
$data.summary.total_projects | Should BeGreaterThan 0
79+
$data.generated_at_utc | Should -Not -BeNullOrEmpty
80+
$data.summary.total_projects | Should -BeGreaterThan 0
8081
foreach ($s in $data.scores) {
81-
$s.health_score | Should Not BeLessThan 0
82-
$s.health_score | Should Not BeGreaterThan 100
82+
$s.health_score | Should -BeGreaterOrEqual 0
83+
$s.health_score | Should -BeLessOrEqual 100
8384
}
8485
}
8586
}

0 commit comments

Comments
 (0)