fascicle 0.12.13 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -1
- package/dist/adapters-DNnzeLxr.js +447 -0
- package/dist/adapters-DNnzeLxr.js.map +1 -0
- package/dist/adapters.d.ts +54 -9
- package/dist/adapters.js +1 -1
- package/dist/agents.d.ts +12 -9
- package/dist/agents.js +1 -1
- package/dist/{core-BVCVUMmH.js → core-DK7g1Z40.js} +887 -74
- package/dist/core-DK7g1Z40.js.map +1 -0
- package/dist/diagram_bin.d.ts +1 -2
- package/dist/diagram_bin.js +5 -2
- package/dist/diagram_bin.js.map +1 -1
- package/dist/{engine-Ct4LBzb9.js → engine-BOGuc0X2.js} +366 -36
- package/dist/engine-BOGuc0X2.js.map +1 -0
- package/dist/index.d.ts +342 -180
- package/dist/index.js +149 -123
- package/dist/index.js.map +1 -1
- package/dist/{invoke-BcPDqE5C.js → invoke-Beef3R3X.js} +3 -3
- package/dist/{invoke-BcPDqE5C.js.map → invoke-Beef3R3X.js.map} +1 -1
- package/dist/mcp.d.ts +8 -9
- package/dist/mcp.js +1 -1
- package/dist/otel.d.ts +3 -4
- package/dist/stdio.d.ts +4 -5
- package/dist/stdio.js +2 -2
- package/dist/testing.d.ts +46 -10
- package/dist/testing.js +540 -4
- package/dist/testing.js.map +1 -1
- package/dist/{trajectory-D1eq9eue.js → trajectory-BI-mrVFT.js} +25 -2
- package/dist/trajectory-BI-mrVFT.js.map +1 -0
- package/dist/{trajectory-ByoOQZ6T.d.ts → trajectory-Bm-mOtqw.d.ts} +34 -3
- package/dist/{types-BasW4Wwb.d.ts → types-CPqLZOEr.d.ts} +40 -2
- package/dist/{types-bEpfDrys.d.ts → types-CZ83Q5nm.d.ts} +12 -7
- package/dist/ui.d.ts +11 -10
- package/dist/ui.js +3 -2
- package/dist/ui.js.map +1 -1
- package/dist/viewer-app/assets/index-DXsB0byD.js +2 -0
- package/dist/viewer-app/index.html +1 -1
- package/dist/viewer.d.ts +7 -8
- package/dist/viewer.js +2 -2
- package/dist/viewer.js.map +1 -1
- package/package.json +28 -28
- package/dist/adapters-CutexJd3.js +0 -270
- package/dist/adapters-CutexJd3.js.map +0 -1
- package/dist/core-BVCVUMmH.js.map +0 -1
- package/dist/engine-Ct4LBzb9.js.map +0 -1
- package/dist/leading_system-CfOIc5fi.js +0 -330
- package/dist/leading_system-CfOIc5fi.js.map +0 -1
- package/dist/trajectory-D1eq9eue.js.map +0 -1
- package/dist/viewer-app/assets/index-BBEYkjnQ.js +0 -2
package/dist/testing.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./engine-
|
|
3
|
-
import { y as schema_validation_error } from "./leading_system-CfOIc5fi.js";
|
|
1
|
+
import { k as aborted_error } from "./core-DK7g1Z40.js";
|
|
2
|
+
import { _ as schema_validation_error } from "./engine-BOGuc0X2.js";
|
|
4
3
|
//#region src/testing/engine_from_generate.ts
|
|
5
4
|
/**
|
|
6
5
|
* Build an `Engine` whose only live member is the supplied `generate`.
|
|
@@ -25,6 +24,543 @@ function engine_from_generate(generate) {
|
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
26
|
//#endregion
|
|
27
|
+
//#region src/testing/checkpoint_store_conformance.ts
|
|
28
|
+
const DEFAULT_TTL_MS = 200;
|
|
29
|
+
const HELD_MS = 6e4;
|
|
30
|
+
const RACERS = 8;
|
|
31
|
+
const KEY = "k";
|
|
32
|
+
const MISSING = "never-set";
|
|
33
|
+
const NULL_KEY = "null";
|
|
34
|
+
const UNDEFINED_KEY = "undefined";
|
|
35
|
+
const RACE_KEY = "race";
|
|
36
|
+
const DAMAGED_KEY = "damaged";
|
|
37
|
+
const CLAIMED_ONLY = "claimed-only";
|
|
38
|
+
const UNCLAIMED = "never-claimed";
|
|
39
|
+
const A = "a";
|
|
40
|
+
const B = "b";
|
|
41
|
+
const CHILD = "child";
|
|
42
|
+
const INNER = "inner";
|
|
43
|
+
const UNUSED = "never-used";
|
|
44
|
+
const FIRST = "first";
|
|
45
|
+
const SECOND = "second";
|
|
46
|
+
const THIRD = "third";
|
|
47
|
+
const FRESH_SCOPE_CLAIM_REFUSED = "a claim inside a fresh scope returned false";
|
|
48
|
+
const FREE_CLAIM_REFUSED = "a claim on a key nobody holds returned false";
|
|
49
|
+
const RENEWAL_REFUSED = "the owner could not renew its own live claim";
|
|
50
|
+
const SAMPLES = [
|
|
51
|
+
{
|
|
52
|
+
candidate: "a",
|
|
53
|
+
converged: true,
|
|
54
|
+
rounds: 2
|
|
55
|
+
},
|
|
56
|
+
{ nested: {
|
|
57
|
+
list: [
|
|
58
|
+
1,
|
|
59
|
+
"two",
|
|
60
|
+
{ three: 3 }
|
|
61
|
+
],
|
|
62
|
+
empty: {}
|
|
63
|
+
} },
|
|
64
|
+
[
|
|
65
|
+
1,
|
|
66
|
+
2,
|
|
67
|
+
3
|
|
68
|
+
],
|
|
69
|
+
[],
|
|
70
|
+
{},
|
|
71
|
+
"plain text",
|
|
72
|
+
"",
|
|
73
|
+
"unicode: naïve café, 世界, 🔑",
|
|
74
|
+
0,
|
|
75
|
+
-1.5,
|
|
76
|
+
true,
|
|
77
|
+
false
|
|
78
|
+
];
|
|
79
|
+
const LOOKALIKES = [
|
|
80
|
+
"a/b",
|
|
81
|
+
"a_b",
|
|
82
|
+
"a:b",
|
|
83
|
+
"a b",
|
|
84
|
+
"A/B",
|
|
85
|
+
"a/b/",
|
|
86
|
+
"../a",
|
|
87
|
+
".",
|
|
88
|
+
"..",
|
|
89
|
+
"鍵",
|
|
90
|
+
"🔑",
|
|
91
|
+
`${"k".repeat(200)}1`,
|
|
92
|
+
`${"k".repeat(200)}2`
|
|
93
|
+
];
|
|
94
|
+
const FLATTENED = [
|
|
95
|
+
"a/b",
|
|
96
|
+
"ab",
|
|
97
|
+
"a.b",
|
|
98
|
+
"a:b",
|
|
99
|
+
"b"
|
|
100
|
+
];
|
|
101
|
+
const BESIDE_A = [
|
|
102
|
+
"a/b",
|
|
103
|
+
"a/",
|
|
104
|
+
"ab",
|
|
105
|
+
"a.b",
|
|
106
|
+
"a b",
|
|
107
|
+
"A"
|
|
108
|
+
];
|
|
109
|
+
/**
|
|
110
|
+
* Throw a check failure carrying `message` unless `condition` holds.
|
|
111
|
+
*/
|
|
112
|
+
function ensure(condition, message) {
|
|
113
|
+
if (!condition) throw new Error(message);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* True for what the contract counts as a miss: `null` or `undefined`.
|
|
117
|
+
*/
|
|
118
|
+
function is_miss(value) {
|
|
119
|
+
return value === null || value === void 0;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Render a value for a failure message, cut short so a large one stays
|
|
123
|
+
* readable.
|
|
124
|
+
*/
|
|
125
|
+
function show(value) {
|
|
126
|
+
const shown = JSON.stringify(value) ?? String(value);
|
|
127
|
+
return shown.length > 80 ? `${shown.slice(0, 77)}...` : shown;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Serialize a value with its object keys sorted, so two values compare equal
|
|
131
|
+
* when a store hands back the same data in a different key order (Postgres
|
|
132
|
+
* `jsonb` does).
|
|
133
|
+
*/
|
|
134
|
+
function canonical(value) {
|
|
135
|
+
return JSON.stringify(sort_keys(value));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Copy a JSON value with every object's keys in sorted order.
|
|
139
|
+
*/
|
|
140
|
+
function sort_keys(value) {
|
|
141
|
+
if (Array.isArray(value)) return value.map(sort_keys);
|
|
142
|
+
if (typeof value !== "object" || value === null) return value;
|
|
143
|
+
const entries = Object.entries(value).toSorted(([x], [y]) => x < y ? -1 : 1);
|
|
144
|
+
return Object.fromEntries(entries.map(([k, v]) => [k, sort_keys(v)]));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Wait `ms` milliseconds.
|
|
148
|
+
*/
|
|
149
|
+
function sleep(ms) {
|
|
150
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Open the scope at `prefix`, or fail the check when the store handed to it
|
|
154
|
+
* has no `scope` (a `make_store` whose stores don't all offer the same
|
|
155
|
+
* capabilities).
|
|
156
|
+
*/
|
|
157
|
+
function scope_of(store, prefix) {
|
|
158
|
+
if (store.scope === void 0) throw new Error("make_store returned a store without scope");
|
|
159
|
+
return store.scope(prefix);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The store's claim pair, or a failure naming the half that's missing. Both
|
|
163
|
+
* are called on the store itself, the way `durable` calls them, so a store
|
|
164
|
+
* whose methods lean on `this` works here too.
|
|
165
|
+
*/
|
|
166
|
+
function claims_of(store) {
|
|
167
|
+
const { claim, release } = store;
|
|
168
|
+
if (claim === void 0 && release === void 0) throw new Error("the store has neither claim nor release");
|
|
169
|
+
if (claim === void 0) throw new Error("the store offers release without claim");
|
|
170
|
+
if (release === void 0) throw new Error("the store offers claim without release");
|
|
171
|
+
return {
|
|
172
|
+
claim: (key, owner, ttl_ms) => claim.call(store, key, owner, ttl_ms),
|
|
173
|
+
release: (key, owner) => release.call(store, key, owner)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Claim `key` for many owners at the same moment and count the winners.
|
|
178
|
+
*/
|
|
179
|
+
async function race_for(claims, key) {
|
|
180
|
+
const owners = Array.from({ length: RACERS }, (_, i) => `racer-${i}`);
|
|
181
|
+
return (await Promise.all(owners.map((owner) => claims.claim(key, owner, HELD_MS)))).filter(Boolean).length;
|
|
182
|
+
}
|
|
183
|
+
const SUITES = [
|
|
184
|
+
{
|
|
185
|
+
checks: [
|
|
186
|
+
{
|
|
187
|
+
name: "a missing key reads as a miss",
|
|
188
|
+
run: async (store) => {
|
|
189
|
+
const value = await store.get(MISSING);
|
|
190
|
+
ensure(is_miss(value), `get on a key nobody set returned ${show(value)}`);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "values round-trip as JSON",
|
|
195
|
+
run: async (store) => {
|
|
196
|
+
await Promise.all(SAMPLES.map((sample, i) => store.set(`sample-${i}`, sample)));
|
|
197
|
+
const read = await Promise.all(SAMPLES.map((_, i) => store.get(`sample-${i}`)));
|
|
198
|
+
SAMPLES.forEach((sample, i) => {
|
|
199
|
+
ensure(canonical(read[i]) === canonical(sample), `set ${show(sample)} and got back ${show(read[i])}`);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "set overwrites a value",
|
|
205
|
+
run: async (store) => {
|
|
206
|
+
await store.set(KEY, { v: 1 });
|
|
207
|
+
await store.set(KEY, { v: 2 });
|
|
208
|
+
const value = await store.get(KEY);
|
|
209
|
+
ensure(canonical(value) === canonical({ v: 2 }), `a second set lost to the first: ${show(value)}`);
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "delete removes a value",
|
|
214
|
+
run: async (store) => {
|
|
215
|
+
await store.set(KEY, { v: 1 });
|
|
216
|
+
await store.delete(KEY);
|
|
217
|
+
const value = await store.get(KEY);
|
|
218
|
+
ensure(is_miss(value), `get after delete returned ${show(value)}`);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
name: "deleting a missing key resolves",
|
|
223
|
+
run: async (store) => {
|
|
224
|
+
await store.delete(MISSING);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "a stored null or undefined reads as a miss",
|
|
229
|
+
run: async (store) => {
|
|
230
|
+
await store.set(NULL_KEY, null);
|
|
231
|
+
await store.set(UNDEFINED_KEY, void 0);
|
|
232
|
+
ensure(is_miss(await store.get(NULL_KEY)), "a stored null read back as a hit");
|
|
233
|
+
ensure(is_miss(await store.get(UNDEFINED_KEY)), "a stored undefined read back as a hit");
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: "keys that encode alike stay apart",
|
|
238
|
+
run: async (store) => {
|
|
239
|
+
await Promise.all(LOOKALIKES.map((key, i) => store.set(key, i)));
|
|
240
|
+
const read = await Promise.all(LOOKALIKES.map((key) => store.get(key)));
|
|
241
|
+
LOOKALIKES.forEach((key, i) => {
|
|
242
|
+
ensure(read[i] === i, `key ${show(key)} read back ${show(read[i])}, another key's value`);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "racing writes leave one whole value",
|
|
248
|
+
run: async (store) => {
|
|
249
|
+
const writes = Array.from({ length: RACERS }, (_, i) => ({
|
|
250
|
+
writer: i,
|
|
251
|
+
body: "x".repeat(4096 + i)
|
|
252
|
+
}));
|
|
253
|
+
await Promise.all(writes.map((write) => store.set(RACE_KEY, write)));
|
|
254
|
+
const value = await store.get(RACE_KEY);
|
|
255
|
+
ensure(writes.some((write) => canonical(write) === canonical(value)), `after ${RACERS} racing sets, get returned ${show(value)}, which none of them wrote`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
applies: () => true
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
checks: [{
|
|
263
|
+
name: "a damaged value reads as a miss",
|
|
264
|
+
run: async (store, env) => {
|
|
265
|
+
await store.set(DAMAGED_KEY, { ok: true });
|
|
266
|
+
await env.corrupt(store, DAMAGED_KEY);
|
|
267
|
+
let value;
|
|
268
|
+
try {
|
|
269
|
+
value = await store.get(DAMAGED_KEY);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
throw new Error(`get threw on a damaged value instead of missing: ${String(err)}`, { cause: err });
|
|
272
|
+
}
|
|
273
|
+
ensure(is_miss(value), `get on a damaged value returned ${show(value)}`);
|
|
274
|
+
}
|
|
275
|
+
}],
|
|
276
|
+
applies: (_, options) => options.corrupt !== void 0
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
checks: [
|
|
280
|
+
{
|
|
281
|
+
name: "a scope is apart from its parent",
|
|
282
|
+
run: async (store) => {
|
|
283
|
+
const child = scope_of(store, CHILD);
|
|
284
|
+
await store.set(KEY, "parent");
|
|
285
|
+
ensure(is_miss(await child.get(KEY)), "a scope read its parent's value");
|
|
286
|
+
await child.set(KEY, "child");
|
|
287
|
+
ensure(await store.get(KEY) === "parent", "a write in a scope changed its parent's value");
|
|
288
|
+
ensure(await child.get(KEY) === "child", "a scope lost its own value");
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
name: "one prefix reaches the same data, another prefix does not",
|
|
293
|
+
run: async (store) => {
|
|
294
|
+
await scope_of(store, A).set(KEY, "a");
|
|
295
|
+
ensure(await scope_of(store, A).get(KEY) === "a", "reopening a scope lost its value");
|
|
296
|
+
ensure(is_miss(await scope_of(store, B).get(KEY)), "scope 'b' read a value set in scope 'a'");
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: "prefixes that encode alike stay apart",
|
|
301
|
+
run: async (store) => {
|
|
302
|
+
await Promise.all(LOOKALIKES.map((prefix, i) => scope_of(store, prefix).set(KEY, i)));
|
|
303
|
+
const read = await Promise.all(LOOKALIKES.map((prefix) => scope_of(store, prefix).get(KEY)));
|
|
304
|
+
LOOKALIKES.forEach((prefix, i) => {
|
|
305
|
+
ensure(read[i] === i, `scope ${show(prefix)} read back ${show(read[i])}, another scope's`);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
name: "nested scopes stay apart from look-alike prefixes",
|
|
311
|
+
run: async (store) => {
|
|
312
|
+
await scope_of(store, A).scope(B).set(KEY, "nested");
|
|
313
|
+
const read = await Promise.all(FLATTENED.map((prefix) => scope_of(store, prefix).get(KEY)));
|
|
314
|
+
FLATTENED.forEach((prefix, i) => {
|
|
315
|
+
ensure(is_miss(read[i]), `scope ${show(prefix)} read the value of scope 'b' in scope 'a'`);
|
|
316
|
+
});
|
|
317
|
+
const a = scope_of(store, A);
|
|
318
|
+
ensure(is_miss(await a.get(KEY)), "a nested scope's value showed up in its parent");
|
|
319
|
+
ensure(await a.scope(B).get(KEY) === "nested", "reopening a nested scope lost its value");
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "clear empties a scope and nothing else",
|
|
324
|
+
run: async (store) => {
|
|
325
|
+
const a = scope_of(store, A);
|
|
326
|
+
await Promise.all([
|
|
327
|
+
store.set(KEY, "root"),
|
|
328
|
+
a.set(KEY, "a"),
|
|
329
|
+
a.scope(INNER).set(KEY, "inner"),
|
|
330
|
+
scope_of(store, B).set(KEY, "b")
|
|
331
|
+
]);
|
|
332
|
+
await a.clear();
|
|
333
|
+
ensure(is_miss(await a.get(KEY)), "a value survived clear");
|
|
334
|
+
ensure(is_miss(await a.scope(INNER).get(KEY)), "a nested scope's value survived clear");
|
|
335
|
+
ensure(await scope_of(store, B).get(KEY) === "b", "clear removed a sibling's value");
|
|
336
|
+
ensure(await store.get(KEY) === "root", "clear removed the parent's value");
|
|
337
|
+
await a.set(KEY, "again");
|
|
338
|
+
ensure(await a.get(KEY) === "again", "a cleared scope refused a new value");
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: "clear leaves look-alike scopes alone",
|
|
343
|
+
run: async (store) => {
|
|
344
|
+
await Promise.all(BESIDE_A.map((prefix, i) => scope_of(store, prefix).set(KEY, i)));
|
|
345
|
+
await scope_of(store, A).clear();
|
|
346
|
+
const read = await Promise.all(BESIDE_A.map((prefix) => scope_of(store, prefix).get(KEY)));
|
|
347
|
+
BESIDE_A.forEach((prefix, i) => {
|
|
348
|
+
ensure(read[i] === i, `clearing scope 'a' emptied scope ${show(prefix)}`);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "clearing an empty scope resolves",
|
|
354
|
+
run: async (store) => {
|
|
355
|
+
await scope_of(store, UNUSED).clear();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
],
|
|
359
|
+
applies: (store) => store.scope !== void 0
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
checks: [
|
|
363
|
+
{
|
|
364
|
+
name: "claim comes with release",
|
|
365
|
+
run: async (store) => {
|
|
366
|
+
claims_of(store);
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
name: "a free key can be claimed",
|
|
371
|
+
run: async (store) => {
|
|
372
|
+
ensure(await claims_of(store).claim(KEY, FIRST, HELD_MS), FREE_CLAIM_REFUSED);
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
name: "a held key refuses another owner",
|
|
377
|
+
run: async (store) => {
|
|
378
|
+
const claims = claims_of(store);
|
|
379
|
+
await claims.claim(KEY, FIRST, HELD_MS);
|
|
380
|
+
ensure(!await claims.claim(KEY, SECOND, HELD_MS), "a second owner claimed a key the first still holds");
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
name: "the owner can renew its claim",
|
|
385
|
+
run: async (store) => {
|
|
386
|
+
const claims = claims_of(store);
|
|
387
|
+
await claims.claim(KEY, FIRST, HELD_MS);
|
|
388
|
+
ensure(await claims.claim(KEY, FIRST, HELD_MS), RENEWAL_REFUSED);
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
name: "release lets another owner in",
|
|
393
|
+
run: async (store) => {
|
|
394
|
+
const claims = claims_of(store);
|
|
395
|
+
await claims.claim(KEY, FIRST, HELD_MS);
|
|
396
|
+
await claims.release(KEY, FIRST);
|
|
397
|
+
ensure(await claims.claim(KEY, SECOND, HELD_MS), "a released key refused the next owner");
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
name: "release by another owner changes nothing",
|
|
402
|
+
run: async (store) => {
|
|
403
|
+
const claims = claims_of(store);
|
|
404
|
+
await claims.claim(KEY, FIRST, HELD_MS);
|
|
405
|
+
await claims.release(KEY, SECOND);
|
|
406
|
+
ensure(!await claims.claim(KEY, SECOND, HELD_MS), "a release by a non-owner freed the owner's claim");
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
name: "releasing a key nobody holds resolves",
|
|
411
|
+
run: async (store) => {
|
|
412
|
+
await claims_of(store).release(UNCLAIMED, FIRST);
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
name: "claims and values stay apart",
|
|
417
|
+
run: async (store) => {
|
|
418
|
+
const claims = claims_of(store);
|
|
419
|
+
await store.set(KEY, "value");
|
|
420
|
+
ensure(await claims.claim(KEY, FIRST, HELD_MS), "a key that holds a value refused a claim");
|
|
421
|
+
ensure(await store.get(KEY) === "value", "claiming a key changed its value");
|
|
422
|
+
await store.delete(KEY);
|
|
423
|
+
ensure(!await claims.claim(KEY, SECOND, HELD_MS), "deleting a value released the claim on the same key");
|
|
424
|
+
await claims.claim(CLAIMED_ONLY, FIRST, HELD_MS);
|
|
425
|
+
ensure(is_miss(await store.get(CLAIMED_ONLY)), "claiming a key gave it a value");
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: "different keys are claimed apart",
|
|
430
|
+
run: async (store) => {
|
|
431
|
+
const claims = claims_of(store);
|
|
432
|
+
ensure(await claims.claim(A, FIRST, HELD_MS), FREE_CLAIM_REFUSED);
|
|
433
|
+
ensure(await claims.claim(B, SECOND, HELD_MS), "a claim on 'a' blocked a claim on 'b'");
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: "exactly one racing claimer wins a free key",
|
|
438
|
+
run: async (store) => {
|
|
439
|
+
const winners = await race_for(claims_of(store), KEY);
|
|
440
|
+
ensure(winners === 1, `${RACERS} owners raced for a free key and ${winners} won`);
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: "an expired claim passes to another owner",
|
|
445
|
+
run: async (store, env) => {
|
|
446
|
+
const claims = claims_of(store);
|
|
447
|
+
await claims.claim(KEY, FIRST, env.ttl_ms);
|
|
448
|
+
await sleep(env.ttl_ms * 2);
|
|
449
|
+
ensure(await claims.claim(KEY, SECOND, HELD_MS), `a claim was still held after its ${env.ttl_ms}ms ran out`);
|
|
450
|
+
ensure(!await claims.claim(KEY, FIRST, HELD_MS), "the first owner took back a claim that had passed to another");
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
name: "exactly one racing claimer takes an expired claim",
|
|
455
|
+
run: async (store, env) => {
|
|
456
|
+
const claims = claims_of(store);
|
|
457
|
+
await claims.claim(KEY, FIRST, env.ttl_ms);
|
|
458
|
+
await sleep(env.ttl_ms * 2);
|
|
459
|
+
const winners = await race_for(claims, KEY);
|
|
460
|
+
ensure(winners === 1, `${RACERS} owners raced for an expired claim and ${winners} won`);
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: "renewing restarts the clock",
|
|
465
|
+
run: async (store, env) => {
|
|
466
|
+
const claims = claims_of(store);
|
|
467
|
+
const started = Date.now();
|
|
468
|
+
await claims.claim(KEY, FIRST, env.ttl_ms);
|
|
469
|
+
await sleep(env.ttl_ms / 2);
|
|
470
|
+
const renewed = Date.now();
|
|
471
|
+
ensure(await claims.claim(KEY, FIRST, env.ttl_ms), RENEWAL_REFUSED);
|
|
472
|
+
await sleep(Math.max(0, started + env.ttl_ms * 1.2 - Date.now()));
|
|
473
|
+
if (Date.now() >= renewed + env.ttl_ms) return;
|
|
474
|
+
ensure(!await claims.claim(KEY, SECOND, HELD_MS), "a renewed claim expired on its original schedule");
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
],
|
|
478
|
+
applies: (store) => store.claim !== void 0 || store.release !== void 0
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
checks: [
|
|
482
|
+
{
|
|
483
|
+
name: "scopes keep the claim capability",
|
|
484
|
+
run: async (store) => {
|
|
485
|
+
ensure(await claims_of(scope_of(store, A)).claim(KEY, FIRST, HELD_MS), FRESH_SCOPE_CLAIM_REFUSED);
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: "claims in different scopes stay apart",
|
|
490
|
+
run: async (store) => {
|
|
491
|
+
const first = await claims_of(scope_of(store, A)).claim(KEY, FIRST, HELD_MS);
|
|
492
|
+
const second = await claims_of(scope_of(store, B)).claim(KEY, SECOND, HELD_MS);
|
|
493
|
+
const third = await claims_of(store).claim(KEY, THIRD, HELD_MS);
|
|
494
|
+
ensure(first, FRESH_SCOPE_CLAIM_REFUSED);
|
|
495
|
+
ensure(second, "scope 'b' couldn't claim a key held in scope 'a'");
|
|
496
|
+
ensure(third, "the parent couldn't claim a key held in a scope");
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: "clear drops the claims under a scope",
|
|
501
|
+
run: async (store) => {
|
|
502
|
+
const a = scope_of(store, A);
|
|
503
|
+
ensure(await claims_of(a).claim(KEY, FIRST, HELD_MS), FRESH_SCOPE_CLAIM_REFUSED);
|
|
504
|
+
await a.clear();
|
|
505
|
+
ensure(await claims_of(a).claim(KEY, SECOND, HELD_MS), "a claim survived clear");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
],
|
|
509
|
+
applies: (store) => store.scope !== void 0 && store.claim !== void 0
|
|
510
|
+
}
|
|
511
|
+
];
|
|
512
|
+
/**
|
|
513
|
+
* Run one check against a fresh store, resolving its failure message or
|
|
514
|
+
* `undefined` when it passed. A `make_store` that throws fails the check.
|
|
515
|
+
*/
|
|
516
|
+
async function run_check(check, make_store, env) {
|
|
517
|
+
try {
|
|
518
|
+
await check.run(await make_store(), env);
|
|
519
|
+
return;
|
|
520
|
+
} catch (err) {
|
|
521
|
+
return err instanceof Error ? err.message : String(err);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Check a `CheckpointStore` against the contract, one fresh store per check.
|
|
526
|
+
*
|
|
527
|
+
* The capabilities are read off the first store `make_store` returns: scope
|
|
528
|
+
* checks run when it has `scope`, claim checks when it has `claim` or
|
|
529
|
+
* `release`, and the damage check when `options.corrupt` is given. Every
|
|
530
|
+
* other check lands in `skipped`. Checks run one at a time, because some wait
|
|
531
|
+
* on claim expiry and a store's backing service may be shared between the
|
|
532
|
+
* stores `make_store` hands out.
|
|
533
|
+
*/
|
|
534
|
+
async function checkpoint_store_conformance(make_store, options = {}) {
|
|
535
|
+
const env = {
|
|
536
|
+
ttl_ms: options.ttl_ms ?? DEFAULT_TTL_MS,
|
|
537
|
+
corrupt: options.corrupt ?? (() => {})
|
|
538
|
+
};
|
|
539
|
+
const probe = await make_store();
|
|
540
|
+
const passed = [];
|
|
541
|
+
const failed = [];
|
|
542
|
+
const skipped = [];
|
|
543
|
+
for (const suite of SUITES) {
|
|
544
|
+
if (!suite.applies(probe, options)) {
|
|
545
|
+
skipped.push(...suite.checks.map((check) => check.name));
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
for (const check of suite.checks) {
|
|
549
|
+
const message = await run_check(check, make_store, env);
|
|
550
|
+
if (message === void 0) passed.push(check.name);
|
|
551
|
+
else failed.push({
|
|
552
|
+
check: check.name,
|
|
553
|
+
message
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
passed,
|
|
559
|
+
failed,
|
|
560
|
+
skipped
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
//#endregion
|
|
28
564
|
//#region src/testing/make_capture_engine.ts
|
|
29
565
|
const DEFAULT_RESULT = {
|
|
30
566
|
content: "ok",
|
|
@@ -251,6 +787,6 @@ function text_of(opts) {
|
|
|
251
787
|
return texts.join("\n");
|
|
252
788
|
}
|
|
253
789
|
//#endregion
|
|
254
|
-
export { engine_from_generate, make_capture_engine, make_script_engine, make_stub_engine, text_of };
|
|
790
|
+
export { checkpoint_store_conformance, engine_from_generate, make_capture_engine, make_script_engine, make_stub_engine, text_of };
|
|
255
791
|
|
|
256
792
|
//# sourceMappingURL=testing.js.map
|