@ts-pf/protocol 0.2.1 → 0.5.0

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,1045 @@
1
+ {
2
+ "protocol": 1,
3
+ "revision": "1.2",
4
+ "binding": "ws",
5
+ "description": "Multiplexed JSON frames over one WebSocket connection, as scripts from the client's side. The same scripts apply to stdio and MessagePort, minus receiveBinary and close codes. See README.md in this directory.",
6
+ "cases": [
7
+ {
8
+ "id": "ws-handshake-ready",
9
+ "description": "The client sends hello first and no call until hello-ok; a call made before hello-ok goes out after it. PROTOCOL.md: Handshake.",
10
+ "steps": [
11
+ { "send": { "type": "hello", "v": 1 } },
12
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
13
+ { "receive": { "type": "hello-ok", "v": 1 } },
14
+ {
15
+ "send": {
16
+ "type": "call",
17
+ "id": "1",
18
+ "path": ["planet", "find"],
19
+ "input": { "id": 1 }
20
+ }
21
+ },
22
+ {
23
+ "receive": {
24
+ "type": "result",
25
+ "id": "1",
26
+ "ok": true,
27
+ "output": { "id": 1, "name": "Earth" }
28
+ }
29
+ },
30
+ {
31
+ "expect": {
32
+ "call": "a",
33
+ "outcome": "value",
34
+ "output": { "id": 1, "name": "Earth" }
35
+ }
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "id": "ws-hello-meta",
41
+ "description": "Connect metadata travels as hello.meta (the recommended credential carrier is meta.authorization). PROTOCOL.md: Handshake; Authenticating with hello.meta.",
42
+ "options": { "meta": { "authorization": "Bearer token-1" } },
43
+ "steps": [
44
+ {
45
+ "send": {
46
+ "type": "hello",
47
+ "v": 1,
48
+ "meta": { "authorization": "Bearer token-1" }
49
+ }
50
+ },
51
+ { "receive": { "type": "hello-ok", "v": 1 } },
52
+ { "call": "a", "path": ["me"] },
53
+ { "send": { "type": "call", "id": "1", "path": ["me"] } },
54
+ {
55
+ "receive": {
56
+ "type": "result",
57
+ "id": "1",
58
+ "ok": true,
59
+ "output": { "user": "u1" }
60
+ }
61
+ },
62
+ {
63
+ "expect": {
64
+ "call": "a",
65
+ "outcome": "value",
66
+ "output": { "user": "u1" }
67
+ }
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "id": "ws-hello-ok-other-version",
73
+ "description": "hello-ok whose v is a number other than 1 fails the connect locally (no hello-error is sent) and closes. Do not retry. PROTOCOL.md: Handshake.",
74
+ "steps": [
75
+ { "send": { "type": "hello", "v": 1 } },
76
+ { "receive": { "type": "hello-ok", "v": 2 } },
77
+ {
78
+ "expect": {
79
+ "handshake": "local-failure",
80
+ "reference": "Invalid response"
81
+ }
82
+ },
83
+ { "expect": { "closed": {} } }
84
+ ]
85
+ },
86
+ {
87
+ "id": "ws-hello-ok-v-not-number",
88
+ "description": "hello-ok whose v is not a JSON number (\"1\") fails the connect locally and closes. PROTOCOL.md: Handshake; Frame types (v).",
89
+ "steps": [
90
+ { "send": { "type": "hello", "v": 1 } },
91
+ { "receive": { "type": "hello-ok", "v": "1" } },
92
+ {
93
+ "expect": {
94
+ "handshake": "local-failure",
95
+ "reference": "Invalid response"
96
+ }
97
+ },
98
+ { "expect": { "closed": {} } }
99
+ ]
100
+ },
101
+ {
102
+ "id": "ws-hello-error-version",
103
+ "description": "hello-error fails the connect with its error, not as a local failure, then the client closes (1000). Do not retry Unsupported protocol version. PROTOCOL.md: Handshake; Close codes; Reconnecting.",
104
+ "steps": [
105
+ { "send": { "type": "hello", "v": 1 } },
106
+ {
107
+ "receive": {
108
+ "type": "hello-error",
109
+ "error": {
110
+ "code": "BAD_REQUEST",
111
+ "message": "Unsupported protocol version"
112
+ }
113
+ }
114
+ },
115
+ {
116
+ "expect": {
117
+ "handshake": "error",
118
+ "error": {
119
+ "code": "BAD_REQUEST",
120
+ "message": "Unsupported protocol version"
121
+ }
122
+ }
123
+ },
124
+ { "expect": { "closed": { "code": 1000 } } }
125
+ ]
126
+ },
127
+ {
128
+ "id": "ws-hello-error-app-code",
129
+ "description": "A server refuses a connection with an application code in hello-error; the client receives that code. PROTOCOL.md: Handshake.",
130
+ "steps": [
131
+ { "send": { "type": "hello", "v": 1 } },
132
+ {
133
+ "receive": {
134
+ "type": "hello-error",
135
+ "error": {
136
+ "code": "UNAUTHORIZED",
137
+ "message": "Session expired",
138
+ "data": { "reason": "expired" }
139
+ }
140
+ }
141
+ },
142
+ {
143
+ "expect": {
144
+ "handshake": "error",
145
+ "error": {
146
+ "code": "UNAUTHORIZED",
147
+ "message": "Session expired",
148
+ "data": { "reason": "expired" }
149
+ }
150
+ }
151
+ },
152
+ { "expect": { "closed": { "code": 1000 } } }
153
+ ]
154
+ },
155
+ {
156
+ "id": "ws-handshake-unexpected-frame",
157
+ "description": "Any parsed frame other than hello-ok / hello-error while handshaking fails the connect locally and closes. PROTOCOL.md: Handshake.",
158
+ "steps": [
159
+ { "send": { "type": "hello", "v": 1 } },
160
+ { "receive": { "type": "result", "id": "1", "ok": true } },
161
+ {
162
+ "expect": {
163
+ "handshake": "local-failure",
164
+ "reference": "Invalid response"
165
+ }
166
+ },
167
+ { "expect": { "closed": {} } }
168
+ ]
169
+ },
170
+ {
171
+ "id": "ws-handshake-peer-close",
172
+ "description": "The server closing before hello-ok fails the connect locally. PROTOCOL.md: Handshake.",
173
+ "steps": [
174
+ { "send": { "type": "hello", "v": 1 } },
175
+ { "serverClose": {} },
176
+ {
177
+ "expect": {
178
+ "handshake": "local-failure",
179
+ "reference": "Connection closed"
180
+ }
181
+ }
182
+ ]
183
+ },
184
+ {
185
+ "id": "ws-abort-before-ready",
186
+ "description": "Aborting a call that is still waiting for hello-ok fails it locally without sending cancel (it has no id) and leaves the connection up for other calls. PROTOCOL.md: Cancel and mid-stream errors.",
187
+ "steps": [
188
+ { "send": { "type": "hello", "v": 1 } },
189
+ { "call": "a", "path": ["planet", "slow"] },
190
+ { "abort": "a" },
191
+ {
192
+ "expect": {
193
+ "call": "a",
194
+ "outcome": "local-failure",
195
+ "reference": "Request aborted"
196
+ }
197
+ },
198
+ { "receive": { "type": "hello-ok", "v": 1 } },
199
+ { "call": "b", "path": ["ping"] },
200
+ { "send": { "type": "call", "id": "1", "path": ["ping"] } },
201
+ {
202
+ "receive": {
203
+ "type": "result",
204
+ "id": "1",
205
+ "ok": true,
206
+ "output": "pong"
207
+ }
208
+ },
209
+ { "expect": { "call": "b", "outcome": "value", "output": "pong" } }
210
+ ]
211
+ },
212
+ {
213
+ "id": "ws-unary-result",
214
+ "description": "Unary call: string id, path as an array, result ok: true resolves to output. PROTOCOL.md: Unary call; Frame types.",
215
+ "steps": [
216
+ { "send": { "type": "hello", "v": 1 } },
217
+ { "receive": { "type": "hello-ok", "v": 1 } },
218
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
219
+ {
220
+ "send": {
221
+ "type": "call",
222
+ "id": "1",
223
+ "path": ["planet", "find"],
224
+ "input": { "id": 1 }
225
+ }
226
+ },
227
+ {
228
+ "receive": {
229
+ "type": "result",
230
+ "id": "1",
231
+ "ok": true,
232
+ "output": { "id": 1, "name": "Earth" }
233
+ }
234
+ },
235
+ {
236
+ "expect": {
237
+ "call": "a",
238
+ "outcome": "value",
239
+ "output": { "id": 1, "name": "Earth" }
240
+ }
241
+ }
242
+ ]
243
+ },
244
+ {
245
+ "id": "ws-unary-void",
246
+ "description": "No input: the call frame omits input. A result without output resolves to no value. PROTOCOL.md: Frame types (omit keys with no value).",
247
+ "steps": [
248
+ { "send": { "type": "hello", "v": 1 } },
249
+ { "receive": { "type": "hello-ok", "v": 1 } },
250
+ { "call": "a", "path": ["planet", "reset"] },
251
+ { "send": { "type": "call", "id": "1", "path": ["planet", "reset"] } },
252
+ { "receive": { "type": "result", "id": "1", "ok": true } },
253
+ { "expect": { "call": "a", "outcome": "value" } }
254
+ ]
255
+ },
256
+ {
257
+ "id": "ws-unary-error-data",
258
+ "description": "result ok: false rejects with that error; data survives. PROTOCOL.md: Unary call; First frame (client).",
259
+ "steps": [
260
+ { "send": { "type": "hello", "v": 1 } },
261
+ { "receive": { "type": "hello-ok", "v": 1 } },
262
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 9 } },
263
+ {
264
+ "send": {
265
+ "type": "call",
266
+ "id": "1",
267
+ "path": ["planet", "find"],
268
+ "input": { "id": 9 }
269
+ }
270
+ },
271
+ {
272
+ "receive": {
273
+ "type": "result",
274
+ "id": "1",
275
+ "ok": false,
276
+ "error": {
277
+ "code": "NOT_FOUND",
278
+ "message": "No planet 9",
279
+ "data": { "id": 9 }
280
+ }
281
+ }
282
+ },
283
+ {
284
+ "expect": {
285
+ "call": "a",
286
+ "outcome": "error",
287
+ "error": {
288
+ "code": "NOT_FOUND",
289
+ "message": "No planet 9",
290
+ "data": { "id": 9 }
291
+ }
292
+ }
293
+ }
294
+ ]
295
+ },
296
+ {
297
+ "id": "ws-unary-unknown-code",
298
+ "description": "An unknown code is surfaced as-is (catch-all). PROTOCOL.md: Protocol errors.",
299
+ "steps": [
300
+ { "send": { "type": "hello", "v": 1 } },
301
+ { "receive": { "type": "hello-ok", "v": 1 } },
302
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
303
+ {
304
+ "send": {
305
+ "type": "call",
306
+ "id": "1",
307
+ "path": ["planet", "find"],
308
+ "input": { "id": 1 }
309
+ }
310
+ },
311
+ {
312
+ "receive": {
313
+ "type": "result",
314
+ "id": "1",
315
+ "ok": false,
316
+ "error": {
317
+ "code": "SOMETHING_NEW",
318
+ "message": "Added after this client shipped"
319
+ }
320
+ }
321
+ },
322
+ {
323
+ "expect": {
324
+ "call": "a",
325
+ "outcome": "error",
326
+ "error": {
327
+ "code": "SOMETHING_NEW",
328
+ "message": "Added after this client shipped"
329
+ }
330
+ }
331
+ }
332
+ ]
333
+ },
334
+ {
335
+ "id": "ws-multiplex",
336
+ "description": "Two in-flight calls complete independently, in any order. PROTOCOL.md: Multiplex.",
337
+ "steps": [
338
+ { "send": { "type": "hello", "v": 1 } },
339
+ { "receive": { "type": "hello-ok", "v": 1 } },
340
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
341
+ {
342
+ "send": {
343
+ "type": "call",
344
+ "id": "1",
345
+ "path": ["planet", "find"],
346
+ "input": { "id": 1 }
347
+ }
348
+ },
349
+ { "call": "b", "path": ["planet", "find"], "input": { "id": 2 } },
350
+ {
351
+ "send": {
352
+ "type": "call",
353
+ "id": "2",
354
+ "path": ["planet", "find"],
355
+ "input": { "id": 2 }
356
+ }
357
+ },
358
+ {
359
+ "receive": {
360
+ "type": "result",
361
+ "id": "2",
362
+ "ok": true,
363
+ "output": { "id": 2, "name": "Mars" }
364
+ }
365
+ },
366
+ {
367
+ "expect": {
368
+ "call": "b",
369
+ "outcome": "value",
370
+ "output": { "id": 2, "name": "Mars" }
371
+ }
372
+ },
373
+ {
374
+ "receive": {
375
+ "type": "result",
376
+ "id": "1",
377
+ "ok": true,
378
+ "output": { "id": 1, "name": "Earth" }
379
+ }
380
+ },
381
+ {
382
+ "expect": {
383
+ "call": "a",
384
+ "outcome": "value",
385
+ "output": { "id": 1, "name": "Earth" }
386
+ }
387
+ }
388
+ ]
389
+ },
390
+ {
391
+ "id": "ws-stream-items-done",
392
+ "description": "A first frame of item resolves the call as a stream (not an error); items follow and done completes it. PROTOCOL.md: First frame (client); streaming-out; Output streams.",
393
+ "steps": [
394
+ { "send": { "type": "hello", "v": 1 } },
395
+ { "receive": { "type": "hello-ok", "v": 1 } },
396
+ { "call": "a", "path": ["chat"], "input": { "prompt": "hi" } },
397
+ {
398
+ "send": {
399
+ "type": "call",
400
+ "id": "1",
401
+ "path": ["chat"],
402
+ "input": { "prompt": "hi" }
403
+ }
404
+ },
405
+ {
406
+ "receive": { "type": "item", "id": "1", "output": { "token": "Hel" } }
407
+ },
408
+ { "expect": { "call": "a", "outcome": "stream" } },
409
+ {
410
+ "expect": {
411
+ "stream": "a",
412
+ "outcome": "item",
413
+ "output": { "token": "Hel" }
414
+ }
415
+ },
416
+ {
417
+ "receive": { "type": "item", "id": "1", "output": { "token": "lo" } }
418
+ },
419
+ {
420
+ "expect": {
421
+ "stream": "a",
422
+ "outcome": "item",
423
+ "output": { "token": "lo" }
424
+ }
425
+ },
426
+ { "receive": { "type": "done", "id": "1" } },
427
+ { "expect": { "stream": "a", "outcome": "done" } }
428
+ ]
429
+ },
430
+ {
431
+ "id": "ws-stream-item-without-output",
432
+ "description": "An item without output yields no value. PROTOCOL.md: streaming-out.",
433
+ "steps": [
434
+ { "send": { "type": "hello", "v": 1 } },
435
+ { "receive": { "type": "hello-ok", "v": 1 } },
436
+ { "call": "a", "path": ["ticks"] },
437
+ { "send": { "type": "call", "id": "1", "path": ["ticks"] } },
438
+ { "receive": { "type": "item", "id": "1" } },
439
+ { "expect": { "call": "a", "outcome": "stream" } },
440
+ { "expect": { "stream": "a", "outcome": "item" } },
441
+ { "receive": { "type": "done", "id": "1" } },
442
+ { "expect": { "stream": "a", "outcome": "done" } }
443
+ ]
444
+ },
445
+ {
446
+ "id": "ws-stream-empty",
447
+ "description": "A first frame of done resolves the call as an empty, already complete stream. PROTOCOL.md: First frame (client); Legal sequences.",
448
+ "steps": [
449
+ { "send": { "type": "hello", "v": 1 } },
450
+ { "receive": { "type": "hello-ok", "v": 1 } },
451
+ { "call": "a", "path": ["chat"], "input": { "prompt": "" } },
452
+ {
453
+ "send": {
454
+ "type": "call",
455
+ "id": "1",
456
+ "path": ["chat"],
457
+ "input": { "prompt": "" }
458
+ }
459
+ },
460
+ { "receive": { "type": "done", "id": "1" } },
461
+ { "expect": { "call": "a", "outcome": "stream" } },
462
+ { "expect": { "stream": "a", "outcome": "done" } }
463
+ ]
464
+ },
465
+ {
466
+ "id": "ws-stream-mid-error",
467
+ "description": "In a stream, result ok: false ends the stream with that failure; no done follows. PROTOCOL.md: streaming-out; Output streams.",
468
+ "steps": [
469
+ { "send": { "type": "hello", "v": 1 } },
470
+ { "receive": { "type": "hello-ok", "v": 1 } },
471
+ { "call": "a", "path": ["chat"], "input": { "prompt": "hi" } },
472
+ {
473
+ "send": {
474
+ "type": "call",
475
+ "id": "1",
476
+ "path": ["chat"],
477
+ "input": { "prompt": "hi" }
478
+ }
479
+ },
480
+ {
481
+ "receive": { "type": "item", "id": "1", "output": { "token": "Hel" } }
482
+ },
483
+ { "expect": { "call": "a", "outcome": "stream" } },
484
+ {
485
+ "expect": {
486
+ "stream": "a",
487
+ "outcome": "item",
488
+ "output": { "token": "Hel" }
489
+ }
490
+ },
491
+ {
492
+ "receive": {
493
+ "type": "result",
494
+ "id": "1",
495
+ "ok": false,
496
+ "error": { "code": "UPSTREAM_FAILED", "message": "upstream died" }
497
+ }
498
+ },
499
+ {
500
+ "expect": {
501
+ "stream": "a",
502
+ "outcome": "error",
503
+ "error": { "code": "UPSTREAM_FAILED", "message": "upstream died" }
504
+ }
505
+ }
506
+ ]
507
+ },
508
+ {
509
+ "id": "ws-stream-illegal-frames-ignored",
510
+ "description": "While streaming, result ok: true and unknown types are illegal and ignored; after done, a late item or done is for an id no longer in flight and ignored. PROTOCOL.md: streaming-out; Legal sequences.",
511
+ "steps": [
512
+ { "send": { "type": "hello", "v": 1 } },
513
+ { "receive": { "type": "hello-ok", "v": 1 } },
514
+ { "call": "a", "path": ["count"] },
515
+ { "send": { "type": "call", "id": "1", "path": ["count"] } },
516
+ { "receive": { "type": "item", "id": "1", "output": 1 } },
517
+ { "expect": { "call": "a", "outcome": "stream" } },
518
+ { "expect": { "stream": "a", "outcome": "item", "output": 1 } },
519
+ {
520
+ "receive": { "type": "result", "id": "1", "ok": true, "output": 99 }
521
+ },
522
+ { "receive": { "type": "progress", "id": "1", "percent": 50 } },
523
+ { "receive": { "type": "item", "id": "1", "output": 2 } },
524
+ { "expect": { "stream": "a", "outcome": "item", "output": 2 } },
525
+ { "receive": { "type": "done", "id": "1" } },
526
+ { "expect": { "stream": "a", "outcome": "done" } },
527
+ { "receive": { "type": "item", "id": "1", "output": 3 } },
528
+ { "receive": { "type": "done", "id": "1" } },
529
+ { "call": "b", "path": ["ping"] },
530
+ { "send": { "type": "call", "id": "2", "path": ["ping"] } },
531
+ {
532
+ "receive": {
533
+ "type": "result",
534
+ "id": "2",
535
+ "ok": true,
536
+ "output": "pong"
537
+ }
538
+ },
539
+ { "expect": { "call": "b", "outcome": "value", "output": "pong" } }
540
+ ]
541
+ },
542
+ {
543
+ "id": "ws-stream-peer-close",
544
+ "description": "The server closing the connection mid-stream ends the stream with a local failure. PROTOCOL.md: streaming-out.",
545
+ "steps": [
546
+ { "send": { "type": "hello", "v": 1 } },
547
+ { "receive": { "type": "hello-ok", "v": 1 } },
548
+ { "call": "a", "path": ["chat"], "input": { "prompt": "hi" } },
549
+ {
550
+ "send": {
551
+ "type": "call",
552
+ "id": "1",
553
+ "path": ["chat"],
554
+ "input": { "prompt": "hi" }
555
+ }
556
+ },
557
+ {
558
+ "receive": { "type": "item", "id": "1", "output": { "token": "Hel" } }
559
+ },
560
+ { "expect": { "call": "a", "outcome": "stream" } },
561
+ {
562
+ "expect": {
563
+ "stream": "a",
564
+ "outcome": "item",
565
+ "output": { "token": "Hel" }
566
+ }
567
+ },
568
+ { "serverClose": {} },
569
+ {
570
+ "expect": {
571
+ "stream": "a",
572
+ "outcome": "local-failure",
573
+ "reference": "Connection closed"
574
+ }
575
+ }
576
+ ]
577
+ },
578
+ {
579
+ "id": "ws-late-frames-after-result",
580
+ "description": "item / done after a unary result are for an id no longer in flight: ignored, and the connection stays open. PROTOCOL.md: Multiplex; Legal sequences.",
581
+ "steps": [
582
+ { "send": { "type": "hello", "v": 1 } },
583
+ { "receive": { "type": "hello-ok", "v": 1 } },
584
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
585
+ {
586
+ "send": {
587
+ "type": "call",
588
+ "id": "1",
589
+ "path": ["planet", "find"],
590
+ "input": { "id": 1 }
591
+ }
592
+ },
593
+ {
594
+ "receive": {
595
+ "type": "result",
596
+ "id": "1",
597
+ "ok": true,
598
+ "output": { "id": 1, "name": "Earth" }
599
+ }
600
+ },
601
+ {
602
+ "expect": {
603
+ "call": "a",
604
+ "outcome": "value",
605
+ "output": { "id": 1, "name": "Earth" }
606
+ }
607
+ },
608
+ { "receive": { "type": "item", "id": "1", "output": { "id": 1 } } },
609
+ { "receive": { "type": "done", "id": "1" } },
610
+ {
611
+ "receive": {
612
+ "type": "result",
613
+ "id": "1",
614
+ "ok": false,
615
+ "error": { "code": "INTERNAL", "message": "Internal server error" }
616
+ }
617
+ },
618
+ { "call": "b", "path": ["ping"] },
619
+ { "send": { "type": "call", "id": "2", "path": ["ping"] } },
620
+ {
621
+ "receive": {
622
+ "type": "result",
623
+ "id": "2",
624
+ "ok": true,
625
+ "output": "pong"
626
+ }
627
+ },
628
+ { "expect": { "call": "b", "outcome": "value", "output": "pong" } }
629
+ ]
630
+ },
631
+ {
632
+ "id": "ws-unknown-id-ignored",
633
+ "description": "Frames for an id the client never used are ignored, valid or not; they do not settle another call. PROTOCOL.md: Multiplex.",
634
+ "steps": [
635
+ { "send": { "type": "hello", "v": 1 } },
636
+ { "receive": { "type": "hello-ok", "v": 1 } },
637
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
638
+ {
639
+ "send": {
640
+ "type": "call",
641
+ "id": "1",
642
+ "path": ["planet", "find"],
643
+ "input": { "id": 1 }
644
+ }
645
+ },
646
+ {
647
+ "receive": {
648
+ "type": "result",
649
+ "id": "99",
650
+ "ok": true,
651
+ "output": "not yours"
652
+ }
653
+ },
654
+ { "receive": { "type": "item", "id": "99", "output": "not yours" } },
655
+ { "receive": { "type": "nope", "id": "99" } },
656
+ {
657
+ "receive": {
658
+ "type": "result",
659
+ "id": "1",
660
+ "ok": true,
661
+ "output": { "id": 1, "name": "Earth" }
662
+ }
663
+ },
664
+ {
665
+ "expect": {
666
+ "call": "a",
667
+ "outcome": "value",
668
+ "output": { "id": 1, "name": "Earth" }
669
+ }
670
+ }
671
+ ]
672
+ },
673
+ {
674
+ "id": "ws-unknown-type-in-flight-ignored",
675
+ "description": "An unknown or invalid frame whose id is in flight is ignored: it does not settle the call or close the connection. PROTOCOL.md: Multiplex.",
676
+ "steps": [
677
+ { "send": { "type": "hello", "v": 1 } },
678
+ { "receive": { "type": "hello-ok", "v": 1 } },
679
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
680
+ {
681
+ "send": {
682
+ "type": "call",
683
+ "id": "1",
684
+ "path": ["planet", "find"],
685
+ "input": { "id": 1 }
686
+ }
687
+ },
688
+ { "receive": { "type": "progress", "id": "1", "percent": 50 } },
689
+ {
690
+ "receive": {
691
+ "type": "result",
692
+ "id": "1",
693
+ "ok": true,
694
+ "output": 1,
695
+ "extra": true
696
+ }
697
+ },
698
+ { "receive": { "type": "result", "id": "1", "ok": "yes" } },
699
+ {
700
+ "receive": {
701
+ "type": "result",
702
+ "id": "1",
703
+ "ok": true,
704
+ "output": { "id": 1, "name": "Earth" }
705
+ }
706
+ },
707
+ {
708
+ "expect": {
709
+ "call": "a",
710
+ "outcome": "value",
711
+ "output": { "id": 1, "name": "Earth" }
712
+ }
713
+ }
714
+ ]
715
+ },
716
+ {
717
+ "id": "ws-first-frame-illegal",
718
+ "description": "A first frame for an id that is not result / item / done (here a wrong-direction cancel) fails that call locally; the connection stays open. PROTOCOL.md: First frame (client); Frame types (direction).",
719
+ "steps": [
720
+ { "send": { "type": "hello", "v": 1 } },
721
+ { "receive": { "type": "hello-ok", "v": 1 } },
722
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
723
+ {
724
+ "send": {
725
+ "type": "call",
726
+ "id": "1",
727
+ "path": ["planet", "find"],
728
+ "input": { "id": 1 }
729
+ }
730
+ },
731
+ { "receive": { "type": "cancel", "id": "1" } },
732
+ {
733
+ "expect": {
734
+ "call": "a",
735
+ "outcome": "local-failure",
736
+ "reference": "Invalid response"
737
+ }
738
+ },
739
+ {
740
+ "receive": {
741
+ "type": "result",
742
+ "id": "1",
743
+ "ok": true,
744
+ "output": "late"
745
+ }
746
+ },
747
+ { "call": "b", "path": ["ping"] },
748
+ { "send": { "type": "call", "id": "2", "path": ["ping"] } },
749
+ {
750
+ "receive": {
751
+ "type": "result",
752
+ "id": "2",
753
+ "ok": true,
754
+ "output": "pong"
755
+ }
756
+ },
757
+ { "expect": { "call": "b", "outcome": "value", "output": "pong" } }
758
+ ]
759
+ },
760
+ {
761
+ "id": "ws-peer-close-before-first-frame",
762
+ "description": "The server closing the connection before any frame for an in-flight id fails that call locally. PROTOCOL.md: First frame (client).",
763
+ "steps": [
764
+ { "send": { "type": "hello", "v": 1 } },
765
+ { "receive": { "type": "hello-ok", "v": 1 } },
766
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
767
+ {
768
+ "send": {
769
+ "type": "call",
770
+ "id": "1",
771
+ "path": ["planet", "find"],
772
+ "input": { "id": 1 }
773
+ }
774
+ },
775
+ { "serverClose": {} },
776
+ {
777
+ "expect": {
778
+ "call": "a",
779
+ "outcome": "local-failure",
780
+ "reference": "Connection closed"
781
+ }
782
+ }
783
+ ]
784
+ },
785
+ {
786
+ "id": "ws-cancel-unary",
787
+ "description": "Aborting an in-flight call sends cancel and fails it locally. No frame acknowledges cancel; a late result for that id is ignored (and a client SHOULD NOT reuse the id). PROTOCOL.md: Unary call; Cancel and mid-stream errors.",
788
+ "steps": [
789
+ { "send": { "type": "hello", "v": 1 } },
790
+ { "receive": { "type": "hello-ok", "v": 1 } },
791
+ { "call": "a", "path": ["planet", "slow"] },
792
+ { "send": { "type": "call", "id": "1", "path": ["planet", "slow"] } },
793
+ { "abort": "a" },
794
+ { "send": { "type": "cancel", "id": "1" } },
795
+ {
796
+ "expect": {
797
+ "call": "a",
798
+ "outcome": "local-failure",
799
+ "reference": "Request aborted"
800
+ }
801
+ },
802
+ {
803
+ "receive": {
804
+ "type": "result",
805
+ "id": "1",
806
+ "ok": true,
807
+ "output": "too late"
808
+ }
809
+ },
810
+ { "call": "b", "path": ["ping"] },
811
+ { "send": { "type": "call", "id": "2", "path": ["ping"] } },
812
+ {
813
+ "receive": {
814
+ "type": "result",
815
+ "id": "2",
816
+ "ok": true,
817
+ "output": "pong"
818
+ }
819
+ },
820
+ { "expect": { "call": "b", "outcome": "value", "output": "pong" } }
821
+ ]
822
+ },
823
+ {
824
+ "id": "ws-cancel-stream",
825
+ "description": "Stopping a stream early sends cancel (not done or in-done); later item / done for that id are ignored. PROTOCOL.md: streaming-out; Cancel and mid-stream errors.",
826
+ "steps": [
827
+ { "send": { "type": "hello", "v": 1 } },
828
+ { "receive": { "type": "hello-ok", "v": 1 } },
829
+ { "call": "a", "path": ["chat"], "input": { "prompt": "hi" } },
830
+ {
831
+ "send": {
832
+ "type": "call",
833
+ "id": "1",
834
+ "path": ["chat"],
835
+ "input": { "prompt": "hi" }
836
+ }
837
+ },
838
+ {
839
+ "receive": { "type": "item", "id": "1", "output": { "token": "Hel" } }
840
+ },
841
+ { "expect": { "call": "a", "outcome": "stream" } },
842
+ {
843
+ "expect": {
844
+ "stream": "a",
845
+ "outcome": "item",
846
+ "output": { "token": "Hel" }
847
+ }
848
+ },
849
+ { "abort": "a" },
850
+ { "send": { "type": "cancel", "id": "1" } },
851
+ {
852
+ "receive": { "type": "item", "id": "1", "output": { "token": "lo" } }
853
+ },
854
+ { "receive": { "type": "done", "id": "1" } },
855
+ { "call": "b", "path": ["ping"] },
856
+ { "send": { "type": "call", "id": "2", "path": ["ping"] } },
857
+ {
858
+ "receive": {
859
+ "type": "result",
860
+ "id": "2",
861
+ "ok": true,
862
+ "output": "pong"
863
+ }
864
+ },
865
+ { "expect": { "call": "b", "outcome": "value", "output": "pong" } }
866
+ ]
867
+ },
868
+ {
869
+ "id": "ws-input-stream",
870
+ "description": "A streamed input sends call with stream: true and no input, then one in-item per value and in-done. PROTOCOL.md: Input-stream send path; Input streams.",
871
+ "steps": [
872
+ { "send": { "type": "hello", "v": 1 } },
873
+ { "receive": { "type": "hello-ok", "v": 1 } },
874
+ {
875
+ "call": "a",
876
+ "path": ["planet", "ingest"],
877
+ "inputStream": [{ "chunk": 1 }, { "chunk": 2 }]
878
+ },
879
+ {
880
+ "send": {
881
+ "type": "call",
882
+ "id": "1",
883
+ "path": ["planet", "ingest"],
884
+ "stream": true
885
+ }
886
+ },
887
+ { "send": { "type": "in-item", "id": "1", "input": { "chunk": 1 } } },
888
+ { "send": { "type": "in-item", "id": "1", "input": { "chunk": 2 } } },
889
+ { "send": { "type": "in-done", "id": "1" } },
890
+ {
891
+ "receive": {
892
+ "type": "result",
893
+ "id": "1",
894
+ "ok": true,
895
+ "output": { "received": 2 }
896
+ }
897
+ },
898
+ {
899
+ "expect": {
900
+ "call": "a",
901
+ "outcome": "value",
902
+ "output": { "received": 2 }
903
+ }
904
+ }
905
+ ]
906
+ },
907
+ {
908
+ "id": "ws-non-json-text",
909
+ "description": "A text message that is not JSON closes the connection (1000); in-flight calls fail locally. PROTOCOL.md: Multiplex; Close codes.",
910
+ "steps": [
911
+ { "send": { "type": "hello", "v": 1 } },
912
+ { "receive": { "type": "hello-ok", "v": 1 } },
913
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
914
+ {
915
+ "send": {
916
+ "type": "call",
917
+ "id": "1",
918
+ "path": ["planet", "find"],
919
+ "input": { "id": 1 }
920
+ }
921
+ },
922
+ { "receiveText": "this is not json" },
923
+ { "expect": { "closed": { "code": 1000 } } },
924
+ {
925
+ "expect": {
926
+ "call": "a",
927
+ "outcome": "local-failure",
928
+ "reference": "Connection closed"
929
+ }
930
+ }
931
+ ]
932
+ },
933
+ {
934
+ "id": "ws-non-object-json",
935
+ "description": "A text message that parses to a non-object closes the connection (1000). PROTOCOL.md: Multiplex; Close codes.",
936
+ "steps": [
937
+ { "send": { "type": "hello", "v": 1 } },
938
+ { "receive": { "type": "hello-ok", "v": 1 } },
939
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
940
+ {
941
+ "send": {
942
+ "type": "call",
943
+ "id": "1",
944
+ "path": ["planet", "find"],
945
+ "input": { "id": 1 }
946
+ }
947
+ },
948
+ { "receiveText": "[{\"type\":\"result\",\"id\":\"1\",\"ok\":true}]" },
949
+ { "expect": { "closed": { "code": 1000 } } },
950
+ {
951
+ "expect": {
952
+ "call": "a",
953
+ "outcome": "local-failure",
954
+ "reference": "Connection closed"
955
+ }
956
+ }
957
+ ]
958
+ },
959
+ {
960
+ "id": "ws-invalid-frame-without-id",
961
+ "description": "An invalid frame with no usable id after ready closes the connection. PROTOCOL.md: Multiplex; Close codes.",
962
+ "steps": [
963
+ { "send": { "type": "hello", "v": 1 } },
964
+ { "receive": { "type": "hello-ok", "v": 1 } },
965
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
966
+ {
967
+ "send": {
968
+ "type": "call",
969
+ "id": "1",
970
+ "path": ["planet", "find"],
971
+ "input": { "id": 1 }
972
+ }
973
+ },
974
+ { "receive": { "type": "result", "ok": true, "output": 1 } },
975
+ { "expect": { "closed": { "code": 1000 } } },
976
+ {
977
+ "expect": {
978
+ "call": "a",
979
+ "outcome": "local-failure",
980
+ "reference": "Connection closed"
981
+ }
982
+ }
983
+ ]
984
+ },
985
+ {
986
+ "id": "ws-numeric-id",
987
+ "description": "Ids are non-empty strings: a frame whose id is the number 1 has no usable id, so it closes the connection instead of settling call \"1\". PROTOCOL.md: Frame types (id); Multiplex; Close codes.",
988
+ "steps": [
989
+ { "send": { "type": "hello", "v": 1 } },
990
+ { "receive": { "type": "hello-ok", "v": 1 } },
991
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
992
+ {
993
+ "send": {
994
+ "type": "call",
995
+ "id": "1",
996
+ "path": ["planet", "find"],
997
+ "input": { "id": 1 }
998
+ }
999
+ },
1000
+ {
1001
+ "receive": {
1002
+ "type": "result",
1003
+ "id": 1,
1004
+ "ok": true,
1005
+ "output": { "id": 1, "name": "Earth" }
1006
+ }
1007
+ },
1008
+ { "expect": { "closed": { "code": 1000 } } },
1009
+ {
1010
+ "expect": {
1011
+ "call": "a",
1012
+ "outcome": "local-failure",
1013
+ "reference": "Connection closed"
1014
+ }
1015
+ }
1016
+ ]
1017
+ },
1018
+ {
1019
+ "id": "ws-binary-message",
1020
+ "description": "A binary WebSocket message closes the connection with 1002 without parsing it; in-flight calls fail locally. PROTOCOL.md: Framing; Close codes.",
1021
+ "steps": [
1022
+ { "send": { "type": "hello", "v": 1 } },
1023
+ { "receive": { "type": "hello-ok", "v": 1 } },
1024
+ { "call": "a", "path": ["planet", "find"], "input": { "id": 1 } },
1025
+ {
1026
+ "send": {
1027
+ "type": "call",
1028
+ "id": "1",
1029
+ "path": ["planet", "find"],
1030
+ "input": { "id": 1 }
1031
+ }
1032
+ },
1033
+ { "receiveBinary": "eyJ0eXBlIjoicmVzdWx0IiwiaWQiOiIxIiwib2siOnRydWV9" },
1034
+ { "expect": { "closed": { "code": 1002 } } },
1035
+ {
1036
+ "expect": {
1037
+ "call": "a",
1038
+ "outcome": "local-failure",
1039
+ "reference": "Connection closed"
1040
+ }
1041
+ }
1042
+ ]
1043
+ }
1044
+ ]
1045
+ }