Sessions and the Control API
Sessions
Every request belongs to a Session, named by its x-mock-session header. Requests without the
header use the default Session. Each Session has its own Selection: active Collection plus
per-Route overrides. So parallel tests can share one decoy without seeing each other's changes.
New Sessions start on the default Collection. Decoy holds up to 10,000 Sessions with a
Selection. Past that, the one changed least recently is ended as if it had called endSession,
with a warning; the default Session is never ended this way.
Control API
Command-shaped POST endpoints under the reserved /__decoy__ path. Pick the Session with
x-mock-session; leave it out for the default Session. Every call, reset and endSession
too, sends content-type: application/json; anything else gets 415, so a web page on another
site can't switch your Scenarios with a form or a simple fetch.
useRoute swaps the Behavior of that route:case where it sits in the active Collection, so
more specific Cases listed after it still win. A route:case the Collection doesn't list goes
after all of its entries, and among those the last useRoute call wins.
Success returns 200 with the Session's Selection. Unknown Collections or Behavior addresses,
malformed JSON and unknown body fields return 400 {"error":"..."}, a missing JSON content type
returns 415, and unknown /__decoy__ paths return 404.
send
POST /__decoy__/control/send pushes a message to the live connections of a Route: open
server-streaming gRPC calls and WebSocket sockets.
- gRPC:
messageis the response message as protobuf JSON; it goes through the Route's Pipeline. One that doesn't fit the method's output type gets400with the reason, and nothing is sent. - WebSocket: the Route’s output Pipeline transforms each recipient’s message, including strings. Without output steps, strings go out as-is and other values become JSON text.
- Only connections opened in the same Session (
x-mock-session) get it. - With no live connection yet,
sendwaits for one up totimeoutmilliseconds (default5000, at most 5 minutes: a longertimeoutis cut to that). - Each connection queues up to 64 unread messages. A connection whose queue is full skips the
message and doesn't count in
delivered; if every one is full,sendwaits as above. - After a reload,
messageis encoded with the current output type, also for streams opened before it; an older client skips fields it doesn't know. A stream whose Route now answers with a different message type doesn't get it.
Malformed JSON or an unknown body field returns 400 and a missing JSON content type 415, as
for the other verbs.
wait
POST /__decoy__/control/wait with connected: true returns once the caller's Session has a live
connection of the Route, so a test can send knowing the page's socket or stream is open.
- Only connections opened in the same Session (
x-mock-session) count, and only thosesendcan reach: a WebSocket socket always counts; a gRPC stream counts only while it stays open forsend(its Case has nostatus) and was opened with the Route's current output type. A finite scripted stream (its Case ends with astatus) is never registered, sowaitanswers408. - It waits up to
timeoutmilliseconds (default5000, at most 5 minutes). connected: trueis the only condition so far.
Malformed JSON or an unknown body field returns 400 and a missing JSON content type 415, as
for the other verbs.
Health
GET /__decoy__/health → 200 {"status":"ok"} while Decoy is serving. It is a liveness check
only: no diagnostics, and it never touches any Session.