Skip to content

Add Pester test suite and CI workflow#3

Merged
cgfixit merged 4 commits into
mainfrom
optimize/add-pester-tests
Jun 30, 2026
Merged

Add Pester test suite and CI workflow#3
cgfixit merged 4 commits into
mainfrom
optimize/add-pester-tests

Conversation

@cgfixit

@cgfixit cgfixit commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • New test file tests/sccmpatch.Tests.ps1 with 19 Pester tests covering:

    • Static analysis (5 tests): syntax validity, parameter declarations (Stage ValidateSet, Proxies type, PollDelay/DrainTimeoutMinutes defaults), CmdletBinding attribute
    • Exit code coverage (9 tests): verifies all 10 documented exit codes (0, 10, 20, 30, 40, 50, 60, 90, 99, 3010) are present with correct error messages
    • Robustness checks (5 tests): $ErrorActionPreference = 'Stop', null-safe $task.Info.WorkDetails access, $runningSessions null guard, cached $ProxyIdSet hashtable usage
    • Write-ProxyLog (3 tests): function existence, parameter signatures, default Level = 'INFO'
  • New CI workflow .github/workflows/pester.yml — runs on push/PR to main, uses pwsh on ubuntu-latest, uploads NUnit XML results as artifact.

Branching note

This branch is based on optimize/script-robustness (PR #1) since the robustness tests validate changes introduced there. Merge PR #1 first, then this one.

Test plan

  • Verify Pester workflow runs green on this PR
  • Confirm all 19 tests pass
  • Check NUnit XML artifact is uploaded

Generated by Claude Code

claude added 2 commits June 30, 2026 03:49
…xy IDs

- Set $ErrorActionPreference = 'Stop' inside the try block so unhandled
  errors in disable/enable/service operations bubble up to the catch
  instead of silently continuing.

- Guard against null dereference in drain loop: check $task.Info and
  $task.Info.WorkDetails before accessing SourceProxyId.

- Guard $runningSessions being null before piping to Get-VBRTaskSession,
  preventing pipeline errors when no sessions are active.

- Replace per-iteration Get-VBRViProxy lookup with a pre-built hashtable
  ($ProxyIdSet) keyed by proxy ID. Eliminates a redundant VBR API call
  on every poll cycle, reducing API load during drain waits.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDj3zuCAvrsZcQKsPpPHvA
Tests cover:
- Static analysis: syntax validity, parameter declarations, CmdletBinding
- Exit code coverage: all 10 documented exit codes verified present
- Robustness checks: ErrorActionPreference, null-safe task info access,
  session pipeline guard, cached proxy ID lookup
- Write-ProxyLog: function existence, parameter signatures, defaults

CI workflow runs Pester on ubuntu-latest with pwsh, uploads NUnit XML
results as an artifact.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDj3zuCAvrsZcQKsPpPHvA
@github-actions

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 2 package(s) with unknown licenses.
See the Details below.

License Issues

.github/workflows/pester.yml

PackageVersionLicenseIssue Type
actions/checkout4.*.*NullUnknown License
actions/upload-artifact4.*.*NullUnknown License

OpenSSF Scorecard

PackageVersionScoreDetails
actions/actions/checkout 4.*.* 🟢 6.9
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Maintained🟢 1016 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Packaging⚠️ -1packaging workflow not detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
Signed-Releases⚠️ -1no releases found
Security-Policy🟢 9security policy file detected
Branch-Protection🟢 5branch protection is not maximal on development and all release branches
SAST🟢 10SAST tool is run on all commits
actions/actions/upload-artifact 4.*.* 🟢 5.5
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Binary-Artifacts🟢 10no binaries found in the repo
Maintained🟢 34 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Packaging⚠️ -1packaging workflow not detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Pinned-Dependencies⚠️ 1dependency not pinned by hash detected -- score normalized to 1
License🟢 10license file detected
Fuzzing⚠️ 0project is not fuzzed
Signed-Releases⚠️ -1no releases found
Security-Policy🟢 9security policy file detected
SAST🟢 10SAST tool is run on all commits
Branch-Protection⚠️ 0branch protection not enabled on development/release branches

Scanned Files

  • .github/workflows/pester.yml

PowerShell's parser interprets `$Node:` as a scope-qualified variable
reference (like `$env:PATH`), causing a parse error: "':' was not
followed by a valid variable name character." Use `${Node}` to
explicitly delimit the variable name from the literal colon.

This bug was caught by the new Pester "parses without syntax errors"
test — the script parsed successfully on Windows PowerShell 5.1 (which
is more lenient) but fails on PowerShell 7 (cross-platform).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDj3zuCAvrsZcQKsPpPHvA
Comment thread tests/sccmpatch.Tests.ps1 Fixed
@cgfixit cgfixit marked this pull request as ready for review June 30, 2026 03:55
PSScriptAnalyzer flagged positional parameter usage on Join-Path.
Switch to explicit -Path, -ChildPath, -AdditionalChildPath.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDj3zuCAvrsZcQKsPpPHvA
@cgfixit cgfixit merged commit 6019f99 into main Jun 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants