microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
scripts/tests/plugins/PluginHelpers.Tests.ps1
309lines · modecode
| 1 | #Requires -Modules Pester |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | |
| 5 | BeforeAll { |
| 6 | Import-Module $PSScriptRoot/../../plugins/Modules/PluginHelpers.psm1 -Force |
| 7 | } |
| 8 | |
| 9 | Describe 'Get-ArtifactFiles - hve-core path exclusion' { |
| 10 | BeforeAll { |
| 11 | $script:repoRoot = Join-Path $TestDrive 'repo' |
| 12 | $ghDir = Join-Path $script:repoRoot '.github' |
| 13 | |
| 14 | # Create agent files |
| 15 | $agentsDir = Join-Path $ghDir 'agents' |
| 16 | New-Item -ItemType Directory -Path $agentsDir -Force | Out-Null |
| 17 | Set-Content -Path (Join-Path $agentsDir 'good.agent.md') -Value '---\ndescription: good\n---' |
| 18 | |
| 19 | # Create instruction files (shared) |
| 20 | $instrDir = Join-Path $ghDir 'instructions' |
| 21 | New-Item -ItemType Directory -Path $instrDir -Force | Out-Null |
| 22 | Set-Content -Path (Join-Path $instrDir 'shared.instructions.md') -Value '---\ndescription: shared\n---' |
| 23 | |
| 24 | # Create repo-specific files under .github/instructions/hve-core/ |
| 25 | $hveCoreInstrDir = Join-Path $instrDir 'hve-core' |
| 26 | New-Item -ItemType Directory -Path $hveCoreInstrDir -Force | Out-Null |
| 27 | Set-Content -Path (Join-Path $hveCoreInstrDir 'workflows.instructions.md') -Value '---\ndescription: repo-specific\n---' |
| 28 | |
| 29 | # Create repo-specific files under .github/agents/hve-core/ |
| 30 | $hveCoreAgentsDir = Join-Path $agentsDir 'hve-core' |
| 31 | New-Item -ItemType Directory -Path $hveCoreAgentsDir -Force | Out-Null |
| 32 | Set-Content -Path (Join-Path $hveCoreAgentsDir 'internal.agent.md') -Value '---\ndescription: repo-specific agent\n---' |
| 33 | |
| 34 | # Create a prompt file |
| 35 | $promptsDir = Join-Path $ghDir 'prompts' |
| 36 | New-Item -ItemType Directory -Path $promptsDir -Force | Out-Null |
| 37 | Set-Content -Path (Join-Path $promptsDir 'gen-plan.prompt.md') -Value '---\ndescription: prompt\n---' |
| 38 | } |
| 39 | |
| 40 | It 'Excludes files under .github/instructions/hve-core/' { |
| 41 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 42 | $paths = $items | ForEach-Object { $_.path } |
| 43 | $paths | Should -Not -Contain '.github/instructions/hve-core/workflows.instructions.md' |
| 44 | } |
| 45 | |
| 46 | It 'Excludes files under .github/agents/hve-core/' { |
| 47 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 48 | $paths = $items | ForEach-Object { $_.path } |
| 49 | $paths | Should -Not -Contain '.github/agents/hve-core/internal.agent.md' |
| 50 | } |
| 51 | |
| 52 | It 'Includes shared instruction files' { |
| 53 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 54 | $paths = $items | ForEach-Object { $_.path } |
| 55 | $paths | Should -Contain '.github/instructions/shared.instructions.md' |
| 56 | } |
| 57 | |
| 58 | It 'Includes non-hve-core agent files' { |
| 59 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 60 | $paths = $items | ForEach-Object { $_.path } |
| 61 | $paths | Should -Contain '.github/agents/good.agent.md' |
| 62 | } |
| 63 | |
| 64 | It 'Includes prompt files' { |
| 65 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 66 | $paths = $items | ForEach-Object { $_.path } |
| 67 | $paths | Should -Contain '.github/prompts/gen-plan.prompt.md' |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | Describe 'Get-ArtifactFiles - deprecated path exclusion' { |
| 72 | BeforeAll { |
| 73 | $script:repoRoot = Join-Path $TestDrive 'repo-deprecated' |
| 74 | $ghDir = Join-Path $script:repoRoot '.github' |
| 75 | |
| 76 | # Create non-deprecated artifacts |
| 77 | $agentsDir = Join-Path $ghDir 'agents/rpi' |
| 78 | New-Item -ItemType Directory -Path $agentsDir -Force | Out-Null |
| 79 | Set-Content -Path (Join-Path $agentsDir 'active.agent.md') -Value '---\ndescription: active\n---' |
| 80 | |
| 81 | $promptsDir = Join-Path $ghDir 'prompts/rpi' |
| 82 | New-Item -ItemType Directory -Path $promptsDir -Force | Out-Null |
| 83 | Set-Content -Path (Join-Path $promptsDir 'active.prompt.md') -Value '---\ndescription: active\n---' |
| 84 | |
| 85 | # Create deprecated artifacts |
| 86 | $deprecatedAgentsDir = Join-Path $ghDir 'deprecated/agents' |
| 87 | New-Item -ItemType Directory -Path $deprecatedAgentsDir -Force | Out-Null |
| 88 | Set-Content -Path (Join-Path $deprecatedAgentsDir 'old.agent.md') -Value '---\ndescription: deprecated\n---' |
| 89 | |
| 90 | $deprecatedPromptsDir = Join-Path $ghDir 'deprecated/prompts' |
| 91 | New-Item -ItemType Directory -Path $deprecatedPromptsDir -Force | Out-Null |
| 92 | Set-Content -Path (Join-Path $deprecatedPromptsDir 'old.prompt.md') -Value '---\ndescription: deprecated\n---' |
| 93 | |
| 94 | $deprecatedInstrDir = Join-Path $ghDir 'deprecated/instructions' |
| 95 | New-Item -ItemType Directory -Path $deprecatedInstrDir -Force | Out-Null |
| 96 | Set-Content -Path (Join-Path $deprecatedInstrDir 'old.instructions.md') -Value '---\ndescription: deprecated\n---' |
| 97 | |
| 98 | # Create deprecated skill |
| 99 | $deprecatedSkillDir = Join-Path $ghDir 'deprecated/skills/old-skill' |
| 100 | New-Item -ItemType Directory -Path $deprecatedSkillDir -Force | Out-Null |
| 101 | Set-Content -Path (Join-Path $deprecatedSkillDir 'SKILL.md') -Value '---\nname: old-skill\ndescription: deprecated\n---' |
| 102 | |
| 103 | # Create non-deprecated skill (under .github/skills/) |
| 104 | $skillDir = Join-Path $ghDir 'skills/experimental/good-skill' |
| 105 | New-Item -ItemType Directory -Path $skillDir -Force | Out-Null |
| 106 | Set-Content -Path (Join-Path $skillDir 'SKILL.md') -Value '---\nname: good-skill\ndescription: active\n---' |
| 107 | } |
| 108 | |
| 109 | It 'Excludes deprecated agent files' { |
| 110 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 111 | $paths = $items | ForEach-Object { $_.path } |
| 112 | $paths | Should -Not -Contain '.github/deprecated/agents/old.agent.md' |
| 113 | } |
| 114 | |
| 115 | It 'Excludes deprecated prompt files' { |
| 116 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 117 | $paths = $items | ForEach-Object { $_.path } |
| 118 | $paths | Should -Not -Contain '.github/deprecated/prompts/old.prompt.md' |
| 119 | } |
| 120 | |
| 121 | It 'Excludes deprecated instruction files' { |
| 122 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 123 | $paths = $items | ForEach-Object { $_.path } |
| 124 | $paths | Should -Not -Contain '.github/deprecated/instructions/old.instructions.md' |
| 125 | } |
| 126 | |
| 127 | It 'Excludes deprecated skill directories' { |
| 128 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 129 | $paths = $items | ForEach-Object { $_.path } |
| 130 | $paths | Should -Not -Contain '.github/deprecated/skills/old-skill' |
| 131 | } |
| 132 | |
| 133 | It 'Includes non-deprecated artifacts' { |
| 134 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 135 | $paths = $items | ForEach-Object { $_.path } |
| 136 | $paths | Should -Contain '.github/agents/rpi/active.agent.md' |
| 137 | $paths | Should -Contain '.github/prompts/rpi/active.prompt.md' |
| 138 | } |
| 139 | |
| 140 | It 'Includes non-deprecated skills' { |
| 141 | $items = Get-ArtifactFiles -RepoRoot $script:repoRoot |
| 142 | $paths = $items | ForEach-Object { $_.path } |
| 143 | $paths | Should -Contain '.github/skills/experimental/good-skill' |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | Describe 'Test-DeprecatedPath' { |
| 148 | It 'Returns true for path containing /deprecated/ segment' { |
| 149 | Test-DeprecatedPath -Path '.github/deprecated/agents/old.agent.md' | Should -BeTrue |
| 150 | } |
| 151 | |
| 152 | It 'Returns true for path with backslash deprecated segment' { |
| 153 | Test-DeprecatedPath -Path '.github\deprecated\agents\old.agent.md' | Should -BeTrue |
| 154 | } |
| 155 | |
| 156 | It 'Returns false for path without deprecated segment' { |
| 157 | Test-DeprecatedPath -Path '.github/agents/rpi/active.agent.md' | Should -BeFalse |
| 158 | } |
| 159 | |
| 160 | It 'Returns false when deprecated appears in filename only' { |
| 161 | Test-DeprecatedPath -Path '.github/agents/deprecated-notes.agent.md' | Should -BeFalse |
| 162 | } |
| 163 | |
| 164 | It 'Returns true for mid-path deprecated directory' { |
| 165 | Test-DeprecatedPath -Path 'skills/deprecated/old-skill/SKILL.md' | Should -BeTrue |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | Describe 'Test-HveCoreRepoSpecificPath' { |
| 170 | It 'Returns true for path starting with hve-core/' { |
| 171 | Test-HveCoreRepoSpecificPath -RelativePath 'hve-core/workflows.instructions.md' | Should -BeTrue |
| 172 | } |
| 173 | |
| 174 | It 'Returns false for path not starting with hve-core/' { |
| 175 | Test-HveCoreRepoSpecificPath -RelativePath 'rpi/active.agent.md' | Should -BeFalse |
| 176 | } |
| 177 | |
| 178 | It 'Returns false when hve-core appears mid-path' { |
| 179 | Test-HveCoreRepoSpecificPath -RelativePath 'shared/hve-core/foo.md' | Should -BeFalse |
| 180 | } |
| 181 | |
| 182 | It 'Returns true for nested path under hve-core/' { |
| 183 | Test-HveCoreRepoSpecificPath -RelativePath 'hve-core/deep/nested.md' | Should -BeTrue |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | Describe 'Test-HveCoreRepoRelativePath' { |
| 188 | It 'Returns true for .github/agents/hve-core/ path' { |
| 189 | Test-HveCoreRepoRelativePath -Path '.github/agents/hve-core/internal.agent.md' | Should -BeTrue |
| 190 | } |
| 191 | |
| 192 | It 'Returns true for .github/instructions/hve-core/ path' { |
| 193 | Test-HveCoreRepoRelativePath -Path '.github/instructions/hve-core/workflows.instructions.md' | Should -BeTrue |
| 194 | } |
| 195 | |
| 196 | It 'Returns true for .github/prompts/hve-core/ path' { |
| 197 | Test-HveCoreRepoRelativePath -Path '.github/prompts/hve-core/internal.prompt.md' | Should -BeTrue |
| 198 | } |
| 199 | |
| 200 | It 'Returns false for non-.github path' { |
| 201 | Test-HveCoreRepoRelativePath -Path 'scripts/plugins/foo.ps1' | Should -BeFalse |
| 202 | } |
| 203 | |
| 204 | It 'Returns false for .github path without hve-core segment' { |
| 205 | Test-HveCoreRepoRelativePath -Path '.github/agents/rpi/active.agent.md' | Should -BeFalse |
| 206 | } |
| 207 | |
| 208 | It 'Returns false for hve-core at wrong nesting level' { |
| 209 | Test-HveCoreRepoRelativePath -Path '.github/hve-core/foo.md' | Should -BeFalse |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | Describe 'Resolve-CollectionItemMaturity' { |
| 214 | It 'Returns stable for null' { |
| 215 | $result = Resolve-CollectionItemMaturity -Maturity $null |
| 216 | $result | Should -Be 'stable' |
| 217 | } |
| 218 | |
| 219 | It 'Returns stable for empty string' { |
| 220 | $result = Resolve-CollectionItemMaturity -Maturity '' |
| 221 | $result | Should -Be 'stable' |
| 222 | } |
| 223 | |
| 224 | It 'Returns stable for whitespace' { |
| 225 | $result = Resolve-CollectionItemMaturity -Maturity ' ' |
| 226 | $result | Should -Be 'stable' |
| 227 | } |
| 228 | |
| 229 | It 'Passes through preview' { |
| 230 | $result = Resolve-CollectionItemMaturity -Maturity 'preview' |
| 231 | $result | Should -Be 'preview' |
| 232 | } |
| 233 | |
| 234 | It 'Passes through experimental' { |
| 235 | $result = Resolve-CollectionItemMaturity -Maturity 'experimental' |
| 236 | $result | Should -Be 'experimental' |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | Describe 'Test-ArtifactDeprecated' { |
| 241 | It 'Returns true for deprecated' { |
| 242 | $result = Test-ArtifactDeprecated -Maturity 'deprecated' |
| 243 | $result | Should -BeTrue |
| 244 | } |
| 245 | |
| 246 | It 'Returns false for stable' { |
| 247 | $result = Test-ArtifactDeprecated -Maturity 'stable' |
| 248 | $result | Should -BeFalse |
| 249 | } |
| 250 | |
| 251 | It 'Returns false for preview' { |
| 252 | $result = Test-ArtifactDeprecated -Maturity 'preview' |
| 253 | $result | Should -BeFalse |
| 254 | } |
| 255 | |
| 256 | It 'Returns false for experimental' { |
| 257 | $result = Test-ArtifactDeprecated -Maturity 'experimental' |
| 258 | $result | Should -BeFalse |
| 259 | } |
| 260 | |
| 261 | It 'Returns false for null (defaults to stable)' { |
| 262 | $result = Test-ArtifactDeprecated -Maturity $null |
| 263 | $result | Should -BeFalse |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | Describe 'Get-PluginItemName' { |
| 268 | It 'Strips .agent.md suffix' { |
| 269 | $result = Get-PluginItemName -FileName 'task-researcher.agent.md' -Kind 'agent' |
| 270 | $result | Should -Be 'task-researcher.md' |
| 271 | } |
| 272 | |
| 273 | It 'Strips .prompt.md suffix' { |
| 274 | $result = Get-PluginItemName -FileName 'gen-plan.prompt.md' -Kind 'prompt' |
| 275 | $result | Should -Be 'gen-plan.md' |
| 276 | } |
| 277 | |
| 278 | It 'Strips .instructions.md suffix' { |
| 279 | $result = Get-PluginItemName -FileName 'csharp.instructions.md' -Kind 'instruction' |
| 280 | $result | Should -Be 'csharp.md' |
| 281 | } |
| 282 | |
| 283 | It 'Returns skill directory name unchanged' { |
| 284 | $result = Get-PluginItemName -FileName 'video-to-gif' -Kind 'skill' |
| 285 | $result | Should -Be 'video-to-gif' |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | Describe 'Get-PluginSubdirectory' { |
| 290 | It 'Maps agent to agents' { |
| 291 | $result = Get-PluginSubdirectory -Kind 'agent' |
| 292 | $result | Should -Be 'agents' |
| 293 | } |
| 294 | |
| 295 | It 'Maps prompt to commands' { |
| 296 | $result = Get-PluginSubdirectory -Kind 'prompt' |
| 297 | $result | Should -Be 'commands' |
| 298 | } |
| 299 | |
| 300 | It 'Maps instruction to instructions' { |
| 301 | $result = Get-PluginSubdirectory -Kind 'instruction' |
| 302 | $result | Should -Be 'instructions' |
| 303 | } |
| 304 | |
| 305 | It 'Maps skill to skills' { |
| 306 | $result = Get-PluginSubdirectory -Kind 'skill' |
| 307 | $result | Should -Be 'skills' |
| 308 | } |
| 309 | } |
| 310 | |