microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/update-npm-script

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/tests/agents/activation-harness/Test-AdrCreationActivation.Tests.ps1

189lines · modecode

1#Requires -Modules Pester
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4
5# Test-AdrCreationActivation.Tests.ps1
6#
7# Activation-harness regression suite for @adr-creation. Exercises the four
8# canonical activation scenarios (CleanWorkspace, SteadyState, GovernEntry,
9# AdoptTemplate) via Get-AgentActivationFingerprint and asserts:
10# * baseline.json remains a well-formed reference for explicit drift audits
11# * CleanWorkspace cold-start byte budget < 44,000 bytes (PD-04=A)
12# * Lifecycle Dispatch load-set composition (always-attach vs on-demand)
13# * pester runner emits logs/pester-summary.json + logs/pester-failures.json
14
15[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '',
16 Justification = 'Consumed by Pester -ForEach blocks at discovery time')]
17param()
18
19BeforeDiscovery {
20 $ScenarioCases = @(
21 @{ ScenarioName = 'CleanWorkspace' }
22 @{ ScenarioName = 'SteadyState' }
23 @{ ScenarioName = 'GovernEntry' }
24 @{ ScenarioName = 'AdoptTemplate' }
25 )
26}
27
28BeforeAll {
29 $script:RepoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '../../../..')).Path
30 $modulePath = Join-Path $script:RepoRoot 'scripts/agents/activation-harness/Get-AgentActivationFingerprint.psm1'
31 Import-Module -Name $modulePath -Force
32
33 $script:AgentRelPath = '.github/agents/project-planning/adr-creation.agent.md'
34 $script:AgentPath = Join-Path $script:RepoRoot $script:AgentRelPath
35
36 $baselinePath = Join-Path $script:RepoRoot 'scripts/agents/activation-harness/baseline.json'
37 $script:Baseline = Get-Content -LiteralPath $baselinePath -Raw -Encoding UTF8 |
38 ConvertFrom-Json -AsHashtable
39
40 $script:ColdStartBudget = 44000
41
42 $script:Fingerprints = @{}
43 foreach ($name in @('CleanWorkspace', 'SteadyState', 'GovernEntry', 'AdoptTemplate')) {
44 $script:Fingerprints[$name] = Get-AgentActivationFingerprint `
45 -AgentPath $script:AgentPath `
46 -ScenarioName $name `
47 -RepoRoot $script:RepoRoot
48 }
49}
50
51AfterAll {
52 Remove-Module -Name 'Get-AgentActivationFingerprint' -Force -ErrorAction SilentlyContinue
53}
54
55Describe '@adr-creation activation harness module contract' -Tag 'Unit' {
56 It 'exports Get-AgentActivationFingerprint' {
57 Get-Command -Name Get-AgentActivationFingerprint -ErrorAction Stop | Should -Not -BeNullOrEmpty
58 }
59
60 It 'returns a hashtable with required keys for scenario <ScenarioName>' -ForEach $ScenarioCases {
61 $fp = $script:Fingerprints[$ScenarioName]
62 $fp.Keys | Should -Contain 'ScenarioName'
63 $fp.Keys | Should -Contain 'AgentBytes'
64 $fp.Keys | Should -Contain 'ColdStartBytes'
65 $fp.Keys | Should -Contain 'LoadedFiles'
66 $fp.Keys | Should -Contain 'Hash'
67 $fp.ScenarioName | Should -Be $ScenarioName
68 }
69}
70
71Describe '@adr-creation activation baseline reference is well formed' -Tag 'Unit' {
72 It 'baseline.json contains scenario <ScenarioName>' -ForEach $ScenarioCases {
73 $script:Baseline.Keys | Should -Contain $ScenarioName
74
75 $expected = $script:Baseline[$ScenarioName]
76 $expected | Should -Not -BeNullOrEmpty -Because "baseline.json must contain an entry for $ScenarioName"
77 }
78
79 It 'baseline scenario <ScenarioName> has required fingerprint fields' -ForEach $ScenarioCases {
80 $expected = $script:Baseline[$ScenarioName]
81 $expected.Keys | Should -Contain 'ScenarioName'
82 $expected.Keys | Should -Contain 'AgentBytes'
83 $expected.Keys | Should -Contain 'ColdStartBytes'
84 $expected.Keys | Should -Contain 'LoadedFiles'
85 $expected.Keys | Should -Contain 'Hash'
86
87 $expected['ScenarioName'] | Should -Be $ScenarioName
88 $expected['Hash'] | Should -Match '^[a-f0-9]{64}$'
89 [int]$expected['AgentBytes'] | Should -BeGreaterThan 0
90 [int]$expected['ColdStartBytes'] | Should -BeGreaterThan 0
91 $expected['LoadedFiles'] | Should -Not -BeNullOrEmpty
92 }
93
94 It 'baseline scenario <ScenarioName> loaded file entries have paths and byte counts' -ForEach $ScenarioCases {
95 $expected = $script:Baseline[$ScenarioName]
96
97 foreach ($loadedFile in $expected['LoadedFiles']) {
98 $loadedFile.Keys | Should -Contain 'Path'
99 $loadedFile.Keys | Should -Contain 'Bytes'
100 $loadedFile['Path'] | Should -Match '\S'
101 [int]$loadedFile['Bytes'] | Should -BeGreaterThan 0
102 }
103 }
104}
105
106Describe '@adr-creation cold-start byte budget' -Tag 'Unit' {
107 It 'CleanWorkspace ColdStartBytes is below the PD-04 budget' {
108 $current = $script:Fingerprints['CleanWorkspace']
109 $current.ColdStartBytes | Should -BeLessThan $script:ColdStartBudget -Because @"
110Cold-start byte budget violation (PD-04=A).
111Target : less than $($script:ColdStartBudget) bytes
112Actual : $($current.ColdStartBytes) bytes
113Loaded : $($current.LoadedFiles | ForEach-Object { "$($_.Path) ($($_.Bytes))" } | Join-String -Separator '; ')
114"@
115 }
116}
117
118Describe '@adr-creation lifecycle dispatch load-set composition' -Tag 'Unit' {
119 BeforeAll {
120 $script:CleanLoaded = $script:Fingerprints['CleanWorkspace'].LoadedFiles | ForEach-Object { $_.Path }
121 $script:SteadyLoaded = $script:Fingerprints['SteadyState'].LoadedFiles | ForEach-Object { $_.Path }
122 $script:GovernLoaded = $script:Fingerprints['GovernEntry'].LoadedFiles | ForEach-Object { $_.Path }
123 $script:AdoptLoaded = $script:Fingerprints['AdoptTemplate'].LoadedFiles | ForEach-Object { $_.Path }
124 }
125
126 It 'CleanWorkspace includes the agent file itself' {
127 $script:CleanLoaded | Should -Contain '.github/agents/project-planning/adr-creation.agent.md'
128 }
129
130 It 'CleanWorkspace includes adr-identity.instructions.md (always-on identity)' {
131 $script:CleanLoaded | Should -Contain '.github/instructions/project-planning/adr-identity.instructions.md'
132 }
133
134 It 'CleanWorkspace includes shared disclaimer-language.instructions.md' {
135 $script:CleanLoaded | Should -Contain '.github/instructions/shared/disclaimer-language.instructions.md'
136 }
137
138 It 'CleanWorkspace excludes adr-handoff.instructions.md (Govern on-demand)' {
139 $script:CleanLoaded | Should -Not -Contain '.github/instructions/project-planning/adr-handoff.instructions.md'
140 }
141
142 It 'CleanWorkspace excludes adr-byo-template.instructions.md (adopt-template on-demand)' {
143 $script:CleanLoaded | Should -Not -Contain '.github/instructions/project-planning/adr-byo-template.instructions.md'
144 }
145
146 It 'SteadyState is a strict superset of CleanWorkspace' {
147 foreach ($file in $script:CleanLoaded) {
148 $script:SteadyLoaded | Should -Contain $file
149 }
150 }
151
152 It 'GovernEntry includes adr-handoff.instructions.md (Govern Table A trigger)' {
153 $script:GovernLoaded | Should -Contain '.github/instructions/project-planning/adr-handoff.instructions.md'
154 }
155
156 It 'AdoptTemplate includes adr-byo-template.instructions.md (Table B trigger)' {
157 $script:AdoptLoaded | Should -Contain '.github/instructions/project-planning/adr-byo-template.instructions.md'
158 }
159}
160
161Describe '@adr-creation activation scenarios produce distinct fingerprints' -Tag 'Unit' {
162 It 'GovernEntry hash differs from SteadyState (Govern Table A on-demand load)' {
163 $script:Fingerprints['GovernEntry'].Hash | Should -Not -Be $script:Fingerprints['SteadyState'].Hash
164 }
165
166 It 'AdoptTemplate hash differs from SteadyState (Table B on-demand load)' {
167 $script:Fingerprints['AdoptTemplate'].Hash | Should -Not -Be $script:Fingerprints['SteadyState'].Hash
168 }
169
170 It 'AdoptTemplate hash differs from GovernEntry (distinct dispatch tables)' {
171 $script:Fingerprints['AdoptTemplate'].Hash | Should -Not -Be $script:Fingerprints['GovernEntry'].Hash
172 }
173
174 It 'CleanWorkspace hash differs from SteadyState (cold-start vs steady)' {
175 $script:Fingerprints['CleanWorkspace'].Hash | Should -Not -Be $script:Fingerprints['SteadyState'].Hash
176 }
177}
178
179Describe '@adr-creation activation harness emits Pester runner artifacts' -Tag 'Unit' {
180 It 'logs/pester-summary.json exists after this suite is invoked via Invoke-PesterTests.ps1' {
181 $summaryPath = Join-Path $script:RepoRoot 'logs/pester-summary.json'
182 Test-Path -LiteralPath $summaryPath | Should -BeTrue -Because 'Invoke-PesterTests.ps1 writes this file before discovery completes'
183 }
184
185 It 'logs/pester-failures.json exists after this suite is invoked via Invoke-PesterTests.ps1' {
186 $failuresPath = Join-Path $script:RepoRoot 'logs/pester-failures.json'
187 Test-Path -LiteralPath $failuresPath | Should -BeTrue
188 }
189}
190