@ftrdotdev/pi-tracker 0.7.0 → 0.9.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.
@@ -1,24 +1,33 @@
1
1
  import { assert, layer } from "@effect/vitest";
2
2
  import { Effect, Option, Result } from "effect";
3
- import {
4
- TodoList,
5
- TrackerState,
6
- decodeStateEffect,
7
- emptyState,
8
- encodeState,
9
- migrateState,
10
- } from "./domain.ts";
3
+ import { TodoList, TrackerState, decodeStateEffect, encodeState, migrateState } from "./domain.ts";
11
4
  import { TrackerStore } from "./store.ts";
12
5
 
13
6
  /**
14
- * The suite shares one `TrackerStore.layer` (one `Ref`), so every test starts
15
- * from a known state via `reset(emptyState())`.
7
+ * `buildPerTest` gives every case its own store (`TrackerStore.layer` builds one
8
+ * `Ref` per build), so no case can leak state into the next (D14).
16
9
  */
17
- layer(TrackerStore.layer)("TrackerStore", (it) => {
10
+ layer(TrackerStore.layer, { buildPerTest: true })("TrackerStore", (it) => {
11
+ // Fresh-store law (D14): the harness must build one store per test, so an
12
+ // earlier case cannot leak a list into this one.
13
+ it.effect("each test starts from an empty store (seed)", () =>
14
+ Effect.gen(function* () {
15
+ const store = yield* TrackerStore;
16
+ yield* store.createList("Work");
17
+ assert.strictEqual((yield* store.state).lists.length, 1);
18
+ }),
19
+ );
20
+
21
+ it.effect("each test starts from an empty store", () =>
22
+ Effect.gen(function* () {
23
+ const store = yield* TrackerStore;
24
+ assert.strictEqual((yield* store.state).lists.length, 0);
25
+ }),
26
+ );
27
+
18
28
  it.effect("createList adds a list and advances the counter", () =>
19
29
  Effect.gen(function* () {
20
30
  const store = yield* TrackerStore;
21
- yield* store.reset(emptyState());
22
31
 
23
32
  const list = yield* store.createList("Work");
24
33
  assert.strictEqual(list.id, 1);
@@ -34,7 +43,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
34
43
  it.effect("createList trims whitespace", () =>
35
44
  Effect.gen(function* () {
36
45
  const store = yield* TrackerStore;
37
- yield* store.reset(emptyState());
38
46
 
39
47
  const list = yield* store.createList(" Work ");
40
48
  assert.strictEqual(list.name, "Work");
@@ -44,12 +52,11 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
44
52
  it.effect("createList rejects empty names", () =>
45
53
  Effect.gen(function* () {
46
54
  const store = yield* TrackerStore;
47
- yield* store.reset(emptyState());
48
55
 
49
56
  for (const bad of ["", " "]) {
50
57
  const result = yield* Effect.result(store.createList(bad));
51
- assert(Result.isFailure(result), `expected "${bad}" to be rejected`);
52
- const failure = Option.getOrThrow(Result.getFailure(result));
58
+ if (!Result.isFailure(result)) assert.fail(`expected "${bad}" to be rejected`);
59
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
53
60
  assert.strictEqual(failure.reason, "EmptyText");
54
61
  assert.strictEqual(failure._tag, "TrackerError");
55
62
  }
@@ -59,12 +66,14 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
59
66
  it.effect("createList rejects duplicate names (case-sensitive)", () =>
60
67
  Effect.gen(function* () {
61
68
  const store = yield* TrackerStore;
62
- yield* store.reset(emptyState());
63
69
 
64
70
  yield* store.createList("Work");
65
71
  const result = yield* Effect.result(store.createList("Work"));
66
- assert(Result.isFailure(result));
67
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "DuplicateListName");
72
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
73
+ assert.strictEqual(
74
+ Result.getFailure(result).pipe(Option.getOrThrow).reason,
75
+ "DuplicateListName",
76
+ );
68
77
 
69
78
  // Different case is a different name.
70
79
  const other = yield* store.createList("work");
@@ -75,7 +84,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
75
84
  it.effect("createList makes the first list active", () =>
76
85
  Effect.gen(function* () {
77
86
  const store = yield* TrackerStore;
78
- yield* store.reset(emptyState());
79
87
 
80
88
  const list = yield* store.createList("Work");
81
89
  const state = yield* store.state;
@@ -86,7 +94,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
86
94
  it.effect("createList switches to the new list by default (activate opt-out)", () =>
87
95
  Effect.gen(function* () {
88
96
  const store = yield* TrackerStore;
89
- yield* store.reset(emptyState());
90
97
 
91
98
  const a = yield* store.createList("A");
92
99
  const b = yield* store.createList("B");
@@ -98,7 +105,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
98
105
  it.effect("createList with activate=false keeps the current active list", () =>
99
106
  Effect.gen(function* () {
100
107
  const store = yield* TrackerStore;
101
- yield* store.reset(emptyState());
102
108
 
103
109
  const a = yield* store.createList("A");
104
110
  yield* store.createList("B", { activate: false });
@@ -109,7 +115,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
109
115
  it.effect("createList with activate=false on an empty state leaves no active list", () =>
110
116
  Effect.gen(function* () {
111
117
  const store = yield* TrackerStore;
112
- yield* store.reset(emptyState());
113
118
 
114
119
  yield* store.createList("A", { activate: false });
115
120
  assert.strictEqual((yield* store.state).activeListId, null);
@@ -119,7 +124,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
119
124
  it.effect("createList with initial items creates the list with its items in one call", () =>
120
125
  Effect.gen(function* () {
121
126
  const store = yield* TrackerStore;
122
- yield* store.reset(emptyState());
123
127
 
124
128
  const list = yield* store.createList("Work", { initialItems: ["a", "b"] });
125
129
  assert.strictEqual(list.id, 1);
@@ -140,7 +144,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
140
144
  it.effect("createList trims initial item texts", () =>
141
145
  Effect.gen(function* () {
142
146
  const store = yield* TrackerStore;
143
- yield* store.reset(emptyState());
144
147
 
145
148
  const list = yield* store.createList("Work", { initialItems: [" a ", "b"] });
146
149
  assert.deepStrictEqual(
@@ -153,15 +156,15 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
153
156
  it.effect("createList rejects empty initial item texts atomically", () =>
154
157
  Effect.gen(function* () {
155
158
  const store = yield* TrackerStore;
156
- yield* store.reset(emptyState());
157
159
 
158
160
  const before = yield* store.state;
159
161
  for (const bad of [["a", ""], ["a", " "], [""]]) {
160
162
  const result = yield* Effect.result(store.createList("Work", { initialItems: bad }));
161
- assert(Result.isFailure(result), JSON.stringify(bad));
162
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "EmptyText");
163
+ if (!Result.isFailure(result)) assert.fail(JSON.stringify(bad));
164
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "EmptyText");
163
165
  // No list, no items, no counter movement.
164
- assert.deepStrictEqual(yield* store.state, before);
166
+ const after = yield* store.state;
167
+ assert.deepStrictEqual(after, before);
165
168
  }
166
169
  }),
167
170
  );
@@ -169,7 +172,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
169
172
  it.effect("createList with initial items and activate=false keeps the previous active list", () =>
170
173
  Effect.gen(function* () {
171
174
  const store = yield* TrackerStore;
172
- yield* store.reset(emptyState());
173
175
 
174
176
  const a = yield* store.createList("A");
175
177
  const b = yield* store.createList("B", { initialItems: ["x"], activate: false });
@@ -182,19 +184,20 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
182
184
  it.effect("createList rejects duplicate names even with initial items", () =>
183
185
  Effect.gen(function* () {
184
186
  const store = yield* TrackerStore;
185
- yield* store.reset(emptyState());
186
187
 
187
188
  yield* store.createList("Work");
188
189
  const result = yield* Effect.result(store.createList("Work", { initialItems: ["x"] }));
189
- assert(Result.isFailure(result));
190
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "DuplicateListName");
190
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
191
+ assert.strictEqual(
192
+ Result.getFailure(result).pipe(Option.getOrThrow).reason,
193
+ "DuplicateListName",
194
+ );
191
195
  }),
192
196
  );
193
197
 
194
198
  it.effect("deleting the active list clears it; creating again re-activates", () =>
195
199
  Effect.gen(function* () {
196
200
  const store = yield* TrackerStore;
197
- yield* store.reset(emptyState());
198
201
 
199
202
  const a = yield* store.createList("A");
200
203
  yield* store.deleteList(a.id);
@@ -208,7 +211,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
208
211
  it.effect("setActiveList with null clears the active list (deselect)", () =>
209
212
  Effect.gen(function* () {
210
213
  const store = yield* TrackerStore;
211
- yield* store.reset(emptyState());
212
214
 
213
215
  yield* store.createList("A");
214
216
  yield* store.setActiveList(null);
@@ -219,7 +221,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
219
221
  it.effect("deleteList removes the list and resets the active pointer", () =>
220
222
  Effect.gen(function* () {
221
223
  const store = yield* TrackerStore;
222
- yield* store.reset(emptyState());
223
224
 
224
225
  const a = yield* store.createList("A");
225
226
  yield* store.createList("B");
@@ -236,7 +237,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
236
237
  it.effect("deleteList keeps the active pointer when deleting another list", () =>
237
238
  Effect.gen(function* () {
238
239
  const store = yield* TrackerStore;
239
- yield* store.reset(emptyState());
240
240
 
241
241
  const a = yield* store.createList("A");
242
242
  const b = yield* store.createList("B");
@@ -251,11 +251,10 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
251
251
  it.effect("deleteList fails for an unknown list", () =>
252
252
  Effect.gen(function* () {
253
253
  const store = yield* TrackerStore;
254
- yield* store.reset(emptyState());
255
254
 
256
255
  const result = yield* Effect.result(store.deleteList(99));
257
- assert(Result.isFailure(result));
258
- const failure = Option.getOrThrow(Result.getFailure(result));
256
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
257
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
259
258
  assert.strictEqual(failure.reason, "ListNotFound");
260
259
  assert.strictEqual(failure.listId, 99); // optional field populated
261
260
  }),
@@ -264,7 +263,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
264
263
  it.effect("setActiveList accepts null to clear and rejects unknown ids", () =>
265
264
  Effect.gen(function* () {
266
265
  const store = yield* TrackerStore;
267
- yield* store.reset(emptyState());
268
266
 
269
267
  const a = yield* store.createList("A");
270
268
  yield* store.setActiveList(a.id);
@@ -274,15 +272,14 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
274
272
  assert.strictEqual((yield* store.state).activeListId, null);
275
273
 
276
274
  const bad = yield* Effect.result(store.setActiveList(7));
277
- assert(Result.isFailure(bad));
278
- assert.strictEqual(Option.getOrThrow(Result.getFailure(bad)).reason, "ListNotFound");
275
+ if (!Result.isFailure(bad)) assert.fail("expected a failure");
276
+ assert.strictEqual(Result.getFailure(bad).pipe(Option.getOrThrow).reason, "ListNotFound");
279
277
  }),
280
278
  );
281
279
 
282
280
  it.effect("addItem appends a pending item", () =>
283
281
  Effect.gen(function* () {
284
282
  const store = yield* TrackerStore;
285
- yield* store.reset(emptyState());
286
283
 
287
284
  const list = yield* store.createList("Work");
288
285
  const item = yield* store.addItem(list.id, "write plan");
@@ -297,7 +294,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
297
294
  it.effect("addItem trims text and rejects empty text", () =>
298
295
  Effect.gen(function* () {
299
296
  const store = yield* TrackerStore;
300
- yield* store.reset(emptyState());
301
297
 
302
298
  const list = yield* store.createList("Work");
303
299
  const item = yield* store.addItem(list.id, " ship ");
@@ -305,8 +301,8 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
305
301
 
306
302
  for (const bad of ["", " "]) {
307
303
  const result = yield* Effect.result(store.addItem(list.id, bad));
308
- assert(Result.isFailure(result), `expected "${bad}" to be rejected`);
309
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "EmptyText");
304
+ if (!Result.isFailure(result)) assert.fail(`expected "${bad}" to be rejected`);
305
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "EmptyText");
310
306
  }
311
307
  }),
312
308
  );
@@ -314,7 +310,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
314
310
  it.effect("addItems appends several items in order", () =>
315
311
  Effect.gen(function* () {
316
312
  const store = yield* TrackerStore;
317
- yield* store.reset(emptyState());
318
313
 
319
314
  const list = yield* store.createList("Work");
320
315
  const items = yield* store.addItems(list.id, ["a", "b", "c"]);
@@ -338,7 +333,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
338
333
  it.effect("addItems trims texts", () =>
339
334
  Effect.gen(function* () {
340
335
  const store = yield* TrackerStore;
341
- yield* store.reset(emptyState());
342
336
 
343
337
  const list = yield* store.createList("Work");
344
338
  const items = yield* store.addItems(list.id, [" a ", "b"]);
@@ -352,16 +346,16 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
352
346
  it.effect("addItems rejects empty texts atomically", () =>
353
347
  Effect.gen(function* () {
354
348
  const store = yield* TrackerStore;
355
- yield* store.reset(emptyState());
356
349
 
357
350
  const list = yield* store.createList("Work");
358
351
  const before = yield* store.state;
359
352
 
360
353
  for (const bad of [["a", ""], ["a", " "], [""]]) {
361
354
  const result = yield* Effect.result(store.addItems(list.id, bad));
362
- assert(Result.isFailure(result), JSON.stringify(bad));
363
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "EmptyText");
364
- assert.deepStrictEqual(yield* store.state, before);
355
+ if (!Result.isFailure(result)) assert.fail(JSON.stringify(bad));
356
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "EmptyText");
357
+ const after = yield* store.state;
358
+ assert.deepStrictEqual(after, before);
365
359
  }
366
360
  }),
367
361
  );
@@ -369,29 +363,26 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
369
363
  it.effect("addItem fails for an unknown list", () =>
370
364
  Effect.gen(function* () {
371
365
  const store = yield* TrackerStore;
372
- yield* store.reset(emptyState());
373
366
 
374
367
  const result = yield* Effect.result(store.addItem(42, "x"));
375
- assert(Result.isFailure(result));
376
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "ListNotFound");
368
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
369
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "ListNotFound");
377
370
  }),
378
371
  );
379
372
 
380
373
  it.effect("addItems fails for an unknown list", () =>
381
374
  Effect.gen(function* () {
382
375
  const store = yield* TrackerStore;
383
- yield* store.reset(emptyState());
384
376
 
385
377
  const result = yield* Effect.result(store.addItems(42, ["x"]));
386
- assert(Result.isFailure(result));
387
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "ListNotFound");
378
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
379
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "ListNotFound");
388
380
  }),
389
381
  );
390
382
 
391
383
  it.effect("addItems with a single text behaves like addItem", () =>
392
384
  Effect.gen(function* () {
393
385
  const store = yield* TrackerStore;
394
- yield* store.reset(emptyState());
395
386
 
396
387
  const list = yield* store.createList("Work");
397
388
  const items = yield* store.addItems(list.id, ["write plan"]);
@@ -404,7 +395,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
404
395
  it.effect("updateItem sets done", () =>
405
396
  Effect.gen(function* () {
406
397
  const store = yield* TrackerStore;
407
- yield* store.reset(emptyState());
408
398
 
409
399
  const list = yield* store.createList("Work");
410
400
  yield* store.addItem(list.id, "write plan");
@@ -420,7 +410,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
420
410
  it.effect("updateItem sets the task text", () =>
421
411
  Effect.gen(function* () {
422
412
  const store = yield* TrackerStore;
423
- yield* store.reset(emptyState());
424
413
 
425
414
  const list = yield* store.createList("Work");
426
415
  yield* store.addItem(list.id, "write plan");
@@ -436,7 +425,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
436
425
  it.effect("updateItem combines text and done in one patch", () =>
437
426
  Effect.gen(function* () {
438
427
  const store = yield* TrackerStore;
439
- yield* store.reset(emptyState());
440
428
 
441
429
  const list = yield* store.createList("Work");
442
430
  yield* store.addItem(list.id, "write plan");
@@ -449,7 +437,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
449
437
  it.effect("keeps the description across a title-only patch", () =>
450
438
  Effect.gen(function* () {
451
439
  const store = yield* TrackerStore;
452
- yield* store.reset(emptyState());
453
440
 
454
441
  const list = yield* store.createList("Work");
455
442
  yield* store.addItem(list.id, { title: "T", description: "D" });
@@ -464,7 +451,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
464
451
  it.effect("round-trips a path reference with its symbol and span", () =>
465
452
  Effect.gen(function* () {
466
453
  const store = yield* TrackerStore;
467
- yield* store.reset(emptyState());
468
454
 
469
455
  const list = yield* store.createList("Work");
470
456
  yield* store.addItem(list.id, {
@@ -481,7 +467,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
481
467
  it.effect("round-trips a decision reference", () =>
482
468
  Effect.gen(function* () {
483
469
  const store = yield* TrackerStore;
484
- yield* store.reset(emptyState());
485
470
 
486
471
  const list = yield* store.createList("Work");
487
472
  yield* store.addItem(list.id, {
@@ -496,7 +481,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
496
481
  it.effect("an update patch replaces the whole declaration list", () =>
497
482
  Effect.gen(function* () {
498
483
  const store = yield* TrackerStore;
499
- yield* store.reset(emptyState());
500
484
 
501
485
  const list = yield* store.createList("Work");
502
486
  yield* store.addItem(list.id, {
@@ -515,7 +499,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
515
499
  it.effect("updateItem with an empty patch is a no-op", () =>
516
500
  Effect.gen(function* () {
517
501
  const store = yield* TrackerStore;
518
- yield* store.reset(emptyState());
519
502
 
520
503
  const list = yield* store.createList("Work");
521
504
  yield* store.addItem(list.id, "write plan");
@@ -531,25 +514,24 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
531
514
  it.effect("updateItem rejects empty task text", () =>
532
515
  Effect.gen(function* () {
533
516
  const store = yield* TrackerStore;
534
- yield* store.reset(emptyState());
535
517
 
536
518
  const list = yield* store.createList("Work");
537
519
  yield* store.addItem(list.id, "write plan");
538
520
  const stateBefore = yield* store.state;
539
521
 
540
522
  const result = yield* Effect.result(store.updateItem("Work:1", { title: " " }));
541
- assert(Result.isFailure(result));
542
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "EmptyText");
523
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
524
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "EmptyText");
543
525
 
544
526
  // State unchanged after the failed mutation.
545
- assert.deepStrictEqual(yield* store.state, stateBefore);
527
+ const after = yield* store.state;
528
+ assert.deepStrictEqual(after, stateBefore);
546
529
  }),
547
530
  );
548
531
 
549
532
  it.effect("updateItems applies several patches within one list", () =>
550
533
  Effect.gen(function* () {
551
534
  const store = yield* TrackerStore;
552
- yield* store.reset(emptyState());
553
535
 
554
536
  const list = yield* store.createList("Work");
555
537
  yield* store.addItems(list.id, ["a", "b", "c"]);
@@ -582,7 +564,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
582
564
  it.effect("updateItems fails atomically for an unknown item id", () =>
583
565
  Effect.gen(function* () {
584
566
  const store = yield* TrackerStore;
585
- yield* store.reset(emptyState());
586
567
 
587
568
  const list = yield* store.createList("Work");
588
569
  yield* store.addItem(list.id, "a");
@@ -594,30 +575,29 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
594
575
  { itemId: "Work:99", done: true },
595
576
  ]),
596
577
  );
597
- assert(Result.isFailure(result));
598
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "ItemNotFound");
578
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
579
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "ItemNotFound");
599
580
  // The valid patch in the batch was not applied.
600
- assert.deepStrictEqual(yield* store.state, before);
581
+ const after = yield* store.state;
582
+ assert.deepStrictEqual(after, before);
601
583
  }),
602
584
  );
603
585
 
604
586
  it.effect("updateItems fails for a missing list", () =>
605
587
  Effect.gen(function* () {
606
588
  const store = yield* TrackerStore;
607
- yield* store.reset(emptyState());
608
589
 
609
590
  const result = yield* Effect.result(
610
591
  store.updateItems(999, [{ itemId: "Work:1", done: true }]),
611
592
  );
612
- assert(Result.isFailure(result));
613
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "ListNotFound");
593
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
594
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "ListNotFound");
614
595
  }),
615
596
  );
616
597
 
617
598
  it.effect("updateItems rejects empty replacement text atomically", () =>
618
599
  Effect.gen(function* () {
619
600
  const store = yield* TrackerStore;
620
- yield* store.reset(emptyState());
621
601
 
622
602
  const list = yield* store.createList("Work");
623
603
  yield* store.addItem(list.id, "a");
@@ -629,16 +609,16 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
629
609
  { itemId: "Work:1", title: " " },
630
610
  ]),
631
611
  );
632
- assert(Result.isFailure(result));
633
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "EmptyText");
634
- assert.deepStrictEqual(yield* store.state, before);
612
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
613
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "EmptyText");
614
+ const after = yield* store.state;
615
+ assert.deepStrictEqual(after, before);
635
616
  }),
636
617
  );
637
618
 
638
619
  it.effect("updateItems with duplicate item id: the last patch wins", () =>
639
620
  Effect.gen(function* () {
640
621
  const store = yield* TrackerStore;
641
- yield* store.reset(emptyState());
642
622
 
643
623
  const list = yield* store.createList("Work");
644
624
  yield* store.addItem(list.id, "a");
@@ -664,13 +644,12 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
664
644
  it.effect("updateItem rejects malformed ids with a format hint", () =>
665
645
  Effect.gen(function* () {
666
646
  const store = yield* TrackerStore;
667
- yield* store.reset(emptyState());
668
647
 
669
648
  yield* store.createList("Work");
670
649
  for (const bad of ["Work", "Work:", ":1", "Work:0", "Work:x", "Work:007"]) {
671
650
  const result = yield* Effect.result(store.updateItem(bad, { done: true }));
672
- assert(Result.isFailure(result), `expected "${bad}" to be rejected`);
673
- const failure = Option.getOrThrow(Result.getFailure(result));
651
+ if (!Result.isFailure(result)) assert.fail(`expected "${bad}" to be rejected`);
652
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
674
653
  assert.strictEqual(failure.reason, "ItemNotFound");
675
654
  assert.match(failure.message, /listName:id/);
676
655
  }
@@ -680,21 +659,20 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
680
659
  it.effect("updateItem fails for unknown list or item", () =>
681
660
  Effect.gen(function* () {
682
661
  const store = yield* TrackerStore;
683
- yield* store.reset(emptyState());
684
662
 
685
663
  const list = yield* store.createList("Work");
686
664
  yield* store.addItem(list.id, "write plan");
687
665
 
688
666
  const noList = yield* Effect.result(store.updateItem("Nope:1", { done: true }));
689
- assert(Result.isFailure(noList));
690
- const noListFailure = Option.getOrThrow(Result.getFailure(noList));
667
+ if (!Result.isFailure(noList)) assert.fail("expected a failure");
668
+ const noListFailure = Result.getFailure(noList).pipe(Option.getOrThrow);
691
669
  assert.strictEqual(noListFailure.reason, "ItemNotFound");
692
670
  assert.match(noListFailure.message, /no list named "Nope"/);
693
671
  assert.match(noListFailure.message, /Work/); // names the available list
694
672
 
695
673
  const noItem = yield* Effect.result(store.updateItem("Work:99", { done: true }));
696
- assert(Result.isFailure(noItem));
697
- const failure = Option.getOrThrow(Result.getFailure(noItem));
674
+ if (!Result.isFailure(noItem)) assert.fail("expected a failure");
675
+ const failure = Result.getFailure(noItem).pipe(Option.getOrThrow);
698
676
  assert.strictEqual(failure.reason, "ItemNotFound");
699
677
  assert.strictEqual(failure.listId, list.id);
700
678
  assert.strictEqual(failure.itemId, "Work:99");
@@ -705,7 +683,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
705
683
  it.effect("removeItem removes only the target item (later ids stay stable)", () =>
706
684
  Effect.gen(function* () {
707
685
  const store = yield* TrackerStore;
708
- yield* store.reset(emptyState());
709
686
 
710
687
  const list = yield* store.createList("Work");
711
688
  yield* store.addItem(list.id, "a");
@@ -726,25 +703,23 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
726
703
  it.effect("removeItem fails for unknown list or item", () =>
727
704
  Effect.gen(function* () {
728
705
  const store = yield* TrackerStore;
729
- yield* store.reset(emptyState());
730
706
 
731
707
  const list = yield* store.createList("Work");
732
708
  yield* store.addItem(list.id, "a");
733
709
 
734
710
  const noList = yield* Effect.result(store.removeItem("Nope:1"));
735
- assert(Result.isFailure(noList));
736
- assert.strictEqual(Option.getOrThrow(Result.getFailure(noList)).reason, "ItemNotFound");
711
+ if (!Result.isFailure(noList)) assert.fail("expected a failure");
712
+ assert.strictEqual(Result.getFailure(noList).pipe(Option.getOrThrow).reason, "ItemNotFound");
737
713
 
738
714
  const noItem = yield* Effect.result(store.removeItem("Work:99"));
739
- assert(Result.isFailure(noItem));
740
- assert.strictEqual(Option.getOrThrow(Result.getFailure(noItem)).reason, "ItemNotFound");
715
+ if (!Result.isFailure(noItem)) assert.fail("expected a failure");
716
+ assert.strictEqual(Result.getFailure(noItem).pipe(Option.getOrThrow).reason, "ItemNotFound");
741
717
  }),
742
718
  );
743
719
 
744
720
  it.effect("failed mutations leave the state untouched", () =>
745
721
  Effect.gen(function* () {
746
722
  const store = yield* TrackerStore;
747
- yield* store.reset(emptyState());
748
723
 
749
724
  const list = yield* store.createList("Work");
750
725
  yield* store.addItem(list.id, "keep me");
@@ -765,7 +740,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
765
740
  it.effect("item references are stable ids (listName:id) and survive removal", () =>
766
741
  Effect.gen(function* () {
767
742
  const store = yield* TrackerStore;
768
- yield* store.reset(emptyState());
769
743
 
770
744
  const a = yield* store.createList("A");
771
745
  const b = yield* store.createList("B");
@@ -782,7 +756,7 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
782
756
  // Removing "one" leaves a gap: "two" keeps id 2 instead of becoming B:1.
783
757
  yield* store.removeItem("B:1");
784
758
  const stale = yield* Effect.result(store.updateItem("B:1", { done: true }));
785
- assert(Result.isFailure(stale));
759
+ if (!Result.isFailure(stale)) assert.fail("expected a failure");
786
760
  const second = yield* store.updateItem("B:2", { done: true });
787
761
  assert.strictEqual(second.title, "two");
788
762
 
@@ -800,7 +774,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
800
774
  it.effect("createList assigns sequential ids to initial items", () =>
801
775
  Effect.gen(function* () {
802
776
  const store = yield* TrackerStore;
803
- yield* store.reset(emptyState());
804
777
 
805
778
  const list = yield* store.createList("Work", { initialItems: ["a", "b", "c"] });
806
779
 
@@ -815,7 +788,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
815
788
  it.effect("addItem assigns the list counter and advances it", () =>
816
789
  Effect.gen(function* () {
817
790
  const store = yield* TrackerStore;
818
- yield* store.reset(emptyState());
819
791
 
820
792
  const list = yield* store.createList("Work", { initialItems: ["a", "b"] });
821
793
  const item = yield* store.addItem(list.id, "c");
@@ -828,7 +800,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
828
800
  it.effect("removeItem leaves a gap and does not renumber later items", () =>
829
801
  Effect.gen(function* () {
830
802
  const store = yield* TrackerStore;
831
- yield* store.reset(emptyState());
832
803
 
833
804
  yield* store.createList("Work", { initialItems: ["a", "b", "c"] });
834
805
  yield* store.removeItem("Work:2");
@@ -845,7 +816,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
845
816
  it.effect("a removed id is never reused", () =>
846
817
  Effect.gen(function* () {
847
818
  const store = yield* TrackerStore;
848
- yield* store.reset(emptyState());
849
819
 
850
820
  const list = yield* store.createList("Work", { initialItems: ["a", "b", "c"] });
851
821
  yield* store.removeItem("Work:2");
@@ -862,7 +832,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
862
832
  it.effect("updateItem resolves by id, not by position", () =>
863
833
  Effect.gen(function* () {
864
834
  const store = yield* TrackerStore;
865
- yield* store.reset(emptyState());
866
835
 
867
836
  yield* store.createList("Work", { initialItems: ["a", "b", "c"] });
868
837
  yield* store.removeItem("Work:1");
@@ -883,7 +852,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
883
852
  it.effect("updateItem preserves the item id", () =>
884
853
  Effect.gen(function* () {
885
854
  const store = yield* TrackerStore;
886
- yield* store.reset(emptyState());
887
855
 
888
856
  yield* store.createList("Work", { initialItems: ["a"] });
889
857
  const updated = yield* store.updateItem("Work:1", { done: true, title: "ay" });
@@ -896,7 +864,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
896
864
  it.effect("updateItems preserves every item id in the batch", () =>
897
865
  Effect.gen(function* () {
898
866
  const store = yield* TrackerStore;
899
- yield* store.reset(emptyState());
900
867
 
901
868
  const list = yield* store.createList("Work", { initialItems: ["a", "b", "c"] });
902
869
  const updated = yield* store.updateItems(list.id, [
@@ -918,28 +885,27 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
918
885
  it.effect("the not-found message lists the available ids after a gap", () =>
919
886
  Effect.gen(function* () {
920
887
  const store = yield* TrackerStore;
921
- yield* store.reset(emptyState());
922
888
 
923
889
  yield* store.createList("Work", { initialItems: ["a", "b", "c"] });
924
890
  yield* store.removeItem("Work:2");
925
891
  const before = yield* store.state;
926
892
 
927
893
  const result = yield* Effect.result(store.updateItem("Work:9", { done: true }));
928
- assert(Result.isFailure(result));
929
- const failure = Option.getOrThrow(Result.getFailure(result));
894
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
895
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
930
896
  assert.strictEqual(failure.reason, "ItemNotFound");
931
897
  assert.match(failure.message, /Work:1/);
932
898
  assert.match(failure.message, /Work:3/);
933
899
  assert.equal(failure.message.includes("Work:2"), false);
934
900
  // A stale reference changes nothing.
935
- assert.deepStrictEqual(yield* store.state, before);
901
+ const after = yield* store.state;
902
+ assert.deepStrictEqual(after, before);
936
903
  }),
937
904
  );
938
905
 
939
906
  it.effect("list names may contain colons (ids split on the last colon)", () =>
940
907
  Effect.gen(function* () {
941
908
  const store = yield* TrackerStore;
942
- yield* store.reset(emptyState());
943
909
 
944
910
  const list = yield* store.createList("Work:2024");
945
911
  yield* store.addItem(list.id, "a");
@@ -953,7 +919,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
953
919
  it.effect("createList accepts initial items with dependencies", () =>
954
920
  Effect.gen(function* () {
955
921
  const store = yield* TrackerStore;
956
- yield* store.reset(emptyState());
957
922
 
958
923
  const list = yield* store.createList("Work", {
959
924
  initialItems: ["a", { title: "b", deps: ["Work:1"] }],
@@ -969,7 +934,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
969
934
  it.effect("addItems accepts a mix of bare strings and objects with dependencies", () =>
970
935
  Effect.gen(function* () {
971
936
  const store = yield* TrackerStore;
972
- yield* store.reset(emptyState());
973
937
 
974
938
  const list = yield* store.createList("Work");
975
939
  yield* store.addItem(list.id, "a");
@@ -986,7 +950,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
986
950
  it.effect("a dependency can name a sibling created by the same call", () =>
987
951
  Effect.gen(function* () {
988
952
  const store = yield* TrackerStore;
989
- yield* store.reset(emptyState());
990
953
 
991
954
  const list = yield* store.createList("Work");
992
955
  const items = yield* store.addItems(list.id, ["a", { title: "b", deps: ["Work:1"] }]);
@@ -998,7 +961,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
998
961
  it.effect("a dependency on a missing item is refused and leaves state untouched", () =>
999
962
  Effect.gen(function* () {
1000
963
  const store = yield* TrackerStore;
1001
- yield* store.reset(emptyState());
1002
964
 
1003
965
  const list = yield* store.createList("Work");
1004
966
  yield* store.addItem(list.id, "a");
@@ -1006,37 +968,38 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1006
968
 
1007
969
  const result = yield* Effect.result(store.addItem(list.id, "b", ["Work:9"]));
1008
970
 
1009
- assert(Result.isFailure(result));
1010
- const failure = Option.getOrThrow(Result.getFailure(result));
971
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
972
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
1011
973
  assert.strictEqual(failure.reason, "DependencyNotFound");
1012
974
  assert.match(failure.message, /Work:9/);
1013
- assert.deepStrictEqual(yield* store.state, before);
975
+ const after = yield* store.state;
976
+ assert.deepStrictEqual(after, before);
1014
977
  }),
1015
978
  );
1016
979
 
1017
980
  it.effect("a malformed dependency reference is refused", () =>
1018
981
  Effect.gen(function* () {
1019
982
  const store = yield* TrackerStore;
1020
- yield* store.reset(emptyState());
1021
983
 
1022
984
  const list = yield* store.createList("Work");
1023
985
  const before = yield* store.state;
1024
986
 
1025
987
  for (const bad of ["nonsense", "Work:0", ":1"]) {
1026
988
  const result = yield* Effect.result(store.addItem(list.id, "a", [bad]));
1027
- assert(Result.isFailure(result), `expected ${JSON.stringify(bad)} to be rejected`);
1028
- const failure = Option.getOrThrow(Result.getFailure(result));
989
+ if (!Result.isFailure(result))
990
+ assert.fail(`expected ${JSON.stringify(bad)} to be rejected`);
991
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
1029
992
  assert.strictEqual(failure.reason, "DependencyNotFound");
1030
993
  assert.match(failure.message, /listName:id/);
1031
994
  }
1032
- assert.deepStrictEqual(yield* store.state, before);
995
+ const after = yield* store.state;
996
+ assert.deepStrictEqual(after, before);
1033
997
  }),
1034
998
  );
1035
999
 
1036
1000
  it.effect("a dependency on another list is refused", () =>
1037
1001
  Effect.gen(function* () {
1038
1002
  const store = yield* TrackerStore;
1039
- yield* store.reset(emptyState());
1040
1003
 
1041
1004
  const work = yield* store.createList("Work");
1042
1005
  yield* store.createList("Home", { initialItems: ["x"] });
@@ -1044,18 +1007,18 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1044
1007
 
1045
1008
  const result = yield* Effect.result(store.addItem(work.id, "b", ["Home:1"]));
1046
1009
 
1047
- assert(Result.isFailure(result));
1048
- const failure = Option.getOrThrow(Result.getFailure(result));
1010
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1011
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
1049
1012
  assert.strictEqual(failure.reason, "CrossListDependency");
1050
1013
  assert.match(failure.message, /Home:1/);
1051
- assert.deepStrictEqual(yield* store.state, before);
1014
+ const after = yield* store.state;
1015
+ assert.deepStrictEqual(after, before);
1052
1016
  }),
1053
1017
  );
1054
1018
 
1055
1019
  it.effect("a dependency that closes a cycle is refused, with the path named", () =>
1056
1020
  Effect.gen(function* () {
1057
1021
  const store = yield* TrackerStore;
1058
- yield* store.reset(emptyState());
1059
1022
 
1060
1023
  yield* store.createList("Work", {
1061
1024
  initialItems: ["a", { title: "b", deps: ["Work:1"] }],
@@ -1064,19 +1027,19 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1064
1027
 
1065
1028
  const result = yield* Effect.result(store.updateItem("Work:1", { deps: ["Work:2"] }));
1066
1029
 
1067
- assert(Result.isFailure(result));
1068
- const failure = Option.getOrThrow(Result.getFailure(result));
1030
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1031
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
1069
1032
  assert.strictEqual(failure.reason, "DependencyCycle");
1070
1033
  assert.match(failure.message, /Work:1/);
1071
1034
  assert.match(failure.message, /Work:2/);
1072
- assert.deepStrictEqual(yield* store.state, before);
1035
+ const after = yield* store.state;
1036
+ assert.deepStrictEqual(after, before);
1073
1037
  }),
1074
1038
  );
1075
1039
 
1076
1040
  it.effect("deps replaces the dependency set, and an empty array clears it", () =>
1077
1041
  Effect.gen(function* () {
1078
1042
  const store = yield* TrackerStore;
1079
- yield* store.reset(emptyState());
1080
1043
 
1081
1044
  yield* store.createList("Work", { initialItems: ["a", "b"] });
1082
1045
  yield* store.updateItem("Work:2", { deps: ["Work:1"] });
@@ -1090,7 +1053,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1090
1053
  it.effect("a cycle closed by a later batch patch is refused", () =>
1091
1054
  Effect.gen(function* () {
1092
1055
  const store = yield* TrackerStore;
1093
- yield* store.reset(emptyState());
1094
1056
 
1095
1057
  const list = yield* store.createList("Work", { initialItems: ["a", "b"] });
1096
1058
  const before = yield* store.state;
@@ -1104,16 +1066,19 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1104
1066
  ]),
1105
1067
  );
1106
1068
 
1107
- assert(Result.isFailure(result));
1108
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "DependencyCycle");
1109
- assert.deepStrictEqual(yield* store.state, before);
1069
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1070
+ assert.strictEqual(
1071
+ Result.getFailure(result).pipe(Option.getOrThrow).reason,
1072
+ "DependencyCycle",
1073
+ );
1074
+ const after = yield* store.state;
1075
+ assert.deepStrictEqual(after, before);
1110
1076
  }),
1111
1077
  );
1112
1078
 
1113
1079
  it.effect("a batch patch cannot make an item depend on itself", () =>
1114
1080
  Effect.gen(function* () {
1115
1081
  const store = yield* TrackerStore;
1116
- yield* store.reset(emptyState());
1117
1082
 
1118
1083
  const list = yield* store.createList("Work", { initialItems: ["a"] });
1119
1084
  const before = yield* store.state;
@@ -1122,23 +1087,28 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1122
1087
  store.updateItems(list.id, [{ itemId: "Work:1", deps: ["Work:1"] }]),
1123
1088
  );
1124
1089
 
1125
- assert(Result.isFailure(result));
1126
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "DependencyCycle");
1127
- assert.deepStrictEqual(yield* store.state, before);
1090
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1091
+ assert.strictEqual(
1092
+ Result.getFailure(result).pipe(Option.getOrThrow).reason,
1093
+ "DependencyCycle",
1094
+ );
1095
+ const after = yield* store.state;
1096
+ assert.deepStrictEqual(after, before);
1128
1097
  }),
1129
1098
  );
1130
1099
 
1131
1100
  it.effect("dependencies survive an encode and restore round trip", () =>
1132
1101
  Effect.gen(function* () {
1133
1102
  const store = yield* TrackerStore;
1134
- yield* store.reset(emptyState());
1135
1103
 
1136
1104
  yield* store.createList("Work", {
1137
1105
  initialItems: ["a", { title: "b", deps: ["Work:1"] }],
1138
1106
  });
1139
1107
 
1140
- const snapshot = encodeState(yield* store.state);
1141
- const restored = migrateState(yield* decodeStateEffect(snapshot));
1108
+ const after = yield* store.state;
1109
+ const snapshot = encodeState(after);
1110
+ const decoded = yield* decodeStateEffect(snapshot);
1111
+ const restored = migrateState(decoded);
1142
1112
 
1143
1113
  assert.deepStrictEqual(restored.lists[0]?.items[1]?.deps, ["Work:1"]);
1144
1114
  assert.strictEqual(restored.lists[0]?.items[1]?.id, 2);
@@ -1148,26 +1118,25 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1148
1118
  it.effect("completing a blocked item is refused and leaves state untouched", () =>
1149
1119
  Effect.gen(function* () {
1150
1120
  const store = yield* TrackerStore;
1151
- yield* store.reset(emptyState());
1152
1121
 
1153
1122
  yield* store.createList("Work", { initialItems: ["a", { title: "b", deps: ["Work:1"] }] });
1154
1123
  const before = yield* store.state;
1155
1124
 
1156
1125
  const result = yield* Effect.result(store.updateItem("Work:2", { done: true }));
1157
1126
 
1158
- assert(Result.isFailure(result));
1159
- const failure = Option.getOrThrow(Result.getFailure(result));
1127
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1128
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
1160
1129
  assert.strictEqual(failure.reason, "ItemBlocked");
1161
1130
  assert.match(failure.message, /Work:1/);
1162
1131
  assert.match(failure.message, /blocked/);
1163
- assert.deepStrictEqual(yield* store.state, before);
1132
+ const after = yield* store.state;
1133
+ assert.deepStrictEqual(after, before);
1164
1134
  }),
1165
1135
  );
1166
1136
 
1167
1137
  it.effect("a blocked item can still be un-completed", () =>
1168
1138
  Effect.gen(function* () {
1169
1139
  const store = yield* TrackerStore;
1170
- yield* store.reset(emptyState());
1171
1140
 
1172
1141
  // "b" is done, then its dependency is reopened, so "b" is blocked but
1173
1142
  // must stay reopenable (only completion is gated).
@@ -1185,7 +1154,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1185
1154
  it.effect("completing a ready item unblocks its dependents", () =>
1186
1155
  Effect.gen(function* () {
1187
1156
  const store = yield* TrackerStore;
1188
- yield* store.reset(emptyState());
1189
1157
 
1190
1158
  yield* store.createList("Work", { initialItems: ["a", { title: "b", deps: ["Work:1"] }] });
1191
1159
  yield* store.updateItem("Work:1", { done: true });
@@ -1199,7 +1167,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1199
1167
  it.effect("reopening a dependency is allowed and does not cascade", () =>
1200
1168
  Effect.gen(function* () {
1201
1169
  const store = yield* TrackerStore;
1202
- yield* store.reset(emptyState());
1203
1170
 
1204
1171
  yield* store.createList("Work", { initialItems: ["a", { title: "b", deps: ["Work:1"] }] });
1205
1172
  yield* store.updateItem("Work:1", { done: true });
@@ -1218,25 +1185,24 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1218
1185
  it.effect("removing a depended-on item is refused and names the dependents", () =>
1219
1186
  Effect.gen(function* () {
1220
1187
  const store = yield* TrackerStore;
1221
- yield* store.reset(emptyState());
1222
1188
 
1223
1189
  yield* store.createList("Work", { initialItems: ["a", { title: "b", deps: ["Work:1"] }] });
1224
1190
  const before = yield* store.state;
1225
1191
 
1226
1192
  const result = yield* Effect.result(store.removeItem("Work:1"));
1227
1193
 
1228
- assert(Result.isFailure(result));
1229
- const failure = Option.getOrThrow(Result.getFailure(result));
1194
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1195
+ const failure = Result.getFailure(result).pipe(Option.getOrThrow);
1230
1196
  assert.strictEqual(failure.reason, "ItemDependedOn");
1231
1197
  assert.match(failure.message, /Work:2/);
1232
- assert.deepStrictEqual(yield* store.state, before);
1198
+ const after = yield* store.state;
1199
+ assert.deepStrictEqual(after, before);
1233
1200
  }),
1234
1201
  );
1235
1202
 
1236
1203
  it.effect("removing an item nothing depends on succeeds and leaves other deps intact", () =>
1237
1204
  Effect.gen(function* () {
1238
1205
  const store = yield* TrackerStore;
1239
- yield* store.reset(emptyState());
1240
1206
 
1241
1207
  yield* store.createList("Work", {
1242
1208
  initialItems: ["a", "b", { title: "c", deps: ["Work:2"] }],
@@ -1255,7 +1221,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1255
1221
  it.effect("a batch applies its patches in order, so one call can complete a chain", () =>
1256
1222
  Effect.gen(function* () {
1257
1223
  const store = yield* TrackerStore;
1258
- yield* store.reset(emptyState());
1259
1224
 
1260
1225
  const list = yield* store.createList("Work", {
1261
1226
  initialItems: ["a", { title: "b", deps: ["Work:1"] }, { title: "c", deps: ["Work:2"] }],
@@ -1279,7 +1244,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1279
1244
  it.effect("a batch still refuses a completion that is out of order", () =>
1280
1245
  Effect.gen(function* () {
1281
1246
  const store = yield* TrackerStore;
1282
- yield* store.reset(emptyState());
1283
1247
 
1284
1248
  const list = yield* store.createList("Work", {
1285
1249
  initialItems: ["a", { title: "b", deps: ["Work:1"] }],
@@ -1295,16 +1259,16 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1295
1259
  ]),
1296
1260
  );
1297
1261
 
1298
- assert(Result.isFailure(result));
1299
- assert.strictEqual(Option.getOrThrow(Result.getFailure(result)).reason, "ItemBlocked");
1300
- assert.deepStrictEqual(yield* store.state, before);
1262
+ if (!Result.isFailure(result)) assert.fail("expected a failure");
1263
+ assert.strictEqual(Result.getFailure(result).pipe(Option.getOrThrow).reason, "ItemBlocked");
1264
+ const after = yield* store.state;
1265
+ assert.deepStrictEqual(after, before);
1301
1266
  }),
1302
1267
  );
1303
1268
 
1304
1269
  it.effect("a batch keeps an earlier patch to the same item", () =>
1305
1270
  Effect.gen(function* () {
1306
1271
  const store = yield* TrackerStore;
1307
- yield* store.reset(emptyState());
1308
1272
 
1309
1273
  const list = yield* store.createList("Work", {
1310
1274
  initialItems: ["a", { title: "b", deps: ["Work:1"] }],
@@ -1326,7 +1290,6 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1326
1290
  it.effect("a batch can complete a dependent once its blocker is done", () =>
1327
1291
  Effect.gen(function* () {
1328
1292
  const store = yield* TrackerStore;
1329
- yield* store.reset(emptyState());
1330
1293
 
1331
1294
  const list = yield* store.createList("Work", {
1332
1295
  initialItems: ["a", { title: "b", deps: ["Work:1"] }],
@@ -1342,11 +1305,10 @@ layer(TrackerStore.layer)("TrackerStore", (it) => {
1342
1305
  it.effect("reset replaces the whole state", () =>
1343
1306
  Effect.gen(function* () {
1344
1307
  const store = yield* TrackerStore;
1345
- yield* store.reset(emptyState());
1346
1308
 
1347
1309
  yield* store.createList("A");
1348
- const restored = new TrackerState({
1349
- lists: [new TodoList({ id: 5, name: "R", items: [] })],
1310
+ const restored = TrackerState.make({
1311
+ lists: [TodoList.make({ id: 5, name: "R", items: [] })],
1350
1312
  activeListId: 5,
1351
1313
  nextListId: 6,
1352
1314
  });