@dovetail-ts/conformance 0.0.0-stage → 1.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # @dovetail-ts/conformance
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 480744b: First release of Dovetail: real-time and offline sync for Ember.
8
+
9
+ - `@dovetail-ts/core`: the connection life cycle, live store subscriptions, the optimistic ledger with rebase and rollback, the offline write queue in IndexedDB with a leader tab and dead letters, `DocSession` and `PresenceRoom`.
10
+ - `@dovetail-ts/warp-drive`: the store feed into WarpDrive.
11
+ - `@dovetail-ts/crdt`, `crdt-yjs`, `crdt-loro` and `crdt-automerge`: one `DocEngine` interface with three engines.
12
+ - `@dovetail-ts/tiptap`: co-editing in Tiptap 3 with carets, per-user undo, versions and comment threads.
13
+ - `@dovetail-ts/ember`, `notifications` and `inspector`: presence and status components, the inbox, toasts and activity feeds, and a dev panel.
14
+ - `@dovetail-ts/server`, the transports (`transport-ws`, `transport-sse`, `transport-cable`) and `conformance`: a Node server and one wire protocol that the Rails gems also pass.
15
+ - Adapters for Hocuspocus, Liveblocks, PartyKit and Supabase, and integrations for Switchyard, Millwork, Benchdog and Lattice. The Neon adapter is not in 1.0: it waits for a stable Neon Realtime client (1.1).
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [480744b]
20
+ - @dovetail-ts/protocol@1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joe Gaudet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,52 @@
1
- # Temporary Holding Version
1
+ # @dovetail-ts/conformance
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The protocol conformance suite. It runs against any Dovetail server. The Node server
4
+ (`@dovetail-ts/server`) and the Rails gem (`dovetail-rails`) pass it (ADR 0001, ADR 0012).
5
+
6
+ Part of [Dovetail](https://joegaudet.com/dovetail/). Not released yet.
7
+
8
+ ## Run the cases against your server
9
+
10
+ ```ts
11
+ import { conformanceCases, runCase, transportWire } from '@dovetail-ts/conformance'
12
+ import { WebSocketTransport } from '@dovetail-ts/transport-ws'
13
+
14
+ for (const c of conformanceCases()) {
15
+ await runCase(c, () => transportWire(new WebSocketTransport({ url: 'ws://localhost:3000/ws' })))
16
+ }
17
+ ```
18
+
19
+ | Export | |
20
+ | --------------------------- | ---------------------------------------------------------------------------- |
21
+ | `conformanceCases()` | The cases. Each case is a list of steps on the clients `a` and `b`. |
22
+ | `runCase(case, connect)` | Runs one case. It throws an error that names the step that failed. |
23
+ | `transportWire(transport)` | Opens a transport with `sendText` and makes it a `WireClient`. |
24
+ | `matches(actual, expected)` | The match of an `expect` step: the expected fields, and arrays item by item. |
25
+
26
+ Each step sends a message, sends text that is not valid, closes the connection, or expects the
27
+ next message on its connection. Each case has its own rooms, so the cases can share one server.
28
+
29
+ ## The fixture contract
30
+
31
+ A case can only send and expect messages. So the server under test must install these hooks:
32
+
33
+ | Hook | Rule |
34
+ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
35
+ | `authenticate` | The server refuses a missing or blank token before the hook. The token `bad` is refused. Another token is the user id. The cases send the token `guest` when they need no user. |
36
+ | `authorize` | The room `conformance:forbidden` is refused. In the room `conformance:read-only`, a join is allowed and a write is refused. Each other action is allowed. |
37
+ | `handleWrite` | A delete gets an ack with no document. |
38
+ | | An upsert with the attribute `title: ""` gets a reject: status 422, and one error with the status `"422"` and the pointer `/data/attributes/title`. |
39
+ | | An upsert of a `comment` with the attribute `notify` calls `notify(<notify>, …)` with the id `n-<comment id>`, the verb `commented`, the actor `user` of the writer and the target `comment`. Then it gets an ack with no document. |
40
+ | | Each other upsert gets an ack with its document and the attribute `editedBy` (the user id). |
41
+
42
+ The Node fixture is `suite/fixture.ts`. The Rails fixture is
43
+ `ruby/dovetail-rails/conformance/server.rb`.
44
+
45
+ ## In this repo
46
+
47
+ `pnpm conformance` runs the suite:
48
+
49
+ - `suite/cases.suite.test.ts` checks that each case is a valid script of the protocol.
50
+ - `suite/node.suite.test.ts` runs the cases against the Node server, over WebSocket and SSE.
51
+ - `suite/rails.suite.test.ts` runs the cases against the Rails gem over ActionCable. The
52
+ global setup (`suite/rails-server.ts`) starts the dummy Rails app on a free port.
@@ -0,0 +1,38 @@
1
+ import type { ClientMessage, ServerMessage } from '@dovetail-ts/protocol';
2
+ /** The clients of a case. One connection each. */
3
+ export type ClientName = 'a' | 'b';
4
+ /** One step of a case, on the connection of `client` (`a` by default). */
5
+ export type Step =
6
+ /** Sends a message. */
7
+ {
8
+ client?: ClientName;
9
+ send: ClientMessage;
10
+ }
11
+ /** Sends text that is not a valid message. */
12
+ | {
13
+ client?: ClientName;
14
+ sendRaw: string;
15
+ }
16
+ /**
17
+ * Waits for the next message on the connection. It must have the fields of `expect`, and can
18
+ * have more (a server chooses the session id, for example). Nested objects match the same
19
+ * way. Arrays must have the same length.
20
+ */
21
+ | {
22
+ client?: ClientName;
23
+ expect: Partial<ServerMessage> & {
24
+ type: ServerMessage['type'];
25
+ };
26
+ }
27
+ /** Closes the connection. */
28
+ | {
29
+ client?: ClientName;
30
+ close: true;
31
+ };
32
+ export interface ConformanceCase {
33
+ id: string;
34
+ title: string;
35
+ steps: Step[];
36
+ }
37
+ /** The cases, as a new list on each call. */
38
+ export declare function conformanceCases(): ConformanceCase[];
@@ -0,0 +1,4 @@
1
+ export { conformanceCases } from './cases';
2
+ export type { ClientName, ConformanceCase, Step } from './cases';
3
+ export { matches, runCase, transportWire } from './runner';
4
+ export type { RunOptions, TextTransport, WireClient } from './runner';
package/dist/index.js ADDED
@@ -0,0 +1,776 @@
1
+ import { encodeMessage } from '@dovetail-ts/protocol';
2
+
3
+ // src/cases.ts
4
+ var hello = (client = "a", token = "guest") => [
5
+ { client, send: { type: "hello", versions: [1], token } },
6
+ { client, expect: { type: "welcome", version: 1 } }
7
+ ];
8
+ var joinRoom = (client, room2, id = `j-${client}`) => [
9
+ { client, send: { type: "join", id, room: room2 } },
10
+ { client, expect: { type: "ack", ref: id } }
11
+ ];
12
+ var joined = (client, room2, token) => [
13
+ ...hello(client, token),
14
+ ...joinRoom(client, room2)
15
+ ];
16
+ var room = (id) => `conformance:${id}`;
17
+ var note = (title) => ({
18
+ op: "upsert",
19
+ document: { data: { type: "note", id: "1", attributes: { title } } }
20
+ });
21
+ var comment = (id, notify) => ({
22
+ op: "upsert",
23
+ document: { data: { type: "comment", id, attributes: { body: "Hi", notify } } }
24
+ });
25
+ var notification = (id, readAt, archivedAt = null) => ({
26
+ type: "notification",
27
+ id,
28
+ attributes: {
29
+ verb: "commented",
30
+ createdAt: "2026-12-03T10:00:00.000Z",
31
+ readAt,
32
+ seenAt: null,
33
+ archivedAt
34
+ },
35
+ relationships: {
36
+ actor: { data: { type: "user", id: "u1" } },
37
+ target: { data: { type: "comment", id: id.replace(/^n-/, "") } }
38
+ }
39
+ });
40
+ function conformanceCases() {
41
+ return [
42
+ {
43
+ id: "hello-welcome",
44
+ title: "The server answers hello with welcome and the common version",
45
+ steps: hello()
46
+ },
47
+ {
48
+ id: "hello-unsupported-version",
49
+ title: "The server refuses a hello with no common version",
50
+ steps: [
51
+ { send: { type: "hello", versions: [99] } },
52
+ { expect: { type: "error", code: "unsupported-version" } }
53
+ ]
54
+ },
55
+ {
56
+ id: "hello-first",
57
+ title: "The server needs hello before other messages",
58
+ steps: [
59
+ { send: { type: "ping", id: "p1" } },
60
+ { expect: { type: "error", ref: "p1", code: "invalid-message" } }
61
+ ]
62
+ },
63
+ {
64
+ id: "hello-user",
65
+ title: "The server names the user of the token in welcome",
66
+ steps: [
67
+ { send: { type: "hello", versions: [1], token: "u1" } },
68
+ { expect: { type: "welcome", version: 1, user: { id: "u1" } } }
69
+ ]
70
+ },
71
+ {
72
+ id: "auth-reject",
73
+ title: "The server refuses a token that authenticate refuses",
74
+ steps: [
75
+ { send: { type: "hello", versions: [1], token: "bad" } },
76
+ { expect: { type: "error", code: "unauthorized" } }
77
+ ]
78
+ },
79
+ {
80
+ id: "auth-no-token",
81
+ title: "The server refuses a hello with no token or a blank token, before authenticate",
82
+ steps: [
83
+ { send: { type: "hello", versions: [1] } },
84
+ { expect: { type: "error", code: "unauthorized" } },
85
+ { client: "b", send: { type: "hello", versions: [1], token: " " } },
86
+ { client: "b", expect: { type: "error", code: "unauthorized" } }
87
+ ]
88
+ },
89
+ {
90
+ id: "invalid-message",
91
+ title: "The server answers a message that is not valid with an invalid-message error",
92
+ steps: [
93
+ ...hello(),
94
+ { sendRaw: '{"type":"join","id":"r1"}' },
95
+ { expect: { type: "error", code: "invalid-message" } }
96
+ ]
97
+ },
98
+ {
99
+ id: "parse-name-utf16",
100
+ title: "The server counts the length of a name in UTF-16 units",
101
+ steps: [
102
+ ...hello(),
103
+ { sendRaw: JSON.stringify({ type: "join", id: "j1", room: "\u{1F600}".repeat(200) }) },
104
+ { expect: { type: "error", code: "too-large" } }
105
+ ]
106
+ },
107
+ {
108
+ id: "parse-impossible-date",
109
+ title: "The server refuses a notification with an impossible date-time",
110
+ steps: [
111
+ ...joined("a", "user:u1", "u1"),
112
+ {
113
+ sendRaw: JSON.stringify({
114
+ type: "write",
115
+ id: "w1",
116
+ room: "user:u1",
117
+ op: {
118
+ op: "upsert",
119
+ document: {
120
+ data: {
121
+ type: "notification",
122
+ id: "n1",
123
+ attributes: { readAt: "2026-99-99T99:99:99Z" }
124
+ }
125
+ }
126
+ }
127
+ })
128
+ },
129
+ { expect: { type: "error", code: "invalid-message" } }
130
+ ]
131
+ },
132
+ {
133
+ id: "join-ack",
134
+ title: "The server acks a join",
135
+ steps: joined("a", room("join-ack"))
136
+ },
137
+ {
138
+ id: "join-forbidden",
139
+ title: "The server refuses a join that authorize refuses",
140
+ steps: [
141
+ ...hello(),
142
+ { send: { type: "join", id: "r1", room: "conformance:forbidden" } },
143
+ { expect: { type: "error", ref: "r1", code: "forbidden" } }
144
+ ]
145
+ },
146
+ {
147
+ id: "join-other-user-room",
148
+ title: "The server refuses a join to the per-user room of another user",
149
+ steps: [
150
+ ...hello("a", "u1"),
151
+ { send: { type: "join", id: "r1", room: "user:u2" } },
152
+ { expect: { type: "error", ref: "r1", code: "forbidden" } }
153
+ ]
154
+ },
155
+ {
156
+ id: "leave-ack",
157
+ title: "The server acks a leave",
158
+ steps: [
159
+ ...joined("a", room("leave-ack")),
160
+ { send: { type: "leave", id: "r2", room: room("leave-ack") } },
161
+ { expect: { type: "ack", ref: "r2" } }
162
+ ]
163
+ },
164
+ {
165
+ id: "leave-not-joined",
166
+ title: "The server acks a leave of a room that was never joined or whose join it refused",
167
+ steps: [
168
+ ...hello(),
169
+ { send: { type: "join", id: "j1", room: "conformance:forbidden" } },
170
+ { expect: { type: "error", ref: "j1", code: "forbidden" } },
171
+ { send: { type: "leave", id: "l1", room: "conformance:forbidden" } },
172
+ { expect: { type: "ack", ref: "l1" } },
173
+ { send: { type: "leave", id: "l2", room: room("leave-not-joined") } },
174
+ { expect: { type: "ack", ref: "l2" } }
175
+ ]
176
+ },
177
+ {
178
+ id: "ping-pong",
179
+ title: "The server answers ping with pong",
180
+ steps: [
181
+ ...hello(),
182
+ { send: { type: "ping", id: "p1" } },
183
+ { expect: { type: "pong", ref: "p1" } }
184
+ ]
185
+ },
186
+ {
187
+ id: "write-not-joined",
188
+ title: "The server refuses a write to a room that the client did not join",
189
+ steps: [
190
+ ...hello(),
191
+ {
192
+ send: {
193
+ type: "write",
194
+ id: "w1",
195
+ room: room("write-not-joined"),
196
+ op: { op: "delete", ref: { type: "note", id: "1" } }
197
+ }
198
+ },
199
+ { expect: { type: "error", ref: "w1", code: "not-joined" } }
200
+ ]
201
+ },
202
+ {
203
+ id: "write-ack-feed",
204
+ title: "The server acks a write with the server document, and feeds it to the other members",
205
+ steps: [
206
+ ...joined("a", room("write-ack-feed"), "u1"),
207
+ ...joined("b", room("write-ack-feed")),
208
+ { send: { type: "write", id: "w1", room: room("write-ack-feed"), op: note("Plan") } },
209
+ {
210
+ expect: {
211
+ type: "ack",
212
+ ref: "w1",
213
+ document: { data: { type: "note", id: "1", attributes: { editedBy: "u1" } } }
214
+ }
215
+ },
216
+ {
217
+ client: "b",
218
+ expect: {
219
+ type: "feed",
220
+ room: room("write-ack-feed"),
221
+ ops: [
222
+ {
223
+ op: "upsert",
224
+ document: { data: { type: "note", id: "1", attributes: { title: "Plan" } } }
225
+ }
226
+ ]
227
+ }
228
+ }
229
+ ]
230
+ },
231
+ {
232
+ id: "join-reset",
233
+ title: "The server answers a join with reset when it cannot replay the feed after since",
234
+ steps: [
235
+ ...joined("a", room("join-reset")),
236
+ { send: { type: "write", id: "w1", room: room("join-reset"), op: note("Plan") } },
237
+ { expect: { type: "ack", ref: "w1" } },
238
+ ...hello("b"),
239
+ {
240
+ client: "b",
241
+ send: { type: "join", id: "j1", room: room("join-reset"), since: "c99999999999999999" }
242
+ },
243
+ { client: "b", expect: { type: "ack", ref: "j1", reset: true } },
244
+ { client: "b", send: { type: "ping", id: "p1" } },
245
+ { client: "b", expect: { type: "pong", ref: "p1" } }
246
+ ]
247
+ },
248
+ {
249
+ id: "write-reject",
250
+ title: "The server sends the reject of handleWrite, with the status and the errors",
251
+ steps: [
252
+ ...joined("a", room("write-reject")),
253
+ { send: { type: "write", id: "w1", room: room("write-reject"), op: note("") } },
254
+ {
255
+ expect: {
256
+ type: "reject",
257
+ ref: "w1",
258
+ status: 422,
259
+ errors: [{ status: "422", source: { pointer: "/data/attributes/title" } }]
260
+ }
261
+ }
262
+ ]
263
+ },
264
+ {
265
+ id: "write-delete-feed",
266
+ title: "The server feeds an acked delete to the other members",
267
+ steps: [
268
+ ...joined("a", room("write-delete-feed")),
269
+ ...joined("b", room("write-delete-feed")),
270
+ {
271
+ send: {
272
+ type: "write",
273
+ id: "w1",
274
+ room: room("write-delete-feed"),
275
+ op: { op: "delete", ref: { type: "note", id: "2" } }
276
+ }
277
+ },
278
+ { expect: { type: "ack", ref: "w1" } },
279
+ {
280
+ client: "b",
281
+ expect: {
282
+ type: "feed",
283
+ room: room("write-delete-feed"),
284
+ ops: [{ op: "delete", ref: { type: "note", id: "2" } }]
285
+ }
286
+ }
287
+ ]
288
+ },
289
+ {
290
+ id: "write-notification-shared-room",
291
+ title: "The server refuses a notification in a write to a room that is not a per-user room",
292
+ steps: [
293
+ ...joined("a", room("write-notification-shared-room")),
294
+ {
295
+ send: {
296
+ type: "write",
297
+ id: "w1",
298
+ room: room("write-notification-shared-room"),
299
+ op: { op: "upsert", document: { data: notification("n-fake", null) } }
300
+ }
301
+ },
302
+ { expect: { type: "reject", ref: "w1", status: 403 } }
303
+ ]
304
+ },
305
+ {
306
+ id: "doc-update-relay",
307
+ title: "The server relays a doc update to the other members of the room",
308
+ steps: [
309
+ ...joined("a", room("doc-update-relay")),
310
+ ...joined("b", room("doc-update-relay")),
311
+ {
312
+ client: "a",
313
+ send: { type: "doc-update", room: room("doc-update-relay"), doc: "body", update: "AAEC" }
314
+ },
315
+ {
316
+ client: "b",
317
+ expect: {
318
+ type: "doc-update",
319
+ room: room("doc-update-relay"),
320
+ doc: "body",
321
+ update: "AAEC"
322
+ }
323
+ }
324
+ ]
325
+ },
326
+ {
327
+ id: "doc-update-read-only",
328
+ title: "The server refuses a doc update without the write right, and does not store it",
329
+ steps: [
330
+ ...joined("a", "conformance:read-only"),
331
+ {
332
+ send: {
333
+ type: "doc-update",
334
+ room: "conformance:read-only",
335
+ doc: "doc-update-read-only",
336
+ update: "AAEC"
337
+ }
338
+ },
339
+ { expect: { type: "error", code: "forbidden" } },
340
+ {
341
+ send: {
342
+ type: "doc-sync",
343
+ room: "conformance:read-only",
344
+ doc: "doc-update-read-only",
345
+ step: 2,
346
+ update: "AAED"
347
+ }
348
+ },
349
+ { expect: { type: "error", code: "forbidden" } },
350
+ {
351
+ send: {
352
+ type: "doc-sync",
353
+ room: "conformance:read-only",
354
+ doc: "doc-update-read-only",
355
+ step: 1,
356
+ stateVector: "AA=="
357
+ }
358
+ },
359
+ { expect: { type: "doc-sync", doc: "doc-update-read-only", step: 2, update: "" } }
360
+ ]
361
+ },
362
+ {
363
+ id: "doc-sync-empty",
364
+ title: "The server answers step 1 of a document with no updates with an empty step 2",
365
+ steps: [
366
+ ...joined("a", room("doc-sync-empty")),
367
+ {
368
+ send: {
369
+ type: "doc-sync",
370
+ room: room("doc-sync-empty"),
371
+ doc: "body",
372
+ step: 1,
373
+ stateVector: "AA=="
374
+ }
375
+ },
376
+ {
377
+ expect: {
378
+ type: "doc-sync",
379
+ room: room("doc-sync-empty"),
380
+ doc: "body",
381
+ step: 2,
382
+ update: ""
383
+ }
384
+ }
385
+ ]
386
+ },
387
+ {
388
+ id: "doc-sync-stored",
389
+ title: "The server answers step 1 with the updates that it stored",
390
+ steps: [
391
+ ...joined("a", room("doc-sync-stored")),
392
+ {
393
+ send: { type: "doc-update", room: room("doc-sync-stored"), doc: "body", update: "AAEC" }
394
+ },
395
+ {
396
+ send: {
397
+ type: "doc-sync",
398
+ room: room("doc-sync-stored"),
399
+ doc: "body",
400
+ step: 1,
401
+ stateVector: "AA=="
402
+ }
403
+ },
404
+ { expect: { type: "doc-sync", doc: "body", step: 2, update: "AAEC" } }
405
+ ]
406
+ },
407
+ {
408
+ id: "doc-sync-step-2-relay",
409
+ title: "The server stores a step 2 of a client and relays it as a doc update",
410
+ steps: [
411
+ ...joined("a", room("doc-sync-step-2-relay")),
412
+ ...joined("b", room("doc-sync-step-2-relay")),
413
+ {
414
+ send: {
415
+ type: "doc-sync",
416
+ room: room("doc-sync-step-2-relay"),
417
+ doc: "body",
418
+ step: 2,
419
+ update: "AAED"
420
+ }
421
+ },
422
+ { client: "b", expect: { type: "doc-update", doc: "body", update: "AAED" } }
423
+ ]
424
+ },
425
+ {
426
+ id: "awareness-relay",
427
+ title: "The server relays awareness to the other members of the room, with the client id",
428
+ steps: [
429
+ ...joined("a", room("awareness-relay")),
430
+ ...joined("b", room("awareness-relay")),
431
+ {
432
+ client: "a",
433
+ send: { type: "awareness", room: room("awareness-relay"), state: { typing: true } }
434
+ },
435
+ {
436
+ client: "b",
437
+ expect: { type: "awareness", room: room("awareness-relay"), state: { typing: true } }
438
+ }
439
+ ]
440
+ },
441
+ {
442
+ id: "awareness-user-id",
443
+ title: "The server sets state.user.id of an awareness state to the user of the session",
444
+ steps: [
445
+ ...joined("a", room("awareness-user-id"), "u1"),
446
+ ...joined("b", room("awareness-user-id"), "u2"),
447
+ {
448
+ send: {
449
+ type: "awareness",
450
+ room: room("awareness-user-id"),
451
+ state: { user: { id: "u2", name: "Not me" } }
452
+ }
453
+ },
454
+ {
455
+ client: "b",
456
+ expect: { type: "awareness", state: { user: { id: "u1", name: "Not me" } } }
457
+ }
458
+ ]
459
+ },
460
+ {
461
+ id: "awareness-not-joined",
462
+ title: "The server refuses awareness for a room that the client did not join",
463
+ steps: [
464
+ ...hello(),
465
+ { send: { type: "awareness", room: room("awareness-not-joined"), state: {} } },
466
+ { expect: { type: "error", code: "not-joined" } }
467
+ ]
468
+ },
469
+ {
470
+ id: "awareness-leave",
471
+ title: "The server removes the awareness state of a client that leaves",
472
+ steps: [
473
+ ...joined("a", room("awareness-leave")),
474
+ ...joined("b", room("awareness-leave")),
475
+ { send: { type: "awareness", room: room("awareness-leave"), state: { typing: true } } },
476
+ { client: "b", expect: { type: "awareness", state: { typing: true } } },
477
+ { send: { type: "leave", id: "l1", room: room("awareness-leave") } },
478
+ { expect: { type: "ack", ref: "l1" } },
479
+ {
480
+ client: "b",
481
+ expect: { type: "awareness", room: room("awareness-leave"), state: null }
482
+ }
483
+ ]
484
+ },
485
+ {
486
+ id: "awareness-close",
487
+ title: "The server removes the awareness state of a client that disconnects",
488
+ steps: [
489
+ ...joined("a", room("awareness-close")),
490
+ ...joined("b", room("awareness-close")),
491
+ { send: { type: "awareness", room: room("awareness-close"), state: { typing: true } } },
492
+ { client: "b", expect: { type: "awareness", state: { typing: true } } },
493
+ { close: true },
494
+ {
495
+ client: "b",
496
+ expect: { type: "awareness", room: room("awareness-close"), state: null }
497
+ }
498
+ ]
499
+ },
500
+ {
501
+ id: "notify",
502
+ title: "The server sends a notification on the per-user room of the user",
503
+ steps: [
504
+ ...joined("b", "user:u2", "u2"),
505
+ ...joined("a", room("notify"), "u1"),
506
+ { send: { type: "write", id: "w1", room: room("notify"), op: comment("c-notify", "u2") } },
507
+ { expect: { type: "ack", ref: "w1" } },
508
+ {
509
+ client: "b",
510
+ expect: {
511
+ type: "feed",
512
+ room: "user:u2",
513
+ ops: [
514
+ {
515
+ op: "upsert",
516
+ document: {
517
+ data: {
518
+ type: "notification",
519
+ id: "n-c-notify",
520
+ attributes: { verb: "commented", readAt: null, seenAt: null },
521
+ relationships: {
522
+ actor: { data: { type: "user", id: "u1" } },
523
+ target: { data: { type: "comment", id: "c-notify" } }
524
+ }
525
+ }
526
+ }
527
+ }
528
+ ]
529
+ }
530
+ }
531
+ ]
532
+ },
533
+ {
534
+ id: "notification-mark-read",
535
+ title: "The server marks a notification as read on a write to the per-user room",
536
+ steps: [
537
+ ...joined("b", "user:u2", "u2"),
538
+ ...joined("a", room("notification-mark-read"), "u1"),
539
+ {
540
+ send: {
541
+ type: "write",
542
+ id: "w1",
543
+ room: room("notification-mark-read"),
544
+ op: comment("c-read", "u2")
545
+ }
546
+ },
547
+ { expect: { type: "ack", ref: "w1" } },
548
+ { client: "b", expect: { type: "feed", room: "user:u2" } },
549
+ {
550
+ client: "b",
551
+ send: {
552
+ type: "write",
553
+ id: "w2",
554
+ room: "user:u2",
555
+ op: {
556
+ op: "upsert",
557
+ document: { data: notification("n-c-read", "2026-12-03T11:00:00.000Z") }
558
+ }
559
+ }
560
+ },
561
+ {
562
+ client: "b",
563
+ expect: {
564
+ type: "ack",
565
+ ref: "w2",
566
+ document: {
567
+ data: {
568
+ type: "notification",
569
+ id: "n-c-read",
570
+ attributes: { readAt: "2026-12-03T11:00:00.000Z" }
571
+ }
572
+ }
573
+ }
574
+ }
575
+ ]
576
+ },
577
+ {
578
+ id: "notification-write-keeps-times",
579
+ title: "A notification write sets a time only when it has no value",
580
+ steps: [
581
+ ...joined("b", "user:u2", "u2"),
582
+ ...joined("a", room("notification-write-keeps-times"), "u1"),
583
+ {
584
+ send: {
585
+ type: "write",
586
+ id: "w1",
587
+ room: room("notification-write-keeps-times"),
588
+ op: comment("c-keep", "u2")
589
+ }
590
+ },
591
+ { expect: { type: "ack", ref: "w1" } },
592
+ { client: "b", expect: { type: "feed", room: "user:u2" } },
593
+ {
594
+ client: "b",
595
+ send: {
596
+ type: "write",
597
+ id: "w2",
598
+ room: "user:u2",
599
+ op: {
600
+ op: "upsert",
601
+ document: { data: notification("n-c-keep", null, "2026-12-03T11:00:00.000Z") }
602
+ }
603
+ }
604
+ },
605
+ { client: "b", expect: { type: "ack", ref: "w2" } },
606
+ {
607
+ client: "b",
608
+ send: {
609
+ type: "write",
610
+ id: "w3",
611
+ room: "user:u2",
612
+ op: {
613
+ op: "upsert",
614
+ document: { data: notification("n-c-keep", "2026-12-03T12:00:00.000Z", null) }
615
+ }
616
+ }
617
+ },
618
+ {
619
+ client: "b",
620
+ expect: {
621
+ type: "ack",
622
+ ref: "w3",
623
+ document: {
624
+ data: {
625
+ type: "notification",
626
+ id: "n-c-keep",
627
+ attributes: {
628
+ readAt: "2026-12-03T12:00:00.000Z",
629
+ archivedAt: "2026-12-03T11:00:00.000Z"
630
+ }
631
+ }
632
+ }
633
+ }
634
+ }
635
+ ]
636
+ },
637
+ {
638
+ id: "notification-write-partial",
639
+ title: "A notification write to the per-user room can send only the times that change",
640
+ steps: [
641
+ ...joined("b", "user:u2", "u2"),
642
+ ...joined("a", room("notification-write-partial"), "u1"),
643
+ {
644
+ send: {
645
+ type: "write",
646
+ id: "w1",
647
+ room: room("notification-write-partial"),
648
+ op: comment("c-partial", "u2")
649
+ }
650
+ },
651
+ { expect: { type: "ack", ref: "w1" } },
652
+ { client: "b", expect: { type: "feed", room: "user:u2" } },
653
+ {
654
+ client: "b",
655
+ send: {
656
+ type: "write",
657
+ id: "w2",
658
+ room: "user:u2",
659
+ op: {
660
+ op: "upsert",
661
+ document: {
662
+ data: {
663
+ type: "notification",
664
+ id: "n-c-partial",
665
+ attributes: { seenAt: "2026-12-03T11:00:00.000Z" }
666
+ }
667
+ }
668
+ }
669
+ }
670
+ },
671
+ {
672
+ client: "b",
673
+ expect: {
674
+ type: "ack",
675
+ ref: "w2",
676
+ document: {
677
+ data: {
678
+ type: "notification",
679
+ id: "n-c-partial",
680
+ attributes: { verb: "commented", seenAt: "2026-12-03T11:00:00.000Z", readAt: null }
681
+ }
682
+ }
683
+ }
684
+ }
685
+ ]
686
+ }
687
+ ];
688
+ }
689
+ function matches(actual, expected) {
690
+ if (Array.isArray(expected)) {
691
+ return Array.isArray(actual) && actual.length === expected.length && expected.every((item, i) => matches(actual[i], item));
692
+ }
693
+ if (typeof expected === "object" && expected !== null) {
694
+ if (typeof actual !== "object" || actual === null || Array.isArray(actual)) return false;
695
+ return Object.entries(expected).every(
696
+ ([key, value]) => key in actual && matches(actual[key], value)
697
+ );
698
+ }
699
+ return Object.is(actual, expected);
700
+ }
701
+ async function runCase(c, connect, options = {}) {
702
+ const wires = /* @__PURE__ */ new Map();
703
+ const wire = async (name) => {
704
+ let found = wires.get(name);
705
+ if (!found) wires.set(name, found = await connect(name));
706
+ return found;
707
+ };
708
+ try {
709
+ for (const [index, step] of c.steps.entries()) {
710
+ const client = await wire(step.client ?? "a");
711
+ const where = `${c.id}: step ${index + 1} (client ${step.client ?? "a"})`;
712
+ if ("send" in step) client.sendText(encodeMessage(step.send));
713
+ else if ("sendRaw" in step) client.sendText(step.sendRaw);
714
+ else if ("close" in step) client.close();
715
+ else {
716
+ let actual;
717
+ try {
718
+ actual = await client.next(options.timeoutMs ?? 5e3);
719
+ } catch (error) {
720
+ throw new Error(`${where}: expected ${JSON.stringify(step.expect)}, but ${error}`, {
721
+ cause: error
722
+ });
723
+ }
724
+ if (!matches(actual, step.expect)) {
725
+ throw new Error(
726
+ `${where}: expected ${JSON.stringify(step.expect)}, got ${JSON.stringify(actual)}`
727
+ );
728
+ }
729
+ }
730
+ }
731
+ } finally {
732
+ for (const client of wires.values()) client.close();
733
+ }
734
+ }
735
+ async function transportWire(transport) {
736
+ const queue = [];
737
+ const waiters = [];
738
+ let closed;
739
+ transport.onMessage((message) => {
740
+ const waiter = waiters.shift();
741
+ if (waiter) waiter.resolve(message);
742
+ else queue.push(message);
743
+ });
744
+ transport.onClose((info) => {
745
+ closed = `the connection closed (${info.code} ${info.reason})`;
746
+ for (const waiter of waiters.splice(0)) waiter.reject(new Error(closed));
747
+ });
748
+ await transport.open();
749
+ return {
750
+ sendText: (text) => transport.sendText(text),
751
+ close: () => transport.close(),
752
+ next: (timeoutMs) => new Promise((resolve, reject) => {
753
+ if (queue.length > 0) return resolve(queue.shift());
754
+ if (closed) return reject(new Error(closed));
755
+ const waiter = {
756
+ resolve: (m) => {
757
+ clearTimeout(timer);
758
+ resolve(m);
759
+ },
760
+ reject: (e) => {
761
+ clearTimeout(timer);
762
+ reject(e);
763
+ }
764
+ };
765
+ const timer = setTimeout(() => {
766
+ waiters.splice(waiters.indexOf(waiter), 1);
767
+ reject(new Error(`no message in ${timeoutMs} ms`));
768
+ }, timeoutMs);
769
+ waiters.push(waiter);
770
+ })
771
+ };
772
+ }
773
+
774
+ export { conformanceCases, matches, runCase, transportWire };
775
+ //# sourceMappingURL=index.js.map
776
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cases.ts","../src/runner.ts"],"names":["room"],"mappings":";;;AA6BA,IAAM,KAAA,GAAQ,CAAC,MAAA,GAAqB,GAAA,EAAK,QAAQ,OAAA,KAAoB;AAAA,EACnE,EAAE,MAAA,EAAQ,IAAA,EAAM,EAAE,IAAA,EAAM,OAAA,EAAS,QAAA,EAAU,CAAC,CAAC,CAAA,EAAG,KAAA,EAAM,EAAE;AAAA,EACxD,EAAE,QAAQ,MAAA,EAAQ,EAAE,MAAM,SAAA,EAAW,OAAA,EAAS,GAAE;AAClD,CAAA;AAEA,IAAM,WAAW,CAAC,MAAA,EAAoBA,OAAc,EAAA,GAAK,CAAA,EAAA,EAAK,MAAM,CAAA,CAAA,KAAe;AAAA,EACjF,EAAE,QAAQ,IAAA,EAAM,EAAE,MAAM,MAAA,EAAQ,EAAA,EAAI,IAAA,EAAAA,KAAAA,EAAK,EAAE;AAAA,EAC3C,EAAE,QAAQ,MAAA,EAAQ,EAAE,MAAM,KAAA,EAAO,GAAA,EAAK,IAAG;AAC3C,CAAA;AAEA,IAAM,MAAA,GAAS,CAAC,MAAA,EAAoBA,KAAAA,EAAc,KAAA,KAA2B;AAAA,EAC3E,GAAG,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAA;AAAA,EACtB,GAAG,QAAA,CAAS,MAAA,EAAQA,KAAI;AAC1B,CAAA;AAGA,IAAM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,IAAI,OAAA,CAAQ,CAAC,SAAS,MAAA,KAAW;AAC/B,MAAA,IAAI,MAAM,MAAA,GAAS,CAAA,SAAU,OAAA,CAAQ,KAAA,CAAM,OAAO,CAAA;AAClD,MAAA,IAAI,QAAQ,OAAO,MAAA,CAAO,IAAI,KAAA,CAAM,MAAM,CAAC,CAAA;AAC3C,MAAA,MAAM,MAAA,GAAS;AAAA,QACb,OAAA,EAAS,CAAC,CAAA,KAAe;AACvB,UAAA,YAAA,CAAa,KAAK,CAAA;AAClB,UAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,QACX,CAAA;AAAA,QACA,MAAA,EAAQ,CAAC,CAAA,KAAa;AACpB,UAAA,YAAA,CAAa,KAAK,CAAA;AAClB,UAAA,MAAA,CAAO,CAAC,CAAA;AAAA,QACV;AAAA,OACF;AACA,MAAA,MAAM,KAAA,GAAQ,WAAW,MAAM;AAC7B,QAAA,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAG,CAAC,CAAA;AACzC,QAAA,MAAA,CAAO,IAAI,KAAA,CAAM,CAAA,cAAA,EAAiB,SAAS,KAAK,CAAC,CAAA;AAAA,MACnD,GAAG,SAAS,CAAA;AACZ,MAAA,OAAA,CAAQ,KAAK,MAAM,CAAA;AAAA,IACrB,CAAC;AAAA,GACL;AACF","file":"index.js","sourcesContent":["// The conformance cases (ADR 0001). Each Dovetail server must pass each case: the Node server\n// and the Rails gem (M5). A protocol change needs a new case. The list grows with each\n// milestone. The server under test installs the fixture hooks of the README (ADR 0012).\nimport type { ClientMessage, NotificationResource, ServerMessage } from '@dovetail-ts/protocol'\n\n/** The clients of a case. One connection each. */\nexport type ClientName = 'a' | 'b'\n\n/** One step of a case, on the connection of `client` (`a` by default). */\nexport type Step =\n /** Sends a message. */\n | { client?: ClientName; send: ClientMessage }\n /** Sends text that is not a valid message. */\n | { client?: ClientName; sendRaw: string }\n /**\n * Waits for the next message on the connection. It must have the fields of `expect`, and can\n * have more (a server chooses the session id, for example). Nested objects match the same\n * way. Arrays must have the same length.\n */\n | { client?: ClientName; expect: Partial<ServerMessage> & { type: ServerMessage['type'] } }\n /** Closes the connection. */\n | { client?: ClientName; close: true }\n\nexport interface ConformanceCase {\n id: string\n title: string\n steps: Step[]\n}\n\nconst hello = (client: ClientName = 'a', token = 'guest'): Step[] => [\n { client, send: { type: 'hello', versions: [1], token } },\n { client, expect: { type: 'welcome', version: 1 } },\n]\n\nconst joinRoom = (client: ClientName, room: string, id = `j-${client}`): Step[] => [\n { client, send: { type: 'join', id, room } },\n { client, expect: { type: 'ack', ref: id } },\n]\n\nconst joined = (client: ClientName, room: string, token?: string): Step[] => [\n ...hello(client, token),\n ...joinRoom(client, room),\n]\n\n/** The room of a case. Each case has its own rooms, because the cases share one server. */\nconst room = (id: string) => `conformance:${id}`\n\nconst note = (title: string) => ({\n op: 'upsert' as const,\n document: { data: { type: 'note', id: '1', attributes: { title } } },\n})\n\n/** A comment that the fixture `handleWrite` turns into a notification for `notify`. */\nconst comment = (id: string, notify: string) => ({\n op: 'upsert' as const,\n document: { data: { type: 'comment', id, attributes: { body: 'Hi', notify } } },\n})\n\nconst notification = (\n id: string,\n readAt: string | null,\n archivedAt: string | null = null,\n): NotificationResource => ({\n type: 'notification',\n id,\n attributes: {\n verb: 'commented',\n createdAt: '2026-12-03T10:00:00.000Z',\n readAt,\n seenAt: null,\n archivedAt,\n },\n relationships: {\n actor: { data: { type: 'user', id: 'u1' } },\n target: { data: { type: 'comment', id: id.replace(/^n-/, '') } },\n },\n})\n\n/** The cases, as a new list on each call. */\nexport function conformanceCases(): ConformanceCase[] {\n return [\n {\n id: 'hello-welcome',\n title: 'The server answers hello with welcome and the common version',\n steps: hello(),\n },\n {\n id: 'hello-unsupported-version',\n title: 'The server refuses a hello with no common version',\n steps: [\n { send: { type: 'hello', versions: [99] } },\n { expect: { type: 'error', code: 'unsupported-version' } },\n ],\n },\n {\n id: 'hello-first',\n title: 'The server needs hello before other messages',\n steps: [\n { send: { type: 'ping', id: 'p1' } },\n { expect: { type: 'error', ref: 'p1', code: 'invalid-message' } },\n ],\n },\n {\n id: 'hello-user',\n title: 'The server names the user of the token in welcome',\n steps: [\n { send: { type: 'hello', versions: [1], token: 'u1' } },\n { expect: { type: 'welcome', version: 1, user: { id: 'u1' } } },\n ],\n },\n {\n id: 'auth-reject',\n title: 'The server refuses a token that authenticate refuses',\n steps: [\n { send: { type: 'hello', versions: [1], token: 'bad' } },\n { expect: { type: 'error', code: 'unauthorized' } },\n ],\n },\n {\n id: 'auth-no-token',\n title: 'The server refuses a hello with no token or a blank token, before authenticate',\n steps: [\n { send: { type: 'hello', versions: [1] } },\n { expect: { type: 'error', code: 'unauthorized' } },\n { client: 'b', send: { type: 'hello', versions: [1], token: ' ' } },\n { client: 'b', expect: { type: 'error', code: 'unauthorized' } },\n ],\n },\n {\n id: 'invalid-message',\n title: 'The server answers a message that is not valid with an invalid-message error',\n steps: [\n ...hello(),\n { sendRaw: '{\"type\":\"join\",\"id\":\"r1\"}' },\n { expect: { type: 'error', code: 'invalid-message' } },\n ],\n },\n {\n id: 'parse-name-utf16',\n title: 'The server counts the length of a name in UTF-16 units',\n steps: [\n ...hello(),\n { sendRaw: JSON.stringify({ type: 'join', id: 'j1', room: '\\u{1F600}'.repeat(200) }) },\n { expect: { type: 'error', code: 'too-large' } },\n ],\n },\n {\n id: 'parse-impossible-date',\n title: 'The server refuses a notification with an impossible date-time',\n steps: [\n ...joined('a', 'user:u1', 'u1'),\n {\n sendRaw: JSON.stringify({\n type: 'write',\n id: 'w1',\n room: 'user:u1',\n op: {\n op: 'upsert',\n document: {\n data: {\n type: 'notification',\n id: 'n1',\n attributes: { readAt: '2026-99-99T99:99:99Z' },\n },\n },\n },\n }),\n },\n { expect: { type: 'error', code: 'invalid-message' } },\n ],\n },\n {\n id: 'join-ack',\n title: 'The server acks a join',\n steps: joined('a', room('join-ack')),\n },\n {\n id: 'join-forbidden',\n title: 'The server refuses a join that authorize refuses',\n steps: [\n ...hello(),\n { send: { type: 'join', id: 'r1', room: 'conformance:forbidden' } },\n { expect: { type: 'error', ref: 'r1', code: 'forbidden' } },\n ],\n },\n {\n id: 'join-other-user-room',\n title: 'The server refuses a join to the per-user room of another user',\n steps: [\n ...hello('a', 'u1'),\n { send: { type: 'join', id: 'r1', room: 'user:u2' } },\n { expect: { type: 'error', ref: 'r1', code: 'forbidden' } },\n ],\n },\n {\n id: 'leave-ack',\n title: 'The server acks a leave',\n steps: [\n ...joined('a', room('leave-ack')),\n { send: { type: 'leave', id: 'r2', room: room('leave-ack') } },\n { expect: { type: 'ack', ref: 'r2' } },\n ],\n },\n {\n id: 'leave-not-joined',\n title: 'The server acks a leave of a room that was never joined or whose join it refused',\n steps: [\n ...hello(),\n { send: { type: 'join', id: 'j1', room: 'conformance:forbidden' } },\n { expect: { type: 'error', ref: 'j1', code: 'forbidden' } },\n { send: { type: 'leave', id: 'l1', room: 'conformance:forbidden' } },\n { expect: { type: 'ack', ref: 'l1' } },\n { send: { type: 'leave', id: 'l2', room: room('leave-not-joined') } },\n { expect: { type: 'ack', ref: 'l2' } },\n ],\n },\n {\n id: 'ping-pong',\n title: 'The server answers ping with pong',\n steps: [\n ...hello(),\n { send: { type: 'ping', id: 'p1' } },\n { expect: { type: 'pong', ref: 'p1' } },\n ],\n },\n {\n id: 'write-not-joined',\n title: 'The server refuses a write to a room that the client did not join',\n steps: [\n ...hello(),\n {\n send: {\n type: 'write',\n id: 'w1',\n room: room('write-not-joined'),\n op: { op: 'delete', ref: { type: 'note', id: '1' } },\n },\n },\n { expect: { type: 'error', ref: 'w1', code: 'not-joined' } },\n ],\n },\n {\n id: 'write-ack-feed',\n title: 'The server acks a write with the server document, and feeds it to the other members',\n steps: [\n ...joined('a', room('write-ack-feed'), 'u1'),\n ...joined('b', room('write-ack-feed')),\n { send: { type: 'write', id: 'w1', room: room('write-ack-feed'), op: note('Plan') } },\n {\n expect: {\n type: 'ack',\n ref: 'w1',\n document: { data: { type: 'note', id: '1', attributes: { editedBy: 'u1' } } },\n },\n },\n {\n client: 'b',\n expect: {\n type: 'feed',\n room: room('write-ack-feed'),\n ops: [\n {\n op: 'upsert',\n document: { data: { type: 'note', id: '1', attributes: { title: 'Plan' } } },\n },\n ],\n },\n },\n ],\n },\n {\n id: 'join-reset',\n title: 'The server answers a join with reset when it cannot replay the feed after since',\n steps: [\n ...joined('a', room('join-reset')),\n { send: { type: 'write', id: 'w1', room: room('join-reset'), op: note('Plan') } },\n { expect: { type: 'ack', ref: 'w1' } },\n ...hello('b'),\n {\n client: 'b',\n send: { type: 'join', id: 'j1', room: room('join-reset'), since: 'c99999999999999999' },\n },\n { client: 'b', expect: { type: 'ack', ref: 'j1', reset: true } },\n { client: 'b', send: { type: 'ping', id: 'p1' } },\n { client: 'b', expect: { type: 'pong', ref: 'p1' } },\n ],\n },\n {\n id: 'write-reject',\n title: 'The server sends the reject of handleWrite, with the status and the errors',\n steps: [\n ...joined('a', room('write-reject')),\n { send: { type: 'write', id: 'w1', room: room('write-reject'), op: note('') } },\n {\n expect: {\n type: 'reject',\n ref: 'w1',\n status: 422,\n errors: [{ status: '422', source: { pointer: '/data/attributes/title' } }],\n },\n },\n ],\n },\n {\n id: 'write-delete-feed',\n title: 'The server feeds an acked delete to the other members',\n steps: [\n ...joined('a', room('write-delete-feed')),\n ...joined('b', room('write-delete-feed')),\n {\n send: {\n type: 'write',\n id: 'w1',\n room: room('write-delete-feed'),\n op: { op: 'delete', ref: { type: 'note', id: '2' } },\n },\n },\n { expect: { type: 'ack', ref: 'w1' } },\n {\n client: 'b',\n expect: {\n type: 'feed',\n room: room('write-delete-feed'),\n ops: [{ op: 'delete', ref: { type: 'note', id: '2' } }],\n },\n },\n ],\n },\n {\n id: 'write-notification-shared-room',\n title: 'The server refuses a notification in a write to a room that is not a per-user room',\n steps: [\n ...joined('a', room('write-notification-shared-room')),\n {\n send: {\n type: 'write',\n id: 'w1',\n room: room('write-notification-shared-room'),\n op: { op: 'upsert', document: { data: notification('n-fake', null) } },\n },\n },\n { expect: { type: 'reject', ref: 'w1', status: 403 } },\n ],\n },\n {\n id: 'doc-update-relay',\n title: 'The server relays a doc update to the other members of the room',\n steps: [\n ...joined('a', room('doc-update-relay')),\n ...joined('b', room('doc-update-relay')),\n {\n client: 'a',\n send: { type: 'doc-update', room: room('doc-update-relay'), doc: 'body', update: 'AAEC' },\n },\n {\n client: 'b',\n expect: {\n type: 'doc-update',\n room: room('doc-update-relay'),\n doc: 'body',\n update: 'AAEC',\n },\n },\n ],\n },\n {\n id: 'doc-update-read-only',\n title: 'The server refuses a doc update without the write right, and does not store it',\n steps: [\n ...joined('a', 'conformance:read-only'),\n {\n send: {\n type: 'doc-update',\n room: 'conformance:read-only',\n doc: 'doc-update-read-only',\n update: 'AAEC',\n },\n },\n { expect: { type: 'error', code: 'forbidden' } },\n {\n send: {\n type: 'doc-sync',\n room: 'conformance:read-only',\n doc: 'doc-update-read-only',\n step: 2,\n update: 'AAED',\n },\n },\n { expect: { type: 'error', code: 'forbidden' } },\n {\n send: {\n type: 'doc-sync',\n room: 'conformance:read-only',\n doc: 'doc-update-read-only',\n step: 1,\n stateVector: 'AA==',\n },\n },\n { expect: { type: 'doc-sync', doc: 'doc-update-read-only', step: 2, update: '' } },\n ],\n },\n {\n id: 'doc-sync-empty',\n title: 'The server answers step 1 of a document with no updates with an empty step 2',\n steps: [\n ...joined('a', room('doc-sync-empty')),\n {\n send: {\n type: 'doc-sync',\n room: room('doc-sync-empty'),\n doc: 'body',\n step: 1,\n stateVector: 'AA==',\n },\n },\n {\n expect: {\n type: 'doc-sync',\n room: room('doc-sync-empty'),\n doc: 'body',\n step: 2,\n update: '',\n },\n },\n ],\n },\n {\n id: 'doc-sync-stored',\n title: 'The server answers step 1 with the updates that it stored',\n steps: [\n ...joined('a', room('doc-sync-stored')),\n {\n send: { type: 'doc-update', room: room('doc-sync-stored'), doc: 'body', update: 'AAEC' },\n },\n {\n send: {\n type: 'doc-sync',\n room: room('doc-sync-stored'),\n doc: 'body',\n step: 1,\n stateVector: 'AA==',\n },\n },\n { expect: { type: 'doc-sync', doc: 'body', step: 2, update: 'AAEC' } },\n ],\n },\n {\n id: 'doc-sync-step-2-relay',\n title: 'The server stores a step 2 of a client and relays it as a doc update',\n steps: [\n ...joined('a', room('doc-sync-step-2-relay')),\n ...joined('b', room('doc-sync-step-2-relay')),\n {\n send: {\n type: 'doc-sync',\n room: room('doc-sync-step-2-relay'),\n doc: 'body',\n step: 2,\n update: 'AAED',\n },\n },\n { client: 'b', expect: { type: 'doc-update', doc: 'body', update: 'AAED' } },\n ],\n },\n {\n id: 'awareness-relay',\n title: 'The server relays awareness to the other members of the room, with the client id',\n steps: [\n ...joined('a', room('awareness-relay')),\n ...joined('b', room('awareness-relay')),\n {\n client: 'a',\n send: { type: 'awareness', room: room('awareness-relay'), state: { typing: true } },\n },\n {\n client: 'b',\n expect: { type: 'awareness', room: room('awareness-relay'), state: { typing: true } },\n },\n ],\n },\n {\n id: 'awareness-user-id',\n title: 'The server sets state.user.id of an awareness state to the user of the session',\n steps: [\n ...joined('a', room('awareness-user-id'), 'u1'),\n ...joined('b', room('awareness-user-id'), 'u2'),\n {\n send: {\n type: 'awareness',\n room: room('awareness-user-id'),\n state: { user: { id: 'u2', name: 'Not me' } },\n },\n },\n {\n client: 'b',\n expect: { type: 'awareness', state: { user: { id: 'u1', name: 'Not me' } } },\n },\n ],\n },\n {\n id: 'awareness-not-joined',\n title: 'The server refuses awareness for a room that the client did not join',\n steps: [\n ...hello(),\n { send: { type: 'awareness', room: room('awareness-not-joined'), state: {} } },\n { expect: { type: 'error', code: 'not-joined' } },\n ],\n },\n {\n id: 'awareness-leave',\n title: 'The server removes the awareness state of a client that leaves',\n steps: [\n ...joined('a', room('awareness-leave')),\n ...joined('b', room('awareness-leave')),\n { send: { type: 'awareness', room: room('awareness-leave'), state: { typing: true } } },\n { client: 'b', expect: { type: 'awareness', state: { typing: true } } },\n { send: { type: 'leave', id: 'l1', room: room('awareness-leave') } },\n { expect: { type: 'ack', ref: 'l1' } },\n {\n client: 'b',\n expect: { type: 'awareness', room: room('awareness-leave'), state: null },\n },\n ],\n },\n {\n id: 'awareness-close',\n title: 'The server removes the awareness state of a client that disconnects',\n steps: [\n ...joined('a', room('awareness-close')),\n ...joined('b', room('awareness-close')),\n { send: { type: 'awareness', room: room('awareness-close'), state: { typing: true } } },\n { client: 'b', expect: { type: 'awareness', state: { typing: true } } },\n { close: true },\n {\n client: 'b',\n expect: { type: 'awareness', room: room('awareness-close'), state: null },\n },\n ],\n },\n {\n id: 'notify',\n title: 'The server sends a notification on the per-user room of the user',\n steps: [\n ...joined('b', 'user:u2', 'u2'),\n ...joined('a', room('notify'), 'u1'),\n { send: { type: 'write', id: 'w1', room: room('notify'), op: comment('c-notify', 'u2') } },\n { expect: { type: 'ack', ref: 'w1' } },\n {\n client: 'b',\n expect: {\n type: 'feed',\n room: 'user:u2',\n ops: [\n {\n op: 'upsert',\n document: {\n data: {\n type: 'notification',\n id: 'n-c-notify',\n attributes: { verb: 'commented', readAt: null, seenAt: null },\n relationships: {\n actor: { data: { type: 'user', id: 'u1' } },\n target: { data: { type: 'comment', id: 'c-notify' } },\n },\n },\n },\n },\n ],\n },\n },\n ],\n },\n {\n id: 'notification-mark-read',\n title: 'The server marks a notification as read on a write to the per-user room',\n steps: [\n ...joined('b', 'user:u2', 'u2'),\n ...joined('a', room('notification-mark-read'), 'u1'),\n {\n send: {\n type: 'write',\n id: 'w1',\n room: room('notification-mark-read'),\n op: comment('c-read', 'u2'),\n },\n },\n { expect: { type: 'ack', ref: 'w1' } },\n { client: 'b', expect: { type: 'feed', room: 'user:u2' } },\n {\n client: 'b',\n send: {\n type: 'write',\n id: 'w2',\n room: 'user:u2',\n op: {\n op: 'upsert',\n document: { data: notification('n-c-read', '2026-12-03T11:00:00.000Z') },\n },\n },\n },\n {\n client: 'b',\n expect: {\n type: 'ack',\n ref: 'w2',\n document: {\n data: {\n type: 'notification',\n id: 'n-c-read',\n attributes: { readAt: '2026-12-03T11:00:00.000Z' },\n },\n },\n },\n },\n ],\n },\n {\n id: 'notification-write-keeps-times',\n title: 'A notification write sets a time only when it has no value',\n steps: [\n ...joined('b', 'user:u2', 'u2'),\n ...joined('a', room('notification-write-keeps-times'), 'u1'),\n {\n send: {\n type: 'write',\n id: 'w1',\n room: room('notification-write-keeps-times'),\n op: comment('c-keep', 'u2'),\n },\n },\n { expect: { type: 'ack', ref: 'w1' } },\n { client: 'b', expect: { type: 'feed', room: 'user:u2' } },\n {\n client: 'b',\n send: {\n type: 'write',\n id: 'w2',\n room: 'user:u2',\n op: {\n op: 'upsert',\n document: { data: notification('n-c-keep', null, '2026-12-03T11:00:00.000Z') },\n },\n },\n },\n { client: 'b', expect: { type: 'ack', ref: 'w2' } },\n {\n client: 'b',\n send: {\n type: 'write',\n id: 'w3',\n room: 'user:u2',\n op: {\n op: 'upsert',\n document: { data: notification('n-c-keep', '2026-12-03T12:00:00.000Z', null) },\n },\n },\n },\n {\n client: 'b',\n expect: {\n type: 'ack',\n ref: 'w3',\n document: {\n data: {\n type: 'notification',\n id: 'n-c-keep',\n attributes: {\n readAt: '2026-12-03T12:00:00.000Z',\n archivedAt: '2026-12-03T11:00:00.000Z',\n },\n },\n },\n },\n },\n ],\n },\n {\n id: 'notification-write-partial',\n title: 'A notification write to the per-user room can send only the times that change',\n steps: [\n ...joined('b', 'user:u2', 'u2'),\n ...joined('a', room('notification-write-partial'), 'u1'),\n {\n send: {\n type: 'write',\n id: 'w1',\n room: room('notification-write-partial'),\n op: comment('c-partial', 'u2'),\n },\n },\n { expect: { type: 'ack', ref: 'w1' } },\n { client: 'b', expect: { type: 'feed', room: 'user:u2' } },\n {\n client: 'b',\n send: {\n type: 'write',\n id: 'w2',\n room: 'user:u2',\n op: {\n op: 'upsert',\n document: {\n data: {\n type: 'notification',\n id: 'n-c-partial',\n attributes: { seenAt: '2026-12-03T11:00:00.000Z' },\n },\n },\n },\n },\n },\n {\n client: 'b',\n expect: {\n type: 'ack',\n ref: 'w2',\n document: {\n data: {\n type: 'notification',\n id: 'n-c-partial',\n attributes: { verb: 'commented', seenAt: '2026-12-03T11:00:00.000Z', readAt: null },\n },\n },\n },\n },\n ],\n },\n ]\n}\n","// Runs the conformance cases against a server. A runner gives one wire client for each\n// connection of a case: a WebSocket, SSE or ActionCable transport, or any other wire.\nimport { encodeMessage } from '@dovetail-ts/protocol'\nimport type { ClientTransport } from '@dovetail-ts/protocol'\nimport type { ClientName, ConformanceCase } from './cases'\n\n/** One connection to the server under test, as text frames in and messages out. */\nexport interface WireClient {\n /** Sends one frame as it is. */\n sendText(text: string): void\n /** The next message from the server. Rejects after `timeoutMs`, or when the wire closes. */\n next(timeoutMs: number): Promise<unknown>\n close(): void\n}\n\n/** True when `actual` has each field of `expected`. Arrays must have the same length. */\nexport function matches(actual: unknown, expected: unknown): boolean {\n if (Array.isArray(expected)) {\n return (\n Array.isArray(actual) &&\n actual.length === expected.length &&\n expected.every((item, i) => matches(actual[i], item))\n )\n }\n if (typeof expected === 'object' && expected !== null) {\n if (typeof actual !== 'object' || actual === null || Array.isArray(actual)) return false\n return Object.entries(expected).every(\n ([key, value]) => key in actual && matches((actual as Record<string, unknown>)[key], value),\n )\n }\n return Object.is(actual, expected)\n}\n\nexport interface RunOptions {\n /** The time to wait for each expected message. Default 5000 ms. */\n timeoutMs?: number\n}\n\n/** Runs one case. Throws an error that names the step when the server does not conform. */\nexport async function runCase(\n c: ConformanceCase,\n connect: (client: ClientName) => Promise<WireClient>,\n options: RunOptions = {},\n): Promise<void> {\n const wires = new Map<ClientName, WireClient>()\n const wire = async (name: ClientName) => {\n let found = wires.get(name)\n if (!found) wires.set(name, (found = await connect(name)))\n return found\n }\n try {\n for (const [index, step] of c.steps.entries()) {\n const client = await wire(step.client ?? 'a')\n const where = `${c.id}: step ${index + 1} (client ${step.client ?? 'a'})`\n if ('send' in step) client.sendText(encodeMessage(step.send))\n else if ('sendRaw' in step) client.sendText(step.sendRaw)\n else if ('close' in step) client.close()\n else {\n let actual: unknown\n try {\n actual = await client.next(options.timeoutMs ?? 5000)\n } catch (error) {\n throw new Error(`${where}: expected ${JSON.stringify(step.expect)}, but ${error}`, {\n cause: error,\n })\n }\n if (!matches(actual, step.expect)) {\n throw new Error(\n `${where}: expected ${JSON.stringify(step.expect)}, got ${JSON.stringify(actual)}`,\n )\n }\n }\n }\n } finally {\n for (const client of wires.values()) client.close()\n }\n}\n\n/** A transport with a raw send, as the Dovetail transports have. */\nexport type TextTransport = ClientTransport & { sendText(text: string): void }\n\n/** Opens a transport and makes it a wire client. */\nexport async function transportWire(transport: TextTransport): Promise<WireClient> {\n const queue: unknown[] = []\n const waiters: { resolve(m: unknown): void; reject(e: Error): void }[] = []\n let closed: string | undefined\n transport.onMessage(message => {\n const waiter = waiters.shift()\n if (waiter) waiter.resolve(message)\n else queue.push(message)\n })\n transport.onClose(info => {\n closed = `the connection closed (${info.code} ${info.reason})`\n for (const waiter of waiters.splice(0)) waiter.reject(new Error(closed))\n })\n await transport.open()\n return {\n sendText: text => transport.sendText(text),\n close: () => transport.close(),\n next: timeoutMs =>\n new Promise((resolve, reject) => {\n if (queue.length > 0) return resolve(queue.shift())\n if (closed) return reject(new Error(closed))\n const waiter = {\n resolve: (m: unknown) => {\n clearTimeout(timer)\n resolve(m)\n },\n reject: (e: Error) => {\n clearTimeout(timer)\n reject(e)\n },\n }\n const timer = setTimeout(() => {\n waiters.splice(waiters.indexOf(waiter), 1)\n reject(new Error(`no message in ${timeoutMs} ms`))\n }, timeoutMs)\n waiters.push(waiter)\n }),\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { ClientTransport } from '@dovetail-ts/protocol';
2
+ import type { ClientName, ConformanceCase } from './cases';
3
+ /** One connection to the server under test, as text frames in and messages out. */
4
+ export interface WireClient {
5
+ /** Sends one frame as it is. */
6
+ sendText(text: string): void;
7
+ /** The next message from the server. Rejects after `timeoutMs`, or when the wire closes. */
8
+ next(timeoutMs: number): Promise<unknown>;
9
+ close(): void;
10
+ }
11
+ /** True when `actual` has each field of `expected`. Arrays must have the same length. */
12
+ export declare function matches(actual: unknown, expected: unknown): boolean;
13
+ export interface RunOptions {
14
+ /** The time to wait for each expected message. Default 5000 ms. */
15
+ timeoutMs?: number;
16
+ }
17
+ /** Runs one case. Throws an error that names the step when the server does not conform. */
18
+ export declare function runCase(c: ConformanceCase, connect: (client: ClientName) => Promise<WireClient>, options?: RunOptions): Promise<void>;
19
+ /** A transport with a raw send, as the Dovetail transports have. */
20
+ export type TextTransport = ClientTransport & {
21
+ sendText(text: string): void;
22
+ };
23
+ /** Opens a transport and makes it a wire client. */
24
+ export declare function transportWire(transport: TextTransport): Promise<WireClient>;
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@dovetail-ts/conformance",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "The protocol conformance suite. It runs against any Dovetail server URL.",
5
+ "license": "MIT",
6
+ "author": "Joe Gaudet <joe@joegaudet.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/joegaudet/dovetail.git",
10
+ "directory": "packages/conformance"
11
+ },
12
+ "homepage": "https://joegaudet.com/dovetail/",
13
+ "bugs": "https://github.com/joegaudet/dovetail/issues",
14
+ "keywords": [
15
+ "realtime",
16
+ "offline",
17
+ "sync",
18
+ "crdt"
19
+ ],
20
+ "type": "module",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "CHANGELOG.md",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "dependencies": {
37
+ "@dovetail-ts/protocol": "1.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "tsup": "^8.5.1"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "engines": {
46
+ "node": ">=22.12.0"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc --build --force && tsup"
50
+ }
6
51
  }