From fdcb92abb4090cb18b2ed284872db3cafd98f60f Mon Sep 17 00:00:00 2001 From: Jordan Ritter Date: Mon, 6 Apr 2026 08:33:39 -0700 Subject: [PATCH] fix: add health checks to migration page fixture examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Python Docker: time.sleep(2) → health check loop on /__aimock/health - Python npx: stderr=subprocess.PIPE → subprocess.STDOUT (deadlock fix) + health check - Mokksy Kotlin: add health check wait after docker run -d --- docs/migrate-from-mokksy.html | 10 ++++++++++ docs/migrate-from-python-mocks.html | 21 +++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/migrate-from-mokksy.html b/docs/migrate-from-mokksy.html index c31a64f..2647c3a 100644 --- a/docs/migrate-from-mokksy.html +++ b/docs/migrate-from-mokksy.html @@ -154,6 +154,16 @@

The quick switch

"-p", "4010:4010", "-v", "./fixtures:/fixtures", "ghcr.io/copilotkit/aimock", "-f", "/fixtures") .start().waitFor() + // Wait for server to be ready + repeat(30) { + try { + java.net.URL("http://localhost:4010/__aimock/health") + .readText() + return + } catch (_: Exception) { + Thread.sleep(200) + } + } } @AfterAll diff --git a/docs/migrate-from-python-mocks.html b/docs/migrate-from-python-mocks.html index ceeffdd..7af76a0 100644 --- a/docs/migrate-from-python-mocks.html +++ b/docs/migrate-from-python-mocks.html @@ -256,9 +256,15 @@

aimock (after)

"ghcr.io/copilotkit/aimock:latest", "-f", "/fixtures" ]) - time.sleep(2) # wait for server + # Wait for health endpoint + import requests + for _ in range(30): + try: + if requests.get("http://localhost:4010/__aimock/health").ok: + break + except requests.ConnectionError: + time.sleep(0.2) - # Point OpenAI SDK at the mock os.environ["OPENAI_BASE_URL"] = "http://localhost:4010/v1" os.environ["OPENAI_API_KEY"] = "mock-key" @@ -489,9 +495,16 @@

Alternative: npx fixture (no Docker)

def aimock_server(): proc = subprocess.Popen( ["npx", "aimock", "-p", "4010", "-f", "./fixtures"], - stdout=subprocess.PIPE, stderr=subprocess.PIPE + stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - time.sleep(2) # wait for server + # Wait for health endpoint + import requests + for _ in range(30): + try: + if requests.get("http://localhost:4010/__aimock/health").ok: + break + except requests.ConnectionError: + time.sleep(0.2) os.environ["OPENAI_BASE_URL"] = "http://localhost:4010/v1" os.environ["OPENAI_API_KEY"] = "mock-key"