@ts-pf/protocol 0.2.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,187 @@
1
+ # ts-pf protocol conformance fixtures
2
+
3
+ Language-neutral test vectors for [`PROTOCOL.md`](../PROTOCOL.md). A client in any language proves it follows the protocol by replaying these files against its own code: no server, no network, no dependency on the TypeScript packages. The TypeScript reference client (`FetchLink`, `FetchLink` with `StreamCodec`, `WsLink`) replays the same files in this repository's CI.
4
+
5
+ | File | Binding | What a case is |
6
+ | -------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------ |
7
+ | [`http.json`](http.json) | Unary JSON over HTTP | One request the client must send and one response it must classify |
8
+ | [`http-stream.json`](http-stream.json) | `application/jsonl` output streams over HTTP | The same, where the response may be a stream |
9
+ | [`ws.json`](ws.json) | Message frames over WebSocket | A script of frames the client sends and receives, and what its caller observes |
10
+
11
+ The files are data, not schemas: plain JSON, readable without a validator. They ship in the `@ts-pf/protocol` npm package (`conformance/`), and TypeScript can import them typed from `@ts-pf/protocol/conformance`.
12
+
13
+ Building a client from scratch? The guide [Clients in other languages](https://github.com/crobinson42/ts-pf/blob/main/docs/other-languages.md) puts the spec, the fixtures, and code generation in order.
14
+
15
+ ## Getting the files
16
+
17
+ Pin the package version you test against, and never follow `latest`: a new revision may add cases. You do not need npm:
18
+
19
+ | Source | URL or command |
20
+ | -------- | --------------------------------------------------------------------------------------- |
21
+ | jsDelivr | `https://cdn.jsdelivr.net/npm/@ts-pf/protocol@<version>/conformance/<file>.json` |
22
+ | unpkg | `https://unpkg.com/@ts-pf/protocol@<version>/conformance/<file>.json` |
23
+ | npm | `npm pack @ts-pf/protocol@<version>`, then read `package/conformance/` from the tarball |
24
+
25
+ Commit the files your tests use next to a note of the version (or download them in CI from a pinned URL), so a fixture change reaches you as a reviewed diff.
26
+
27
+ ## Versioning
28
+
29
+ Every file starts with:
30
+
31
+ ```json
32
+ { "protocol": 1, "revision": "1.2", "binding": "http", "description": "…", "cases": [ … ] }
33
+ ```
34
+
35
+ - `protocol` is the wire major (`x-ts-pf-protocol: 1`, `v: 1` on `hello`).
36
+ - `revision` is the `PROTOCOL.md` revision the cases were written against. It changes with the spec: a new revision may add cases, and a case changes only when the spec it cites changes. Pin the package version (or a commit) you test against, and report the `revision` with your results.
37
+ - Case `id`s are unique across all files and stable across revisions, so results can be compared over time.
38
+
39
+ Each case has a `description` that ends with the `PROTOCOL.md` sections it checks (`PROTOCOL.md: Classifying an HTTP response, step 3.`). When a case and the spec disagree, the spec wins; please report it.
40
+
41
+ ## Shared rules
42
+
43
+ - **JSON equality.** "Equal" means the same JSON value: object key order does not matter, numbers compare by value, and a key that is absent is not the same as a key whose value is `null`.
44
+ - **Absent means no value.** `output` (and an item's `output`, and `data`) is omitted when there is none. A client that represents "no value" (`undefined`, `nil`, `None`, `Unit`, …) must produce it for an omitted `output`, and a JSON `null` for `"output": null`.
45
+ - **Errors.** An `error` (or the `code` / `message` / `data` of an `"kind": "error"` expectation) is the failure envelope's `{ code, message, data? }`. The client must surface the same `code`, `message`, and `data` to its caller. A `data` that is absent must surface as no data.
46
+ - **Local failures.** `local-failure` means a failure the client raised itself because no protocol result arrived (see `PROTOCOL.md` "Conventions"); the caller must be able to tell it apart from a failure envelope. How it is reported is up to the client. `reference` is the TypeScript reference client's message for it, informative only.
47
+
48
+ ## HTTP: `http.json` and `http-stream.json`
49
+
50
+ Each case:
51
+
52
+ ```json
53
+ {
54
+ "id": "http-success-output",
55
+ "description": "…",
56
+ "request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
57
+ "expectRequest": {
58
+ "method": "POST",
59
+ "path": "/planet/find",
60
+ "headers": { "content-type": "application/json", "x-ts-pf-protocol": "1" },
61
+ "body": { "input": { "id": 1 } }
62
+ },
63
+ "response": {
64
+ "status": 200,
65
+ "headers": { "content-type": "application/json", "x-ts-pf-protocol": "1" },
66
+ "body": "{\"ok\":true,\"output\":{\"id\":1,\"name\":\"Earth\"}}"
67
+ },
68
+ "expect": { "kind": "success", "output": { "id": 1, "name": "Earth" } }
69
+ }
70
+ ```
71
+
72
+ To replay a case:
73
+
74
+ 1. Configure the client with an empty URL prefix (or any prefix `P`; then the expected path is `P` + `path`) and an HTTP transport you control: an injected HTTP function, a mock engine, or an interceptor that never reaches the network.
75
+ 2. Call `request.procedure` with `request.input`. An absent `input` means a call with no input.
76
+ 3. Check the request the client sent against `expectRequest`:
77
+ - `method` and `path` are equal.
78
+ - Every header in `headers` is present with that value. Names are case-insensitive; values compare exactly, except that `content-type` compares by media type (parameters such as `charset` are ignored). Other headers are allowed. `PROTOCOL.md` says a client SHOULD send `x-ts-pf-protocol: 1`, so a runner reports a missing `x-ts-pf-protocol` as a warning, not a failure; any other value fails.
79
+ - The body parses as JSON and equals `body`, or equals one of `bodyOneOf` (a call with no input may send `{}` or `{"input":null}`).
80
+ 4. Answer with `response`: that `status`, those `headers`, and `body` as the exact response text (it may not be JSON on purpose).
81
+ 5. Check what the caller observes against `expect`.
82
+
83
+ `expect.kind`:
84
+
85
+ | `kind` | The call must |
86
+ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
87
+ | `success` | Succeed with `output` (absent: no value). |
88
+ | `error` | Fail with the failure envelope `code`, `message`, and `data` (absent: no data). Never derive the outcome from the HTTP status. |
89
+ | `transport-failure` | Fail with a transport failure: the body did not decode as an envelope. It must not be reported as success or as an application outcome such as "not found", "unauthenticated", or "forbidden", whatever the HTTP status (`PROTOCOL.md` "Classifying an HTTP response", step 3). The spec does not fix how a client reports it; it should let the caller tell it apart from a decoded failure envelope. A client may additionally retry by status class; a runner gives each case one response, so a retrying client should have retries off or report the final outcome. |
90
+ | `version-mismatch` | Fail because `x-ts-pf-protocol` names another wire major, without decoding the body. The fixture body is a valid 1.x envelope on purpose: a client that decodes it gets the wrong answer. |
91
+ | `stream` | (`http-stream.json` only) Succeed with a stream. Reading it yields exactly `items` in order (each `{ "output": … }`, or `{}` for an item with no value), then ends as `end` says. |
92
+
93
+ `end.kind` for a stream:
94
+
95
+ | `end.kind` | Reading the stream must |
96
+ | ------------------- | -------------------------------------------------------------------------------------------------- |
97
+ | `eof` | Complete successfully after the last item. |
98
+ | `error` | Fail with the in-band failure line's `code`, `message`, and `data`. |
99
+ | `transport-failure` | Fail because a line did not decode. Lines after it are not delivered: a bad line is never skipped. |
100
+
101
+ A client that does not implement streams skips `http-stream.json`; its cases with another `kind` behave as in `http.json`. There are no SSE (`text/event-stream`) cases yet; SSE is optional.
102
+
103
+ For reference (informative, not a requirement), the TypeScript client reports a transport failure as `INTERNAL` `Non-RPC response (HTTP <status>)` when the response has no `x-ts-pf-protocol`, and as its codec's decode error (`BAD_REQUEST` `Invalid JSON`, `Response body must be a JSON object`, or `Invalid RPC envelope`, status `400`) when it carries `x-ts-pf-protocol: 1`; a bad JSONL line ends the stream with the same codec error. Neither is a local failure. See the `PROTOCOL.md` appendix "HTTP (`FetchLink`)".
104
+
105
+ ## WebSocket: `ws.json`
106
+
107
+ Each case is a script that runs over one connection, from the client's side. A runner plays the server: it hands the client a socket (or a test double of one) that it controls, records every message the client sends, and delivers server messages when the script says so.
108
+
109
+ ```json
110
+ {
111
+ "id": "ws-unary-result",
112
+ "description": "…",
113
+ "steps": [
114
+ { "send": { "type": "hello", "v": 1 } },
115
+ { "receive": { "type": "hello-ok", "v": 1 } },
116
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
117
+ {
118
+ "send": {
119
+ "type": "call",
120
+ "id": "1",
121
+ "path": ["planet", "find"],
122
+ "input": { "id": 1 }
123
+ }
124
+ },
125
+ {
126
+ "receive": {
127
+ "type": "result",
128
+ "id": "1",
129
+ "ok": true,
130
+ "output": { "id": 1, "name": "Earth" }
131
+ }
132
+ },
133
+ {
134
+ "expect": {
135
+ "call": "a",
136
+ "outcome": "value",
137
+ "output": { "id": 1, "name": "Earth" }
138
+ }
139
+ }
140
+ ]
141
+ }
142
+ ```
143
+
144
+ Open the connection before the first step, configured with `options` when the case has them (`options.meta` is the connect metadata the client sends as `hello.meta`). Disable the client's own hello timeout and reconnects for the run. Then run the steps in order. Each step has one of these keys:
145
+
146
+ | Step | Meaning |
147
+ | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
148
+ | `send` | The next message the client sends must be one text message whose JSON equals this frame. Wait for it (a short timeout is a failure). |
149
+ | `receive` | Deliver this frame to the client as one compact JSON text message. Some are invalid on purpose. |
150
+ | `receiveText` | Deliver this exact string as a text message (it need not be JSON). |
151
+ | `receiveBinary` | Deliver these bytes (base64) as a binary message. |
152
+ | `serverClose` | The server closes the connection (the value is `{}`). |
153
+ | `call` | The caller starts a call labelled by the value (`"a"`) with `path` and `input` (absent: no input), or with `inputStream`: a streamed input that yields those values and then completes. |
154
+ | `abort` | The caller gives up on call `"a"`: abort it if it is still pending, or stop reading it if it resolved to a stream. |
155
+ | `expect` | An outcome the caller observes, below. |
156
+
157
+ Before each `receive*`, `serverClose`, and `expect` step, and after the last step, let the client run until it is idle. A message the client sent that no `send` step matched fails the case: a client sends exactly the scripted frames, in order, and nothing else (no `call` before `hello-ok`, nothing after `cancel`, no reply to an ignored frame).
158
+
159
+ **Call ids.** Fixture ids are `"1"`, `"2"`, … in the order the client sends `call` frames. A client may number its calls differently: when a `send` step's `call` frame carries an id the script has not seen, bind it to the id the client actually sent (a non-empty string; `PROTOCOL.md` requires it to differ from the ids of calls still in flight, and a client SHOULD NOT reuse a cancelled id) and substitute the bound id in every later `send` and `receive` frame. Ids the script never binds (`"99"`) stand for an id the client never used; a runner whose client could have sent that string substitutes one it did not.
160
+
161
+ `expect` values:
162
+
163
+ | Expectation | The caller must observe |
164
+ | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
165
+ | `{ "call": "a", "outcome": "value", "output"? }` | Call `a` resolved to `output` (absent: no value). |
166
+ | `{ "call": "a", "outcome": "error", "error" }` | Call `a` failed with that failure envelope error. |
167
+ | `{ "call": "a", "outcome": "stream" }` | Call `a` resolved to a stream (the first frame for its id was `item` or `done`). |
168
+ | `{ "call": "a", "outcome": "local-failure", "reference"? }` | Call `a` failed with a local failure. |
169
+ | `{ "stream": "a", "outcome": "item", "output"? }` | The next value read from call `a`'s stream is `output` (absent: no value). |
170
+ | `{ "stream": "a", "outcome": "done" }` | Call `a`'s stream completed successfully. |
171
+ | `{ "stream": "a", "outcome": "error", "error" }` | Reading call `a`'s stream failed with that error. |
172
+ | `{ "stream": "a", "outcome": "local-failure", "reference"? }` | Reading call `a`'s stream failed with a local failure. |
173
+ | `{ "handshake": "error", "error" }` | The connect failed with that `hello-error` error (not a local failure). |
174
+ | `{ "handshake": "local-failure", "reference"? }` | The connect failed with a local failure. |
175
+ | `{ "closed": { "code"? } }` | The client closed the connection, with that WebSocket close code when `code` is present. |
176
+
177
+ A runner whose client exposes no connect result observes a `handshake` expectation on a call made at that point: it must fail the same way (and, had the handshake succeeded, it would send a `call` frame that no `send` step matches).
178
+
179
+ Close codes are advisory (`PROTOCOL.md` "Close codes"): a runner reports a `code` other than the one listed as a warning, except `1002` for a binary message, which the "Framing" table requires.
180
+
181
+ The scripts cover one connection, so they cannot observe reconnects; in real use, a client should not reconnect after a `hello-error` `Unsupported protocol version` at all (`PROTOCOL.md` "Reconnecting").
182
+
183
+ **Other message pipes.** stdio and `MessagePort` carry the same frames: skip the cases that use `receiveBinary`, and ignore `code` in `closed`.
184
+
185
+ ## Reporting results
186
+
187
+ Report, per file, the `revision` you tested and each case `id` as passed, failed (with what the client did instead), or skipped (with the reason, for example "no stream support"). A warning (a missing `x-ts-pf-protocol`, an advisory close code) is reported but does not fail the case. A client conforms to a binding at a revision when every case in that file passes or is skipped for an optional feature it does not implement (`http-stream.json` for a JSON-only client).
@@ -0,0 +1,308 @@
1
+ {
2
+ "protocol": 1,
3
+ "revision": "1.2",
4
+ "binding": "http-stream",
5
+ "description": "Output streams over HTTP as application/jsonl: one envelope per line, success at EOF. The request is the same JSON request as http.json. See README.md in this directory.",
6
+ "cases": [
7
+ {
8
+ "id": "stream-items-then-eof",
9
+ "description": "An application/jsonl response resolves the call to a stream at once; each line is an item and EOF ends it successfully. PROTOCOL.md: Message streams; Classifying an HTTP response, step 5.",
10
+ "request": { "procedure": ["chat"], "input": { "prompt": "hi" } },
11
+ "expectRequest": {
12
+ "method": "POST",
13
+ "path": "/chat",
14
+ "headers": {
15
+ "content-type": "application/json",
16
+ "x-ts-pf-protocol": "1"
17
+ },
18
+ "body": { "input": { "prompt": "hi" } }
19
+ },
20
+ "response": {
21
+ "status": 200,
22
+ "headers": {
23
+ "content-type": "application/jsonl",
24
+ "x-ts-pf-protocol": "1"
25
+ },
26
+ "body": "{\"ok\":true,\"output\":{\"token\":\"Hel\"}}\n{\"ok\":true,\"output\":{\"token\":\"lo\"}}\n"
27
+ },
28
+ "expect": {
29
+ "kind": "stream",
30
+ "items": [
31
+ { "output": { "token": "Hel" } },
32
+ { "output": { "token": "lo" } }
33
+ ],
34
+ "end": { "kind": "eof" }
35
+ }
36
+ },
37
+ {
38
+ "id": "stream-empty",
39
+ "description": "An empty body is a stream with zero items that ends successfully. PROTOCOL.md: Message streams.",
40
+ "request": { "procedure": ["chat"], "input": { "prompt": "" } },
41
+ "expectRequest": {
42
+ "method": "POST",
43
+ "path": "/chat",
44
+ "headers": {
45
+ "content-type": "application/json",
46
+ "x-ts-pf-protocol": "1"
47
+ },
48
+ "body": { "input": { "prompt": "" } }
49
+ },
50
+ "response": {
51
+ "status": 200,
52
+ "headers": {
53
+ "content-type": "application/jsonl",
54
+ "x-ts-pf-protocol": "1"
55
+ },
56
+ "body": ""
57
+ },
58
+ "expect": { "kind": "stream", "items": [], "end": { "kind": "eof" } }
59
+ },
60
+ {
61
+ "id": "stream-blank-lines-ignored",
62
+ "description": "Blank JSONL lines are ignored; they are not items. PROTOCOL.md: Classifying an HTTP response, step 5.",
63
+ "request": { "procedure": ["count"] },
64
+ "expectRequest": {
65
+ "method": "POST",
66
+ "path": "/count",
67
+ "headers": {
68
+ "content-type": "application/json",
69
+ "x-ts-pf-protocol": "1"
70
+ },
71
+ "bodyOneOf": [{}, { "input": null }]
72
+ },
73
+ "response": {
74
+ "status": 200,
75
+ "headers": {
76
+ "content-type": "application/jsonl",
77
+ "x-ts-pf-protocol": "1"
78
+ },
79
+ "body": "{\"ok\":true,\"output\":1}\n\n{\"ok\":true,\"output\":2}\n\n"
80
+ },
81
+ "expect": {
82
+ "kind": "stream",
83
+ "items": [{ "output": 1 }, { "output": 2 }],
84
+ "end": { "kind": "eof" }
85
+ }
86
+ },
87
+ {
88
+ "id": "stream-item-without-output",
89
+ "description": "A success line without output is an item with no value. PROTOCOL.md: Message streams; Classifying an HTTP response, step 2.",
90
+ "request": { "procedure": ["ticks"] },
91
+ "expectRequest": {
92
+ "method": "POST",
93
+ "path": "/ticks",
94
+ "headers": {
95
+ "content-type": "application/json",
96
+ "x-ts-pf-protocol": "1"
97
+ },
98
+ "bodyOneOf": [{}, { "input": null }]
99
+ },
100
+ "response": {
101
+ "status": 200,
102
+ "headers": {
103
+ "content-type": "application/jsonl",
104
+ "x-ts-pf-protocol": "1"
105
+ },
106
+ "body": "{\"ok\":true}\n{\"ok\":true,\"output\":null}\n"
107
+ },
108
+ "expect": {
109
+ "kind": "stream",
110
+ "items": [{}, { "output": null }],
111
+ "end": { "kind": "eof" }
112
+ }
113
+ },
114
+ {
115
+ "id": "stream-mid-stream-error",
116
+ "description": "An ok: false line ends the stream with that failure (HTTP status is already 200). PROTOCOL.md: Message streams; Protocol errors.",
117
+ "request": { "procedure": ["chat"], "input": { "prompt": "hi" } },
118
+ "expectRequest": {
119
+ "method": "POST",
120
+ "path": "/chat",
121
+ "headers": {
122
+ "content-type": "application/json",
123
+ "x-ts-pf-protocol": "1"
124
+ },
125
+ "body": { "input": { "prompt": "hi" } }
126
+ },
127
+ "response": {
128
+ "status": 200,
129
+ "headers": {
130
+ "content-type": "application/jsonl",
131
+ "x-ts-pf-protocol": "1"
132
+ },
133
+ "body": "{\"ok\":true,\"output\":{\"token\":\"Hel\"}}\n{\"ok\":false,\"error\":{\"code\":\"UPSTREAM_FAILED\",\"message\":\"upstream died\",\"data\":{\"retryAfter\":5}}}\n"
134
+ },
135
+ "expect": {
136
+ "kind": "stream",
137
+ "items": [{ "output": { "token": "Hel" } }],
138
+ "end": {
139
+ "kind": "error",
140
+ "code": "UPSTREAM_FAILED",
141
+ "message": "upstream died",
142
+ "data": { "retryAfter": 5 }
143
+ }
144
+ }
145
+ },
146
+ {
147
+ "id": "stream-error-first-line",
148
+ "description": "A failure line before any item still ends a stream: the call already resolved when the content type was read. PROTOCOL.md: Classifying an HTTP response, step 5.",
149
+ "request": { "procedure": ["chat"], "input": { "prompt": "hi" } },
150
+ "expectRequest": {
151
+ "method": "POST",
152
+ "path": "/chat",
153
+ "headers": {
154
+ "content-type": "application/json",
155
+ "x-ts-pf-protocol": "1"
156
+ },
157
+ "body": { "input": { "prompt": "hi" } }
158
+ },
159
+ "response": {
160
+ "status": 200,
161
+ "headers": {
162
+ "content-type": "application/jsonl",
163
+ "x-ts-pf-protocol": "1"
164
+ },
165
+ "body": "{\"ok\":false,\"error\":{\"code\":\"INTERNAL\",\"message\":\"Internal server error\"}}\n"
166
+ },
167
+ "expect": {
168
+ "kind": "stream",
169
+ "items": [],
170
+ "end": {
171
+ "kind": "error",
172
+ "code": "INTERNAL",
173
+ "message": "Internal server error"
174
+ }
175
+ }
176
+ },
177
+ {
178
+ "id": "stream-malformed-line",
179
+ "description": "A line that does not parse ends the stream with a transport failure; it is never skipped, and later lines are not delivered. PROTOCOL.md: Classifying an HTTP response, step 5.",
180
+ "request": { "procedure": ["chat"], "input": { "prompt": "hi" } },
181
+ "expectRequest": {
182
+ "method": "POST",
183
+ "path": "/chat",
184
+ "headers": {
185
+ "content-type": "application/json",
186
+ "x-ts-pf-protocol": "1"
187
+ },
188
+ "body": { "input": { "prompt": "hi" } }
189
+ },
190
+ "response": {
191
+ "status": 200,
192
+ "headers": {
193
+ "content-type": "application/jsonl",
194
+ "x-ts-pf-protocol": "1"
195
+ },
196
+ "body": "{\"ok\":true,\"output\":{\"token\":\"Hel\"}}\n{\"ok\":true,\"outp\n{\"ok\":true,\"output\":{\"token\":\"lo\"}}\n"
197
+ },
198
+ "expect": {
199
+ "kind": "stream",
200
+ "items": [{ "output": { "token": "Hel" } }],
201
+ "end": { "kind": "transport-failure" }
202
+ }
203
+ },
204
+ {
205
+ "id": "stream-line-not-envelope",
206
+ "description": "A JSON line that is not an envelope ends the stream with a transport failure; it is not delivered as an item. PROTOCOL.md: Classifying an HTTP response, step 5.",
207
+ "request": { "procedure": ["chat"], "input": { "prompt": "hi" } },
208
+ "expectRequest": {
209
+ "method": "POST",
210
+ "path": "/chat",
211
+ "headers": {
212
+ "content-type": "application/json",
213
+ "x-ts-pf-protocol": "1"
214
+ },
215
+ "body": { "input": { "prompt": "hi" } }
216
+ },
217
+ "response": {
218
+ "status": 200,
219
+ "headers": {
220
+ "content-type": "application/jsonl",
221
+ "x-ts-pf-protocol": "1"
222
+ },
223
+ "body": "{\"ok\":true,\"output\":{\"token\":\"Hel\"}}\n{\"token\":\"lo\"}\n"
224
+ },
225
+ "expect": {
226
+ "kind": "stream",
227
+ "items": [{ "output": { "token": "Hel" } }],
228
+ "end": { "kind": "transport-failure" }
229
+ }
230
+ },
231
+ {
232
+ "id": "stream-version-mismatch",
233
+ "description": "The version header is checked before the content type: an application/jsonl response from another wire major is not read as a stream. PROTOCOL.md: Classifying an HTTP response, steps 1-5.",
234
+ "request": { "procedure": ["chat"], "input": { "prompt": "hi" } },
235
+ "expectRequest": {
236
+ "method": "POST",
237
+ "path": "/chat",
238
+ "headers": {
239
+ "content-type": "application/json",
240
+ "x-ts-pf-protocol": "1"
241
+ },
242
+ "body": { "input": { "prompt": "hi" } }
243
+ },
244
+ "response": {
245
+ "status": 200,
246
+ "headers": {
247
+ "content-type": "application/jsonl",
248
+ "x-ts-pf-protocol": "2"
249
+ },
250
+ "body": "{\"ok\":true,\"output\":{\"token\":\"Hel\"}}\n{\"ok\":true,\"output\":{\"token\":\"lo\"}}\n"
251
+ },
252
+ "expect": { "kind": "version-mismatch" }
253
+ },
254
+ {
255
+ "id": "stream-pre-stream-failure",
256
+ "description": "A failure before the stream starts is a plain application/json failure envelope with its HTTP status: the call fails, no stream. PROTOCOL.md: Message streams.",
257
+ "request": { "procedure": ["chat"], "input": { "prompt": 1 } },
258
+ "expectRequest": {
259
+ "method": "POST",
260
+ "path": "/chat",
261
+ "headers": {
262
+ "content-type": "application/json",
263
+ "x-ts-pf-protocol": "1"
264
+ },
265
+ "body": { "input": { "prompt": 1 } }
266
+ },
267
+ "response": {
268
+ "status": 422,
269
+ "headers": {
270
+ "content-type": "application/json",
271
+ "x-ts-pf-protocol": "1"
272
+ },
273
+ "body": "{\"ok\":false,\"error\":{\"code\":\"VALIDATION\",\"message\":\"Validation failed\",\"data\":{\"issues\":[{\"message\":\"Expected string\",\"path\":[\"prompt\"]}]}}}"
274
+ },
275
+ "expect": {
276
+ "kind": "error",
277
+ "code": "VALIDATION",
278
+ "message": "Validation failed",
279
+ "data": {
280
+ "issues": [{ "message": "Expected string", "path": ["prompt"] }]
281
+ }
282
+ }
283
+ },
284
+ {
285
+ "id": "stream-client-unary-json",
286
+ "description": "A stream-capable client classifies an application/json response as in http.json (steps 2-4): here a unary success. PROTOCOL.md: Classifying an HTTP response, step 5.",
287
+ "request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
288
+ "expectRequest": {
289
+ "method": "POST",
290
+ "path": "/planet/find",
291
+ "headers": {
292
+ "content-type": "application/json",
293
+ "x-ts-pf-protocol": "1"
294
+ },
295
+ "body": { "input": { "id": 1 } }
296
+ },
297
+ "response": {
298
+ "status": 200,
299
+ "headers": {
300
+ "content-type": "application/json",
301
+ "x-ts-pf-protocol": "1"
302
+ },
303
+ "body": "{\"ok\":true,\"output\":{\"id\":1,\"name\":\"Earth\"}}"
304
+ },
305
+ "expect": { "kind": "success", "output": { "id": 1, "name": "Earth" } }
306
+ }
307
+ ]
308
+ }