169 lines
4.9 KiB
PowerShell
169 lines
4.9 KiB
PowerShell
param(
|
|
[string]$BaseUrl = "http://localhost:9900",
|
|
[string]$SessionId = "mvp-demo-interview-payment-timeout-001",
|
|
[string]$RequestFile = "$PSScriptRoot/../requests/payment-timeout-chat.json",
|
|
[string]$OutputDir = "$PSScriptRoot/../output"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Test-ServiceReachable {
|
|
param([string]$Url)
|
|
|
|
try {
|
|
$request = [System.Net.WebRequest]::Create($Url)
|
|
$request.Method = "GET"
|
|
$request.Timeout = 5000
|
|
$response = $request.GetResponse()
|
|
$response.Close()
|
|
return $true
|
|
} catch [System.Net.WebException] {
|
|
if ($_.Exception.Response -ne $null) {
|
|
$_.Exception.Response.Close()
|
|
return $true
|
|
}
|
|
return $false
|
|
}
|
|
}
|
|
|
|
function Get-TraceData {
|
|
param($TraceResponse)
|
|
|
|
if ($TraceResponse.PSObject.Properties.Name -contains "data") {
|
|
return $TraceResponse.data
|
|
}
|
|
return $TraceResponse
|
|
}
|
|
|
|
function Get-SelfEvaluation {
|
|
param($TraceData)
|
|
|
|
if ($null -eq $TraceData -or $null -eq $TraceData.session) {
|
|
return $null
|
|
}
|
|
return $TraceData.session.selfEvaluation
|
|
}
|
|
|
|
function Get-ToolNames {
|
|
param($TraceData)
|
|
|
|
if ($null -eq $TraceData -or $null -eq $TraceData.toolInvocations) {
|
|
return @()
|
|
}
|
|
return @($TraceData.toolInvocations | ForEach-Object { $_.toolName } | Where-Object { $_ } | Sort-Object -Unique)
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
|
|
|
|
Write-Host "Running interview demo preflight..."
|
|
Write-Host "BaseUrl: $BaseUrl"
|
|
Write-Host "SessionId: $SessionId"
|
|
|
|
if (-not (Test-ServiceReachable -Url $BaseUrl)) {
|
|
throw "Service is not reachable: $BaseUrl. Start the app with mvp-demo profile first: mvn spring-boot:run -Dspring-boot.run.profiles=mvp-demo"
|
|
}
|
|
|
|
$request = Get-Content -Raw -Encoding UTF8 -Path $RequestFile | ConvertFrom-Json
|
|
$request.Id = $SessionId
|
|
$body = $request | ConvertTo-Json -Depth 8
|
|
|
|
$chatRequest = @{
|
|
Method = "Post"
|
|
Uri = "$BaseUrl/api/chat"
|
|
ContentType = "application/json; charset=utf-8"
|
|
Body = $body
|
|
}
|
|
$chat = Invoke-RestMethod @chatRequest
|
|
|
|
$chatPath = Join-Path $OutputDir "chat-response.json"
|
|
$chat | ConvertTo-Json -Depth 30 | Set-Content -Encoding UTF8 -Path $chatPath
|
|
|
|
$runId = $chat.data.runId
|
|
if (-not $runId) {
|
|
throw "Chat response did not include runId; exact trace verification cannot continue."
|
|
}
|
|
|
|
$traceRequest = @{
|
|
Method = "Get"
|
|
Uri = "$BaseUrl/api/diagnosis/$SessionId/trace?runId=$([System.Uri]::EscapeDataString($runId))"
|
|
}
|
|
$trace = Invoke-RestMethod @traceRequest
|
|
|
|
$tracePath = Join-Path $OutputDir "trace-response.json"
|
|
$trace | ConvertTo-Json -Depth 80 | Set-Content -Encoding UTF8 -Path $tracePath
|
|
|
|
$feedbackBody = @{
|
|
sessionId = $SessionId
|
|
runId = $runId
|
|
feedback = "useful"
|
|
} | ConvertTo-Json
|
|
|
|
$feedbackRequest = @{
|
|
Method = "Post"
|
|
Uri = "$BaseUrl/api/feedback"
|
|
ContentType = "application/json; charset=utf-8"
|
|
Body = $feedbackBody
|
|
}
|
|
$feedback = Invoke-RestMethod @feedbackRequest
|
|
|
|
$feedbackPath = Join-Path $OutputDir "feedback-response.json"
|
|
$feedback | ConvertTo-Json -Depth 30 | Set-Content -Encoding UTF8 -Path $feedbackPath
|
|
|
|
$traceData = Get-TraceData -TraceResponse $trace
|
|
$selfEvaluation = Get-SelfEvaluation -TraceData $traceData
|
|
$verifierEvaluation = $null
|
|
if ($null -ne $selfEvaluation) {
|
|
$verifierEvaluation = $selfEvaluation.verifier_evaluation
|
|
}
|
|
|
|
$gatekeeperResult = $null
|
|
$promptAudit = $null
|
|
if ($null -ne $verifierEvaluation) {
|
|
$gatekeeperResult = $verifierEvaluation.gatekeeper_result
|
|
$promptAudit = $verifierEvaluation.prompt_audit
|
|
}
|
|
|
|
$verdict = $null
|
|
$gatekeeperStatus = $null
|
|
$gatekeeperRuleSetVersion = $null
|
|
$promptAuditVersion = $null
|
|
if ($null -ne $verifierEvaluation) {
|
|
$verdict = $verifierEvaluation.verdict
|
|
}
|
|
if ($null -ne $gatekeeperResult) {
|
|
$gatekeeperStatus = $gatekeeperResult.status
|
|
$gatekeeperRuleSetVersion = $gatekeeperResult.rule_set_version
|
|
}
|
|
if ($null -ne $promptAudit) {
|
|
$promptAuditVersion = $promptAudit.version
|
|
}
|
|
$toolNames = Get-ToolNames -TraceData $traceData
|
|
$summaryPath = Join-Path $OutputDir "interview-demo-summary.json"
|
|
|
|
$summary = [ordered]@{
|
|
sessionId = $SessionId
|
|
runId = $runId
|
|
baseUrl = $BaseUrl
|
|
chatSuccess = $chat.data.success
|
|
verdict = $verdict
|
|
gatekeeperStatus = $gatekeeperStatus
|
|
gatekeeperRuleSetVersion = $gatekeeperRuleSetVersion
|
|
promptAuditVersion = $promptAuditVersion
|
|
toolNames = $toolNames
|
|
paths = [ordered]@{
|
|
chat = $chatPath
|
|
trace = $tracePath
|
|
feedback = $feedbackPath
|
|
summary = $summaryPath
|
|
}
|
|
}
|
|
|
|
$summary | ConvertTo-Json -Depth 20 | Set-Content -Encoding UTF8 -Path $summaryPath
|
|
|
|
Write-Host ""
|
|
Write-Host "Interview demo preflight completed."
|
|
Write-Host "Verdict: $($summary.verdict)"
|
|
Write-Host "Gatekeeper rules: $($summary.gatekeeperRuleSetVersion)"
|
|
Write-Host "Prompt audit: $($summary.promptAuditVersion)"
|
|
Write-Host "Summary: $summaryPath"
|