@zsailer/jupyter-server-side-documents-conformance 0.0.0-stage → 0.0.3

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,450 @@
1
+ // GENERATED by compliance/generate.py from the storyboards. Do not edit: change the storyboard, or oracle.yaml, and generate again.
2
+ import { test } from '@jupyterlab/galata';
3
+ import { E, story } from '../../runtime/story';
4
+
5
+ // A person has the notebook open in a tab, so the server holds it. The agent does not touch the file: it edits the server's live copy, and everybody who has the notebook sees the change as it happens.
6
+ test(
7
+ ...story(
8
+ {
9
+ "id": "AI1",
10
+ "group": "ai",
11
+ "title": "An AI agent edits a notebook that is open",
12
+ "requires": [
13
+ "agent"
14
+ ]
15
+ },
16
+ async s => {
17
+ await s.notebook(["c0", "c1", "c2"]);
18
+ const tab = s.tab("tab");
19
+
20
+ await s.step(1, "Your tab", "opens the notebook", async () => {
21
+ await tab.open();
22
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
23
+ });
24
+ await s.step(2, "AI agent", "rewrites c1 as “fixed” through the server, which holds the notebook", async () => {
25
+ await s.agent("rewrites c1 as “fixed” through the server, which holds the notebook", ["c0", "fixed", "c2"]);
26
+ });
27
+ await s.step(3, "Server", "applies the edit to its live copy", async () => {
28
+ // nothing for a test to do: the storyboard states what is so
29
+ });
30
+ await s.step(4, "Your tab", "sees the edit as it happens; nothing to reload", async () => {
31
+ await s.expectTabEventually(tab, ["c0", "fixed", "c2"]);
32
+ });
33
+ await s.step(5, "File on disk", "autosave", async () => {
34
+ // nothing for a test to do: the storyboard states what is so
35
+ });
36
+
37
+ await s.ends([
38
+ { label: "As the story ends", ends: { tab: ["c0", "fixed", "c2"], server: ["c0", "fixed", "c2"], file: ["c0", "fixed", "c2"] } },
39
+ ]);
40
+ }
41
+ )
42
+ );
43
+
44
+ // No tab has the notebook and the server does not hold it. The agent edits the file directly. The next person who opens the notebook finds the agent's work.
45
+ test(
46
+ ...story(
47
+ {
48
+ "id": "AI2",
49
+ "group": "ai",
50
+ "title": "An AI agent edits a notebook that nobody has open",
51
+ "requires": [
52
+ "agent",
53
+ "fileSystem",
54
+ "releaseRoom"
55
+ ]
56
+ },
57
+ async s => {
58
+ await s.notebook(["c0", "c1", "c2"]);
59
+ const tab = s.tab("tab");
60
+
61
+ await s.step(1, "AI agent", "edits the file directly: rewrites c1 as “fixed” and adds a cell “tests”", async () => {
62
+ await s.agent("edits the file directly: rewrites c1 as “fixed” and adds a cell “tests”", ["c0", "fixed", "c2", "tests"]);
63
+ });
64
+ await s.step(2, "File on disk", "now holds the agent's changes", async () => {
65
+ await s.writeFileOutside(["c0", "fixed", "c2", "tests"]);
66
+ });
67
+ await s.step(3, "Your tab", "later, a person opens the notebook", async () => {
68
+ await tab.open();
69
+ await s.expectTab(tab, ["c0", "fixed", "c2", "tests"]);
70
+ });
71
+ await s.step(4, "Server", "builds the notebook from the file, with the agent's changes", async () => {
72
+ await s.releaseRoom();
73
+ });
74
+ await s.step(5, "Your tab", "sees the agent's changes", async () => {
75
+ await s.expectTabEventually(tab, ["c0", "fixed", "c2", "tests"]);
76
+ });
77
+
78
+ await s.ends([
79
+ { label: "As the story ends", ends: { tab: ["c0", "fixed", "c2", "tests"], file: ["c0", "fixed", "c2", "tests"] } },
80
+ ]);
81
+ }
82
+ )
83
+ );
84
+
85
+ // The agent starts while nobody has the notebook open, so it edits the file. Then a person opens the notebook, and the agent's next edit goes through the server, which now holds it.
86
+ test(
87
+ ...story(
88
+ {
89
+ "id": "AI3",
90
+ "group": "ai",
91
+ "title": "A person opens the notebook in the middle of the agent's work",
92
+ "requires": [
93
+ "agent",
94
+ "fileSystem",
95
+ "releaseRoom"
96
+ ]
97
+ },
98
+ async s => {
99
+ await s.notebook(["c0", "c1", "c2"]);
100
+ const tab = s.tab("tab");
101
+
102
+ await s.step(1, "AI agent", "edits the file directly: rewrites c1 as “fixed”", async () => {
103
+ await s.agent("edits the file directly: rewrites c1 as “fixed”", ["c0", "fixed", "c2"]);
104
+ });
105
+ await s.step(2, "File on disk", "now holds the first change", async () => {
106
+ await s.writeFileOutside(["c0", "fixed", "c2"]);
107
+ });
108
+ await s.step(3, "Your tab", "a person opens the notebook", async () => {
109
+ await tab.open();
110
+ await s.expectTab(tab, ["c0", "fixed", "c2"]);
111
+ });
112
+ await s.step(4, "Server", "builds the notebook from the file, with the first change; it now holds the notebook", async () => {
113
+ await s.releaseRoom();
114
+ });
115
+ await s.step(5, "Your tab", "sees the notebook with the first change", async () => {
116
+ await s.expectTabEventually(tab, ["c0", "fixed", "c2"]);
117
+ });
118
+ await s.step(6, "AI agent", "adds a cell “tests” through the server, which now holds the notebook", async () => {
119
+ await s.agent("adds a cell “tests” through the server, which now holds the notebook", ["c0", "fixed", "c2", "tests"]);
120
+ });
121
+ await s.step(7, "Server", "applies the edit to its live copy", async () => {
122
+ // nothing for a test to do: the storyboard states what is so
123
+ });
124
+ await s.step(8, "Your tab", "sees the new cell as it happens", async () => {
125
+ await s.expectTabEventually(tab, ["c0", "fixed", "c2", "tests"]);
126
+ });
127
+ await s.step(9, "File on disk", "autosave", async () => {
128
+ // nothing for a test to do: the storyboard states what is so
129
+ });
130
+
131
+ await s.ends([
132
+ { label: "As the story ends", ends: { tab: ["c0", "fixed", "c2", "tests"], file: ["c0", "fixed", "c2", "tests"] } },
133
+ ]);
134
+ }
135
+ )
136
+ );
137
+
138
+ // The agent edits the live copy while a person has the notebook open. The person closes the tab, but the server keeps holding the notebook for a few minutes, so the agent's next edit still goes through the server. Later the server lets go of the notebook, and the agent's last edit goes to the file. When the person comes back, all three changes are there.
139
+ test(
140
+ ...story(
141
+ {
142
+ "id": "AI4",
143
+ "group": "ai",
144
+ "title": "The last person leaves in the middle of the agent's work",
145
+ "requires": [
146
+ "agent",
147
+ "fileSystem",
148
+ "releaseRoom"
149
+ ]
150
+ },
151
+ async s => {
152
+ await s.notebook(["c0", "c1", "c2"]);
153
+ const tab = s.tab("tab");
154
+
155
+ await s.step(1, "Your tab", "opens the notebook", async () => {
156
+ await tab.open();
157
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
158
+ });
159
+ await s.step(2, "AI agent", "rewrites c1 as “fixed” through the server", async () => {
160
+ await s.agent("rewrites c1 as “fixed” through the server", ["c0", "fixed", "c2"]);
161
+ });
162
+ await s.step(3, "Server", "applies the edit; the tab sees it", async () => {
163
+ // nothing for a test to do: the storyboard states what is so
164
+ });
165
+ await s.step(4, "Your tab", "the person closes the tab", async () => {
166
+ await tab.close();
167
+ });
168
+ await s.step(5, "AI agent", "a minute later the server still holds the notebook, so the agent adds a cell “tests” through it", async () => {
169
+ await s.agent("a minute later the server still holds the notebook, so the agent adds a cell “tests” through it", ["c0", "fixed", "c2", "tests"]);
170
+ });
171
+ await s.step(6, "Server", "applies the edit to its live copy", async () => {
172
+ // nothing for a test to do: the storyboard states what is so
173
+ });
174
+ await s.step(7, "Server", "lets go of the notebook, saving it", async () => {
175
+ await s.releaseRoom();
176
+ });
177
+ await s.step(8, "File on disk", "holds both changes", async () => {
178
+ await s.expectFile(["c0", "fixed", "c2", "tests"]);
179
+ });
180
+ await s.step(9, "AI agent", "now the server does not hold the notebook, so the agent edits the file: adds a cell “docs”", async () => {
181
+ await s.agent("now the server does not hold the notebook, so the agent edits the file: adds a cell “docs”", ["c0", "fixed", "c2", "tests", "docs"]);
182
+ });
183
+ await s.step(10, "File on disk", "holds the third change", async () => {
184
+ await s.writeFileOutside(["c0", "fixed", "c2", "tests", "docs"]);
185
+ });
186
+ await s.step(11, "Your tab", "the person opens the notebook again", async () => {
187
+ await tab.open();
188
+ await s.expectTab(tab, ["c0", "fixed", "c2", "tests", "docs"]);
189
+ });
190
+ await s.step(12, "Server", "builds the notebook from the file: all three changes are there", async () => {
191
+ await s.releaseRoom();
192
+ });
193
+
194
+ await s.ends([
195
+ { label: "As the story ends", ends: { tab: ["c0", "fixed", "c2", "tests", "docs"], file: ["c0", "fixed", "c2", "tests", "docs"] } },
196
+ ]);
197
+ }
198
+ )
199
+ );
200
+
201
+ // A person is typing at the end of c1 in a tab. At the same moment the agent, through the server, rewrites c1 as “fixed”.
202
+ test(
203
+ ...story(
204
+ {
205
+ "id": "AI5",
206
+ "group": "ai",
207
+ "title": "The agent rewrites a cell while a person is typing in it",
208
+ "requires": [
209
+ "agent"
210
+ ],
211
+ "needsAlignment": true
212
+ },
213
+ async s => {
214
+ await s.notebook(["c0", "c1", "c2"]);
215
+ const tab = s.tab("tab");
216
+
217
+ await s.step(1, "Your tab", "opens the notebook", async () => {
218
+ await tab.open();
219
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
220
+ });
221
+ await s.step(2, "Your tab", "types “# check” at the end of c1", async () => {
222
+ await tab.type(1, " +# check");
223
+ await s.settle(tab);
224
+ await s.expectTab(tab, ["c0", "c1 +# check", "c2"]);
225
+ });
226
+ await s.step(3, "AI agent", "at the same moment rewrites c1 as “fixed” through the server", async () => {
227
+ await s.agent("at the same moment rewrites c1 as “fixed” through the server", ["c0", "fixed +# check", "c2"]);
228
+ });
229
+ await s.step(4, "Server", "merges the two edits", async () => {
230
+ // nothing for a test to do: the storyboard states what is so
231
+ });
232
+ await s.step(5, "Your tab", "sees the merged cell", async () => {
233
+ await s.expectTabEventually(tab, ["c0", "fixed +# check", "c2"]);
234
+ });
235
+ await s.step(6, "File on disk", "autosave", async () => {
236
+ // nothing for a test to do: the storyboard states what is so
237
+ });
238
+
239
+ await s.ends([
240
+ { label: "Both are kept", ends: { tab: ["c0", "fixed +# check", "c2"], server: ["c0", "fixed +# check", "c2"], file: ["c0", "fixed +# check", "c2"] } },
241
+ { label: "The agent waits", ends: { tab: ["c0", "c1 +# check", "c2"], server: ["c0", "c1 +# check", "c2"], file: ["c0", "c1 +# check", "c2"] } },
242
+ { label: "The person decides", ends: { tab: ["c0", "c1 +# check", "c2"], server: ["c0", "c1 +# check", "c2"], file: ["c0", "c1 +# check", "c2"] } },
243
+ ]);
244
+ }
245
+ )
246
+ );
247
+
248
+ // A person's tab loses its connection and they type into c1. Meanwhile the agent, through the server, deletes c1. Then the tab reconnects. This is the story Z3 with an agent as the one who deletes.
249
+ test(
250
+ ...story(
251
+ {
252
+ "id": "AI6",
253
+ "group": "ai",
254
+ "title": "The agent deletes a cell that a person edited while offline",
255
+ "requires": [
256
+ "agent"
257
+ ],
258
+ "needsAlignment": true
259
+ },
260
+ async s => {
261
+ await s.notebook(["c0", "c1", "c2"]);
262
+ const tab = s.tab("tab");
263
+
264
+ await s.step(1, "Your tab", "opens the notebook", async () => {
265
+ await tab.open();
266
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
267
+ });
268
+ await s.step(2, "Your tab", "loses its connection", async () => {
269
+ await tab.goOffline();
270
+ });
271
+ await s.step(3, "Your tab", "types “+B-TYPED” at the end of c1", async () => {
272
+ await tab.type(1, " +B-TYPED");
273
+ await s.expectTab(tab, ["c0", "c1 +B-TYPED", "c2"]);
274
+ });
275
+ await s.step(4, "AI agent", "meanwhile deletes c1 through the server", async () => {
276
+ await s.agent("meanwhile deletes c1 through the server", ["c0", "c2"]);
277
+ });
278
+ await s.step(5, "Server", "applies the deletion", async () => {
279
+ // nothing for a test to do: the storyboard states what is so
280
+ });
281
+ await s.step(6, "Your tab", "reconnects", async () => {
282
+ await tab.goOnline();
283
+ });
284
+ await s.step(7, "File on disk", "autosave", async () => {
285
+ // nothing for a test to do: the storyboard states what is so
286
+ });
287
+
288
+ await s.ends([
289
+ { label: "The deletion wins, as for a person", ends: { tab: ["c0", "c2"], server: ["c0", "c2"], file: ["c0", "c2"] } },
290
+ { label: "The typing is kept as a recovered copy", ends: { tab: ["c0", E.contains("c1", "+B-TYPED"), "c2"], server: ["c0", E.contains("c1", "+B-TYPED"), "c2"], file: ["c0", E.contains("c1", "+B-TYPED"), "c2"] } },
291
+ ]);
292
+ }
293
+ )
294
+ );
295
+
296
+ // Nobody has the notebook open, but the server still holds it, so the agent edits the live copy and is told that it worked. The server then dies before the next autosave. When the server starts again, the agent's edit is either in the file or gone.
297
+ test(
298
+ ...story(
299
+ {
300
+ "id": "AI7",
301
+ "group": "ai",
302
+ "title": "The server dies after the agent's edit, before the next autosave",
303
+ "requires": [
304
+ "agent",
305
+ "crashServer"
306
+ ],
307
+ "needsAlignment": true
308
+ },
309
+ async s => {
310
+ await s.notebook(["c0", "c1", "c2"]);
311
+ const tab = s.tab("tab");
312
+
313
+ await s.step(1, "Your tab", "opens the notebook", async () => {
314
+ await tab.open();
315
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
316
+ });
317
+ await s.step(2, "Your tab", "the person closes the tab; the server still holds the notebook", async () => {
318
+ await tab.close();
319
+ });
320
+ await s.step(3, "AI agent", "rewrites c1 as “fixed” through the server", async () => {
321
+ await s.agent("rewrites c1 as “fixed” through the server", ["c0", "fixed", "c2"]);
322
+ });
323
+ await s.step(4, "Server", "applies the edit and saves it to the file before telling the agent that it worked", async () => {
324
+ // nothing for a test to do: the storyboard states what is so
325
+ });
326
+ await s.step(5, "File on disk", "holds the edit", async () => {
327
+ await s.expectFile(["c0", "fixed", "c2"]);
328
+ });
329
+ await s.step(6, "Server", "dies before the next autosave", async () => {
330
+ await s.crashServer();
331
+ });
332
+ await s.step(7, "Server", "starts again from the file", async () => {
333
+ await s.restartServer();
334
+ });
335
+ await s.step(8, "Your tab", "later, a person opens the notebook", async () => {
336
+ await tab.open();
337
+ await s.expectTab(tab, ["c0", "fixed", "c2"]);
338
+ });
339
+
340
+ await s.ends([
341
+ { label: "The agent is told after the edit is saved", ends: { tab: ["c0", "fixed", "c2"], server: ["c0", "fixed", "c2"], file: ["c0", "fixed", "c2"] } },
342
+ { label: "The same bound as typing", ends: { tab: ["c0", "c1", "c2"], server: ["c0", "c1", "c2"], file: ["c0", "c1", "c2"] } },
343
+ ]);
344
+ }
345
+ )
346
+ );
347
+
348
+ // The agent rewrites the file directly while nobody has the notebook open. Before the write is finished, a person opens the notebook and the server reads the file.
349
+ test(
350
+ ...story(
351
+ {
352
+ "id": "AI8",
353
+ "group": "ai",
354
+ "title": "The agent is still writing the file when the server reads it",
355
+ "requires": [
356
+ "agent",
357
+ "fileSystem",
358
+ "releaseRoom",
359
+ "wireFaults"
360
+ ]
361
+ },
362
+ async s => {
363
+ await s.notebook(["c0", "c1", "c2"]);
364
+ const tab = s.tab("tab");
365
+
366
+ await s.step(1, "AI agent", "starts to rewrite the file; the write is not finished", async () => {
367
+ await s.agent("starts to rewrite the file; the write is not finished", ["c0", "fixed", "c2", "tests"]);
368
+ });
369
+ await s.step(2, "File on disk", "is half written: it cannot be read yet", async () => {
370
+ await s.writeFileOutside(["c0", "c1", "c2"]);
371
+ // half written
372
+ });
373
+ await s.step(3, "Your tab", "a person opens the notebook", async () => {
374
+ await tab.open();
375
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
376
+ });
377
+ await s.step(4, "Server", "finds a file it cannot read yet, and waits instead of showing an empty or broken notebook", async () => {
378
+ // finds a file it cannot read yet, and waits instead of showing an empty or broken notebook: the backend's adapter causes this
379
+ });
380
+ await s.step(5, "AI agent", "finishes writing the file: c1 is “fixed” and a cell “tests” is added", async () => {
381
+ await s.agent("finishes writing the file: c1 is “fixed” and a cell “tests” is added", ["c0", "fixed", "c2", "tests"]);
382
+ });
383
+ await s.step(6, "File on disk", "holds the agent's finished work", async () => {
384
+ await s.writeFileOutside(["c0", "fixed", "c2", "tests"]);
385
+ });
386
+ await s.step(7, "Server", "reads the finished file", async () => {
387
+ await s.releaseRoom();
388
+ });
389
+ await s.step(8, "Your tab", "receives the notebook", async () => {
390
+ await s.expectTabEventually(tab, ["c0", "fixed", "c2", "tests"]);
391
+ });
392
+
393
+ await s.ends([
394
+ { label: "As the story ends", ends: { tab: ["c0", "fixed", "c2", "tests"], file: ["c0", "fixed", "c2", "tests"] } },
395
+ ]);
396
+ }
397
+ )
398
+ );
399
+
400
+ // A person types and closes the tab a moment later. The server still holds the notebook, with typing it has not saved yet. The agent takes the notebook for closed and edits the file directly. This depends on the answer to Z5, the same question while the tab is still open.
401
+ test(
402
+ ...story(
403
+ {
404
+ "id": "AI9",
405
+ "group": "ai",
406
+ "title": "The agent writes the file although the server still holds the notebook",
407
+ "requires": [
408
+ "agent",
409
+ "fileSystem"
410
+ ]
411
+ },
412
+ async s => {
413
+ await s.notebook(["c0", "c1", "c2"]);
414
+ const tab = s.tab("tab");
415
+
416
+ await s.step(1, "Your tab", "opens the notebook", async () => {
417
+ await tab.open();
418
+ await s.expectTab(tab, ["c0", "c1", "c2"]);
419
+ });
420
+ await s.step(2, "Your tab", "types “+TYPED” at the end of c0; the server has not saved it yet", async () => {
421
+ await tab.type(0, " +TYPED");
422
+ await s.settle(tab);
423
+ await s.expectTab(tab, ["c0 +TYPED", "c1", "c2"]);
424
+ });
425
+ await s.step(3, "Your tab", "the person closes the tab; the server still holds the notebook and the typing", async () => {
426
+ await tab.close();
427
+ });
428
+ await s.step(4, "AI agent", "takes the notebook for closed and edits the file directly: rewrites c2 as “fixed”", async () => {
429
+ await s.agent("takes the notebook for closed and edits the file directly: rewrites c2 as “fixed”", ["c0", "c1", "fixed"]);
430
+ });
431
+ await s.step(5, "File on disk", "is changed", async () => {
432
+ await s.writeFileOutside(["c0", "c1", "fixed"]);
433
+ });
434
+ await s.step(6, "Server", "notices the change before it saves, and merges it with the typing it holds", async () => {
435
+ // nothing for a test to do: the storyboard states what is so
436
+ });
437
+ await s.step(7, "File on disk", "holds both", async () => {
438
+ // nothing for a test to do: the storyboard states what is so
439
+ });
440
+ await s.step(8, "Your tab", "later, a person opens the notebook", async () => {
441
+ await tab.open();
442
+ await s.expectTab(tab, ["c0 +TYPED", "c1", "fixed"]);
443
+ });
444
+
445
+ await s.ends([
446
+ { label: "As the story ends", ends: { tab: ["c0 +TYPED", "c1", "fixed"], server: ["c0 +TYPED", "c1", "fixed"], file: ["c0 +TYPED", "c1", "fixed"] } },
447
+ ]);
448
+ }
449
+ )
450
+ );