microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e525ede62a19e340ca4e7865cb6bcb43d88e91d8

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/tests/plugins/PluginHelpers.Tests.ps1

324lines · modecode

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