@rikalabs/akter 0.1.0-alpha.0 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -3
- package/README.md +2 -2
- package/dist/actor/definition.d.ts +13 -9
- package/dist/actor/descriptor.d.ts +2 -2
- package/dist/actor/descriptor.js +4 -4
- package/dist/client/calls.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/errors/actor.d.ts +12 -42
- package/dist/errors/actor.js +13 -42
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/members/payload.d.ts +1 -1
- package/dist/protocol/inspection.d.ts +221 -1
- package/dist/protocol/inspection.js +151 -2
- package/dist/protocol/wire.d.ts +6 -49
- package/dist/protocol/wire.js +1 -10
- package/dist/runtime/actors.d.ts +3 -0
- package/dist/runtime/adoption/backfill.js +1 -1
- package/dist/runtime/adoption/enforce.js +2 -2
- package/dist/runtime/adoption/observe.js +1 -1
- package/dist/runtime/adoption/plan.d.ts +1 -1
- package/dist/runtime/adoption/startup.js +1 -1
- package/dist/runtime/adoption/status.d.ts +1 -1
- package/dist/runtime/app.d.ts +65 -0
- package/dist/runtime/app.js +38 -0
- package/dist/runtime/connections/holder.d.ts +11 -1
- package/dist/runtime/connections/holder.js +8 -4
- package/dist/runtime/connections/streams.d.ts +4 -4
- package/dist/runtime/content/store.js +15 -11
- package/dist/runtime/database/bounded.d.ts +4 -18
- package/dist/runtime/database/bounded.js +36 -22
- package/dist/runtime/database/coordination.d.ts +12 -3
- package/dist/runtime/database/coordination.js +29 -36
- package/dist/runtime/database/migrations.d.ts +61 -29
- package/dist/runtime/database/migrations.js +375 -139
- package/dist/runtime/database/replica.d.ts +4 -1
- package/dist/runtime/database/replica.js +4 -1
- package/dist/runtime/database/schema.d.ts +13 -0
- package/dist/runtime/database/schema.js +13 -0
- package/dist/runtime/database/shards.d.ts +31 -13
- package/dist/runtime/database/shards.js +38 -26
- package/dist/runtime/entity/register.d.ts +8 -1
- package/dist/runtime/entity/register.js +58 -7
- package/dist/runtime/fleet/checks.js +4 -4
- package/dist/runtime/fleet/maintainer.d.ts +1 -1
- package/dist/runtime/fleet/maintainer.js +1 -1
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/inspector/layer.d.ts +20 -0
- package/dist/runtime/inspector/layer.js +224 -5
- package/dist/runtime/inspector/queries.d.ts +54 -8
- package/dist/runtime/inspector/queries.js +84 -15
- package/dist/runtime/layer.d.ts +48 -39
- package/dist/runtime/layer.js +124 -56
- package/dist/runtime/operators/audit.d.ts +3 -0
- package/dist/runtime/operators/audit.js +6 -2
- package/dist/runtime/operators/repair.js +30 -10
- package/dist/runtime/operators/seed.js +4 -2
- package/dist/runtime/payloads/versions.d.ts +4 -4
- package/dist/runtime/payloads/versions.js +24 -15
- package/dist/runtime/queries.js +4 -2
- package/dist/runtime/registration.d.ts +5 -2
- package/dist/runtime/registration.js +3 -3
- package/dist/runtime/runner.d.ts +12 -0
- package/dist/runtime/runner.js +12 -0
- package/dist/runtime/storage/codec.d.ts +19 -7
- package/dist/runtime/storage/codec.js +23 -7
- package/dist/runtime/storage/placements.d.ts +6 -1
- package/dist/runtime/storage/placements.js +98 -6
- package/dist/runtime/storage/retention.d.ts +6 -0
- package/dist/runtime/storage/retention.js +25 -13
- package/dist/runtime/subscriptions/relay.js +47 -44
- package/dist/runtime/subscriptions/storage.d.ts +3 -2
- package/dist/runtime/subscriptions/storage.js +9 -6
- package/dist/runtime/telemetry/live.d.ts +255 -0
- package/dist/runtime/telemetry/live.js +540 -0
- package/dist/runtime/telemetry/metrics.d.ts +2 -0
- package/dist/runtime/telemetry/metrics.js +4 -1
- package/dist/runtime/telemetry/sampler.js +33 -13
- package/dist/runtime/telemetry/spans.d.ts +1 -1
- package/dist/runtime/telemetry/spans.js +1 -1
- package/dist/runtime/topology/locks.d.ts +6 -3
- package/dist/runtime/topology/locks.js +27 -4
- package/dist/runtime/turn/execute.d.ts +2 -0
- package/dist/runtime/turn/execute.js +5 -2
- package/dist/runtime/turn/pipeline.d.ts +5 -12
- package/dist/runtime/turn/pipeline.js +11 -11
- package/dist/runtime/turn/relay.d.ts +13 -3
- package/dist/runtime/turn/relay.js +27 -14
- package/dist/runtime/turn/rows.js +4 -4
- package/dist/runtime/workflows/compatibility.d.ts +1 -1
- package/dist/runtime/workflows/compatibility.js +85 -31
- package/dist/runtime/workflows/engine.js +20 -17
- package/dist/serve/layer.js +3 -2
- package/dist/tables/owned.d.ts +1 -1
- package/dist/tables/owned.js +1 -1
- package/dist/testing/actor-test.d.ts +2 -24
- package/dist/testing/actor-test.js +1 -27
- package/dist/testing/index.d.ts +0 -12
- package/dist/testing/index.js +0 -6
- package/package.json +1 -1
- package/dist/runtime/database/neki/migrations.d.ts +0 -31
- package/dist/runtime/database/neki/migrations.js +0 -276
- package/dist/runtime/database/neki/session.d.ts +0 -23
- package/dist/runtime/database/neki/session.js +0 -31
- package/dist/testing/cluster.d.ts +0 -93
- package/dist/testing/cluster.js +0 -296
- package/dist/testing/conformance/access.d.ts +0 -5
- package/dist/testing/conformance/access.js +0 -531
- package/dist/testing/conformance/admission.d.ts +0 -11
- package/dist/testing/conformance/admission.js +0 -182
- package/dist/testing/conformance/adoption.d.ts +0 -2
- package/dist/testing/conformance/adoption.js +0 -1019
- package/dist/testing/conformance/assertions.d.ts +0 -202
- package/dist/testing/conformance/assertions.js +0 -849
- package/dist/testing/conformance/batches.d.ts +0 -41
- package/dist/testing/conformance/batches.js +0 -388
- package/dist/testing/conformance/blobs.d.ts +0 -14
- package/dist/testing/conformance/blobs.js +0 -405
- package/dist/testing/conformance/capacity.d.ts +0 -8
- package/dist/testing/conformance/capacity.js +0 -433
- package/dist/testing/conformance/client.d.ts +0 -5
- package/dist/testing/conformance/client.js +0 -719
- package/dist/testing/conformance/cold-serve.d.ts +0 -16
- package/dist/testing/conformance/cold-serve.js +0 -254
- package/dist/testing/conformance/connections/actors.d.ts +0 -1143
- package/dist/testing/conformance/connections/actors.js +0 -180
- package/dist/testing/conformance/connections/harness.d.ts +0 -1754
- package/dist/testing/conformance/connections/harness.js +0 -142
- package/dist/testing/conformance/connections/holders.d.ts +0 -4
- package/dist/testing/conformance/connections/holders.js +0 -165
- package/dist/testing/conformance/connections/lifecycle.d.ts +0 -4
- package/dist/testing/conformance/connections/lifecycle.js +0 -113
- package/dist/testing/conformance/connections/limits.d.ts +0 -4
- package/dist/testing/conformance/connections/limits.js +0 -127
- package/dist/testing/conformance/connections/reauthorization.d.ts +0 -4
- package/dist/testing/conformance/connections/reauthorization.js +0 -170
- package/dist/testing/conformance/connections/resync.d.ts +0 -4
- package/dist/testing/conformance/connections/resync.js +0 -360
- package/dist/testing/conformance/connections/takeover.d.ts +0 -4
- package/dist/testing/conformance/connections/takeover.js +0 -287
- package/dist/testing/conformance/connections.d.ts +0 -4
- package/dist/testing/conformance/connections.js +0 -15
- package/dist/testing/conformance/content-blobs.d.ts +0 -16
- package/dist/testing/conformance/content-blobs.js +0 -534
- package/dist/testing/conformance/counter.d.ts +0 -16
- package/dist/testing/conformance/counter.js +0 -813
- package/dist/testing/conformance/cron.d.ts +0 -5
- package/dist/testing/conformance/cron.js +0 -665
- package/dist/testing/conformance/drain.d.ts +0 -26
- package/dist/testing/conformance/drain.js +0 -540
- package/dist/testing/conformance/effect-control.d.ts +0 -38
- package/dist/testing/conformance/effect-control.js +0 -1059
- package/dist/testing/conformance/effects.d.ts +0 -23
- package/dist/testing/conformance/effects.js +0 -432
- package/dist/testing/conformance/events.d.ts +0 -28
- package/dist/testing/conformance/events.js +0 -335
- package/dist/testing/conformance/export.d.ts +0 -2
- package/dist/testing/conformance/export.js +0 -368
- package/dist/testing/conformance/fleet.d.ts +0 -444
- package/dist/testing/conformance/fleet.js +0 -1009
- package/dist/testing/conformance/groups.d.ts +0 -7
- package/dist/testing/conformance/groups.js +0 -353
- package/dist/testing/conformance/heap.d.ts +0 -3
- package/dist/testing/conformance/heap.js +0 -149
- package/dist/testing/conformance/http.d.ts +0 -2809
- package/dist/testing/conformance/http.js +0 -1234
- package/dist/testing/conformance/inspection-views.d.ts +0 -8
- package/dist/testing/conformance/inspection-views.js +0 -272
- package/dist/testing/conformance/inspector.d.ts +0 -7
- package/dist/testing/conformance/inspector.js +0 -650
- package/dist/testing/conformance/mint.d.ts +0 -58
- package/dist/testing/conformance/mint.js +0 -692
- package/dist/testing/conformance/multi-runner.d.ts +0 -8
- package/dist/testing/conformance/multi-runner.js +0 -403
- package/dist/testing/conformance/neki/plan.d.ts +0 -19
- package/dist/testing/conformance/neki/plan.js +0 -30
- package/dist/testing/conformance/observability.d.ts +0 -3
- package/dist/testing/conformance/observability.js +0 -343
- package/dist/testing/conformance/offline.d.ts +0 -4
- package/dist/testing/conformance/offline.js +0 -474
- package/dist/testing/conformance/operator-harness.d.ts +0 -57
- package/dist/testing/conformance/operator-harness.js +0 -78
- package/dist/testing/conformance/operator.d.ts +0 -3
- package/dist/testing/conformance/operator.js +0 -379
- package/dist/testing/conformance/outbox-cross-shard.d.ts +0 -14
- package/dist/testing/conformance/outbox-cross-shard.js +0 -160
- package/dist/testing/conformance/outbox.d.ts +0 -36
- package/dist/testing/conformance/outbox.js +0 -437
- package/dist/testing/conformance/payload-migrations.d.ts +0 -3
- package/dist/testing/conformance/payload-migrations.js +0 -612
- package/dist/testing/conformance/pipeline.d.ts +0 -3
- package/dist/testing/conformance/pipeline.js +0 -1040
- package/dist/testing/conformance/placement.d.ts +0 -22
- package/dist/testing/conformance/placement.js +0 -539
- package/dist/testing/conformance/platform.d.ts +0 -40
- package/dist/testing/conformance/platform.js +0 -101
- package/dist/testing/conformance/progress.d.ts +0 -39
- package/dist/testing/conformance/progress.js +0 -666
- package/dist/testing/conformance/properties.d.ts +0 -6
- package/dist/testing/conformance/properties.js +0 -295
- package/dist/testing/conformance/protocols.d.ts +0 -4
- package/dist/testing/conformance/protocols.js +0 -618
- package/dist/testing/conformance/provider/advertise.d.ts +0 -21
- package/dist/testing/conformance/provider/advertise.js +0 -44
- package/dist/testing/conformance/read-your-writes.d.ts +0 -20
- package/dist/testing/conformance/read-your-writes.js +0 -192
- package/dist/testing/conformance/reducers.d.ts +0 -8
- package/dist/testing/conformance/reducers.js +0 -258
- package/dist/testing/conformance/relay.d.ts +0 -42
- package/dist/testing/conformance/relay.js +0 -1115
- package/dist/testing/conformance/restore.d.ts +0 -43
- package/dist/testing/conformance/restore.js +0 -341
- package/dist/testing/conformance/retention.d.ts +0 -14
- package/dist/testing/conformance/retention.js +0 -463
- package/dist/testing/conformance/rls.d.ts +0 -24
- package/dist/testing/conformance/rls.js +0 -576
- package/dist/testing/conformance/simulation.d.ts +0 -31
- package/dist/testing/conformance/simulation.js +0 -167
- package/dist/testing/conformance/single-shard.d.ts +0 -2
- package/dist/testing/conformance/single-shard.js +0 -125
- package/dist/testing/conformance/singleton.d.ts +0 -3
- package/dist/testing/conformance/singleton.js +0 -293
- package/dist/testing/conformance/statements.d.ts +0 -60
- package/dist/testing/conformance/statements.js +0 -108
- package/dist/testing/conformance/streams.d.ts +0 -7
- package/dist/testing/conformance/streams.js +0 -280
- package/dist/testing/conformance/subscriptions/access.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/access.js +0 -98
- package/dist/testing/conformance/subscriptions/actors.d.ts +0 -4910
- package/dist/testing/conformance/subscriptions/actors.js +0 -372
- package/dist/testing/conformance/subscriptions/cluster.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/cluster.js +0 -89
- package/dist/testing/conformance/subscriptions/delivery.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/delivery.js +0 -253
- package/dist/testing/conformance/subscriptions/deploys.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/deploys.js +0 -162
- package/dist/testing/conformance/subscriptions/epochs.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/epochs.js +0 -169
- package/dist/testing/conformance/subscriptions/failures.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/failures.js +0 -108
- package/dist/testing/conformance/subscriptions/feeds.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/feeds.js +0 -218
- package/dist/testing/conformance/subscriptions/harness.d.ts +0 -124
- package/dist/testing/conformance/subscriptions/harness.js +0 -143
- package/dist/testing/conformance/subscriptions/operator.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/operator.js +0 -128
- package/dist/testing/conformance/subscriptions/retention.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/retention.js +0 -288
- package/dist/testing/conformance/subscriptions/routing.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/routing.js +0 -179
- package/dist/testing/conformance/subscriptions.d.ts +0 -4
- package/dist/testing/conformance/subscriptions.js +0 -19
- package/dist/testing/conformance/tables.d.ts +0 -125
- package/dist/testing/conformance/tables.js +0 -664
- package/dist/testing/conformance/transports/actors.d.ts +0 -1907
- package/dist/testing/conformance/transports/actors.js +0 -163
- package/dist/testing/conformance/transports/client.d.ts +0 -3
- package/dist/testing/conformance/transports/client.js +0 -237
- package/dist/testing/conformance/transports/feeds.d.ts +0 -3
- package/dist/testing/conformance/transports/feeds.js +0 -232
- package/dist/testing/conformance/transports/harness.d.ts +0 -93
- package/dist/testing/conformance/transports/harness.js +0 -84
- package/dist/testing/conformance/transports/streams.d.ts +0 -3
- package/dist/testing/conformance/transports/streams.js +0 -96
- package/dist/testing/conformance/transports/websocket.d.ts +0 -3
- package/dist/testing/conformance/transports/websocket.js +0 -384
- package/dist/testing/conformance/transports/wire.d.ts +0 -141
- package/dist/testing/conformance/transports/wire.js +0 -204
- package/dist/testing/conformance/transports.d.ts +0 -3
- package/dist/testing/conformance/transports.js +0 -11
- package/dist/testing/conformance/watch.d.ts +0 -59
- package/dist/testing/conformance/watch.js +0 -879
- package/dist/testing/conformance/workflow-engine.d.ts +0 -97
- package/dist/testing/conformance/workflow-engine.js +0 -253
- package/dist/testing/conformance/workflow-versions.d.ts +0 -3
- package/dist/testing/conformance/workflow-versions.js +0 -545
- package/dist/testing/conformance/workflows/access.d.ts +0 -4
- package/dist/testing/conformance/workflows/access.js +0 -147
- package/dist/testing/conformance/workflows/actors.d.ts +0 -2317
- package/dist/testing/conformance/workflows/actors.js +0 -305
- package/dist/testing/conformance/workflows/basics.d.ts +0 -4
- package/dist/testing/conformance/workflows/basics.js +0 -144
- package/dist/testing/conformance/workflows/engine.d.ts +0 -4
- package/dist/testing/conformance/workflows/engine.js +0 -80
- package/dist/testing/conformance/workflows/guards.d.ts +0 -4
- package/dist/testing/conformance/workflows/guards.js +0 -172
- package/dist/testing/conformance/workflows/harness.d.ts +0 -14
- package/dist/testing/conformance/workflows/harness.js +0 -44
- package/dist/testing/conformance/workflows/recovery.d.ts +0 -4
- package/dist/testing/conformance/workflows/recovery.js +0 -181
- package/dist/testing/conformance/workflows/starts.d.ts +0 -4
- package/dist/testing/conformance/workflows/starts.js +0 -57
- package/dist/testing/conformance/workflows/suspension.d.ts +0 -4
- package/dist/testing/conformance/workflows/suspension.js +0 -106
- package/dist/testing/conformance/workflows/waits.d.ts +0 -4
- package/dist/testing/conformance/workflows/waits.js +0 -284
- package/dist/testing/conformance/workflows.d.ts +0 -4
- package/dist/testing/conformance/workflows.js +0 -19
- package/dist/testing/conformance.d.ts +0 -330
- package/dist/testing/conformance.js +0 -364
- package/dist/testing/foundation.d.ts +0 -41
- package/dist/testing/foundation.js +0 -517
- package/dist/testing/simulate-cluster.d.ts +0 -112
- package/dist/testing/simulate-cluster.js +0 -257
- package/dist/testing/simulate.d.ts +0 -90
- package/dist/testing/simulate.js +0 -127
|
@@ -1,692 +0,0 @@
|
|
|
1
|
-
import { Cause, Effect, Exit, Fiber, Layer, Schema } from "effect";
|
|
2
|
-
import { SqlClient } from "effect/sql";
|
|
3
|
-
import { Actor, Actors, CurrentCaller, Intent, NotCreated, System, Unauthorized, } from "../../index.js";
|
|
4
|
-
import { deriveMintId } from "../../identity/mint.js";
|
|
5
|
-
import { InternalActors } from "../../runtime/actors.js";
|
|
6
|
-
import { Outcome } from "../../runtime/request.js";
|
|
7
|
-
import { routingKey } from "../../runtime/storage/codec.js";
|
|
8
|
-
import { ActorTest } from "../actor-test.js";
|
|
9
|
-
import { enqueue, holding, transactions } from "./batches.js";
|
|
10
|
-
import { CLAIM_LEASE } from "./outbox.js";
|
|
11
|
-
class Refused extends Schema.TaggedError()("Refused", {}) {
|
|
12
|
-
}
|
|
13
|
-
const Open = Actor.command("Open", { payload: Schema.String, error: Refused });
|
|
14
|
-
const Title = Actor.command("Title", { success: Schema.String });
|
|
15
|
-
const childState = Actor.state({
|
|
16
|
-
title: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
|
|
17
|
-
});
|
|
18
|
-
const Task = Actor.make("MintTask", {
|
|
19
|
-
state: childState,
|
|
20
|
-
api: { Open, Title },
|
|
21
|
-
createdBy: Open,
|
|
22
|
-
});
|
|
23
|
-
const Note = Actor.make("MintNote", {
|
|
24
|
-
placement: "actor",
|
|
25
|
-
state: Actor.state({
|
|
26
|
-
title: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
|
|
27
|
-
opens: Schema.Int.pipe(Schema.withDecodingDefault(Effect.succeed(0))),
|
|
28
|
-
}),
|
|
29
|
-
api: { Open, Title },
|
|
30
|
-
createdBy: Open,
|
|
31
|
-
});
|
|
32
|
-
const Ids = Schema.Array(Schema.String);
|
|
33
|
-
const Plan = Actor.command("Plan", { payload: Schema.Int, success: Ids });
|
|
34
|
-
const PlanMixed = Actor.command("PlanMixed", { success: Ids });
|
|
35
|
-
const PlanLater = Actor.command("PlanLater", { success: Schema.String });
|
|
36
|
-
const PlanAcross = Actor.command("PlanAcross", { success: Schema.String });
|
|
37
|
-
const PlanThenRefuse = Actor.command("PlanThenRefuse", { error: Refused });
|
|
38
|
-
const PlanDelayed = Actor.command("PlanDelayed", { success: Ids });
|
|
39
|
-
const PlanDelayedThenRefuse = Actor.command("PlanDelayedThenRefuse", { error: Refused });
|
|
40
|
-
const PlanThenDie = Actor.command("PlanThenDie");
|
|
41
|
-
const PlanRefusedChild = Actor.command("PlanRefusedChild", { success: Schema.String });
|
|
42
|
-
const MintOnly = Actor.command("MintOnly");
|
|
43
|
-
const MintUnmintable = Actor.command("MintUnmintable");
|
|
44
|
-
const Escape = Actor.command("Escape");
|
|
45
|
-
const Steal = Actor.command("Steal");
|
|
46
|
-
const PlanKeyed = Actor.command("PlanKeyed");
|
|
47
|
-
const PlanStagedFirst = Actor.command("PlanStagedFirst", {
|
|
48
|
-
payload: Schema.String,
|
|
49
|
-
success: Schema.String,
|
|
50
|
-
});
|
|
51
|
-
const Planner = Actor.make("MintPlanner", {
|
|
52
|
-
key: Schema.String,
|
|
53
|
-
api: {
|
|
54
|
-
Plan,
|
|
55
|
-
PlanMixed,
|
|
56
|
-
PlanLater,
|
|
57
|
-
PlanAcross,
|
|
58
|
-
PlanThenRefuse,
|
|
59
|
-
PlanDelayed,
|
|
60
|
-
PlanDelayedThenRefuse,
|
|
61
|
-
PlanThenDie,
|
|
62
|
-
PlanRefusedChild,
|
|
63
|
-
MintOnly,
|
|
64
|
-
MintUnmintable,
|
|
65
|
-
Escape,
|
|
66
|
-
Steal,
|
|
67
|
-
PlanStagedFirst,
|
|
68
|
-
PlanKeyed,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const SoloPlan = Actor.command("SoloPlan", { success: Schema.String });
|
|
72
|
-
const SoloPlanner = Actor.make("MintSoloPlanner", { key: Actor.singleton, api: { SoloPlan } });
|
|
73
|
-
const Former = Actor.make("MintFormerChild", { state: childState, api: { Open, Title } });
|
|
74
|
-
const Job = Actor.make("MintNamedJob", {
|
|
75
|
-
key: Schema.String,
|
|
76
|
-
state: childState,
|
|
77
|
-
api: { Open, Title },
|
|
78
|
-
createdBy: Open,
|
|
79
|
-
});
|
|
80
|
-
const runs = [];
|
|
81
|
-
let escaped = Effect.succeed("");
|
|
82
|
-
const openTask = Effect.fnUntraced(function* (title) {
|
|
83
|
-
const id = yield* (yield* Planner.Turn).mint(Task);
|
|
84
|
-
yield* (yield* Task.intents(id)).Open(title);
|
|
85
|
-
return id;
|
|
86
|
-
});
|
|
87
|
-
const openNote = Effect.fnUntraced(function* (title) {
|
|
88
|
-
const id = yield* (yield* Planner.Turn).mint(Note);
|
|
89
|
-
yield* (yield* Note.intents(id)).Open(title);
|
|
90
|
-
return id;
|
|
91
|
-
});
|
|
92
|
-
export const mintLayer = Layer.mergeAll(Task.toLayer(Effect.succeed({
|
|
93
|
-
Open: Effect.fnUntraced(function* (title) {
|
|
94
|
-
yield* (yield* Task.Turn).state.set({ title });
|
|
95
|
-
if (title === "refuse")
|
|
96
|
-
return yield* Refused.make({});
|
|
97
|
-
}),
|
|
98
|
-
Title: Effect.fnUntraced(function* () {
|
|
99
|
-
return (yield* Task.Turn).state.title;
|
|
100
|
-
}),
|
|
101
|
-
})), Note.toLayer(Effect.succeed({
|
|
102
|
-
Open: Effect.fnUntraced(function* (title) {
|
|
103
|
-
const turn = yield* Note.Turn;
|
|
104
|
-
yield* turn.state.set({ title, opens: turn.state.opens + 1 });
|
|
105
|
-
}),
|
|
106
|
-
Title: Effect.fnUntraced(function* () {
|
|
107
|
-
return (yield* Note.Turn).state.title;
|
|
108
|
-
}),
|
|
109
|
-
})), Planner.toLayer(Effect.succeed({
|
|
110
|
-
Plan: Effect.fnUntraced(function* (count) {
|
|
111
|
-
const ids = [];
|
|
112
|
-
for (let index = 0; index < count; index++)
|
|
113
|
-
ids.push(yield* openTask(`task ${index}`));
|
|
114
|
-
runs.push(ids);
|
|
115
|
-
return ids;
|
|
116
|
-
}),
|
|
117
|
-
PlanMixed: Effect.fnUntraced(function* () {
|
|
118
|
-
const ids = [yield* openTask("task"), yield* openNote("note")];
|
|
119
|
-
return ids;
|
|
120
|
-
}),
|
|
121
|
-
PlanLater: Effect.fnUntraced(function* () {
|
|
122
|
-
const id = yield* (yield* Planner.Turn).mint(Task);
|
|
123
|
-
yield* (yield* Task.intents(id)).Open("later").pipe(Intent.after("1 hour"));
|
|
124
|
-
return id;
|
|
125
|
-
}),
|
|
126
|
-
PlanAcross: Effect.fnUntraced(function* () {
|
|
127
|
-
const id = yield* (yield* Planner.Turn).mint(Note);
|
|
128
|
-
yield* (yield* Note.intents(id)).Open("across").pipe(Intent.after("1 minute"));
|
|
129
|
-
return id;
|
|
130
|
-
}),
|
|
131
|
-
PlanThenRefuse: Effect.fnUntraced(function* () {
|
|
132
|
-
runs.push([yield* openTask("refused")]);
|
|
133
|
-
return yield* Refused.make({});
|
|
134
|
-
}),
|
|
135
|
-
PlanDelayed: Effect.fnUntraced(function* () {
|
|
136
|
-
const id = yield* (yield* Planner.Turn).mint(Task);
|
|
137
|
-
yield* (yield* Task.intents(id)).Open("delayed").pipe(Intent.after("1 hour"));
|
|
138
|
-
runs.push([id]);
|
|
139
|
-
return [id];
|
|
140
|
-
}),
|
|
141
|
-
PlanDelayedThenRefuse: Effect.fnUntraced(function* () {
|
|
142
|
-
const id = yield* (yield* Planner.Turn).mint(Task);
|
|
143
|
-
yield* (yield* Task.intents(id)).Open("delayed").pipe(Intent.after("1 hour"));
|
|
144
|
-
runs.push([id]);
|
|
145
|
-
return yield* Refused.make({});
|
|
146
|
-
}),
|
|
147
|
-
PlanThenDie: Effect.fnUntraced(function* () {
|
|
148
|
-
runs.push([yield* openTask("died")]);
|
|
149
|
-
return yield* Effect.die(new Error("Planner defect after minting"));
|
|
150
|
-
}),
|
|
151
|
-
PlanRefusedChild: () => openTask("refuse"),
|
|
152
|
-
MintOnly: Effect.fnUntraced(function* () {
|
|
153
|
-
yield* (yield* Planner.Turn).mint(Task);
|
|
154
|
-
}),
|
|
155
|
-
MintUnmintable: Effect.fnUntraced(function* () {
|
|
156
|
-
const unmintable = Planner;
|
|
157
|
-
yield* (yield* Planner.Turn).mint(unmintable);
|
|
158
|
-
}),
|
|
159
|
-
Escape: Effect.fnUntraced(function* () {
|
|
160
|
-
escaped = (yield* Planner.Turn).mint(Task);
|
|
161
|
-
}),
|
|
162
|
-
Steal: () => Effect.asVoid(Effect.suspend(() => escaped)),
|
|
163
|
-
PlanKeyed: Effect.fnUntraced(function* () {
|
|
164
|
-
const id = yield* (yield* Planner.Turn).mint(Task);
|
|
165
|
-
runs.push([id]);
|
|
166
|
-
yield* (yield* Task.intents(id)).Open("keyed").pipe(Intent.key("slot"));
|
|
167
|
-
}),
|
|
168
|
-
PlanStagedFirst: Effect.fnUntraced(function* (known) {
|
|
169
|
-
yield* (yield* Task.intents(known)).Open("staged first");
|
|
170
|
-
return yield* (yield* Planner.Turn).mint(Task);
|
|
171
|
-
}),
|
|
172
|
-
})), SoloPlanner.toLayer(Effect.succeed({
|
|
173
|
-
SoloPlan: Effect.fnUntraced(function* () {
|
|
174
|
-
const id = yield* (yield* SoloPlanner.Turn).mint(Task);
|
|
175
|
-
yield* (yield* Task.intents(id)).Open("solo");
|
|
176
|
-
return id;
|
|
177
|
-
}),
|
|
178
|
-
})), Job.toLayer(Effect.succeed({
|
|
179
|
-
Open: Effect.fnUntraced(function* (title) {
|
|
180
|
-
yield* (yield* Job.Turn).state.set({ title });
|
|
181
|
-
}),
|
|
182
|
-
Title: Effect.fnUntraced(function* () {
|
|
183
|
-
return (yield* Job.Turn).state.title;
|
|
184
|
-
}),
|
|
185
|
-
})), Former.toLayer(Effect.succeed({
|
|
186
|
-
Open: Effect.fnUntraced(function* (title) {
|
|
187
|
-
yield* (yield* Former.Turn).state.set({ title });
|
|
188
|
-
}),
|
|
189
|
-
Title: Effect.fnUntraced(function* () {
|
|
190
|
-
return (yield* Former.Turn).state.title;
|
|
191
|
-
}),
|
|
192
|
-
})));
|
|
193
|
-
const task = (id) => Task.get(id);
|
|
194
|
-
const note = (id) => Note.get(id);
|
|
195
|
-
const expected = (parent, commandId, ordinal, child = "MintTask") => deriveMintId({ parent, commandId, ordinal, child });
|
|
196
|
-
/** The System caller a parent's creating intent carries, rebuilt outside any turn. */
|
|
197
|
-
const proven = (parent, commandId, ordinal = 0) => System.make({ source: "actor", ref: parent, mint: { commandId, ordinal } });
|
|
198
|
-
/** Opens a task as `caller`, which the handle binds when it is acquired, and returns its failure. */
|
|
199
|
-
const openAs = (id, title, caller) => task(id).pipe(Effect.flatMap((child) => child.Open(title)), Effect.provideService(CurrentCaller, caller), Effect.flip);
|
|
200
|
-
const created = Effect.fnUntraced(function* (actor, id) {
|
|
201
|
-
const test = yield* ActorTest;
|
|
202
|
-
return yield* test.receiptsFor({ tenant: test.tenant, actor, id }, "Open");
|
|
203
|
-
});
|
|
204
|
-
/**
|
|
205
|
-
* Gives the last command enqueued behind a held turn time to finish its
|
|
206
|
-
* `queued` hook, which the batch waits for, so every waiting command is in
|
|
207
|
-
* the next batch.
|
|
208
|
-
*/
|
|
209
|
-
const settle = Effect.sleep("500 millis");
|
|
210
|
-
/** Plans one task whose creating intent is due in an hour, and returns the task's id. */
|
|
211
|
-
export const planLaterTask = (parent) => Planner.get(parent).pipe(Effect.flatMap((planner) => planner.PlanLater()));
|
|
212
|
-
/** The title of a created minted task. */
|
|
213
|
-
export const mintedTitle = (id) => task(id).pipe(Effect.flatMap((child) => child.Title()));
|
|
214
|
-
/** Mints one child from a tenant-placed planner, for the single-shard statement check. */
|
|
215
|
-
export const mintWorkload = Effect.gen(function* () {
|
|
216
|
-
yield* (yield* Planner.get("p-shard")).Plan(1);
|
|
217
|
-
}).pipe(Effect.orDie);
|
|
218
|
-
/** Selects a child in the opposite routing-key half from its tenant-placed parent. */
|
|
219
|
-
export const planAcrossShard = Effect.fnUntraced(function* (scenario) {
|
|
220
|
-
const planner = yield* Planner.get(scenario);
|
|
221
|
-
const actors = yield* Actors;
|
|
222
|
-
const parentKey = routingKey({ ref: planner.ref, placement: "tenant" });
|
|
223
|
-
for (let attempt = 0; attempt < 256; attempt++) {
|
|
224
|
-
const commandId = yield* actors.mintCommandId;
|
|
225
|
-
const id = yield* expected(planner.ref, commandId, 0, "MintNote");
|
|
226
|
-
const ref = { ...planner.ref, actor: "MintNote", id };
|
|
227
|
-
const childKey = routingKey({ ref, placement: "actor" });
|
|
228
|
-
if (parentKey < 0n === childKey < 0n)
|
|
229
|
-
continue;
|
|
230
|
-
yield* planner.PlanAcross().pipe(Actor.commandId(commandId));
|
|
231
|
-
return { planner, ref, parentKey, childKey, commandId };
|
|
232
|
-
}
|
|
233
|
-
return yield* Effect.die(new Error("No minted child in the opposite routing-key half"));
|
|
234
|
-
});
|
|
235
|
-
/** Minted-id cases: ids derive from the command id and ordinal, stay stable across a rerun after a crash, and create each child once. */
|
|
236
|
-
export const mintConformance = [
|
|
237
|
-
{
|
|
238
|
-
name: "creates a child across routing keys only from a committed relay delivery and replays it after a crash before outbox deletion",
|
|
239
|
-
run: ({ expect, environment, fixture }) => environment.run(Effect.gen(function* () {
|
|
240
|
-
const test = yield* ActorTest;
|
|
241
|
-
const internal = yield* InternalActors;
|
|
242
|
-
const { planner, ref, parentKey, childKey, commandId } = yield* planAcrossShard("cross-mint");
|
|
243
|
-
const caller = proven(planner.ref, commandId);
|
|
244
|
-
const forged = {
|
|
245
|
-
ref,
|
|
246
|
-
caller,
|
|
247
|
-
command: "Open",
|
|
248
|
-
commandId: yield* (yield* Actors).mintCommandId,
|
|
249
|
-
payload: yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Struct({ value: Schema.String })))({ value: "forged" }),
|
|
250
|
-
};
|
|
251
|
-
const denied = { reason: Unauthorized.make({ code: "access_denied" }) };
|
|
252
|
-
expect(parentKey < 0n).toBe(childKey >= 0n);
|
|
253
|
-
expect(yield* internal.deliver(forged).pipe(Effect.flip)).toMatchObject(denied);
|
|
254
|
-
for (const intent of [
|
|
255
|
-
{ ...planner.ref, tenant: "another-tenant" },
|
|
256
|
-
{ ...planner.ref, actor: "MintSoloPlanner" },
|
|
257
|
-
{ ...planner.ref, id: "another-parent" },
|
|
258
|
-
])
|
|
259
|
-
expect(yield* internal.deliver({ ...forged, intent }).pipe(Effect.flip)).toMatchObject(denied);
|
|
260
|
-
expect(yield* internal.execute({ ...forged, intent: planner.ref }).pipe(Effect.flip)).toMatchObject(denied);
|
|
261
|
-
expect(yield* internal
|
|
262
|
-
.deliver({
|
|
263
|
-
...forged,
|
|
264
|
-
intent: planner.ref,
|
|
265
|
-
caller: proven(planner.ref, commandId, 1),
|
|
266
|
-
})
|
|
267
|
-
.pipe(Effect.flip)).toMatchObject(denied);
|
|
268
|
-
expect(yield* created(ref.actor, ref.id)).toBe(0);
|
|
269
|
-
yield* test.crashNext("beforeOutboxDelete");
|
|
270
|
-
const pause = yield* test.pauseNext("beforeOutboxDelete");
|
|
271
|
-
yield* test.advance("1 minute");
|
|
272
|
-
expect(yield* created(ref.actor, ref.id)).toBe(1);
|
|
273
|
-
expect(yield* test.inspect(ref)).toMatchObject({
|
|
274
|
-
state: { title: "across", opens: 1 },
|
|
275
|
-
receipts: 1,
|
|
276
|
-
});
|
|
277
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ outbox: 1 });
|
|
278
|
-
const delivery = fixture.deliveries.get(ref.id);
|
|
279
|
-
expect(delivery.intent).toEqual(planner.ref);
|
|
280
|
-
expect(yield* internal.execute(delivery).pipe(Effect.flip)).toMatchObject(denied);
|
|
281
|
-
expect(yield* internal
|
|
282
|
-
.execute({
|
|
283
|
-
...forged,
|
|
284
|
-
commandId: yield* (yield* Actors).mintCommandId,
|
|
285
|
-
caller: System.make({ source: "process" }),
|
|
286
|
-
intent: planner.ref,
|
|
287
|
-
})
|
|
288
|
-
.pipe(Effect.flip)).toMatchObject(denied);
|
|
289
|
-
const draining = yield* test.advance(CLAIM_LEASE).pipe(Effect.forkChild);
|
|
290
|
-
yield* pause.reached;
|
|
291
|
-
expect(yield* created(ref.actor, ref.id)).toBe(1);
|
|
292
|
-
expect(yield* test.inspect(ref)).toMatchObject({
|
|
293
|
-
state: { title: "across", opens: 1 },
|
|
294
|
-
receipts: 1,
|
|
295
|
-
});
|
|
296
|
-
yield* pause.release;
|
|
297
|
-
yield* Fiber.join(draining);
|
|
298
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ outbox: 0 });
|
|
299
|
-
expect(yield* internal.deliver(delivery)).toEqual(Outcome.cases.Success.make({ value: '{"value":null}' }));
|
|
300
|
-
expect(yield* created(ref.actor, ref.id)).toBe(1);
|
|
301
|
-
expect(yield* test.inspect(ref)).toMatchObject({
|
|
302
|
-
state: { title: "across", opens: 1 },
|
|
303
|
-
receipts: 1,
|
|
304
|
-
});
|
|
305
|
-
})),
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
name: "mints ids from the command id and ordinal and creates each child once from its intent",
|
|
309
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
310
|
-
const test = yield* ActorTest;
|
|
311
|
-
const planner = yield* Planner.get("derive");
|
|
312
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
313
|
-
const held = [yield* test.pauseNext("afterClaim"), yield* test.pauseNext("afterClaim")];
|
|
314
|
-
const ids = yield* planner.Plan(2).pipe(Actor.commandId(commandId));
|
|
315
|
-
expect(ids).toEqual([
|
|
316
|
-
yield* expected(planner.ref, commandId, 0),
|
|
317
|
-
yield* expected(planner.ref, commandId, 1),
|
|
318
|
-
]);
|
|
319
|
-
expect(new Set(ids).size).toBe(2);
|
|
320
|
-
for (const pause of held)
|
|
321
|
-
yield* pause.reached;
|
|
322
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({
|
|
323
|
-
receipts: 1,
|
|
324
|
-
outbox: 2,
|
|
325
|
-
});
|
|
326
|
-
for (const id of ids)
|
|
327
|
-
expect(yield* created("MintTask", id)).toBe(0);
|
|
328
|
-
for (const pause of held)
|
|
329
|
-
yield* pause.release;
|
|
330
|
-
yield* test.advance(0);
|
|
331
|
-
for (const [index, id] of ids.entries()) {
|
|
332
|
-
expect(yield* (yield* task(id)).Title()).toBe(`task ${index}`);
|
|
333
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
334
|
-
}
|
|
335
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ outbox: 0 });
|
|
336
|
-
expect(yield* planner.Plan(2).pipe(Actor.commandId(commandId))).toEqual(ids);
|
|
337
|
-
})),
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
name: "mints distinct ids per parent, per ordinal, and per child type from one command id",
|
|
341
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
342
|
-
const test = yield* ActorTest;
|
|
343
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
344
|
-
const first = yield* Planner.get("distinct-a");
|
|
345
|
-
const second = yield* Planner.get("distinct-b");
|
|
346
|
-
const a = yield* first.PlanMixed().pipe(Actor.commandId(commandId));
|
|
347
|
-
const b = yield* second.PlanMixed().pipe(Actor.commandId(commandId));
|
|
348
|
-
expect(a).toEqual([
|
|
349
|
-
yield* expected(first.ref, commandId, 0),
|
|
350
|
-
yield* expected(first.ref, commandId, 1, "MintNote"),
|
|
351
|
-
]);
|
|
352
|
-
expect(new Set([...a, ...b]).size).toBe(4);
|
|
353
|
-
yield* test.advance(0);
|
|
354
|
-
expect(yield* (yield* task(a[0])).Title()).toBe("task");
|
|
355
|
-
expect(yield* (yield* note(a[1])).Title()).toBe("note");
|
|
356
|
-
expect(yield* (yield* note(b[1])).Title()).toBe("note");
|
|
357
|
-
})),
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
name: "mints the same ids when a beforeCommit crash reruns the command",
|
|
361
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
362
|
-
const test = yield* ActorTest;
|
|
363
|
-
const planner = yield* Planner.get("crash-before");
|
|
364
|
-
const before = runs.length;
|
|
365
|
-
yield* test.crashNext("beforeCommit");
|
|
366
|
-
const ids = yield* planner.Plan(2);
|
|
367
|
-
expect(runs.slice(before)).toEqual([ids, ids]);
|
|
368
|
-
yield* test.advance(0);
|
|
369
|
-
for (const id of ids)
|
|
370
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
371
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({
|
|
372
|
-
receipts: 1,
|
|
373
|
-
outbox: 0,
|
|
374
|
-
});
|
|
375
|
-
})),
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
name: "replays minted ids after an afterCommit crash and creates each child once",
|
|
379
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
380
|
-
const test = yield* ActorTest;
|
|
381
|
-
const planner = yield* Planner.get("crash-after");
|
|
382
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
383
|
-
const before = runs.length;
|
|
384
|
-
yield* test.crashNext("afterCommit");
|
|
385
|
-
const ids = yield* planner.Plan(2).pipe(Actor.commandId(commandId));
|
|
386
|
-
expect(yield* planner.Plan(2).pipe(Actor.commandId(commandId))).toEqual(ids);
|
|
387
|
-
expect(runs.slice(before)).toEqual([ids]);
|
|
388
|
-
yield* test.advance(0);
|
|
389
|
-
for (const id of ids)
|
|
390
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
391
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({
|
|
392
|
-
receipts: 1,
|
|
393
|
-
outbox: 0,
|
|
394
|
-
});
|
|
395
|
-
})),
|
|
396
|
-
},
|
|
397
|
-
{
|
|
398
|
-
name: "mints per command when several commands wait at one parent",
|
|
399
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
400
|
-
const test = yield* ActorTest;
|
|
401
|
-
const planner = yield* Planner.get("queued");
|
|
402
|
-
const actors = yield* Actors;
|
|
403
|
-
const commandIds = [yield* actors.mintCommandId, yield* actors.mintCommandId];
|
|
404
|
-
const pause = yield* test.pauseNext("beforeCommit");
|
|
405
|
-
const first = yield* planner
|
|
406
|
-
.Plan(1)
|
|
407
|
-
.pipe(Actor.commandId(commandIds[0]), Effect.forkChild);
|
|
408
|
-
yield* pause.reached;
|
|
409
|
-
const second = yield* planner
|
|
410
|
-
.Plan(1)
|
|
411
|
-
.pipe(Actor.commandId(commandIds[1]), Effect.forkChild);
|
|
412
|
-
yield* pause.release;
|
|
413
|
-
expect(yield* Fiber.join(first)).toEqual([
|
|
414
|
-
yield* expected(planner.ref, commandIds[0], 0),
|
|
415
|
-
]);
|
|
416
|
-
expect(yield* Fiber.join(second)).toEqual([
|
|
417
|
-
yield* expected(planner.ref, commandIds[1], 0),
|
|
418
|
-
]);
|
|
419
|
-
})),
|
|
420
|
-
},
|
|
421
|
-
{
|
|
422
|
-
name: "turn batch: commands that mint share one transaction, mint the ids each would mint alone, and a declared failure in the batch creates no child",
|
|
423
|
-
requiresIndependentConnections: true,
|
|
424
|
-
timeoutMs: 60_000,
|
|
425
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
426
|
-
const test = yield* ActorTest;
|
|
427
|
-
const actors = yield* Actors;
|
|
428
|
-
const planner = yield* Planner.get("batch-shared");
|
|
429
|
-
const [lone, one, refused, two] = yield* Effect.forEach(Array.from({ length: 4 }), () => actors.mintCommandId);
|
|
430
|
-
const [loneChild, oneChild, rolledBack, twoChild] = yield* Effect.forEach([lone, one, refused, two], (id) => expected(planner.ref, id, 0));
|
|
431
|
-
yield* test.advance(0);
|
|
432
|
-
const before = runs.length;
|
|
433
|
-
const first = yield* holding(planner.PlanDelayed().pipe(Actor.commandId(lone)));
|
|
434
|
-
const [a, r, b] = yield* enqueue([
|
|
435
|
-
planner.PlanDelayed().pipe(Actor.commandId(one), Effect.exit),
|
|
436
|
-
planner.PlanDelayedThenRefuse().pipe(Actor.commandId(refused), Effect.exit),
|
|
437
|
-
planner.PlanDelayed().pipe(Actor.commandId(two), Effect.exit),
|
|
438
|
-
]);
|
|
439
|
-
yield* settle;
|
|
440
|
-
yield* first.release;
|
|
441
|
-
yield* Fiber.join(first.fiber);
|
|
442
|
-
expect(yield* Fiber.join(a)).toEqual(Exit.succeed([oneChild]));
|
|
443
|
-
expect(yield* Fiber.join(r)).toEqual(Exit.fail(Refused.make({})));
|
|
444
|
-
expect(yield* Fiber.join(b)).toEqual(Exit.succeed([twoChild]));
|
|
445
|
-
const committed = yield* transactions(planner.ref);
|
|
446
|
-
expect(new Set([one, refused, two].map((id) => committed.get(id))).size).toBe(1);
|
|
447
|
-
expect(committed.get(one)).not.toBe(committed.get(lone));
|
|
448
|
-
expect(new Set([loneChild, oneChild, twoChild, rolledBack]).size).toBe(4);
|
|
449
|
-
expect(new Set(runs.slice(before).flat())).toEqual(new Set([loneChild, oneChild, twoChild, rolledBack]));
|
|
450
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ receipts: 4, outbox: 3 });
|
|
451
|
-
const settled = runs.length;
|
|
452
|
-
expect(yield* planner.PlanDelayed().pipe(Actor.commandId(two))).toEqual([twoChild]);
|
|
453
|
-
expect(runs.length).toBe(settled);
|
|
454
|
-
yield* test.advance("1 hour");
|
|
455
|
-
for (const id of [loneChild, oneChild, twoChild])
|
|
456
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
457
|
-
expect(yield* created("MintTask", rolledBack)).toBe(0);
|
|
458
|
-
expect(yield* openAs(rolledBack, "rolled back", proven(planner.ref, refused))).toMatchObject({ reason: Unauthorized.make({ code: "access_denied" }) });
|
|
459
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ outbox: 0 });
|
|
460
|
-
})),
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
name: "turn batch: a crash before the shared commit reruns each minting command alone with the same ids, and a crash after it replays them, each child created once",
|
|
464
|
-
requiresIndependentConnections: true,
|
|
465
|
-
timeoutMs: 120_000,
|
|
466
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
467
|
-
const test = yield* ActorTest;
|
|
468
|
-
const actors = yield* Actors;
|
|
469
|
-
const planner = yield* Planner.get("batch-crash");
|
|
470
|
-
const [lone, between, ...ids] = yield* Effect.forEach(Array.from({ length: 8 }), () => actors.mintCommandId);
|
|
471
|
-
const derived = yield* Effect.forEach([lone, between, ...ids], (id) => expected(planner.ref, id, 0));
|
|
472
|
-
const [loneChild, betweenChild] = derived;
|
|
473
|
-
const early = derived.slice(2, 5);
|
|
474
|
-
const late = derived.slice(5);
|
|
475
|
-
yield* test.advance(0);
|
|
476
|
-
const before = runs.length;
|
|
477
|
-
const first = yield* holding(planner.PlanDelayed().pipe(Actor.commandId(lone)));
|
|
478
|
-
const beforeCrash = yield* enqueue(ids
|
|
479
|
-
.slice(0, 3)
|
|
480
|
-
.map((id) => planner.PlanDelayed().pipe(Actor.commandId(id), Effect.orDie)));
|
|
481
|
-
yield* settle;
|
|
482
|
-
yield* test.crashNext("beforeCommit");
|
|
483
|
-
yield* first.release;
|
|
484
|
-
yield* Fiber.join(first.fiber);
|
|
485
|
-
expect(yield* Effect.forEach(beforeCrash, Fiber.join)).toEqual(early.map((id) => [id]));
|
|
486
|
-
const executions = (id) => runs.slice(before).filter(([only]) => only === id).length;
|
|
487
|
-
expect(early.map(executions).some((count) => count > 1)).toBe(true);
|
|
488
|
-
let committed = yield* transactions(planner.ref);
|
|
489
|
-
expect(new Set(ids.slice(0, 3).map((id) => committed.get(id))).size).toBe(3);
|
|
490
|
-
const second = yield* holding(planner.PlanDelayed().pipe(Actor.commandId(between)));
|
|
491
|
-
const afterCrash = yield* enqueue(ids.slice(3).map((id) => planner.PlanDelayed().pipe(Actor.commandId(id), Effect.orDie)));
|
|
492
|
-
yield* settle;
|
|
493
|
-
const shared = yield* test.pauseNext("beforeCommit");
|
|
494
|
-
yield* second.release;
|
|
495
|
-
yield* Fiber.join(second.fiber);
|
|
496
|
-
yield* shared.reached;
|
|
497
|
-
yield* test.crashNext("afterCommit");
|
|
498
|
-
yield* shared.release;
|
|
499
|
-
expect(yield* Effect.forEach(afterCrash, Fiber.join)).toEqual(late.map((id) => [id]));
|
|
500
|
-
expect(late.map(executions)).toEqual([1, 1, 1]);
|
|
501
|
-
committed = yield* transactions(planner.ref);
|
|
502
|
-
expect(new Set(ids.slice(3).map((id) => committed.get(id))).size).toBe(1);
|
|
503
|
-
const children = new Set([loneChild, betweenChild, ...early, ...late]);
|
|
504
|
-
expect(children.size).toBe(8);
|
|
505
|
-
expect(new Set(runs.slice(before).flat())).toEqual(children);
|
|
506
|
-
yield* test.advance("1 hour");
|
|
507
|
-
for (const id of children)
|
|
508
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
509
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ receipts: 8, outbox: 0 });
|
|
510
|
-
})),
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
name: "creates no child from a declared failure, a defect, or a mint without a creating intent",
|
|
514
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
515
|
-
const test = yield* ActorTest;
|
|
516
|
-
const planner = yield* Planner.get("rollback");
|
|
517
|
-
const before = runs.length;
|
|
518
|
-
const refusedId = yield* (yield* Actors).mintCommandId;
|
|
519
|
-
expect(yield* planner.PlanThenRefuse().pipe(Actor.commandId(refusedId), Effect.flip)).toBeInstanceOf(Refused);
|
|
520
|
-
const rolledBack = yield* expected(planner.ref, refusedId, 0);
|
|
521
|
-
expect(yield* openAs(rolledBack, "rolled back", proven(planner.ref, refusedId))).toMatchObject({ reason: Unauthorized.make({ code: "access_denied" }) });
|
|
522
|
-
const died = yield* planner.PlanThenDie().pipe(Effect.exit);
|
|
523
|
-
expect(Exit.isFailure(died) && Cause.pretty(died.cause)).toContain("Planner defect");
|
|
524
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
525
|
-
const unstaged = yield* planner.MintOnly().pipe(Actor.commandId(commandId), Effect.exit);
|
|
526
|
-
const orphan = yield* expected(planner.ref, commandId, 0);
|
|
527
|
-
expect(Exit.isFailure(unstaged) && Cause.pretty(unstaged.cause)).toContain(`Minted actor MintTask/${orphan} has no creating intent`);
|
|
528
|
-
yield* test.advance(0);
|
|
529
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({
|
|
530
|
-
receipts: 1,
|
|
531
|
-
outbox: 0,
|
|
532
|
-
});
|
|
533
|
-
for (const [id] of runs.slice(before))
|
|
534
|
-
expect(yield* created("MintTask", id)).toBe(0);
|
|
535
|
-
})),
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
name: "refuses a proven creating call while its parent's turn has not committed",
|
|
539
|
-
requiresIndependentConnections: true,
|
|
540
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
541
|
-
const test = yield* ActorTest;
|
|
542
|
-
const planner = yield* Planner.get("uncommitted");
|
|
543
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
544
|
-
const id = yield* expected(planner.ref, commandId, 0);
|
|
545
|
-
const pause = yield* test.pauseNext("beforeCommit");
|
|
546
|
-
const parent = yield* planner.Plan(1).pipe(Actor.commandId(commandId), Effect.forkChild);
|
|
547
|
-
yield* pause.reached;
|
|
548
|
-
expect(yield* openAs(id, "early", proven(planner.ref, commandId))).toMatchObject({
|
|
549
|
-
reason: Unauthorized.make({ code: "access_denied" }),
|
|
550
|
-
});
|
|
551
|
-
expect(yield* created("MintTask", id)).toBe(0);
|
|
552
|
-
yield* pause.release;
|
|
553
|
-
expect(yield* Fiber.join(parent)).toEqual([id]);
|
|
554
|
-
yield* test.advance(0);
|
|
555
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
556
|
-
expect(yield* (yield* task(id)).Title()).toBe("task 0");
|
|
557
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ outbox: 0 });
|
|
558
|
-
})),
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
name: "keeps a minted child uncreated when its creating turn fails with a declared error",
|
|
562
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
563
|
-
const test = yield* ActorTest;
|
|
564
|
-
const planner = yield* Planner.get("child-refuses");
|
|
565
|
-
const id = yield* planner.PlanRefusedChild();
|
|
566
|
-
yield* test.advance(0);
|
|
567
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
568
|
-
expect(yield* test.inspect(planner.ref)).toMatchObject({ receipts: 1, outbox: 0 });
|
|
569
|
-
expect(yield* (yield* task(id)).Title().pipe(Effect.flip)).toMatchObject({
|
|
570
|
-
reason: NotCreated.make({}),
|
|
571
|
-
});
|
|
572
|
-
})),
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
name: "refuses a minted child's creating command without its parent's mint proof",
|
|
576
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
577
|
-
const test = yield* ActorTest;
|
|
578
|
-
const planner = yield* Planner.get("forged");
|
|
579
|
-
const other = yield* Planner.get("forged-other");
|
|
580
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
581
|
-
const id = yield* planner.PlanLater().pipe(Actor.commandId(commandId));
|
|
582
|
-
const child = yield* task(id);
|
|
583
|
-
const denied = {
|
|
584
|
-
reason: Unauthorized.make({ code: "access_denied" }),
|
|
585
|
-
};
|
|
586
|
-
expect(yield* child.Open("client").pipe(Effect.flip)).toMatchObject(denied);
|
|
587
|
-
const forged = System.make({
|
|
588
|
-
source: "actor",
|
|
589
|
-
ref: other.ref,
|
|
590
|
-
onBehalfOf: { subject: "alice" },
|
|
591
|
-
mint: { commandId, ordinal: 0 },
|
|
592
|
-
});
|
|
593
|
-
const impostor = yield* task(id).pipe(Effect.provideService(CurrentCaller, forged));
|
|
594
|
-
expect(yield* impostor.Open("impostor").pipe(Effect.flip)).toMatchObject(denied);
|
|
595
|
-
const uncommitted = yield* (yield* Actors).mintCommandId;
|
|
596
|
-
expect(yield* openAs(yield* expected(planner.ref, uncommitted, 0), "never planned", proven(planner.ref, uncommitted))).toMatchObject(denied);
|
|
597
|
-
expect(yield* openAs(id, "proven early", proven(planner.ref, commandId))).toMatchObject(denied);
|
|
598
|
-
const sql = yield* SqlClient.SqlClient;
|
|
599
|
-
const [row] = yield* sql `
|
|
600
|
-
SELECT intent_id, scheduled_at_ms::text AS scheduled FROM actor_outbox
|
|
601
|
-
WHERE target_type = 'MintTask' AND target_id = ${id}`.pipe(Effect.orDie);
|
|
602
|
-
const presented = yield* (yield* Actors).mintCommandId;
|
|
603
|
-
const move = (from, to, scheduled) => sql `UPDATE actor_outbox SET intent_id = ${to}, scheduled_at_ms = ${scheduled}::bigint
|
|
604
|
-
WHERE intent_id = ${from}`.pipe(Effect.orDie);
|
|
605
|
-
yield* move(row.intent_id, presented, "0");
|
|
606
|
-
for (const title of ["later", "hijacked"])
|
|
607
|
-
expect(yield* task(id).pipe(Actor.as(proven(planner.ref, commandId)), Effect.flatMap((forger) => forger.Open(title).pipe(Actor.commandId(presented))), Effect.flip)).toMatchObject(denied);
|
|
608
|
-
yield* move(presented, row.intent_id, row.scheduled);
|
|
609
|
-
expect(yield* created("MintTask", id)).toBe(0);
|
|
610
|
-
yield* test.advance("1 hour");
|
|
611
|
-
expect(yield* child.Title()).toBe("later");
|
|
612
|
-
expect(yield* created("MintTask", id)).toBe(1);
|
|
613
|
-
yield* child.Open("reopened");
|
|
614
|
-
expect(yield* child.Title()).toBe("reopened");
|
|
615
|
-
})),
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
name: "gives the proof to a creating intent staged before its child was minted",
|
|
619
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
620
|
-
const planner = yield* Planner.get("staged-first");
|
|
621
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
622
|
-
const known = yield* expected(planner.ref, commandId, 0);
|
|
623
|
-
expect(yield* planner.PlanStagedFirst(known).pipe(Actor.commandId(commandId))).toBe(known);
|
|
624
|
-
yield* (yield* ActorTest).advance(0);
|
|
625
|
-
expect(yield* (yield* task(known)).Title()).toBe("staged first");
|
|
626
|
-
expect(yield* created("MintTask", known)).toBe(1);
|
|
627
|
-
})),
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
name: "mints from a singleton parent with an empty parent id",
|
|
631
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
632
|
-
const solo = yield* SoloPlanner.get();
|
|
633
|
-
const commandId = yield* (yield* Actors).mintCommandId;
|
|
634
|
-
const id = yield* solo.SoloPlan().pipe(Actor.commandId(commandId));
|
|
635
|
-
expect(id).toBe(yield* expected({ ...solo.ref, id: "" }, commandId, 0));
|
|
636
|
-
yield* (yield* ActorTest).advance(0);
|
|
637
|
-
expect(yield* (yield* task(id)).Title()).toBe("solo");
|
|
638
|
-
})),
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
name: "creates a named actor whose declared key is a UUIDv8 without a mint proof",
|
|
642
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
643
|
-
const planner = yield* Planner.get("named");
|
|
644
|
-
const id = yield* expected(planner.ref, "named", 0);
|
|
645
|
-
const job = yield* Job.get(id);
|
|
646
|
-
yield* job.Open("named");
|
|
647
|
-
expect(yield* job.Title()).toBe("named");
|
|
648
|
-
})),
|
|
649
|
-
},
|
|
650
|
-
{
|
|
651
|
-
name: "reaches a minted id on an unkeyed actor that no longer declares policy.createdBy",
|
|
652
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
653
|
-
const planner = yield* Planner.get("former");
|
|
654
|
-
const id = yield* expected(planner.ref, "former", 0, "MintFormerChild");
|
|
655
|
-
const child = yield* Former.get(id);
|
|
656
|
-
yield* child.Open("kept");
|
|
657
|
-
expect(yield* child.Title()).toBe("kept");
|
|
658
|
-
})),
|
|
659
|
-
},
|
|
660
|
-
{
|
|
661
|
-
name: "keeps create() children open to any authorized caller of the creating command",
|
|
662
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
663
|
-
const child = yield* Task.create();
|
|
664
|
-
yield* child.Open("direct");
|
|
665
|
-
expect(yield* child.Title()).toBe("direct");
|
|
666
|
-
})),
|
|
667
|
-
},
|
|
668
|
-
{
|
|
669
|
-
name: "rejects a mint capability that escaped its turn, a keyed creating intent, and an actor that cannot be minted",
|
|
670
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
671
|
-
const planner = yield* Planner.get("escape");
|
|
672
|
-
yield* planner.Escape();
|
|
673
|
-
const stolen = yield* planner.Steal().pipe(Effect.exit);
|
|
674
|
-
expect(Exit.isFailure(stolen) && Cause.pretty(stolen.cause)).toContain("Mint capability escaped its turn");
|
|
675
|
-
const keyed = yield* planner.PlanKeyed().pipe(Effect.exit);
|
|
676
|
-
expect(Exit.isFailure(keyed) && Cause.pretty(keyed.cause)).toContain(`Minted actor MintTask/${runs.at(-1)[0]} has a keyed creating intent`);
|
|
677
|
-
expect(yield* (yield* ActorTest).inspect(planner.ref)).toMatchObject({ outbox: 0 });
|
|
678
|
-
const unmintable = yield* planner.MintUnmintable().pipe(Effect.exit);
|
|
679
|
-
expect(Exit.isFailure(unmintable) && Cause.pretty(unmintable.cause)).toContain("turn.mint needs an unkeyed actor that declares createdBy");
|
|
680
|
-
})),
|
|
681
|
-
},
|
|
682
|
-
];
|
|
683
|
-
/** Minted-id actors. */
|
|
684
|
-
export const mintSuite = {
|
|
685
|
-
fixture: () => ({ deliveries: new Map(), onTurn: undefined }),
|
|
686
|
-
layer: () => mintLayer,
|
|
687
|
-
turn: (fixture) => (point, request) => Effect.sync(() => {
|
|
688
|
-
if (point === "afterClaim")
|
|
689
|
-
fixture.deliveries.set(request.ref.id, request);
|
|
690
|
-
fixture.onTurn?.(point, request);
|
|
691
|
-
}),
|
|
692
|
-
};
|