Repository navigation
Expand file tree
/
Copy pathtest.ps1
More file actions
139 lines (126 loc) · 6.6 KB
/
Copy pathtest.ps1
File metadata and controls
139 lines (126 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#Requires -Version 7.0
<#
.SYNOPSIS
Runs the repository's tests, by tier.
.DESCRIPTION
The root test script required by opinions O-06 and O-07. The unit tier runs the structural
validators for the content package and feature files plus any Pester tests that live with a
project under src/. The integration and e2e tiers run the Pester tests in tests/integration
and tests/e2e. A tier with nothing to run passes and says so.
.PARAMETER Tier
Which tier to run: unit, integration, e2e, or all (the default); harness is opt-in (needs Docker).
.PARAMETER Filter
Optional Pester full-name filter (wildcards allowed) applied to every tier that runs Pester.
.EXAMPLE
./test.ps1
./test.ps1 -Tier unit
./test.ps1 -Tier e2e -Filter '*setup*'
#>
[CmdletBinding()]
param(
[Parameter()]
[ValidateSet('all', 'unit', 'integration', 'e2e', 'harness')]
[string]$Tier = 'all',
[Parameter()]
[string]$Filter
)
$ErrorActionPreference = 'Stop'
function Invoke-PesterTier {
param([string]$Name, [string[]]$Paths)
$files = foreach ($p in $Paths) {
Get-ChildItem -Path $p -Recurse -Filter '*.Tests.ps1' -File -ErrorAction SilentlyContinue
}
if (-not $files) {
Write-Host "[$Name] no Pester tests found." -ForegroundColor Yellow
return
}
if (-not (Get-Module -ListAvailable -Name Pester)) {
throw 'Pester is not installed. Run ./initialize.ps1 first.'
}
$config = New-PesterConfiguration
$config.Run.Path = $files.FullName
$config.Run.PassThru = $true
if ($Filter) { $config.Filter.FullName = $Filter }
$result = Invoke-Pester -Configuration $config
if ($result.FailedCount -gt 0) { throw "[$Name] $($result.FailedCount) test(s) failed." }
Write-Host "[$Name] $($result.PassedCount) passed." -ForegroundColor Green
}
Push-Location $PSScriptRoot
try {
if ($Tier -in 'all', 'unit') {
$problems = @()
$problems += & (Join-Path 'scripts' 'Test-SkillStructure.ps1')
$problems += & (Join-Path 'scripts' 'Test-FeatureStructure.ps1')
# The feature files are pulled from the knowledge base pages and never edited by hand (decision record 0019)
$problems += & (Join-Path 'src' 'aa-sdlc' 'scripts' 'Sync-FeatureFiles.ps1') -KnowledgeRoot (Join-Path 'docs' 'knowledge') -FeaturesRoot 'features' -Check
$problems += & (Join-Path 'scripts' 'Test-WorkflowStructure.ps1')
# Every skill carries its guidance verbatim from docs/guidance.md (decision record 0011)
$problems += & (Join-Path 'scripts' 'Test-SkillGuidance.ps1')
# Every discipline agent is generated from the workflow data, never edited by hand (decision record 0015)
$problems += & (Join-Path 'scripts' 'Sync-Agents.ps1') -Check
# The website must be current with the workflow data when its repository is checked out (decision record 0007)
$problems += & (Join-Path 'scripts' 'Test-WebsiteCurrency.ps1')
if ($problems.Count -gt 0) {
$problems | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
throw "[unit] structural validation failed with $($problems.Count) problem(s)."
}
Write-Host '[unit] structural validation passed.' -ForegroundColor Green
# The aa CLI's Go tests live with the module (O-07); they need the embedded content present
& (Join-Path 'scripts' 'Sync-EmbeddedContent.ps1') | Out-Null
Push-Location (Join-Path 'src' 'aa-sdlc-cli')
try {
$goArgs = @('test', './...')
if ($Filter) { $goArgs += @('-run', $Filter) }
& go @goArgs
if ($LASTEXITCODE -ne 0) { throw '[unit] go test failed.' }
Write-Host '[unit] go test passed.' -ForegroundColor Green
} finally { Pop-Location }
Invoke-PesterTier -Name 'unit' -Paths @('src', (Join-Path 'tests' 'unit'))
}
if ($Tier -in 'all', 'integration') {
# The @cli feature files run with godog against the built binary (decision record 0005)
$exe = if ($IsWindows) { 'aa.exe' } else { 'aa' }
$bin = Join-Path $PSScriptRoot '.build' 'aa-sdlc-cli' $exe
if (-not (Test-Path $bin)) { & (Join-Path $PSScriptRoot 'build.ps1') | Out-Null }
Push-Location (Join-Path 'tests' 'integration')
try {
$env:AA_BIN = $bin
$goArgs = @('test', './...', '-count=1')
if ($Filter) { $goArgs += @('-run', $Filter) }
& go @goArgs
if ($LASTEXITCODE -ne 0) { throw '[integration] feature tests failed.' }
Write-Host '[integration] feature tests passed.' -ForegroundColor Green
} finally {
Remove-Item Env:AA_BIN -ErrorAction SilentlyContinue
Pop-Location
}
Invoke-PesterTier -Name 'integration' -Paths @((Join-Path 'tests' 'integration'))
}
if ($Tier -in 'all', 'e2e') {
Invoke-PesterTier -Name 'e2e' -Paths @((Join-Path 'tests' 'e2e'))
}
# The harness tier is opt-in, not part of all: it needs Docker and the network. It installs every
# agent harness that runs headless on Linux into one image and checks aa against each real install
# (tests/harness, decision record 0014). Its report is .build/harness-out/harness-report.json.
if ($Tier -eq 'harness') {
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { throw '[harness] Docker is required for the harness tier.' }
& ./build.ps1 | Out-Null
$linuxDir = Join-Path $PSScriptRoot '.build' 'linux'
$outDir = Join-Path $PSScriptRoot '.build' 'harness-out'
New-Item -ItemType Directory -Path $linuxDir, $outDir -Force | Out-Null
Push-Location (Join-Path 'src' 'aa-sdlc-cli')
try {
$env:CGO_ENABLED = '0'; $env:GOOS = 'linux'; $env:GOARCH = 'amd64'
& go build -trimpath -o (Join-Path $linuxDir 'aa') ./cmd/aa
if ($LASTEXITCODE -ne 0) { throw '[harness] go build for linux/amd64 failed.' }
} finally {
Remove-Item Env:GOOS, Env:GOARCH -ErrorAction SilentlyContinue
Pop-Location
}
& docker build -q -t aa-sdlc-harnesses (Join-Path 'tests' 'harness') | Out-Null
if ($LASTEXITCODE -ne 0) { throw '[harness] building the harness image failed.' }
& docker run --rm -v "${linuxDir}:/aa:ro" -v "${PSScriptRoot}:/repo:ro" -v "${outDir}:/out" aa-sdlc-harnesses pwsh -NoProfile -File /repo/tests/harness/Test-Harness.ps1
if ($LASTEXITCODE -ne 0) { throw "[harness] $LASTEXITCODE harness(es) failed; see .build/harness-out/harness-report.json." }
Write-Host '[harness] every installed harness passed.' -ForegroundColor Green
}
} finally { Pop-Location }