From 68662ed804bf723ac6803b3312e16d64db744898 Mon Sep 17 00:00:00 2001 From: DanliaQwerty20 Date: Tue, 15 Sep 2026 22:37:51 +0300 Subject: [PATCH] fix: run acceptance test in Compose network --- README.md | 2 ++ scripts/check.ps1 | 2 +- scripts/run-calendar.ps1 | 32 +++++++++++++++++++++----------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5793ccf..9d2579a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ Runner сам получает короткоживущий JWT у локаль `fake-calendar` доступен только в тестовом режиме и требует отдельный `X-Test-Key`; секреты не хранятся в Git. Для одинакового запуска в Docker Desktop и Linux runner имя `host.docker.internal` явно связывается со стандартным Docker `host-gateway`. +Если задан `DOCKER_NETWORK`, k6 подключается к существующей Compose-сети и принимает внутренние +имена `channel-gateway`, `action-service` и `calendar-mcp`. Сам `test-lab` эту сеть не создаёт. Путь начинается с публичной границы `Channel Gateway`, затем проходит через Agent Runtime, Action Service, Temporal и Calendar MCP. Один JWT передаётся по этому пути; каждый защищённый сервис diff --git a/scripts/check.ps1 b/scripts/check.ps1 index 617af0b..0eea349 100644 --- a/scripts/check.ps1 +++ b/scripts/check.ps1 @@ -19,7 +19,7 @@ foreach ($oldName in @("utterance", "tenant_id", "actor_id", "available_connecto if ($calendarScript -match "/api/v1/proposals") { throw "Acceptance-test must start through Channel Gateway." } $runner = Get-Content scripts/run-calendar.ps1 -Raw -foreach ($required in @("ACTION_TOKEN", "KEYCLOAK_URL", "OIDC_REALM", "OIDC_CLIENT_ID", "TEST_USERNAME", "TEST_PASSWORD", "protocol/openid-connect/token", "--add-host", "host.docker.internal:host-gateway")) { +foreach ($required in @("ACTION_TOKEN", "KEYCLOAK_URL", "OIDC_REALM", "OIDC_CLIENT_ID", "TEST_USERNAME", "TEST_PASSWORD", "protocol/openid-connect/token", "--add-host", "host.docker.internal:host-gateway", "DOCKER_NETWORK", "--network")) { if ($runner -notmatch [regex]::Escape($required)) { throw "Calendar runner does not support $required." } } diff --git a/scripts/run-calendar.ps1 b/scripts/run-calendar.ps1 index 7190eaa..af46525 100644 --- a/scripts/run-calendar.ps1 +++ b/scripts/run-calendar.ps1 @@ -2,7 +2,8 @@ param( [string]$ChannelUrl = "", [string]$ActionUrl = "", [string]$CalendarTestUrl = "", - [string]$KeycloakUrl = "" + [string]$KeycloakUrl = "", + [string]$DockerNetwork = "" ) $ErrorActionPreference = "Stop" @@ -23,11 +24,17 @@ function Get-Setting([string]$Name, [switch]$Secret) { function Assert-LocalUrl([string]$Url) { $uri = [Uri]$url - if ($uri.Scheme -ne "http" -or $uri.Host -notin @("localhost", "127.0.0.1", "host.docker.internal")) { + $allowedHosts = @("localhost", "127.0.0.1", "host.docker.internal") + if ($DockerNetwork) { $allowedHosts += @("channel-gateway", "action-service", "calendar-mcp") } + if ($uri.Scheme -ne "http" -or $uri.Host -notin $allowedHosts) { throw "Calendar acceptance test allows local HTTP URLs only." } } +$DockerNetwork = if ($DockerNetwork) { $DockerNetwork } else { [Environment]::GetEnvironmentVariable("DOCKER_NETWORK") } +if ($DockerNetwork -and $DockerNetwork -notmatch '^[a-zA-Z0-9][a-zA-Z0-9_.-]+$') { + throw "DOCKER_NETWORK contains unsupported characters." +} $ChannelUrl = if ($ChannelUrl) { $ChannelUrl } else { Get-Setting "CHANNEL_URL" } $ActionUrl = if ($ActionUrl) { $ActionUrl } else { Get-Setting "ACTION_URL" } $CalendarTestUrl = if ($CalendarTestUrl) { $CalendarTestUrl } else { Get-Setting "CALENDAR_TEST_URL" } @@ -54,15 +61,18 @@ $parts = $token.Split('.') if ($parts.Count -ne 3) { throw "ACTION_TOKEN is not a JWT." } $calendarTestKey = Get-Setting "CALENDAR_TEST_API_KEY" -Secret $k6Image = Get-Setting "K6_IMAGE" +$dockerArgs = @("run", "--rm", "--add-host", "host.docker.internal:host-gateway") +if ($DockerNetwork) { $dockerArgs += @("--network", $DockerNetwork) } +$dockerArgs += @( + "--volume", "${PWD}/tests:/tests:ro", + "--env", "CHANNEL_URL=$ChannelUrl", + "--env", "ACTION_URL=$ActionUrl", + "--env", "CALENDAR_TEST_URL=$CalendarTestUrl", + "--env", "CALENDAR_TEST_API_KEY=$calendarTestKey", + "--env", "ACTION_TOKEN=$token", + $k6Image, "run", "/tests/calendar-event.js" +) -& docker run --rm ` - --add-host "host.docker.internal:host-gateway" ` - --volume "${PWD}/tests:/tests:ro" ` - --env "CHANNEL_URL=$ChannelUrl" ` - --env "ACTION_URL=$ActionUrl" ` - --env "CALENDAR_TEST_URL=$CalendarTestUrl" ` - --env "CALENDAR_TEST_API_KEY=$calendarTestKey" ` - --env "ACTION_TOKEN=$token" ` - $k6Image run /tests/calendar-event.js +& docker @dockerArgs if ($LASTEXITCODE -ne 0) { throw "Calendar acceptance scenario failed." }