Reference

Proxy Setup

Everything you need to integrate Gostly into a real development or CI environment: TLS termination, multiple services, per-service modes, and connecting CI pipelines.

Basic single-service setup

Use the public Gostly Compose repository and its setup.sh flow described in Install & Deploy. Your account supplies the license key; the repository supplies the Compose files and environment template. Keep the proxy, dashboard/control API, database and one-shot migration service together. Once ready, register one upstream using a matching host or path rule, as shown below:

TLS for HTTPS environments

For HTTPS interception, set ENABLE_TLS_INTERCEPTION for the proxy, publish port 8443 and trust the proxy CA in your test client. Neither supplied Compose file publishes 8443, and only the Full file passes ENABLE_TLS_INTERCEPTION from .env. The TLS guide gives the override that adds them. The agent can terminate TLS itself by setting ENABLE_TLS_INTERCEPTION and publishing port 8443 — a CONNECT forward proxy on that port that mints per-host certificates from an embedded CA. Distribute the CA once by fetching it from the proxy and trust-installing it per OS:

curl http://<agent>:8080/ca.crt > gostly-ca.crt
# then add gostly-ca.crt to the client/OS trust store

Or, if you prefer to terminate TLS at the edge, front the proxy with Caddy, which handles TLS and forwards to Gostly over plain HTTP:

# Caddyfile
mock.internal.example.com {
  reverse_proxy ghost-proxy:8080
}
services:
  caddy:
    image: caddy:2-alpine
    ports:
      - "443:443"
      - "80:80"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
    depends_on:
      - ghost-proxy

  ghost-proxy:
    image: &lt;your-registry-host&gt;/gostlyai/proxy:latest
    container_name: ghost-proxy
    # Do NOT expose port directly — traffic comes through Caddy
    environment:
      GOSTLY_LICENSE_KEY: "YOUR_LICENSE_KEY"
      BACKEND_URL: "https://api.example.com"
      MOCK_DIR: /data/mocks
      MODE_FILE_PATH: /data/mode.txt
    volumes:
      - gostly-data:/data  # the install's data volume, not a host ./data bind

Self-signed upstream certs

If your upstream uses a self-signed certificate (common in staging environments), set ACCEPT_INVALID_CERTS=true on the proxy. This also turns off certificate verification on the proxy's own connections to the Gostly API and inference services in your stack (license validation and the usage-telemetry upload always verify certificates), and it emits a startup warning — do not use in production against real upstreams.

HTTP and HTTPS use their configured proxy path. WebSocket forwarding and opt-in frame capture are separate from HTTP mock replay. Frame capture is off by default and follows the routed service's capture setting. Captured frames are not replayed, and frame bodies have no per-frame redaction. See WebSocket capture for the listener, configuration and data-handling scope.

Multiple upstream services

A single ghost-proxy instance handles multiple upstream services simultaneously. You register each service via the API with a routing rule — either host-based (matched on the Host request header) or path-based (matched on a URL prefix). Each service gets its own mock library, mode, chaos config, and redaction rules.

Register services after the stack is running. The control plane runs fail-closed, so every call on port 8000 carries the X-API-Key header (the value of GHOST_API_KEY from your .env):

# Host-based routing — route by the Host header your app sends
curl -X POST http://localhost:8000/v1/services \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "name":          "payments",
    "upstream_url":  "https://payments.internal",
    "routing_type":  "host",
    "routing_value": "payments.internal"
  }'

# Path-based routing — route by URL prefix
curl -X POST http://localhost:8000/v1/services \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "name":          "users",
    "upstream_url":  "https://users.internal",
    "routing_type":  "path",
    "routing_value": "/api/users"
  }'

Wait for the configured service to synchronize to the proxy before recording; resolve missing-upstream or authentication errors first. Requests that don't match any registered service fall through to BACKEND_URL (the default upstream configured at startup).

When more than one routing rule matches a request, a host rule that equals the request's Host header wins. Otherwise the longest matching path prefix wins: with one service on /api and another on /api/orders, a request for /api/orders/42 goes to the /api/orders service, and other paths that start with /api go to the /api service. Path prefixes are compared character for character and are case-sensitive.

After recording, build the service library and wait for the build to complete without errors. Each service can then be switched to a different mode independently:

# Switch one service to MOCK while others stay in LEARN
curl -X PUT http://localhost:8000/v1/services/{service_id} \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"mode": "MOCK"}'

# Or set the global mode. A service that has its own mode keeps it.
curl -X POST http://localhost:8000/v1/mode \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"mode": "MOCK"}'

The global mode applies to every service that has no mode of its own. A service you switched individually keeps that mode when the global mode changes.

Example: test a read-only agent tool

Follow the order-tool failure example to inspect a local decoder, prepare an authored one-attempt HTTP 503 case and check the result at the HTTP, wrapper, agent and application boundaries. The decoder makes no requests; your own tool and harness supply the HTTP execution and agent evaluation.

CI integration

Reuse the generated stack with pinned images, a reviewed test library, and the same service routing configuration used to build it. Supply registry access and installation credentials through your CI secret store. Registry pulls and license validation have separate connectivity needs from replay; do not assume the entire installation process is offline.

Choose the inputs for the run

  • Prepared library. Retain reviewed fixtures and matching route configuration. Import through the supported format importer, confirm serving state and select MOCK before invoking application tests.
  • Synthetic service model. Build and review the model separately, then compile, plan/apply its definition and import the emitted fixtures. The runner does not compile a code model automatically. See the service-model handoff.
  • Existing CI command. With a compatible runner copied from the Gostly source, gostly_ci.py run --manifest … -- <your-test-command> can seed supported manifest fixtures and run the supplied command. You supply the runner file, manifest, stack, dependencies, credentials and routing.

Check the dependency before the application

  1. Start the complete stack and wait for database setup and service configuration to finish.
  2. Confirm the intended library loaded, choose MOCK explicitly, and check readiness before running application tests.
  3. Run one known request and verify its status, body and response source. Check that the upstream request count stays unchanged separately.
  4. Run your test suite against the proxy, then stop the disposable CI stack while preserving any evidence you need.

Reset your application's database, caches and other state separately. An episode-aware run also needs the client's journal headers and the runner's companion verifier; see API time & episodes. A prepared dependency and its evidence do not establish your application's correctness.

Share reviewed test data

Keep .env, data/traffic/, and data/license_cache.json private. Local replay bodies may contain user data; review data/mocks/ before sharing it. Preserve the generated writable runtime volumes instead of mounting the entire data directory read-only.

Chaos injection

Faults and injected latency are rules in a service's behaviour document, applied at runtime without restarting the proxy. Read the document's ETag, then write the document with it as If-Match. Useful for resilience testing:

# The current document's ETag ($SERVICE_ID is the svc_... id)
curl -si "http://localhost:8000/v1/services/$SERVICE_ID/behavior?format=json" \
  -H "X-API-Key: $GHOST_API_KEY" | grep -i '^etag'

# 5% of requests answer 500, after 50-300 ms of injected latency (metadata.name: the service name)
curl -X PUT "http://localhost:8000/v1/services/$SERVICE_ID/behavior" \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "If-Match: $ETAG" \
  -d '{
    "apiVersion": "gostly.behavior.v1",
    "kind": "ServiceBehavior",
    "metadata": {"name": "payments"},
    "spec": {"rules": [{
      "id": "payments-flaky",
      "match": {"path": "/**"},
      "timing": {"latency": {"jitter": {"minMs": 50, "maxMs": 300}}},
      "faults": {"probability": 0.05, "response": {"status": 500}}
    }]}
  }'