microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feat/devcontainer-python-uv-887

Branches

Tags

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

Clone

HTTPS

Download ZIP

.github/skills/installer/hve-core-installer/tests/eject.Tests.ps1

136lines · modecode

1#Requires -Modules Pester
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4
5Describe 'eject' -Tag 'Unit' {
6 BeforeAll {
7 $script:scriptPath = Join-Path $PSScriptRoot '../scripts/eject.ps1'
8 $script:testRoot = Join-Path ([System.IO.Path]::GetTempPath()) "hve-test-eject-$([guid]::NewGuid().ToString('N'))"
9 }
10
11 BeforeEach {
12 New-Item -ItemType Directory -Path $script:testRoot -Force | Out-Null
13 Push-Location $script:testRoot
14 }
15
16 AfterEach {
17 Pop-Location
18 }
19
20 AfterAll {
21 if (Test-Path $script:testRoot) {
22 Remove-Item $script:testRoot -Recurse -Force -ErrorAction SilentlyContinue
23 }
24 }
25
26 Context 'Successful ejection' {
27 It 'Sets file status to ejected in manifest' {
28 $manifest = @{
29 source = 'microsoft/hve-core'
30 version = '1.0.0'
31 files = @{
32 '.github/agents/task-implementor.agent.md' = @{
33 version = '1.0.0'
34 sha256 = 'abc123'
35 status = 'managed'
36 }
37 }
38 }
39 $manifest | ConvertTo-Json -Depth 10 | Set-Content '.hve-tracking.json'
40
41 & $script:scriptPath -FilePath '.github/agents/task-implementor.agent.md'
42
43 $updated = Get-Content '.hve-tracking.json' | ConvertFrom-Json -AsHashtable
44 $updated.files['.github/agents/task-implementor.agent.md'].status | Should -Be 'ejected'
45 }
46
47 It 'Adds ejectedAt timestamp to the file entry' {
48 $manifest = @{
49 source = 'microsoft/hve-core'
50 version = '1.0.0'
51 files = @{
52 '.github/agents/task-implementor.agent.md' = @{
53 version = '1.0.0'
54 sha256 = 'abc123'
55 status = 'managed'
56 }
57 }
58 }
59 $manifest | ConvertTo-Json -Depth 10 | Set-Content '.hve-tracking.json'
60
61 & $script:scriptPath -FilePath '.github/agents/task-implementor.agent.md'
62
63 $updated = Get-Content '.hve-tracking.json' | ConvertFrom-Json -AsHashtable
64 $updated.files['.github/agents/task-implementor.agent.md'].ejectedAt | Should -Not -BeNullOrEmpty
65 }
66
67 It 'Preserves other files in the manifest' {
68 $manifest = @{
69 source = 'microsoft/hve-core'
70 version = '1.0.0'
71 files = @{
72 '.github/agents/task-implementor.agent.md' = @{
73 version = '1.0.0'
74 sha256 = 'abc123'
75 status = 'managed'
76 }
77 '.github/agents/task-researcher.agent.md' = @{
78 version = '1.0.0'
79 sha256 = 'def456'
80 status = 'managed'
81 }
82 }
83 }
84 $manifest | ConvertTo-Json -Depth 10 | Set-Content '.hve-tracking.json'
85
86 & $script:scriptPath -FilePath '.github/agents/task-implementor.agent.md'
87
88 $updated = Get-Content '.hve-tracking.json' | ConvertFrom-Json -AsHashtable
89 $updated.files['.github/agents/task-researcher.agent.md'].status | Should -Be 'managed'
90 }
91 }
92
93 Context 'File not found in manifest' {
94 It 'Outputs error message for untracked file' {
95 $manifest = @{
96 source = 'microsoft/hve-core'
97 version = '1.0.0'
98 files = @{}
99 }
100 $manifest | ConvertTo-Json -Depth 10 | Set-Content '.hve-tracking.json'
101
102 $output = & $script:scriptPath -FilePath '.github/agents/nonexistent.md' 6>&1 | Out-String
103
104 $output | Should -Match 'not found in tracking manifest'
105 }
106
107 It 'Does not modify manifest when file is not tracked' {
108 $manifest = @{
109 source = 'microsoft/hve-core'
110 version = '1.0.0'
111 files = @{
112 '.github/agents/task-implementor.agent.md' = @{
113 version = '1.0.0'
114 sha256 = 'abc123'
115 status = 'managed'
116 }
117 }
118 }
119 $manifest | ConvertTo-Json -Depth 10 | Set-Content '.hve-tracking.json'
120
121 & $script:scriptPath -FilePath '.github/agents/nonexistent.md'
122
123 $updated = Get-Content '.hve-tracking.json' | ConvertFrom-Json -AsHashtable
124 $updated.files['.github/agents/task-implementor.agent.md'].status | Should -Be 'managed'
125 }
126 }
127
128 Context 'Parameter validation' {
129 It 'Has a mandatory FilePath parameter' {
130 $command = Get-Command $script:scriptPath
131 $param = $command.Parameters['FilePath']
132 $param | Should -Not -BeNullOrEmpty
133 $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.Mandatory } | Should -Not -BeNullOrEmpty
134 }
135 }
136}
137