microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
627a87791c9fc94fbfbd596589ce6a1faaaa013d

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

204lines · 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
100 $instrDir = Join-Path $script:repoRoot '.github/instructions'
101 $agentsDir = Join-Path $script:repoRoot '.github/agents'
102 $sharedDir = Join-Path $instrDir 'shared'
103 $hveCoreAgentsDir = Join-Path $agentsDir 'hve-core'
104
105 New-Item -ItemType Directory -Path $instrDir -Force | Out-Null
106 New-Item -ItemType Directory -Path $agentsDir -Force | Out-Null
107 New-Item -ItemType Directory -Path $sharedDir -Force | Out-Null
108 New-Item -ItemType Directory -Path $hveCoreAgentsDir -Force | Out-Null
109
110 # Root-level (repo-specific) files
111 Set-Content -Path (Join-Path $instrDir 'workflows.instructions.md') -Value '---\ndescription: repo-specific\n---'
112 Set-Content -Path (Join-Path $agentsDir 'internal.agent.md') -Value '---\ndescription: repo-specific agent\n---'
113
114 # Subdirectory (collection-scoped) files
115 Set-Content -Path (Join-Path $sharedDir 'hve-core-location.instructions.md') -Value '---\ndescription: shared\n---'
116 Set-Content -Path (Join-Path $hveCoreAgentsDir 'rpi-agent.agent.md') -Value '---\ndescription: distributable agent\n---'
117 }
118
119 BeforeEach {
120 # Clear collection files between tests to prevent cross-contamination
121 if (Test-Path $script:collectionsDir) {
122 Remove-Item -Path $script:collectionsDir -Recurse -Force
123 }
124 New-Item -ItemType Directory -Path $script:collectionsDir -Force | Out-Null
125 }
126
127 It 'Fails validation for root-level instruction' {
128 $manifest = [ordered]@{
129 id = 'test-reject-instr'
130 name = 'Test Reject Instruction'
131 description = 'Tests repo-specific instruction rejection'
132 items = @(
133 [ordered]@{
134 path = '.github/instructions/workflows.instructions.md'
135 kind = 'instruction'
136 }
137 )
138 }
139 $yaml = ConvertTo-Yaml -Data $manifest
140 Set-Content -Path (Join-Path $script:collectionsDir 'test-reject-instr.collection.yml') -Value $yaml
141
142 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
143 $result.Success | Should -BeFalse
144 $result.ErrorCount | Should -BeGreaterOrEqual 1
145 }
146
147 It 'Passes validation for instruction in subdirectory' {
148 $manifest = [ordered]@{
149 id = 'test-allow-location'
150 name = 'Test Allow Location'
151 description = 'Tests that subdirectory instructions are allowed'
152 items = @(
153 [ordered]@{
154 path = '.github/instructions/shared/hve-core-location.instructions.md'
155 kind = 'instruction'
156 }
157 )
158 }
159 $yaml = ConvertTo-Yaml -Data $manifest
160 Set-Content -Path (Join-Path $script:collectionsDir 'test-allow-location.collection.yml') -Value $yaml
161
162 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
163 $result.Success | Should -BeTrue
164 }
165
166 It 'Fails validation for root-level agent' {
167 $manifest = [ordered]@{
168 id = 'test-reject-agent'
169 name = 'Test Reject Agent'
170 description = 'Tests repo-specific agent rejection'
171 items = @(
172 [ordered]@{
173 path = '.github/agents/internal.agent.md'
174 kind = 'agent'
175 }
176 )
177 }
178 $yaml = ConvertTo-Yaml -Data $manifest
179 Set-Content -Path (Join-Path $script:collectionsDir 'test-reject-agent.collection.yml') -Value $yaml
180
181 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
182 $result.Success | Should -BeFalse
183 $result.ErrorCount | Should -BeGreaterOrEqual 1
184 }
185
186 It 'Passes validation for agent in subdirectory' {
187 $manifest = [ordered]@{
188 id = 'test-allow-agent'
189 name = 'Test Allow Agent'
190 description = 'Tests that subdirectory agents pass'
191 items = @(
192 [ordered]@{
193 path = '.github/agents/hve-core/rpi-agent.agent.md'
194 kind = 'agent'
195 }
196 )
197 }
198 $yaml = ConvertTo-Yaml -Data $manifest
199 Set-Content -Path (Join-Path $script:collectionsDir 'test-allow-agent.collection.yml') -Value $yaml
200
201 $result = Invoke-CollectionValidation -RepoRoot $script:repoRoot
202 $result.Success | Should -BeTrue
203 }
204}
205