1+ param (
2+ [switch ]$SkipInstall ,
3+ [switch ]$SkipTests ,
4+ [switch ]$SkipBrowser ,
5+ [switch ]$KeepProcesses ,
6+ [switch ]$Headed ,
7+ [int ]$TimeoutSec = 90
8+ )
9+
10+ Set-StrictMode - Version Latest
11+ $ErrorActionPreference = ' Stop'
12+
13+ . (Join-Path $PSScriptRoot ' ../../Tools/powershell/SampleValidation.ps1' )
14+
15+ $appRoot = $PSScriptRoot
16+ $envFile = Join-Path $appRoot ' .env'
17+ $nodeEnvironment = Get-ValidationNodeEnvironment
18+ $runtimeHandle = $null
19+
20+ try {
21+ Write-Step ' Preflight checks'
22+ Assert-CommandExists ' node'
23+ Assert-CommandExists ' npm'
24+
25+ if (-not $SkipInstall ) {
26+ Write-Step ' Installing dependencies'
27+ Invoke-ExternalCommand - FilePath ' npm' - Arguments @ (' install' ) - WorkingDirectory $appRoot - Environment $nodeEnvironment
28+ }
29+
30+ Write-Step ' Building MCP server'
31+ Invoke-ExternalCommand - FilePath ' npm' - Arguments @ (' run' , ' build' ) - WorkingDirectory $appRoot - Environment $nodeEnvironment
32+
33+ if ($SkipTests ) {
34+ Write-Host ' Skipping tests because -SkipTests was specified.' - ForegroundColor Yellow
35+ }
36+ else {
37+ Write-Host ' No automated test script is defined for this sample.' - ForegroundColor Yellow
38+ }
39+
40+ if (-not (Test-Path $envFile )) {
41+ Write-Host ' Skipping runtime smoke check because .env is missing.' - ForegroundColor Yellow
42+ Write-ValidationSummary - Status ' SKIP_CONFIG' - Message ' Build validation passed; runtime smoke skipped because .env is missing.'
43+ return
44+ }
45+
46+ $environment = Get-DotEnvMap - Path $envFile
47+ if (-not $environment.ContainsKey (' PORT' )) {
48+ $environment [' PORT' ] = ' 3100'
49+ }
50+
51+ Write-Step ' Starting MCP server'
52+ $logPath = New-ValidationLogPath - WorkingDirectory $appRoot - Name ' mcp-server'
53+ $runtimeHandle = Start-LoggedProcess - FilePath ' npm' - Arguments @ (' run' , ' start' ) - WorkingDirectory $appRoot - LogPath $logPath - Environment (Merge-EnvironmentTables @ ($nodeEnvironment , $environment ))
54+
55+ $healthUrl = " http://localhost:$ ( $environment [' PORT' ]) /health"
56+ $healthResponse = Wait-ForHttpEndpoint - Url $healthUrl - TimeoutSec $TimeoutSec - AllowedStatusCodes @ (200 ) - ProcessHandle $runtimeHandle
57+ $body = [string ]$healthResponse.Content
58+ if ($body -notmatch ' "status"\s*:\s*"ok"' ) {
59+ throw " Health endpoint returned an unexpected response: $body "
60+ }
61+
62+ Write-Host " Runtime smoke check passed at $healthUrl " - ForegroundColor Green
63+ Write-ValidationSummary - Status ' PASS' - Message " Build and runtime smoke checks passed at $healthUrl ."
64+ }
65+ catch {
66+ Write-ValidationSummary - Status ' FAIL' - Message $_.Exception.Message
67+ throw
68+ }
69+ finally {
70+ if ($null -ne $runtimeHandle -and -not $KeepProcesses ) {
71+ Stop-LoggedProcess - Handle $runtimeHandle
72+ }
73+ }
0 commit comments