microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-hardcoded-paths-in-artifacts

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/tests/pester.config.ps1

125lines · modecode

1#!/usr/bin/env pwsh
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4#
5# pester.config.ps1
6#
7# Purpose: Pester 5.x configuration for HVE-Core PowerShell testing
8# Author: HVE Core Team
9#
10
11[CmdletBinding()]
12param(
13 [Parameter()]
14 [switch]$CI,
15
16 [Parameter()]
17 [switch]$CodeCoverage,
18
19 [Parameter()]
20 [string[]]$TestPath = @("$PSScriptRoot")
21)
22
23# Dynamically discover skill test directories when using the default TestPath.
24# Skills live at .github/skills/<skill>/ or .github/skills/<collection>/<skill>/
25# so we probe two fixed depths.
26if (-not $PSBoundParameters.ContainsKey('TestPath')) {
27 $scriptRoot = Split-Path $PSScriptRoot -Parent
28 $repoRoot = Split-Path $scriptRoot -Parent
29 $skillsPath = Join-Path $repoRoot '.github' 'skills'
30 if (Test-Path $skillsPath) {
31 $skillTestDirs = @()
32 foreach ($depth in @('*', '*/*')) {
33 $pattern = Join-Path $skillsPath $depth 'tests'
34 $skillTestDirs += @(Get-Item -Path $pattern -ErrorAction SilentlyContinue |
35 Where-Object { $_.PSIsContainer -and (Test-Path (Join-Path $_.Parent.FullName 'scripts')) })
36 }
37 if ($skillTestDirs) {
38 $TestPath = @($TestPath) + @($skillTestDirs.FullName)
39 }
40 }
41}
42
43$configuration = New-PesterConfiguration
44
45# Run configuration
46$configuration.Run.Path = @($TestPath)
47$configuration.Run.Exit = $CI.IsPresent
48$configuration.Run.PassThru = $true
49$configuration.Run.TestExtension = '.Tests.ps1'
50
51# Filter configuration
52$configuration.Filter.ExcludeTag = @('Integration', 'Slow')
53
54# Output configuration
55$configuration.Output.Verbosity = if ($CI.IsPresent) { 'Normal' } else { 'Detailed' }
56$configuration.Output.CIFormat = if ($CI.IsPresent) { 'GithubActions' } else { 'Auto' }
57$configuration.Output.CILogLevel = 'Error'
58
59# Test result configuration (NUnit XML for CI artifact upload)
60$configuration.TestResult.Enabled = $CI.IsPresent
61$configuration.TestResult.OutputFormat = 'NUnitXml'
62$configuration.TestResult.OutputPath = Join-Path $PSScriptRoot '../../logs/pester-results.xml'
63$configuration.TestResult.TestSuiteName = 'HVE-Core-PowerShell-Tests'
64
65# Code coverage configuration
66if ($CodeCoverage.IsPresent) {
67 $configuration.CodeCoverage.Enabled = $true
68 $configuration.CodeCoverage.OutputFormat = 'JaCoCo'
69 $configuration.CodeCoverage.OutputPath = Join-Path $PSScriptRoot '../../logs/coverage.xml'
70
71 # Resolve coverage paths explicitly - Join-Path with wildcards returns literal paths without file system expansion in Pester configuration
72 $scriptRoot = Split-Path $PSScriptRoot -Parent
73 $coverageDirs = @('linting', 'security', 'lib', 'extension', 'plugins')
74
75 $coveragePaths = $coverageDirs | ForEach-Object {
76 Get-ChildItem -Path (Join-Path $scriptRoot $_) -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue
77 } | Where-Object {
78 $_.FullName -notmatch '\.Tests\.ps1$'
79 } | Select-Object -ExpandProperty FullName
80
81 # Resolve skill script coverage paths from repo root.
82 # Skills live at .github/skills/<skill>/ or .github/skills/<collection>/<skill>/
83 # so probe two fixed depths, matching test directory discovery above.
84 $repoRoot = Split-Path $scriptRoot -Parent
85 $skillsPath = Join-Path $repoRoot '.github/skills'
86 if (Test-Path $skillsPath) {
87 $skillRoots = @()
88 foreach ($depth in @('*', '*/*')) {
89 $pattern = Join-Path $skillsPath $depth 'scripts'
90 $skillRoots += @(Get-Item -Path $pattern -ErrorAction SilentlyContinue |
91 Where-Object { $_.PSIsContainer } |
92 ForEach-Object { $_.Parent })
93 }
94
95 $skillCoveragePaths = $skillRoots | ForEach-Object {
96 $skillRoot = $_.FullName
97 $skillScripts = Join-Path $skillRoot 'scripts'
98 $paths = @()
99
100 $paths += Get-ChildItem -Path $skillRoot -Include '*.ps1', '*.psm1' -File -ErrorAction SilentlyContinue
101
102 if (Test-Path $skillScripts) {
103 $paths += Get-ChildItem -Path $skillScripts -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue
104 }
105
106 $paths
107 } | Where-Object { $_.FullName -notmatch '\.Tests\.ps1$' } |
108 Select-Object -ExpandProperty FullName
109 if ($skillCoveragePaths) {
110 $coveragePaths = @($coveragePaths) + @($skillCoveragePaths)
111 }
112 }
113
114 if ($coveragePaths.Count -gt 0) {
115 $configuration.CodeCoverage.Path = $coveragePaths
116 }
117
118 $configuration.CodeCoverage.ExcludeTests = $true
119 $configuration.CodeCoverage.CoveragePercentTarget = 80
120}
121
122# Should configuration
123$configuration.Should.ErrorAction = 'Stop'
124
125return $configuration
126