diff --git a/README.md b/README.md index 4bed92c..b3de6f1 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Implements [Universal-Agent-Memory-Specification.md](Universal-Agent-Memory-Spec **Tooling** - `scripts\provision.cmd` (tenant, principal, key, namespace, grant, revoke, list, purge); see AGENTS.md section 1. Needed for tenants, the first admin of a tenant and top-level namespaces; the rest can go through the management API. Quote permission lists in PowerShell: `'"read,write"'`. - `scripts\export-memories.ps1` / `scripts/export-memories.sh`: dump every readable memory (set `AMK_KEY`). +- `pwsh scripts/smoke-prod.ps1`: post-deploy check of a running server (readiness, the API key via `/me`, a consolidation dry run); reads `.amk.env`, or `-BaseUrl -Key -NamespaceId`. Writes nothing. - `scripts/ops.sh`: the same tools for a Linux server (migrate, provision, embed, backup, verify, restore, repair). - `scripts\embed.cmd status|run|reindex`: semantic index status, catch up on pending/failed items, or rebuild (after changing the model). - Tests (containers must be running): `bash tests/phase1-api.sh` (79 checks), `bash tests/phase2-api.sh` (45), `bash tests/phase3-context.sh` (60), `bash tests/phase3-semantic.sh` (30; stops and restarts the ollama container once), `bash tests/phase3-learning.sh` (93), `bash tests/phase3-portability.sh` (47), `bash tests/backup-restore.sh` (21; starts a throw-away container on port 8802), `bash tests/phase3-jobs.sh` (41; stops the embed-worker container while it runs), `bash tests/observability.sh` (25; restarts the container; the metrics checks need `AMK_METRICS_TOKEN`), `bash tests/admin-api.sh` (91), `bash tests/phase3-consolidation.sh` (42), `bash tests/retrieval-benchmark.sh` (5 threshold checks over 56 labelled queries; stops and restarts the ollama container). Each creates and purges its own tenants. diff --git a/scripts/smoke-prod.ps1 b/scripts/smoke-prod.ps1 new file mode 100644 index 0000000..74b07fc --- /dev/null +++ b/scripts/smoke-prod.ps1 @@ -0,0 +1,85 @@ +# Post-deploy smoke test for a running Agent Memory server (by default the production server in .amk.env). +# Checks readiness, the API key (GET /me) and consolidation (dry run, writes nothing). +# +# pwsh scripts/smoke-prod.ps1 uses AMK_URL, AMK_KEY and AMK_NAMESPACE from .amk.env +# pwsh scripts/smoke-prod.ps1 -BaseUrl http://localhost:8801/api/v1 -Key amk_... -NamespaceId +# +# The key is never printed. Exit code 0 when every check passes, 1 otherwise. +[CmdletBinding()] +param( + [string]$BaseUrl, + [string]$Key, + [string]$NamespaceId, + [string]$EnvFile = (Join-Path $PSScriptRoot '..' '.amk.env') +) +$ErrorActionPreference = 'Stop' + +# Values not given on the command line come from .amk.env (KEY=value lines; git-ignored, local only). +if (Test-Path $EnvFile) { + $settings = @{} + foreach ($line in Get-Content $EnvFile) { + if ($line -match '^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$') { + $settings[$Matches[1]] = $Matches[2].Trim('"').Trim("'") + } + } + if (-not $BaseUrl) { $BaseUrl = $settings['AMK_URL'] } + if (-not $Key) { $Key = $settings['AMK_KEY'] } + if (-not $NamespaceId) { $NamespaceId = $settings['AMK_NAMESPACE'] } +} +if (-not $BaseUrl -or -not $Key -or -not $NamespaceId) { + Write-Error "Need -BaseUrl, -Key and -NamespaceId (or AMK_URL, AMK_KEY and AMK_NAMESPACE in $EnvFile)." +} +$BaseUrl = $BaseUrl.TrimEnd('/') +$headers = @{ Authorization = "Bearer $Key" } +$failed = 0 + +function Invoke-Check { + param([string]$Name, [string]$Method, [string]$Path, [hashtable]$Headers, [string]$Body, [scriptblock]$Test) + try { + $params = @{ Uri = "$BaseUrl$Path"; Method = $Method; SkipHttpErrorCheck = $true; TimeoutSec = 30 } + if ($Headers) { $params.Headers = $Headers } + if ($Body) { $params.Body = $Body; $params.ContentType = 'application/json' } + $resp = Invoke-WebRequest @params + $data = $null + if ($resp.Content) { $data = $resp.Content | ConvertFrom-Json } + $detail = & $Test $resp.StatusCode $data + if ($detail -is [string] -and $detail.StartsWith('FAIL')) { + Write-Host "FAIL $Name - $($detail.Substring(4).Trim())" -ForegroundColor Red + $script:failed++ + } else { + Write-Host "ok $Name - $detail" -ForegroundColor Green + } + } catch { + Write-Host "FAIL $Name - $($_.Exception.Message)" -ForegroundColor Red + $script:failed++ + } +} + +Write-Host "Smoke test against $BaseUrl" + +Invoke-Check 'health/ready' GET '/health/ready' $null $null { + param($code, $d) + if ($code -ne 200) { return "FAIL HTTP $code" } + "HTTP 200, status $($d.status)" +} + +Invoke-Check 'me (API key)' GET '/me' $headers $null { + param($code, $d) + if ($code -ne 200) { return "FAIL HTTP $code (key invalid or server not updated)" } + $paths = ($d.grants | ForEach-Object { "$($_.path) [$($_.permissions -join ',')]" }) -join '; ' + "principal $($d.name) ($($d.type)), grants: $paths" +} + +$consBody = @{ namespace_id = $NamespaceId } | ConvertTo-Json -Compress +Invoke-Check 'consolidations (dry run)' POST '/consolidations' $headers $consBody { + param($code, $d) + if ($code -ne 200) { return "FAIL HTTP $code" } + "experiences considered $($d.experiences_considered), groups $(@($d.groups).Count), candidates created $($d.candidates_created)" +} + +if ($failed -gt 0) { + Write-Host "$failed check(s) failed" -ForegroundColor Red + exit 1 +} +Write-Host 'All checks passed' -ForegroundColor Green +exit 0