@quo-systems/quo 0.2.9 → 0.2.11

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.
Files changed (78) hide show
  1. package/README.md +19 -10
  2. package/SPEC.md +301 -110
  3. package/dist/being/being.d.ts +2 -2
  4. package/dist/being/being.js +34 -12
  5. package/dist/being/digest.js +26 -8
  6. package/dist/being/index.d.ts +2 -2
  7. package/dist/being/index.js +2 -2
  8. package/dist/being/silence.d.ts +2 -0
  9. package/dist/being/silence.js +12 -0
  10. package/dist/being/types.d.ts +4 -2
  11. package/dist/being/types.js +25 -0
  12. package/dist/conformance/assert.js +40 -6
  13. package/dist/conformance/beings.d.ts +48 -5
  14. package/dist/conformance/beings.js +39 -8
  15. package/dist/conformance/estate.js +110 -21
  16. package/dist/conformance/index.d.ts +5 -2
  17. package/dist/conformance/index.js +165 -7
  18. package/dist/harbor/core.d.ts +5 -2
  19. package/dist/harbor/core.js +195 -45
  20. package/dist/harbor/dial.js +32 -15
  21. package/dist/harbor/index.d.ts +1 -0
  22. package/dist/harbor/index.js +3 -0
  23. package/dist/harbor/memory.d.ts +3 -3
  24. package/dist/harbor/memory.js +7 -12
  25. package/dist/harbor/reach.js +42 -17
  26. package/dist/ward/allowance.js +15 -4
  27. package/dist/ward/arithmetic.d.ts +1 -0
  28. package/dist/ward/arithmetic.js +22 -6
  29. package/dist/ward/cells.d.ts +3 -1
  30. package/dist/ward/cells.js +79 -21
  31. package/dist/ward/door.d.ts +3 -2
  32. package/dist/ward/door.js +38 -10
  33. package/dist/ward/ground.d.ts +5 -1
  34. package/dist/ward/ground.js +38 -1
  35. package/dist/ward/heirs.d.ts +2 -3
  36. package/dist/ward/heirs.js +19 -13
  37. package/dist/ward/index.d.ts +1 -0
  38. package/dist/ward/index.js +3 -0
  39. package/dist/ward/owner.d.ts +6 -27
  40. package/dist/ward/owner.js +59 -33
  41. package/dist/ward/partition.d.ts +3 -0
  42. package/dist/ward/partition.js +109 -4
  43. package/dist/ward/seal.d.ts +1 -0
  44. package/dist/ward/seal.js +41 -13
  45. package/dist/ward/stance.d.ts +7 -3
  46. package/dist/ward/stance.js +156 -66
  47. package/dist/ward/ward.d.ts +10 -0
  48. package/dist/ward/ward.js +123 -51
  49. package/package.json +4 -2
  50. package/src/being/being.ts +33 -11
  51. package/src/being/digest.ts +28 -13
  52. package/src/being/index.ts +2 -2
  53. package/src/being/silence.ts +14 -0
  54. package/src/being/types.ts +39 -5
  55. package/src/conformance/assert.ts +37 -4
  56. package/src/conformance/beings.ts +41 -10
  57. package/src/conformance/estate.ts +107 -20
  58. package/src/conformance/index.ts +188 -13
  59. package/src/harbor/core.ts +203 -46
  60. package/src/harbor/dial.ts +46 -17
  61. package/src/harbor/index.ts +3 -0
  62. package/src/harbor/memory.ts +8 -13
  63. package/src/harbor/reach.ts +47 -21
  64. package/src/ward/allowance.ts +15 -4
  65. package/src/ward/arithmetic.ts +25 -8
  66. package/src/ward/cells.ts +76 -25
  67. package/src/ward/door.ts +38 -12
  68. package/src/ward/ground.ts +52 -3
  69. package/src/ward/heirs.ts +19 -13
  70. package/src/ward/index.ts +3 -0
  71. package/src/ward/owner.ts +65 -46
  72. package/src/ward/partition.ts +109 -5
  73. package/src/ward/seal.ts +41 -12
  74. package/src/ward/stance.ts +163 -64
  75. package/src/ward/ward.ts +124 -52
  76. package/vectors/arithmetic.json +7 -0
  77. package/vectors/framing.json +30 -15
  78. package/vectors/wire.json +4 -4
@@ -22,7 +22,7 @@
22
22
  // harbors, and that is where the promise of Quo is held: a being never learns
23
23
  // where the other one is, so every answer, after every move, under every
24
24
  // topology, is the answer the model wrote without knowing the topology
25
- // either. Held forty times a run, it is the promise at a scale a scene
25
+ // either. Held after every one of sixty moves, it is the promise at a scale a scene
26
26
  // cannot reach, and it is what makes a migration honest: if no answer can
27
27
  // tell the topology apart, moving a ward between harbors cannot be felt.
28
28
  // The model itself is the script's own bookkeeping and takes nothing from a
@@ -35,10 +35,10 @@
35
35
  // A model that kept one symmetric edge would be a wrong model, and would
36
36
  // agree happily with a ward that had drifted.
37
37
  import { assert } from './assert.js';
38
- import { isSilence, isUnreached, isWord, wordOf } from '../being/silence.js';
38
+ import { isSilence, isUnreached, told } from '../being/silence.js';
39
39
  import { Member } from './beings.js';
40
- const HEX64 = /^[0-9a-f]{64}$/;
41
- const said = (x, w) => isWord(x) && wordOf(x) === w;
40
+ import { HEX64 } from './index.js';
41
+ const said = (x, w) => told(x) === w;
42
42
  // A pseudo-random source in the language alone: the estate must replay, on
43
43
  // every terrain, from a number a failure can print.
44
44
  const rolls = (seed) => () => {
@@ -51,9 +51,48 @@ const rolls = (seed) => () => {
51
51
  // Held after every move. Each line is a way the bookkeeping could stop being
52
52
  // a graph: an arc with one end, an arc with two owners, a relation filed in
53
53
  // two places at once, a count that went backwards, a secret in the cells.
54
- function ledger(c, before, where) {
54
+ function ledger(c, before, where, g) {
55
55
  const at = (why) => `${where}: ${why}`;
56
56
  const heirsSeen = new Set();
57
+ // What the model knows, which the ward's own bookkeeping cannot tell it.
58
+ // Without this the ledger only checks the ward against itself, and a drift
59
+ // is caught late, if the sweep happens to ask the affected arc, or never.
60
+ if (g) {
61
+ for (const s of g.seats) {
62
+ const heir = c.wards[c.binds[s.host].ward].heirs[s.inv.heir];
63
+ if (!s.live) {
64
+ assert.ok(!heir, at(`${s.host} kicked ${s.id} and the heir is still held`));
65
+ assert.ok(!(s.id in c.binds[s.host].occupants), at(`${s.host} kicked ${s.id} and still holds the occupant`));
66
+ continue;
67
+ }
68
+ assert.ok(heir, at(`${s.host}'s live seat ${s.id} has no heir`));
69
+ assert.equal(heir.id, s.id, at(`the heir for ${s.host}/${s.id} is filed under ${heir.id}`));
70
+ // A seat nobody has knocked is a heir that has never spoken: fresh, and
71
+ // at zero. One that answered has spoken, so it is neither.
72
+ assert.equal(heir.fresh, !s.answered, at(`${s.host}/${s.id} is ${s.answered ? 'answered' : 'unknocked'} and its heir says fresh=${heir.fresh}`));
73
+ assert.equal(heir.mark === 0, !s.answered, at(`${s.host}/${s.id} is ${s.answered ? 'answered' : 'unknocked'} and its heir is at ${heir.mark}`));
74
+ }
75
+ for (const h of g.holds) {
76
+ const standing = c.binds[h.owner].standings[h.id];
77
+ if (!h.live) {
78
+ assert.ok(!standing, at(`${h.owner} dropped ${h.id} and the standing is still there`));
79
+ continue;
80
+ }
81
+ assert.ok(standing, at(`${h.owner}'s live standing ${h.id} is gone from the bind table`));
82
+ assert.equal(standing.heir, h.seat.inv.heir, at(`${h.owner}/${h.id} names a heir that is not the seat it was born on`));
83
+ // The count she has spent, against the number the far door honoured.
84
+ // Her side is never behind: she takes a number, then it crosses.
85
+ const far = c.wards[c.binds[h.seat.host].ward].heirs[h.seat.inv.heir];
86
+ if (far)
87
+ assert.ok(standing.seq >= far.mark, at(`${h.owner}/${h.id} counted ${standing.seq} and the far door has honoured ${far.mark}`));
88
+ }
89
+ // Every seat and hold the model knows about, and no relation the ward
90
+ // holds that the model never made.
91
+ const mine = new Set(g.seats.filter((s) => s.live).map((s) => `${s.host}/${s.id}`));
92
+ for (const [key, b] of Object.entries(c.binds))
93
+ for (const id of Object.keys(b.occupants))
94
+ assert.ok(mine.has(`${key}/${id}`), at(`${key} holds an occupant ${id} the model never made`));
95
+ }
57
96
  for (const [pk, w] of Object.entries(c.wards)) {
58
97
  for (const [heir, r] of Object.entries(w.heirs)) {
59
98
  assert.ok(!heirsSeen.has(heir), at(`heir ${heir} is held by two wards`));
@@ -151,6 +190,18 @@ export function estate(label, make, { canDown, test }) {
151
190
  const pick = (xs) => xs[Math.floor(roll() * xs.length)];
152
191
  const hands = {};
153
192
  const g = { seats: [], holds: [] };
193
+ // What this run actually got to. A generated walk protects only the
194
+ // states it reaches, and a list of assertions nobody ran is a list of
195
+ // assertions nobody has. Every case named here is checked off as it
196
+ // fires and the run fails at the end if one never did.
197
+ const reached = new Set();
198
+ const MUST = [
199
+ 'a kicked seat knocked by the guest it bound, who hears removed',
200
+ 'a standing dropped by its owner, whose host is never told',
201
+ 'a seat kicked by its host, whose guest is never told',
202
+ 'a relation taken, so it lives in the standing and not the knock',
203
+ 'a ward moved to another harbor under everyone standing on it',
204
+ ];
154
205
  let minted = 0;
155
206
  const born = async (key) => (hands[key] = await w.boot(key, Member));
156
207
  for (const key of ['M1', 'M2', 'M3'])
@@ -177,23 +228,40 @@ export function estate(label, make, { canDown, test }) {
177
228
  // taken it the invitation is not a knock any more -- it joins the
178
229
  // standing's lane, and is exactly as alive as the standing is.
179
230
  for (const s of g.seats) {
180
- out.push(async () => {
231
+ const knock = async () => {
181
232
  const guest = s.guest ?? pick(keys.filter((k) => k !== s.host));
182
233
  const hold = g.holds.find((h) => h.seat === s);
183
234
  const back = await hands[guest].being.knock(s.inv, 'ping');
184
- if (s.live && (s.guest === null || s.guest === guest) && (hold === undefined || hold.live)) {
235
+ // Whether this knock is heard at all: the seat has no guest yet,
236
+ // or its guest is this one, and nothing of hers has dropped the
237
+ // key the door would bind her by. A hold exists only where a
238
+ // guest does, so the two tests are one condition and not two.
239
+ // Then the seat says which answer: alive is the pong, kicked is
240
+ // `removed`, and unheard is silence whichever it is.
241
+ const speaks = (s.guest === null || s.guest === guest) && (hold === undefined || hold.live);
242
+ if (!speaks)
243
+ assert.ok(isSilence(back), `${guest} knocking ${s.host}/${s.id} should be silence`);
244
+ else if (s.live) {
185
245
  assert.deepEqual(back, { pong: s.id }, `${guest} knocking ${s.host}/${s.id}`);
186
246
  s.guest = guest;
187
247
  s.answered = true;
188
248
  }
189
- else if (!s.live && (s.guest === null || (s.guest === guest && (hold === undefined || hold.live)))) {
190
- // kicked, and she speaks under a key the door bound for this seat: she hears why
249
+ else {
191
250
  assert.ok(said(back, 'removed'), `${guest} knocking kicked ${s.host}/${s.id} should hear removed`);
251
+ reached.add('a kicked seat knocked by the guest it bound, who hears removed');
192
252
  }
193
- else
194
- assert.ok(isSilence(back), `${guest} knocking ${s.host}/${s.id} should be silence`);
195
253
  return `${guest} knocks ${s.host}/${s.id}`;
196
- });
254
+ };
255
+ out.push(knock);
256
+ // Weighted, not written twice: the case this move exists to protect
257
+ // is a seat kicked after it answered and before it was taken, and a
258
+ // uniform walk over a list that grows with every invitation reaches
259
+ // it by luck if at all. Three entries make it likely by
260
+ // construction, and the count at the end of the run makes it
261
+ // certain: a walk that never got there fails rather than passing
262
+ // quietly on an assertion that never ran.
263
+ if (!s.live && s.answered && !s.taken)
264
+ out.push(knock, knock);
197
265
  // a stranger on a spent seat: silence, and nothing rebinds
198
266
  if (s.guest !== null)
199
267
  out.push(async () => {
@@ -213,6 +281,7 @@ export function estate(label, make, { canDown, test }) {
213
281
  assert.equal(await hands[s.guest].being.take(id, s.inv), id);
214
282
  s.taken = true;
215
283
  g.holds.push({ owner: s.guest, id, seat: s, live: true });
284
+ reached.add('a relation taken, so it lives in the standing and not the knock');
216
285
  assert.equal(await hands[s.guest].being.take(`${id}-again`, s.inv), null); // spent for her
217
286
  return `${s.guest} takes ${s.host}/${s.id} as ${id}`;
218
287
  });
@@ -221,6 +290,7 @@ export function estate(label, make, { canDown, test }) {
221
290
  out.push(async () => {
222
291
  hands[h.owner].being.standings.remove(h.id);
223
292
  h.live = false;
293
+ reached.add('a standing dropped by its owner, whose host is never told');
224
294
  assert.equal(hands[h.owner].being.standings[h.id], undefined);
225
295
  return `${h.owner} drops ${h.id}`;
226
296
  });
@@ -229,6 +299,7 @@ export function estate(label, make, { canDown, test }) {
229
299
  out.push(async () => {
230
300
  hands[s.host].being.occupants.remove(s.id);
231
301
  s.live = false;
302
+ reached.add('a seat kicked by its host, whose guest is never told');
232
303
  return `${s.host} kicks ${s.id}`;
233
304
  });
234
305
  // a new being: an estate grows
@@ -238,11 +309,10 @@ export function estate(label, make, { canDown, test }) {
238
309
  out.push(async () => {
239
310
  const who = pick(keys);
240
311
  await w.migrate(who);
312
+ reached.add('a ward moved to another harbor under everyone standing on it');
241
313
  return `${who}'s ward moves harbor`;
242
314
  });
243
315
  // weather: the host's door is gone. unreached, never silence, and the
244
- // relation is exactly where it was when it comes back.
245
- // weather: the host's door is gone. unreached, never silence, and the
246
316
  // relation is exactly where it was when it comes back. The move is on
247
317
  // the list under every topology even where there is nothing to cut,
248
318
  // because the list is the script: a move missing in one world would
@@ -279,21 +349,40 @@ export function estate(label, make, { canDown, test }) {
279
349
  // sequence debuggable at all.
280
350
  const trace = [];
281
351
  const at = (step) => `seed ${seed} step ${step}\n ${trace.join('\n ')}`;
282
- for (let step = 1; step <= 60; step++) {
283
- const move = pick(moves());
352
+ // Whatever fails inside a step carries the trace that got there. One
353
+ // wrapper, so the move and the sweep are decorated the same way and a
354
+ // third thing added to a step cannot be decorated a fourth.
355
+ const inStep = async (step, work) => {
284
356
  try {
285
- trace.push(await move());
357
+ return await work();
286
358
  }
287
359
  catch (e) {
288
360
  throw new Error(`${at(step)}\n -> ${e.message}`, { cause: e });
289
361
  }
362
+ };
363
+ for (let step = 1; step <= 60; step++) {
364
+ const move = pick(moves());
365
+ // The move that failed goes into the trace before it runs, not after
366
+ // it returns: a move names itself as it finishes, so a throw left the
367
+ // trace ending at the last move that worked and saying nothing about
368
+ // the one that did not. It is written in twice, provisionally and
369
+ // then as it named itself, and the provisional line goes when the
370
+ // real one lands.
371
+ trace.push(`step ${step}: a move that has not said what it did`);
372
+ const did = await inStep(step, move);
373
+ trace[trace.length - 1] = did;
290
374
  const c = w.census();
291
- ledger(c, before, at(step));
375
+ ledger(c, before, at(step), g);
292
376
  before = c;
293
- await sweep(step).catch((e) => {
294
- throw new Error(`${at(step)}\n -> ${e.message}`, { cause: e });
295
- });
377
+ await inStep(step, () => sweep(step));
296
378
  }
379
+ // And the walk is held to having gone somewhere. Sixty moves under one
380
+ // seed is a sample, not a proof, so the states the chapter is written
381
+ // to protect are named and counted: a run that never reached one has
382
+ // not tested it, and says so here rather than passing on an assertion
383
+ // that never ran.
384
+ const missed = MUST.filter((what) => !reached.has(what));
385
+ assert.deepEqual(missed, [], `seed ${seed} never reached: ${missed.join('; ')}\n ${trace.join('\n ')}`);
297
386
  });
298
387
  }
299
388
  }
@@ -1,5 +1,5 @@
1
1
  import type { BeingClass, Cells, Invitation, JsonObject } from '../being/types.ts';
2
- import { Printer, Shop, Customer, Echo, Member } from './beings.ts';
2
+ import { Printer, Shop, Customer, Echo, Maker, Member } from './beings.ts';
3
3
  export type Handle<B = unknown> = {
4
4
  pk: string;
5
5
  being: B;
@@ -52,8 +52,11 @@ export type World = {
52
52
  heir(inv: Invitation): HeirView | undefined;
53
53
  census(): Census;
54
54
  migrate(key: string): Promise<void>;
55
+ owner(key: string): (method?: string, args?: JsonObject) => Promise<unknown>;
55
56
  };
56
- export { Printer, Shop, Customer, Echo, Member };
57
+ export { Printer, Shop, Customer, Echo, Maker, Member };
58
+ export declare const HEX64: RegExp;
59
+ export declare const HEX128: RegExp;
57
60
  export type Runner = (name: string, opts: {
58
61
  skip?: string | false;
59
62
  }, fn: () => Promise<void> | void) => void;
@@ -12,21 +12,27 @@
12
12
  // handle.being the object, as the test drives it
13
13
  // handle.cells her cells, as the ward keeps them
14
14
  // handle.down = true | false her door is unreachable (needs canDown)
15
- // handle.minted.has(pk) every pk her side ever minted
15
+ // handle.minted.has(pk) the last eight pks her side minted
16
16
  // handle.forgeKnock(invitation) make her side knock with a key of its own, unannounced
17
17
  // world.census() every partition in the world, as values
18
18
  // world.migrate(key) her ward moves to another harbor, same seed, same pk
19
19
  //
20
20
  // Every assertion here is the truth's. Nothing here knows how a ward is built.
21
21
  import { assert } from './assert.js';
22
- import { silence, isSilence, isUnreached, isWord, wordOf } from '../being/silence.js';
22
+ import { silence, isSilence, isUnreached, told } from '../being/silence.js';
23
23
  import { digest } from '../being/digest.js';
24
- import { Printer, Shop, Customer, Echo, Member } from './beings.js';
24
+ import { Printer, Shop, Customer, Echo, Maker, Member } from './beings.js';
25
25
  import { estate } from './estate.js';
26
- export { Printer, Shop, Customer, Echo, Member };
27
- const HEX64 = /^[0-9a-f]{64}$/;
26
+ export { Printer, Shop, Customer, Echo, Maker, Member };
27
+ // The two shapes the suite asserts, spelled here for the whole folder. They
28
+ // are spelled again in `src/ward/seal.ts`, and that is the point: this suite
29
+ // is what a second kit runs against its own ward, so it states the shapes it
30
+ // expects instead of importing ours, and nothing under `src/conformance`
31
+ // reaches into `src/ward` for anything.
32
+ export const HEX64 = /^[0-9a-f]{64}$/; // one key, one secret, one digest
33
+ export const HEX128 = /^[0-9a-f]{128}$/; // a ward pk: the signing pk then the padlock
28
34
  // Her ward's word, as she receives it.
29
- const said = (x, w) => isWord(x) && wordOf(x) === w;
35
+ const said = (x, w) => told(x) === w;
30
36
  export function conform(label, make, { canDown = true, test }) {
31
37
  const t = (name, fn) => test(`[${label}] ${name}`, {}, fn);
32
38
  const down = (name, fn) => test(`[${label}] ${name}`, { skip: !canDown && 'nothing to cut inside one ward' }, fn);
@@ -47,7 +53,7 @@ export function conform(label, make, { canDown = true, test }) {
47
53
  const inv = await shop.being.invite('gold');
48
54
  assert.deepEqual(Object.keys(shop.cells.occupants), ['cust1']);
49
55
  assert.deepEqual(Object.keys(inv).sort(), ['heir', 'secret', 'ward']);
50
- assert.match(inv.ward, /^[0-9a-f]{128}$/);
56
+ assert.match(inv.ward, HEX128);
51
57
  assert.match(inv.heir, HEX64);
52
58
  assert.match(inv.secret, HEX64);
53
59
  assert.equal(inv.ward, shop.pk);
@@ -148,6 +154,156 @@ export function conform(label, make, { canDown = true, test }) {
148
154
  assert.ok(said(await alice.being.join(inv2), 'removed'));
149
155
  assert.deepEqual(Object.keys(alice.cells.standings), ['shop']);
150
156
  });
157
+ // ---- the names that are nobody's to take
158
+ //
159
+ // Two lists, refused at both ends of the same namespace. The ward speaks
160
+ // under its own words, so a being who could mint one would be a being whose
161
+ // ward is indistinguishable from an occupant of hers. And standings are
162
+ // reached by name, so a relation taken as one of the calls on them would be
163
+ // a relation nothing can reach. A kit that ported invite without either
164
+ // list passes every other scene in this file.
165
+ t('the reserved ids and the calls on standings are refused at invite and at take, and nothing is written for them', async () => {
166
+ // alice hosts here rather than the shop, because the shop's own `invite`
167
+ // takes a tier and mints the id itself. This one is the stance's, which
168
+ // is where the rule lives.
169
+ const { alice, bob } = await world();
170
+ for (const id of ['OWNER', 'PUBLIC', 'knock', 'take', 'remove']) {
171
+ assert.equal(await alice.being.invite(id), null, `${id} is not hers to mint`);
172
+ assert.equal(Object.hasOwn(alice.cells.occupants, id), false, `and nothing was written for ${id}`);
173
+ // The other end: a guest is answered and then refused the name.
174
+ const inv = (await alice.being.invite(`for-${id}`));
175
+ assert.deepEqual(await bob.being.knock(inv, 'hi'), { heard: 'hi' }, `the knock for ${id} was answered`);
176
+ assert.equal(await bob.being.take(id, inv), null, `take refuses ${id} for the same reason`);
177
+ assert.equal(Object.hasOwn(bob.cells.standings, id), false, `and nothing was written for ${id}`);
178
+ assert.equal(await bob.being.take(`as-${id}`, inv), `as-${id}`, 'and an ordinary id takes the same invitation');
179
+ }
180
+ // And the three calls are still the calls, not records that shadowed them.
181
+ for (const call of ['knock', 'take', 'remove'])
182
+ assert.equal(typeof bob.being.standings[call], 'function', `standings.${call} is the call`);
183
+ });
184
+ // ---- the owner
185
+ //
186
+ // The second pointer a ward hands back. Every ask below answers an object,
187
+ // because the owner hears objects and never a word: a refusal is `{ error }`
188
+ // with its reason, which is what a side renders.
189
+ t('the owner boots, marks one public being, invites, knocks, removes and unboots, and refuses each in an object', async () => {
190
+ const { w, shop, alice } = await world();
191
+ const ask = w.owner('S');
192
+ const bp = (await ask());
193
+ assert.deepEqual(bp.asks.map((a) => a.name), ['boot', 'public', 'invite', 'knock', 'remove', 'unboot'], 'six asks, in this order');
194
+ for (const a of bp.asks) {
195
+ assert.equal(typeof a.description, 'string', `${a.name} says what it is for`);
196
+ assert.equal(a.input.type, 'object', `${a.name} takes one object`);
197
+ }
198
+ assert.match(bp.notes.pk, HEX128);
199
+ assert.equal(typeof bp.notes.beings, 'object');
200
+ assert.deepEqual(await ask('nosuch'), { error: 'unknown ask' });
201
+ // boot: a key already taken is refused, and so is a class nobody holds.
202
+ assert.deepEqual(await ask('boot', { key: 'S', class: 'Shop' }), { error: 'no such class, or key taken' });
203
+ assert.deepEqual(await ask('boot', { key: 'fresh', class: 'NoSuchClass' }), { error: 'no such class, or key taken' });
204
+ assert.deepEqual(await ask('boot', { key: 42, class: 'Shop' }), { error: 'no such class, or key taken' }, 'a name is a string or it is nothing');
205
+ // public: one per ward, null takes the mark off, and the ward is nobody's
206
+ // public being.
207
+ assert.deepEqual(await ask('public', { key: 'nobody' }), { error: 'no such being' });
208
+ assert.deepEqual(await ask('public', { key: bp.notes.pk }), { error: 'no such being' }, 'the ward is a being to nobody outside');
209
+ // invite and remove, on a being of the ward, by id.
210
+ assert.deepEqual(await ask('invite', { being: 'nobody', id: 'x' }), { error: 'no such being' });
211
+ const inv = (await ask('invite', { being: 'S', id: 'by-owner', notes: { tier: 'gold' } }));
212
+ assert.match(inv.heir, HEX64);
213
+ assert.deepEqual(shop.cells.occupants['by-owner'].notes, { tier: 'gold' }, 'the notes she minted under are hers to read');
214
+ assert.deepEqual(await ask('remove', { being: 'S', id: 'nothing-of-hers' }), { error: 'nothing to remove' });
215
+ assert.deepEqual(await ask('remove', { being: 'S', id: 'by-owner' }), { removed: 'by-owner' });
216
+ assert.equal(Object.hasOwn(shop.cells.occupants, 'by-owner'), false);
217
+ // knock: the owner knocks for a being of hers and takes the standing.
218
+ const forA = (await ask('invite', { being: 'S', id: 'for-alice' }));
219
+ const knocked = (await w.owner('A'))('knock', { being: 'A', id: 'via-owner', invitation: forA, method: 'hello' });
220
+ assert.deepEqual(await knocked, { taken: 'via-owner', answer: { welcome: true } });
221
+ assert.deepEqual(Object.keys(alice.cells.standings), ['via-owner']);
222
+ assert.deepEqual(await alice.being.standings['via-owner'].ask('hello'), { welcome: true }, 'and it is an ordinary standing');
223
+ // unboot: the inverse of boot, and the ward refuses itself.
224
+ assert.deepEqual(await ask('unboot', { being: bp.notes.pk }), { error: 'no such being' });
225
+ assert.deepEqual(await ask('unboot', { being: 'nobody' }), { error: 'no such being' });
226
+ const gone = (await ask('unboot', { being: 'S' }));
227
+ assert.equal(gone.unbooted, 'S');
228
+ assert.ok(gone.removed.includes('for-alice'), 'her relations went with her, and the owner is told which');
229
+ assert.ok(said(await alice.being.standings['via-owner'].ask('hello'), 'removed'), 'and her occupant hears removed at the door');
230
+ });
231
+ // The one public being, marked and unmarked through the owner. A second
232
+ // one would leave the first holding every relation she had, reachable by
233
+ // nobody at the bare pk and told by nobody that she had been replaced.
234
+ t('a ward has one public being: a second is refused, null takes the mark off, and she keeps everything she held', async () => {
235
+ const { w, alice } = await world();
236
+ const ask = w.owner('A');
237
+ assert.deepEqual(await ask('public', { key: 'A' }), { public: 'A' });
238
+ assert.deepEqual(await ask('public', { key: 'A' }), { public: 'A' }, 'marking the same one again is not a second');
239
+ const bp = (await ask());
240
+ assert.equal(bp.notes.beings.A.public, true, 'and the owner sees which one she is');
241
+ const inv = (await alice.being.invite('kept'));
242
+ assert.deepEqual(await ask('public', { key: null }), { public: null }, 'null takes the mark off');
243
+ const off = (await ask());
244
+ assert.equal(off.notes.beings.A.public, false);
245
+ assert.ok(Object.hasOwn(alice.cells.occupants, 'kept'), 'retiring her is not destroying her: every relation she held is still hers');
246
+ assert.equal(inv.ward, alice.pk);
247
+ });
248
+ // A relation she dropped is nobody's. The word is her own ward's, said to
249
+ // her and never crossing a door, because there is no door left to ask.
250
+ t('a standing she dropped is dropped: the word is hers, nothing crosses, and the far side is never told', async () => {
251
+ const { shop, alice } = await world();
252
+ await alice.being.join(await shop.being.invite());
253
+ const standing = alice.being.standings.shop;
254
+ alice.being.standings.remove('shop');
255
+ assert.deepEqual(alice.cells.standings, {}, 'gone from her cells');
256
+ assert.equal(alice.being.standings.shop, undefined, 'and gone from her stance');
257
+ assert.ok(said(await standing.ask('hello'), 'dropped'), 'a handle she kept over the drop reaches nothing, and says so');
258
+ assert.ok(Object.hasOwn(shop.cells.occupants, 'cust1'), 'the far side holds her seat still: dropping is hers alone and she tells nobody');
259
+ });
260
+ // ---- a being may make
261
+ //
262
+ // `boot` is on every stance, so a kit that never wired it hands its beings a
263
+ // call that answers null for ever and nothing else here would notice.
264
+ t('a being boots one of her ward s classes from inside her own answer, and may ask for a way back to what she made', async () => {
265
+ const { w } = await world();
266
+ const maker = await w.boot('MK', Maker);
267
+ // A harbor holds the classes its device gave it, so one Member is booted
268
+ // to put the class there. What the maker does after that is the ward's.
269
+ await w.boot('MEM', Member);
270
+ assert.deepEqual(await maker.being.open({ class: 'Member', key: 'made-1' }), { made: 'made-1' });
271
+ assert.deepEqual(await maker.being.open({ class: 'Member', key: 'made-1' }), { made: null }, 'a key already taken makes nobody');
272
+ assert.deepEqual(await maker.being.open({ class: 'NoSuchClass', key: 'made-2' }), { made: null }, 'a class the harbor does not hold makes nobody');
273
+ assert.deepEqual(maker.cells.made, ['made-1']);
274
+ // With an id she holds a standing to what she made, and the being made
275
+ // knows her by her own key and by nothing else.
276
+ assert.deepEqual(await maker.being.open({ class: 'Member', key: 'made-3', id: 'mine' }), { made: 'made-3' });
277
+ assert.deepEqual(await maker.being.say({ id: 'mine' }), { said: { pong: 'MK' } }, 'she asks through the relation, and arrives under her own key');
278
+ assert.deepEqual(await maker.being.say({ id: 'nothing' }), { said: null });
279
+ });
280
+ // The case the estate's walk reaches by weight and this reaches by hand: a
281
+ // seat kicked after it answered and before it was taken. She holds a key
282
+ // the door bound for her, so she is the one person who hears why, and she
283
+ // hears it every time. A kit that forgot to keep the last keys of a
284
+ // forgotten heir answers her silence, which is what it says to a stranger,
285
+ // and she cannot tell being kicked from never having been let in.
286
+ t('a relation kicked between the knock and the take: she hears removed, every time, and the take births nothing', async () => {
287
+ const { shop, alice, bob } = await world();
288
+ const inv = await shop.being.invite();
289
+ assert.deepEqual(await alice.being.knock(inv, 'hello'), { welcome: true }, 'she knocked and was answered');
290
+ shop.being.occupants.remove('cust1'); // kicked, and she is not told
291
+ for (let i = 0; i < 3; i++)
292
+ assert.ok(said(await alice.being.knock(inv, 'hello'), 'removed'), `knock ${i}: a spent heir stays spent, and she hears why every time`);
293
+ // And the take still births one: it reads the knock record, which says
294
+ // she was answered, and the far side kicking her afterwards is not
295
+ // something her side can know or should guess at. The standing is hers,
296
+ // and it is the standing that hears removed from then on. A kit that
297
+ // refused the take here would leave her with no record to read the
298
+ // refusal through, and nothing to drop.
299
+ assert.equal(await alice.being.take('shop', inv), 'shop', 'the take reads the knock record, and the knock was answered');
300
+ assert.ok(said(await alice.being.standings.shop.ask('hello'), 'removed'), 'and the standing is where she hears it now');
301
+ alice.being.standings.remove('shop');
302
+ assert.deepEqual(alice.cells.standings, {}, 'hers to drop, like any other');
303
+ // And only to her: the same invitation in anyone else's hand is silence,
304
+ // because the keys the door kept are hers and nobody else's.
305
+ assert.ok(isSilence(await bob.being.knock(inv, 'hello')), 'a stranger holding the same invitation learns nothing at all');
306
+ });
151
307
  t('take without a knock, or after a knock that was not answered, births nothing', async () => {
152
308
  const { shop, alice } = await world();
153
309
  const inv = await shop.being.invite();
@@ -384,6 +540,8 @@ export function conform(label, make, { canDown = true, test }) {
384
540
  // ---- public
385
541
  t('a public being is asked by anyone as {}; a knock on her needs no heir and may be taken; a ward with none is silence; an unknown pk is unreached', async () => {
386
542
  const w = await make();
543
+ // A being written by hand: no base class, one answer, and the stance is
544
+ // all she is handed. She is a being to the ward on those terms alone.
387
545
  class Pub {
388
546
  s;
389
547
  constructor(s) {
@@ -1,4 +1,4 @@
1
- import type { WardPointers } from '../ward/ground.ts';
1
+ import { type WardPointers } from '../ward/ground.ts';
2
2
  import type { BeingClass, BeingLike } from '../being/types.ts';
3
3
  import { type Reach } from './reach.ts';
4
4
  import type { Kept, Store, WardRecord } from './store.ts';
@@ -6,8 +6,8 @@ export type Hosted = WardPointers & {
6
6
  pk: string;
7
7
  name: string;
8
8
  record: WardRecord;
9
- partition: Record<string, unknown>;
10
9
  being(key: string): BeingLike | undefined;
10
+ keys(): string[];
11
11
  save(): Promise<void>;
12
12
  };
13
13
  export type Bound = {
@@ -28,11 +28,14 @@ export declare class Harbor {
28
28
  readonly reaches: Map<string, Bound>;
29
29
  readonly down: Set<string>;
30
30
  readonly refused: Map<string, number>;
31
+ readonly faults: Map<string, number>;
32
+ readonly unbooted: string[];
31
33
  readonly classes: Record<string, BeingClass>;
32
34
  readonly fallbacks: Reach[];
33
35
  readonly announcers: Set<() => void>;
34
36
  constructor(store: Store, loader?: Loader);
35
37
  boot(): Promise<void>;
38
+ partitionOf(name: string): Record<string, unknown> | undefined;
36
39
  carry(pk: string, bytes: Uint8Array): Promise<Uint8Array | undefined>;
37
40
  deliver(pk: string, bytes: Uint8Array): Promise<Uint8Array | undefined>;
38
41
  hint(pk: string, url: string): void;