-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathtest-dependency-integration.ps1
More file actions
352 lines (293 loc) · 11.2 KB
/
Copy pathtest-dependency-integration.ps1
File metadata and controls
352 lines (293 loc) · 11.2 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# Extension to build isolation script for APM Dependencies Integration Testing
# Tests real dependency scenarios with actual GitHub repositories
# Used in CI pipeline for comprehensive dependency validation
$ErrorActionPreference = "Continue"
# --- Logging functions ---
function Write-DepInfo {
param([string]$Message)
Write-Host "i $Message" -ForegroundColor Blue
}
function Write-DepSuccess {
param([string]$Message)
Write-Host "OK $Message" -ForegroundColor Green
}
function Write-DepError {
param([string]$Message)
Write-Host "FAIL $Message" -ForegroundColor Red
}
function Write-DepTestHeader {
param([string]$Message)
Write-Host "TEST $Message" -ForegroundColor Yellow
}
# --- Test real dependency installation ---
function Test-RealDependencyInstallation {
param(
[string]$TestDir,
[string]$ApmBinary
)
Write-DepTestHeader "Testing real dependency installation with microsoft/apm-sample-package"
Push-Location $TestDir
try {
# Create apm.yml with real dependency
@"
name: dependency-test-project
version: 1.0.0
description: Test project for dependency integration testing
author: CI Test
target: copilot
dependencies:
apm:
- microsoft/apm-sample-package
scripts:
start: "echo 'Project with apm-sample-package dependency loaded'"
"@ | Set-Content -Path "apm.yml" -Encoding UTF8
# Test apm deps list (should show no dependencies initially)
Write-DepInfo "Testing 'apm deps list' with no dependencies installed"
$depsOutput = & $ApmBinary deps list 2>&1 | Out-String
Write-Host "DEBUG: Actual output from 'apm deps list':"
Write-Host "--- OUTPUT START ---"
Write-Host $depsOutput
Write-Host "--- OUTPUT END ---"
if ($depsOutput -match "No APM dependencies installed") {
Write-DepSuccess "Correctly shows no dependencies installed"
} else {
Write-DepError "Expected 'No APM dependencies installed' message"
Write-DepError "Got: $depsOutput"
return $false
}
# Test apm install (should download real dependency)
Write-DepInfo "Testing 'apm install' with real GitHub dependency"
& $ApmBinary install
if ($LASTEXITCODE -ne 0) {
Write-DepError "Failed to install real dependency"
return $false
}
# Verify installation
if (-not (Test-Path "apm_modules\microsoft\apm-sample-package")) {
Write-DepError "Dependency not installed: apm_modules\microsoft\apm-sample-package not found"
return $false
}
# Verify dependency structure
if (-not (Test-Path "apm_modules\microsoft\apm-sample-package\apm.yml")) {
Write-DepError "Dependency missing apm.yml"
return $false
}
if (-not (Test-Path "apm_modules\microsoft\apm-sample-package\.apm")) {
Write-DepError "Dependency missing .apm directory"
return $false
}
# Check for expected prompt files
if (-not (Test-Path "apm_modules\microsoft\apm-sample-package\.apm\prompts\design-review.prompt.md")) {
Write-DepError "Dependency missing expected prompt file: .apm\prompts\design-review.prompt.md"
return $false
}
Write-DepSuccess "Real dependency installation verified"
# Test apm deps list (should now show installed dependency)
Write-DepInfo "Testing 'apm deps list' with installed dependency"
$depsOutput = & $ApmBinary deps list 2>&1 | Out-String
if ($depsOutput -match "apm-sample-package") {
Write-DepSuccess "Correctly shows installed dependency"
} else {
Write-DepError "Expected to see installed dependency in list"
return $false
}
# Test apm deps tree
Write-DepInfo "Testing 'apm deps tree'"
$treeOutput = & $ApmBinary deps tree 2>&1 | Out-String
if ($treeOutput -match "apm-sample-package") {
Write-DepSuccess "Dependency tree shows installed dependency"
} else {
Write-DepError "Expected to see dependency in tree output"
return $false
}
# Test apm deps info
Write-DepInfo "Testing 'apm deps info apm-sample-package'"
$infoOutput = & $ApmBinary deps info apm-sample-package 2>&1 | Out-String
if ($infoOutput -match "apm-sample-package") {
Write-DepSuccess "Dependency info command works"
} else {
Write-DepError "Expected dependency info to show package details"
return $false
}
Write-DepSuccess "All real dependency tests passed"
return $true
} finally {
Pop-Location
}
}
# --- Test multi-dependency scenario ---
function Test-MultiDependencyScenario {
param(
[string]$TestDir,
[string]$ApmBinary
)
Write-DepTestHeader "Testing multi-dependency scenario with both test repositories"
Push-Location $TestDir
try {
# Create apm.yml with multiple dependencies
@"
name: multi-dependency-test
version: 1.0.0
description: Test project for multi-dependency scenario
author: CI Test
target: copilot
dependencies:
apm:
- microsoft/apm-sample-package
- github/awesome-copilot/skills/review-and-refactor
scripts:
start: "echo 'Project with multiple dependencies loaded'"
"@ | Set-Content -Path "apm.yml" -Encoding UTF8
# Clean any existing dependencies
if (Test-Path "apm_modules") {
Remove-Item -Recurse -Force "apm_modules" -ErrorAction SilentlyContinue
}
# Install multiple dependencies
Write-DepInfo "Installing multiple real dependencies"
& $ApmBinary install
if ($LASTEXITCODE -ne 0) {
Write-DepError "Failed to install multiple dependencies"
return $false
}
# Verify both dependencies installed
if (-not (Test-Path "apm_modules\microsoft\apm-sample-package")) {
Write-DepError "First dependency not installed: apm-sample-package"
return $false
}
if (-not (Test-Path "apm_modules\github\awesome-copilot\skills\review-and-refactor")) {
Write-DepError "Second dependency not installed: github/awesome-copilot/skills/review-and-refactor"
return $false
}
# Test deps list shows both
$depsOutput = & $ApmBinary deps list 2>&1 | Out-String
if ($depsOutput -notmatch "apm-sample-package") {
Write-DepError "Multi-dependency list missing apm-sample-package"
return $false
}
if ($depsOutput -notmatch "design-guidelines|apm-sample-package") {
Write-DepError "Multi-dependency list missing design-guidelines"
return $false
}
Write-DepSuccess "Multi-dependency scenario verified"
return $true
} finally {
Pop-Location
}
}
# --- Test dependency update workflow ---
function Test-DependencyUpdate {
param(
[string]$TestDir,
[string]$ApmBinary
)
Write-DepTestHeader "Testing dependency update workflow"
Push-Location $TestDir
try {
# Should have dependencies installed from previous test
if (-not (Test-Path "apm_modules")) {
Write-DepError "No dependencies found for update test"
return $false
}
# Test update all dependencies
Write-DepInfo "Testing 'apm deps update' for all dependencies"
& $ApmBinary deps update
if ($LASTEXITCODE -ne 0) {
Write-DepError "Failed to update all dependencies"
return $false
}
# Test update specific dependency
Write-DepInfo "Testing 'apm deps update apm-sample-package'"
& $ApmBinary deps update apm-sample-package
if ($LASTEXITCODE -ne 0) {
Write-DepError "Failed to update specific dependency"
return $false
}
Write-DepSuccess "Dependency update workflow verified"
return $true
} finally {
Pop-Location
}
}
# --- Test dependency cleanup ---
function Test-DependencyCleanup {
param(
[string]$TestDir,
[string]$ApmBinary
)
Write-DepTestHeader "Testing dependency cleanup"
Push-Location $TestDir
try {
# Test deps clean
Write-DepInfo "Testing 'apm deps clean'"
"y" | & $ApmBinary deps clean
if ($LASTEXITCODE -ne 0) {
Write-DepError "Failed to clean dependencies"
return $false
}
# Verify cleanup
if (Test-Path "apm_modules") {
Write-DepError "apm_modules directory still exists after cleanup"
return $false
}
# Verify deps list shows no dependencies
$depsOutput = & $ApmBinary deps list 2>&1 | Out-String
Write-Host "DEBUG: Actual output from 'apm deps list' after cleanup:"
Write-Host "--- OUTPUT START ---"
Write-Host $depsOutput
Write-Host "--- OUTPUT END ---"
if ($depsOutput -match "No APM dependencies installed") {
Write-DepSuccess "Correctly shows no dependencies after cleanup"
} else {
Write-DepError "Expected no dependencies after cleanup"
Write-DepError "Got: $depsOutput"
return $false
}
Write-DepSuccess "Dependency cleanup verified"
return $true
} finally {
Pop-Location
}
}
# --- Main function for dependency integration testing ---
function Test-DependencyIntegration {
param(
[Parameter(Mandatory)]
[string]$BinaryPath
)
Write-DepInfo "=== APM Dependencies Integration Testing ==="
Write-DepInfo "Testing with real GitHub repositories:"
Write-DepInfo " - microsoft/apm-sample-package"
Write-DepInfo " - github/awesome-copilot/skills/review-and-refactor"
# Create isolated test directory
$testDir = Join-Path $env:TEMP "apm-dep-test-$PID"
New-Item -ItemType Directory -Path $testDir -Force | Out-Null
# Check for GitHub token
if (-not $env:GITHUB_CLI_PAT -and -not $env:GITHUB_TOKEN) {
Write-DepError "GitHub token required for dependency testing"
Write-DepInfo "Set GITHUB_CLI_PAT or GITHUB_TOKEN environment variable"
return $false
}
try {
# Run dependency tests in sequence
if (-not (Test-RealDependencyInstallation -TestDir $testDir -ApmBinary $BinaryPath)) { return $false }
if (-not (Test-MultiDependencyScenario -TestDir $testDir -ApmBinary $BinaryPath)) { return $false }
if (-not (Test-DependencyUpdate -TestDir $testDir -ApmBinary $BinaryPath)) { return $false }
if (-not (Test-DependencyCleanup -TestDir $testDir -ApmBinary $BinaryPath)) { return $false }
Write-DepSuccess "=== All dependency integration tests passed! ==="
return $true
} finally {
# Cleanup
if (Test-Path $testDir) {
Remove-Item -Recurse -Force $testDir -ErrorAction SilentlyContinue
}
}
}
# If run directly (not dot-sourced)
if ($MyInvocation.InvocationName -ne ".") {
if ($args.Count -lt 1) {
Write-DepError "Usage: .\test-dependency-integration.ps1 <apm_binary_path>"
exit 1
}
$result = Test-DependencyIntegration -BinaryPath $args[0]
if (-not $result) { exit 1 }
}