microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v2.3.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/tests/plugins/Validate-Collections.Tests.ps1

199lines · modecode

1#Requires -Modules Pester
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4
5BeforeAll {
6 . $PSScriptRoot/../../plugins/Validate-Collections.ps1
7}
8
9Describe 'Test-KindSuffix' {
10 It 'Returns empty for valid agent path' {
11 $result = Test-KindSuffix -Kind 'agent' -ItemPath '.github/agents/rpi-agent.agent.md' -RepoRoot $TestDrive
12 $result | Should -BeNullOrEmpty
13 }
14
15 It 'Returns empty for valid prompt path' {
16 $result = Test-KindSuffix -Kind 'prompt' -ItemPath '.github/prompts/gen-plan.prompt.md' -RepoRoot $TestDrive
17 $result | Should -BeNullOrEmpty
18 }
19
20 It 'Returns empty for valid instruction path' {
21 $result = Test-KindSuffix -Kind 'instruction' -ItemPath '.github/instructions/csharp.instructions.md' -RepoRoot $TestDrive
22 $result | Should -BeNullOrEmpty
23 }
24
25 It 'Returns empty for valid skill path with SKILL.md' {
26 $skillDir = Join-Path $TestDrive '.github/skills/video-to-gif'
27 New-Item -ItemType Directory -Path $skillDir -Force | Out-Null
28 Set-Content -Path (Join-Path $skillDir 'SKILL.md') -Value '# Skill'
29
30 $result = Test-KindSuffix -Kind 'skill' -ItemPath '.github/skills/video-to-gif' -RepoRoot $TestDrive
31 $result | Should -BeNullOrEmpty
32 }
33
34 It 'Returns error for invalid agent suffix' {
35 $result = Test-KindSuffix -Kind 'agent' -ItemPath '.github/agents/bad.prompt.md' -RepoRoot $TestDrive
36 $result | Should -Match "kind 'agent' expects"
37 }
38
39 It 'Returns error for invalid prompt suffix' {
40 $result = Test-KindSuffix -Kind 'prompt' -ItemPath '.github/prompts/bad.agent.md' -RepoRoot $TestDrive
41 $result | Should -Match "kind 'prompt' expects"
42 }
43
44 It 'Returns error when SKILL.md missing for skill kind' {
45 $emptySkillDir = Join-Path $TestDrive '.github/skills/no-skill'
46 New-Item -ItemType Directory -Path $emptySkillDir -Force | Out-Null
47
48 $result = Test-KindSuffix -Kind 'skill' -ItemPath '.github/skills/no-skill' -RepoRoot $TestDrive
49 $result | Should -Match "kind 'skill' expects SKILL.md"
50 }
51}
52
53Describe 'Resolve-ItemMaturity' {
54 It 'Returns stable for null maturity' {
55 $result = Resolve-ItemMaturity -Maturity $null
56 $result | Should -Be 'stable'
57 }
58
59 It 'Returns stable for empty string' {
60 $result = Resolve-ItemMaturity -Maturity ''
61 $result | Should -Be 'stable'
62 }
63
64 It 'Returns stable for whitespace' {
65 $result = Resolve-ItemMaturity -Maturity ' '
66 $result | Should -Be 'stable'
67 }
68
69 It 'Passes through explicit value' {
70 $result = Resolve-ItemMaturity -Maturity 'preview'
71 $result | Should -Be 'preview'
72 }
73
74 It 'Passes through experimental value' {
75 $result = Resolve-ItemMaturity -Maturity 'experimental'
76 $result | Should -Be 'experimental'
77 }
78}
79
80Describe 'Get-CollectionItemKey' {
81 It 'Builds correct composite key' {
82 $result = Get-CollectionItemKey -Kind 'agent' -ItemPath '.github/agents/rpi-agent.agent.md'
83 $result | Should -Be 'agent|.github/agents/rpi-agent.agent.md'
84 }
85
86 It 'Builds key for instruction kind' {
87 $result = Get-CollectionItemKey -Kind 'instruction' -ItemPath '.github/instructions/csharp.instructions.md'
88 $result | Should -Be 'instruction|.github/instructions/csharp.instructions.md'
89 }
90}
91
92Describe 'Invoke-CollectionValidation - repo-specific path rejection' {
93 BeforeAll {
94 Import-Module PowerShell-Yaml -ErrorAction Stop
95
96 $script:repoRoot = Join-Path $TestDrive 'repo'
97 $script:collectionsDir = Join-Path $script:repoRoot 'collections'
98
99 # Create artifact directories and files referenced by test collections
100 $instrDir = Join-Path $script:repoRoot '.github/instructions'
101 $hveCoreInstrDir = Join-Path $instrDir 'hve-core'
102 $agentsDir = Join-Path $script:repoRoot '.github/agents'
103 $hveCoreAgentsDir = Join-Path $agentsDir 'hve-core'
104
105 New-Item -ItemType Directory -Path $hveCoreInstrDir -Force | Out-Null
106 New-Item -ItemType Directory -Path $hveCoreAgentsDir -Force | Out-Null
107
108 Set-Content -Path (Join-Path $hveCoreInstrDir 'workflows.instructions.md') -Value '---\ndescription: repo-specific\n---'
109 Set-Content -Path (Join-Path $instrDir 'hve-core-location.instructions.md') -Value '---\ndescription: shared\n---'
110 Set-Content -Path (Join-Path $hveCoreAgentsDir 'some.agent.md') -Value '---\ndescription: repo-specific agent\n---'
111 Set-Content -Path (Join-Path $agentsDir 'good.agent.md') -Value '---\ndescription: good agent\n---'
112 }
113
114 BeforeEach {
115 # Clear collection files between tests to prevent cross-contamination
116 if (Test-Path $script:collectionsDir) {
117 Remove-Item -Path $script:collectionsDir -Recurse -Force
118 }
119 New-Item -ItemType Directory -Path $script:collectionsDir -Force | Out-Null
120 }
121
122 It 'Fails validation for instruction under .github/instructions/hve-core/' {
123 $manifest = [ordered]@{
124 id = 'test-reject-instr'
125 name = 'Test Reject Instruction'
126 description = 'Tests repo-specific instruction rejection'
127 items = @(
128 [ordered]@{
129 path = '.github/instructions/hve-core/workflows.instructions.md'
130 kind = 'instruction'
131 }
132 )
133 }
134 $yaml = ConvertTo-Yaml -Data $manifest
135 Set-Content -Path (Join-Path $script:collectionsDir 'test-reject-instr.collection.yml') -Value $yaml
136
137 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
138 $result.Success | Should -BeFalse
139 $result.ErrorCount | Should -BeGreaterOrEqual 1
140 }
141
142 It 'Does NOT reject hve-core-location.instructions.md (not under hve-core/ subdirectory)' {
143 $manifest = [ordered]@{
144 id = 'test-allow-location'
145 name = 'Test Allow Location'
146 description = 'Tests that hve-core-location is allowed'
147 items = @(
148 [ordered]@{
149 path = '.github/instructions/hve-core-location.instructions.md'
150 kind = 'instruction'
151 }
152 )
153 }
154 $yaml = ConvertTo-Yaml -Data $manifest
155 Set-Content -Path (Join-Path $script:collectionsDir 'test-allow-location.collection.yml') -Value $yaml
156
157 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
158 $result.Success | Should -BeTrue
159 }
160
161 It 'Fails validation for agent under .github/agents/hve-core/' {
162 $manifest = [ordered]@{
163 id = 'test-reject-agent'
164 name = 'Test Reject Agent'
165 description = 'Tests repo-specific agent rejection'
166 items = @(
167 [ordered]@{
168 path = '.github/agents/hve-core/some.agent.md'
169 kind = 'agent'
170 }
171 )
172 }
173 $yaml = ConvertTo-Yaml -Data $manifest
174 Set-Content -Path (Join-Path $script:collectionsDir 'test-reject-agent.collection.yml') -Value $yaml
175
176 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
177 $result.Success | Should -BeFalse
178 $result.ErrorCount | Should -BeGreaterOrEqual 1
179 }
180
181 It 'Passes validation for agent NOT under hve-core/ subdirectory' {
182 $manifest = [ordered]@{
183 id = 'test-allow-agent'
184 name = 'Test Allow Agent'
185 description = 'Tests that normal agents pass'
186 items = @(
187 [ordered]@{
188 path = '.github/agents/good.agent.md'
189 kind = 'agent'
190 }
191 )
192 }
193 $yaml = ConvertTo-Yaml -Data $manifest
194 Set-Content -Path (Join-Path $script:collectionsDir 'test-allow-agent.collection.yml') -Value $yaml
195
196 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
197 $result.Success | Should -BeTrue
198 }
199}
200