@byollm/relay 0.1.0-alpha.21 → 0.1.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,512 @@
1
+ import { PublicIdentity, JobStub, SealedEnvelope, ClaimedStub } from '@byollm/protocol';
2
+
3
+ /**
4
+ * The relay's routing state — byollm_009 §7, reachable at last.
5
+ *
6
+ * §7 described a state machine the direct plane could not produce. There, the
7
+ * site and the upstream are the same party: it seals when it likes, and a job
8
+ * is never claimed-but-unsealed. Here they are different parties, and the gap
9
+ * between them is a state:
10
+ *
11
+ * ```
12
+ * queued ──claim──▶ awaiting-payload ──sealed──▶ ready ──fetch──▶ running
13
+ * ▲ │ │
14
+ * └────────────────────┘ ▼
15
+ * site never seals, or seals too late ok | error | canceled
16
+ * ```
17
+ *
18
+ * The relay cannot seal, so it cannot shortcut this. A payload is encrypted
19
+ * to *the device that claimed it*, and nobody knows which device that is until
20
+ * the claim happens — which is precisely why claim-then-fetch makes a blind
21
+ * relay possible at all. The window is the price.
22
+ *
23
+ * ## What the relay holds, and what it cannot
24
+ *
25
+ * Stubs (metadata the site chose to publish), sealed envelopes it cannot open,
26
+ * and public keys. There is no field on any type in this file that could hold
27
+ * a private key or a plaintext, which is `RELAY_BLIND` expressed as a data
28
+ * model rather than as a policy.
29
+ */
30
+ /** Where a routed job is. */
31
+ type RoutedState = "queued" | "awaiting-payload" | "ready" | "running" | "done";
32
+ /**
33
+ * How long a site has to seal after one of its jobs is claimed.
34
+ *
35
+ * **Distinct from the lease, and distinct from the job's TTL** — byollm_009
36
+ * §7.1. Three clocks, three different questions:
37
+ *
38
+ * - the **TTL** asks how long the work is worth doing at all;
39
+ * - the **lease** asks how long this device gets to run it;
40
+ * - this asks how long we wait for a site that has gone away.
41
+ *
42
+ * Collapsing any pair of them looks harmless until a site restarts during a
43
+ * deploy: with only a lease, the device sits politely holding a job whose
44
+ * payload will never arrive, and the lease's whole minute is spent waiting on
45
+ * a party that is not coming back. Short, because a site that is up answers in
46
+ * milliseconds and a site that is down will not answer sooner for waiting.
47
+ */
48
+ declare const AWAITING_PAYLOAD_MS = 10000;
49
+ /** A job the relay is routing. Metadata and ciphertext, nothing else. */
50
+ /** Why a daemon gave a job back. Only `refused` means "not me, ever". */
51
+ type ReleaseReason = "shutdown" | "pause" | "revoked" | "backend-down" | "refused";
52
+ interface RoutedJob {
53
+ readonly id: string;
54
+ /** Which site enqueued it — the party that will be asked to seal. */
55
+ readonly siteId: string;
56
+ /**
57
+ * Everything the relay knows about the work, which is everything the site
58
+ * chose to publish and not one field more (byollm_009 §6).
59
+ */
60
+ readonly stub: JobStub;
61
+ state: RoutedState;
62
+ /** Set from the claim; the site seals to these keys. */
63
+ claimedBy?: {
64
+ readonly runnerId: string;
65
+ readonly owner: string;
66
+ readonly device: PublicIdentity;
67
+ readonly leaseId: string;
68
+ readonly leaseExpiresAt: number;
69
+ };
70
+ /** When {@link AWAITING_PAYLOAD_MS} runs out for this claim. */
71
+ awaitingUntil?: number;
72
+ /**
73
+ * Runners that released this job with reason `refused` — cloud_008 §2.1.
74
+ *
75
+ * `REFUSAL_NOT_REOFFERED`, which the relay did not implement: it dropped
76
+ * `ReleaseRequest.reason` on the floor. The field's own docstring says why
77
+ * that is not cosmetic — an upstream cannot evaluate a daemon's *local*
78
+ * `named` allowlist, so it may legitimately offer work the daemon then
79
+ * declines, and without a record the two spin between claim and release
80
+ * forever. The direct plane has always kept this list.
81
+ */
82
+ refusedBy: string[];
83
+ /**
84
+ * The site withdrew this job — cloud_008 §2.2.
85
+ *
86
+ * A flag rather than a state, because a cancelled job that a device is
87
+ * *running* is not finished: the daemon has to be told, abort its backend
88
+ * call and report `canceled`, and the ordinary `complete` path then closes
89
+ * it. Making it a state would strand the in-flight case between two
90
+ * machines' ideas of what happened.
91
+ */
92
+ cancelled?: boolean;
93
+ /** Sealed to the claiming device by the site. Opaque here. */
94
+ payload?: SealedEnvelope;
95
+ /** Sealed to the site by the device. Opaque here. */
96
+ result?: SealedEnvelope;
97
+ /**
98
+ * The result's clear-text discriminator — byollm_009 §6.1.
99
+ *
100
+ * The one outcome fact the relay is given, and the reason it is given:
101
+ * without it the relay cannot stop dispatching a finished job. A routing
102
+ * hint and never a fact — the *site* verifies it against the sealed
103
+ * outcome, because only the site can open the envelope. The relay acts on
104
+ * it and is entitled to be wrong; a lying daemon costs it a dispatch
105
+ * decision, not a security property.
106
+ */
107
+ disposition?: "ok" | "error" | "canceled";
108
+ }
109
+ /** A device the relay has seen recently. */
110
+ interface Presence {
111
+ readonly runnerId: string;
112
+ readonly owner: string;
113
+ readonly device: PublicIdentity;
114
+ lastSeenAt: number;
115
+ }
116
+ /**
117
+ * What a routing store must do, expressed as operations — cloud_006 §3.2.
118
+ *
119
+ * Every method below is a **decision plus its write**, never a read the caller
120
+ * follows with a mutation. That is the whole point, and it is the difference
121
+ * between an interface a shared store can implement and one it cannot.
122
+ *
123
+ * `claim` is the specimen. It used to live in `DaemonPlane` as
124
+ * `jobs()` → filter → mutate, which is atomic for exactly one reason: Node is
125
+ * single-threaded and these Maps are local, so nothing runs between the read
126
+ * and the write. Neither survives a store on a network, and
127
+ * `packages/relay/test/two-replicas.test.ts` holds the resulting race as a
128
+ * failing assertion.
129
+ *
130
+ * So the rule for anything added here: **if a caller has to read, decide, and
131
+ * write back, the operation is in the wrong place.** Move the decision in.
132
+ *
133
+ * ## Why the projection does not come with it
134
+ *
135
+ * `claim` takes `owners: string[]` rather than a projection or a predicate.
136
+ * A closure cannot travel to Valkey, and the projection replicates for free
137
+ * from the control plane — so the caller collapses it with
138
+ * `Projection.ownersRunnableBy` and hands over data the store can match on.
139
+ * That keeps the store ignorant of consent, which is also what keeps it
140
+ * replaceable.
141
+ */
142
+ interface ClaimInput {
143
+ readonly runnerId: string;
144
+ readonly owner: string;
145
+ readonly device: PublicIdentity;
146
+ /** The site this relay routes for. Multi-tenancy widens this to a set. */
147
+ readonly siteId: string;
148
+ /** Job kinds this device can actually run. */
149
+ readonly kinds: ReadonlySet<string>;
150
+ /** Whose work it may run — the projection, already collapsed to data. */
151
+ readonly owners: ReadonlySet<string>;
152
+ readonly max: number;
153
+ readonly leaseMs: number;
154
+ }
155
+ /**
156
+ * Where the store's sense of time comes from — cloud_006 §3.4.
157
+ *
158
+ * **The store owns its clock; callers do not pass one.** Every deadline the
159
+ * relay decides — a lease's expiry, the `awaiting-payload` window, what a
160
+ * sweep considers due — is now stamped by one source, and it is the same
161
+ * source that will later stamp them for every replica.
162
+ *
163
+ * It used to be a parameter. `claim` took `now`, `sweep` took `now`, and each
164
+ * plane called its own `now()` before calling in — which is fine in one
165
+ * process and is the recurring bug the moment there are two. A lease granted
166
+ * by a pod whose clock runs fast is short; the same lease swept by a pod whose
167
+ * clock runs slow outlives it. Nobody is wrong and the lease has no length.
168
+ *
169
+ * A Valkey-backed store returns `TIME` here, so the deadline and the sweep
170
+ * that enforces it are read from the same server. The injected clock stays for
171
+ * tests, which is what lets them move time instead of sleeping.
172
+ *
173
+ * **What deliberately does not use this**: request-signature freshness. That
174
+ * is checked against the *local* clock on purpose — it is a question about the
175
+ * caller's clock versus this process's, `MAX_CLOCK_SKEW_MS` already tolerates
176
+ * two minutes of disagreement, and a network round trip to timestamp every
177
+ * inbound request would be a cost with no property behind it.
178
+ */
179
+ interface RelayStateOptions {
180
+ readonly now?: () => number | Promise<number>;
181
+ }
182
+ /** Why a lease-scoped operation was refused, in the caller's vocabulary. */
183
+ type HolderRefusal = "not-found" | "not-holder" | "stale-lease" | "not-ready";
184
+ /**
185
+ * In-memory routing state.
186
+ *
187
+ * Deliberately not durable. The skeleton proves the protocol, and the
188
+ * production hub replaces this with the closed multi-tenant router behind the
189
+ * same shape (cloud_004 §9). Anything a restart loses here is a job that
190
+ * returns to its site's queue — which is the behaviour a lapsed lease already
191
+ * has to produce, so nothing new needs to be true for this to be safe.
192
+ */
193
+ declare class RelayState implements RoutingStore {
194
+ #private;
195
+ constructor(options?: RelayStateOptions);
196
+ /** The one clock every deadline in this store is stamped from. */
197
+ now(): Promise<number>;
198
+ /**
199
+ * Take a stub for routing. The payload is not here and will not be.
200
+ *
201
+ * **Idempotent by job id, and that is a security property rather than a
202
+ * convenience.** Site-plane calls are authenticated by signature, and
203
+ * byollm_009 §4.2's argument for signing the request instead of a
204
+ * server-issued nonce rests entirely on every write being idempotent per the
205
+ * instance it names. This one was not: re-enqueueing a known id built a
206
+ * fresh `queued` job over the top of the old one, discarding a live claim,
207
+ * its lease and any payload the site had already sealed to a device. A
208
+ * replayed enqueue inside the two-minute freshness window was therefore a
209
+ * way to yank a job back from the machine running it — the `release` bug of
210
+ * §4.2, rediscovered on the other plane.
211
+ *
212
+ * So a known id returns what is already routing, unchanged. A site that
213
+ * restarts and republishes its queue is the normal case, and it must not
214
+ * disturb work in flight.
215
+ */
216
+ enqueue(input: {
217
+ id: string;
218
+ siteId: string;
219
+ stub: JobStub;
220
+ }): Promise<RoutedJob>;
221
+ job(jobId: string): Promise<RoutedJob | undefined>;
222
+ jobs(): Promise<RoutedJob[]>;
223
+ /** Jobs a site must seal for, right now. */
224
+ awaiting(siteId: string): Promise<RoutedJob[]>;
225
+ /** Sealed results waiting to go home. */
226
+ finished(siteId: string): Promise<RoutedJob[]>;
227
+ /**
228
+ * Claim work — one operation, because it has to be.
229
+ *
230
+ * Moved here wholesale from `DaemonPlane`, where it was a scan followed by
231
+ * per-job mutation. Nothing about the *decision* changed; what changed is
232
+ * that a store can now implement it, because the filter and the write are
233
+ * one call rather than a loop the caller drives.
234
+ *
235
+ * The order of the guards is worth preserving as-is when this becomes a Lua
236
+ * script: cheapest first, and `owners` last because it is the only one that
237
+ * needed the projection.
238
+ */
239
+ claim(input: ClaimInput): Promise<ClaimedStub[]>;
240
+ /**
241
+ * Hand over the sealed payload to the device that holds the lease.
242
+ *
243
+ * The read and the state transition are one operation for the same reason
244
+ * `claim` is: `running` must be set by whoever was told the envelope, or two
245
+ * replicas can both hand out the same work and both believe they were first.
246
+ */
247
+ takePayload(input: {
248
+ jobId: string;
249
+ runnerId: string;
250
+ leaseId: string;
251
+ }): Promise<{
252
+ envelope: SealedEnvelope;
253
+ } | {
254
+ refused: HolderRefusal;
255
+ }>;
256
+ /**
257
+ * Record a finished job.
258
+ *
259
+ * `RESULT_IDEMPOTENT` lives here rather than in the caller: a replayed
260
+ * result must be a no-op decided by the same operation that would have
261
+ * written it, or two replicas can both decide they were the first.
262
+ */
263
+ complete(input: {
264
+ jobId: string;
265
+ runnerId: string;
266
+ leaseId: string;
267
+ envelope: SealedEnvelope;
268
+ disposition: "ok" | "error" | "canceled";
269
+ }): Promise<{
270
+ accepted: boolean;
271
+ duplicate?: boolean;
272
+ state: RoutedState;
273
+ } | {
274
+ refused: HolderRefusal;
275
+ }>;
276
+ /** Give back leases this runner holds, naming each grant it means. */
277
+ releaseLeases(input: {
278
+ runnerId: string;
279
+ leases: readonly {
280
+ jobId: string;
281
+ leaseId: string;
282
+ }[];
283
+ reason?: ReleaseReason;
284
+ }): Promise<string[]>;
285
+ /**
286
+ * Take a site's sealed payload for a claimed job.
287
+ *
288
+ * Refuses anything not `awaiting-payload`, which is what makes the timeout
289
+ * mean something: a late seal must not land on a claim that has moved.
290
+ */
291
+ seal(input: {
292
+ jobId: string;
293
+ siteId: string;
294
+ envelope: SealedEnvelope;
295
+ }): Promise<{
296
+ state: RoutedState;
297
+ } | {
298
+ refused: "not-found" | "too-late";
299
+ was?: RoutedState;
300
+ }>;
301
+ /** {@link RoutingStore.cancel} — the site withdraws a job. */
302
+ cancel(input: {
303
+ jobId: string;
304
+ siteId: string;
305
+ }): Promise<boolean>;
306
+ /** {@link RoutingStore.cancelRequests} — cancelled jobs this runner holds. */
307
+ cancelRequests(runnerId: string): Promise<string[]>;
308
+ /** {@link RoutingStore.renewLeases} — extend what is still held, name what is not. */
309
+ renewLeases(input: {
310
+ runnerId: string;
311
+ leases: readonly {
312
+ jobId: string;
313
+ leaseId: string;
314
+ }[];
315
+ leaseMs: number;
316
+ }): Promise<{
317
+ renewed: {
318
+ jobId: string;
319
+ expiresAt: number;
320
+ }[];
321
+ lost: string[];
322
+ }>;
323
+ seen(presence: Omit<Presence, "lastSeenAt">): Promise<Presence>;
324
+ presence(runnerId: string): Promise<Presence | undefined>;
325
+ everyone(): Promise<Presence[]>;
326
+ /**
327
+ * Fire whatever the clock says is due, and report it.
328
+ *
329
+ * Returns the jobs it requeued so a caller can log or surface them — a
330
+ * timeout that fires invisibly is indistinguishable from a job that was
331
+ * never claimed, and those want very different debugging.
332
+ */
333
+ sweep(): Promise<RoutedJob[]>;
334
+ }
335
+
336
+ /**
337
+ * What the relay needs from a place to keep routing state — cloud_006 §3.2.
338
+ *
339
+ * `RelayState` implements this in memory and is the reference; a Valkey-backed
340
+ * store implements the same thing across replicas. The interface exists so the
341
+ * relay depends on the *contract* rather than on either, and so the properties
342
+ * below are stated once rather than rediscovered per implementation.
343
+ *
344
+ * ## Every method is a decision plus its write
345
+ *
346
+ * Not one is a read the caller follows with a mutation. That is the whole
347
+ * design, and it is not a style preference: `claim` used to be
348
+ * `jobs()` → filter → mutate in the plane, which is atomic for exactly one
349
+ * reason — Node is single-threaded and the Maps are local. Neither survives a
350
+ * store on a network, and `packages/relay/test/two-replicas.test.ts` holds the
351
+ * resulting race as a failing assertion.
352
+ *
353
+ * **The rule for anything added here:** if a caller has to read, decide, and
354
+ * write back, the operation is in the wrong place. Move the decision in.
355
+ *
356
+ * ## What an implementation must guarantee
357
+ *
358
+ * 1. **`claim` is atomic.** Two callers claiming concurrently must not both
359
+ * receive the same job. `CLAIM_ATOMIC` is a protocol MUST.
360
+ * 2. **`enqueue` is idempotent by job id.** A known id returns what is already
361
+ * routing rather than rebuilding it — byollm_009 §4.2's replay argument
362
+ * rests on every write being idempotent per the instance it names.
363
+ * 3. **`complete` is idempotent.** A replayed result changes nothing, and the
364
+ * decision is made by the same operation that would have written it.
365
+ * 4. **Lease-scoped operations name the grant.** `takePayload`, `complete` and
366
+ * `releaseLeases` check the lease *id*, not just the runner — a runner
367
+ * survives a claim-release-reclaim cycle and a grant does not.
368
+ * 5. **`now()` is the only clock.** Every deadline the store stamps and every
369
+ * deadline it enforces come from here (§3.4). An implementation backed by a
370
+ * server returns that server's time, so two replicas cannot disagree about
371
+ * how long a lease is.
372
+ *
373
+ * ## What it must not do
374
+ *
375
+ * Hold a key, or learn about consent. `claim` takes `owners` as data because a
376
+ * predicate cannot travel to Valkey — and the effect is that the store cannot
377
+ * express an opinion about who may route, only about what it was told. That is
378
+ * what keeps `RELAY_BLIND` a property of the shape rather than of the code.
379
+ */
380
+ interface RoutingStore {
381
+ /** The one clock every deadline in this store is stamped from. */
382
+ now(): Promise<number>;
383
+ /** Take a stub for routing. Idempotent by id. */
384
+ enqueue(input: {
385
+ id: string;
386
+ siteId: string;
387
+ stub: JobStub;
388
+ }): Promise<RoutedJob>;
389
+ job(jobId: string): Promise<RoutedJob | undefined>;
390
+ jobs(): Promise<RoutedJob[]>;
391
+ /** Jobs a site must seal for, right now. */
392
+ awaiting(siteId: string): Promise<RoutedJob[]>;
393
+ /** Sealed results waiting to go home. */
394
+ finished(siteId: string): Promise<RoutedJob[]>;
395
+ /** Grant work to a device — one operation, because it has to be. */
396
+ claim(input: ClaimInput): Promise<ClaimedStub[]>;
397
+ /** Hand the sealed payload to the device that holds the lease. */
398
+ takePayload(input: {
399
+ jobId: string;
400
+ runnerId: string;
401
+ leaseId: string;
402
+ }): Promise<{
403
+ envelope: SealedEnvelope;
404
+ } | {
405
+ refused: HolderRefusal;
406
+ }>;
407
+ /** Record a finished job. Idempotent. */
408
+ complete(input: {
409
+ jobId: string;
410
+ runnerId: string;
411
+ /**
412
+ * The grant the result was produced under — cloud_008 §1.4a.
413
+ *
414
+ * `takePayload` and `releaseLeases` have always checked this and said why;
415
+ * the operation that *writes* checked only the runner, which survives a
416
+ * claim-release-reclaim cycle.
417
+ */
418
+ leaseId: string;
419
+ envelope: SealedEnvelope;
420
+ disposition: "ok" | "error" | "canceled";
421
+ }): Promise<{
422
+ accepted: boolean;
423
+ duplicate?: boolean;
424
+ state: RoutedState;
425
+ } | {
426
+ refused: HolderRefusal;
427
+ }>;
428
+ /** Give back the grants this runner names. */
429
+ releaseLeases(input: {
430
+ runnerId: string;
431
+ leases: readonly {
432
+ jobId: string;
433
+ leaseId: string;
434
+ }[];
435
+ /**
436
+ * Why — cloud_008 §2.1. `refused` MUST be remembered and that job MUST
437
+ * NOT be offered to that runner again (`REFUSAL_NOT_REOFFERED`); every
438
+ * other reason means "not now" and must leave the job claimable by the
439
+ * same device, or a restart would strand its own work.
440
+ */
441
+ reason?: ReleaseReason;
442
+ }): Promise<string[]>;
443
+ /** Take a site's sealed payload for a claimed job. */
444
+ seal(input: {
445
+ jobId: string;
446
+ siteId: string;
447
+ envelope: SealedEnvelope;
448
+ }): Promise<{
449
+ state: RoutedState;
450
+ } | {
451
+ refused: "not-found" | "too-late";
452
+ was?: RoutedState;
453
+ }>;
454
+ /**
455
+ * Extend the leases this runner still holds, and name the ones it does not.
456
+ *
457
+ * One call because it is one question — cloud_008 §0.6. This was
458
+ * `lostLeases`, which answered only the second half, and the relay's
459
+ * heartbeat answered the first half with the literal `leases: []`. A daemon
460
+ * was therefore told, every few seconds, that none of its work had been
461
+ * renewed; the sweep requeued at `leaseMs` regardless of how alive the
462
+ * device was, and any job that took longer than a lease was handed to
463
+ * somebody else while the first device was still running it. The direct
464
+ * plane has always renewed here (`handlers.ts` §3), so this was also the two
465
+ * upstreams disagreeing about a rule the daemon cannot see.
466
+ *
467
+ * Renewal and loss come from one read of one state: asked separately they
468
+ * are two answers to "who holds this now", and under two replicas they can
469
+ * differ.
470
+ */
471
+ renewLeases(input: {
472
+ runnerId: string;
473
+ leases: readonly {
474
+ jobId: string;
475
+ leaseId: string;
476
+ }[];
477
+ leaseMs: number;
478
+ }): Promise<{
479
+ renewed: readonly {
480
+ jobId: string;
481
+ expiresAt: number;
482
+ }[];
483
+ lost: readonly string[];
484
+ }>;
485
+ /**
486
+ * The site withdraws a job — cloud_008 §2.2.
487
+ *
488
+ * Returns false when the job is not this site's, which is the same scoping
489
+ * every other site-plane operation carries: a site must not cancel
490
+ * somebody else's work by guessing an id.
491
+ */
492
+ cancel(input: {
493
+ jobId: string;
494
+ siteId: string;
495
+ }): Promise<boolean>;
496
+ /**
497
+ * Cancelled jobs this runner is holding, for the heartbeat to report.
498
+ *
499
+ * The relay answered `cancel: []` unconditionally, so a site could not stop
500
+ * a job it had already withdrawn — a device went on running work whose
501
+ * result nobody would accept, on somebody's own machine, at their expense.
502
+ */
503
+ cancelRequests(runnerId: string): Promise<string[]>;
504
+ /** Record a device as present. The store stamps when. */
505
+ seen(presence: Omit<Presence, "lastSeenAt">): Promise<Presence>;
506
+ presence(runnerId: string): Promise<Presence | undefined>;
507
+ everyone(): Promise<Presence[]>;
508
+ /** Fire whatever the clock says is due, and report it. */
509
+ sweep(): Promise<RoutedJob[]>;
510
+ }
511
+
512
+ export { AWAITING_PAYLOAD_MS as A, type ClaimInput as C, type HolderRefusal as H, type Presence as P, type RoutingStore as R, RelayState as a, type ReleaseReason as b, type RoutedJob as c, type RoutedState as d };
@@ -0,0 +1,67 @@
1
+ import { R as RoutingStore } from './store-C_NtPAvT.js';
2
+ import '@byollm/protocol';
3
+
4
+ /**
5
+ * The routing store's behaviour, written once and run against every
6
+ * implementation — cloud_008 finding 54.
7
+ *
8
+ * There were two copies. This package tested `RelayState`; `byollm-cloud`
9
+ * tested `ValkeyRoutingStore` with a file that opened by explaining it was
10
+ * "written once and parameterised… a second copy of the scenario is a second
11
+ * place for two implementations to quietly diverge" — and was itself the
12
+ * second copy. It had drifted to sixteen cases against the eighteen in the
13
+ * ledger, which is exactly the divergence the sentence predicted, happening
14
+ * to the sentence.
15
+ *
16
+ * So the contract lives here, in the package that declares `RoutingStore`,
17
+ * and both repositories import it. A store that cannot pass this is not a
18
+ * routing store, whatever it implements.
19
+ *
20
+ * ## Why this ships in the published package
21
+ *
22
+ * Because the implementation that matters most is in another repository. A
23
+ * contract only the author can run is a description; one a third party runs
24
+ * against their own implementation is a contract. `@byollm/relay/store-contract`
25
+ * is a subpath export so nothing that imports the relay itself pulls in a
26
+ * test framework.
27
+ *
28
+ * ## What this cannot prove
29
+ *
30
+ * `CLAIM_ATOMIC` is a MUST and every case here would pass against a store
31
+ * that read, decided and wrote in three steps — in one process there is
32
+ * nothing to interleave. Concurrency belongs with the implementation that
33
+ * has a network in it, and `byollm-cloud`'s suite runs it against Valkey with
34
+ * many connections. Named here so the omission is a decision rather than an
35
+ * oversight.
36
+ */
37
+ /** The control-plane site id these cases route under. */
38
+ declare const CONTRACT_SITE = "site_store";
39
+ interface StoreContractOptions {
40
+ /**
41
+ * A fresh, empty store, and how to dispose of it.
42
+ *
43
+ * Arrow-typed rather than a method, because the caller passes these
44
+ * around: a method signature lets `this` travel with the call, and a
45
+ * factory read off an options object is exactly where that goes wrong.
46
+ */
47
+ readonly make: () => Promise<{
48
+ store: RoutingStore;
49
+ done: () => Promise<void>;
50
+ }>;
51
+ /**
52
+ * Whether this store writes stubs as bytes and reads them back.
53
+ *
54
+ * An in-process store holds typed objects and cannot hold a stub it cannot
55
+ * parse; a serialising one can, because what it wrote may have been written
56
+ * by a previous version. The case that covers it is skipped rather than
57
+ * hidden — a reader should know which half of this contract each store is
58
+ * proving (cloud_008 §2.1a).
59
+ */
60
+ readonly serialising?: boolean;
61
+ /** Write a stub's raw bytes, bypassing serialisation. */
62
+ readonly writeRawStub?: (store: RoutingStore, id: string, raw: string) => Promise<void>;
63
+ }
64
+ /** Run the contract. Call inside a suite; it declares its own `describe`. */
65
+ declare function describeStoreContract(name: string, options: StoreContractOptions): void;
66
+
67
+ export { CONTRACT_SITE, type StoreContractOptions, describeStoreContract };