@effect-agent/testing 0.1.0-beta.38 → 0.1.0-beta.39
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/dist/certification.d.mts +102 -0
- package/dist/certification.mjs +561 -0
- package/dist/certification.mjs.map +1 -0
- package/dist/chaos.d.mts +124 -0
- package/dist/chaos.mjs +738 -0
- package/dist/chaos.mjs.map +1 -0
- package/dist/code-executor.d.mts +48 -0
- package/dist/code-executor.mjs +565 -0
- package/dist/code-executor.mjs.map +1 -0
- package/dist/deterministic-layers-D6gCdoPM.mjs +354 -0
- package/dist/deterministic-layers-D6gCdoPM.mjs.map +1 -0
- package/dist/docs-researcher.d.mts +254 -0
- package/dist/docs-researcher.mjs +479 -0
- package/dist/docs-researcher.mjs.map +1 -0
- package/dist/index.d.mts +2 -2947
- package/dist/index.mjs +2 -4913
- package/dist/scripted-model-CEwVM9JY.mjs +169 -0
- package/dist/scripted-model-CEwVM9JY.mjs.map +1 -0
- package/dist/scripted-model-dOa_e0-n.d.mts +677 -0
- package/dist/travel-planner.d.mts +1767 -0
- package/dist/travel-planner.mjs +2102 -0
- package/dist/travel-planner.mjs.map +1 -0
- package/package.json +33 -10
- package/src/certification.ts +71 -61
- package/src/chaos.ts +52 -64
- package/src/code-executor.ts +3 -0
- package/src/docs-researcher.ts +2 -0
- package/src/fixtures/docs-researcher/definition.ts +7 -7
- package/src/fixtures/docs-researcher/harness.ts +5 -5
- package/src/fixtures/docs-researcher/index.ts +1 -1
- package/src/fixtures/travel-planner/definition.ts +1 -1
- package/src/fixtures/travel-planner/deterministic-layers.ts +6 -4
- package/src/fixtures/travel-planner/phase2.ts +1 -1
- package/src/fixtures/travel-planner/phase3.ts +14 -18
- package/src/fixtures/travel-planner/phase4.ts +7 -7
- package/src/fixtures/travel-planner/phase5.ts +5 -5
- package/src/fixtures/travel-planner/phase6.ts +30 -29
- package/src/fixtures/travel-planner/subagents-durable.ts +6 -6
- package/src/fixtures/travel-planner/subagents.ts +4 -4
- package/src/index.ts +1 -10
- package/src/travel-planner.ts +2 -0
- package/dist/index.mjs.map +0 -1
- package/src/code-executor-conformance.d.ts +0 -30
- package/src/fixtures/warehouse/index.ts +0 -412
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Crypto, Duration, Effect, Layer } from "effect";
|
|
2
|
+
import { DurableRuntimeFailpointLocation, SubmissionLedger, ThreadStore, WakeScheduler } from "@effect-agent/thread";
|
|
3
|
+
import { CertificationCaseResult, CertificationReport, CertificationScenario, CertificationSweepResult, CertificationTierThreeReport } from "@effect-agent/thread/testing";
|
|
4
|
+
//#region src/certification.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* P7 WP2 — `certifyDurableAdapters` (plan §1): the one certification entry point a durable
|
|
7
|
+
* adapter pair runs to earn a Schema-encoded certificate.
|
|
8
|
+
*
|
|
9
|
+
* - **Tier 1 — port contract**: the two shared conformance case arrays, verbatim, through
|
|
10
|
+
* `certifyPorts` (TEST-004/STORE-010).
|
|
11
|
+
* - **Tier 2 — coordinator protocol + failpoint convergence**: the durable coordinator is
|
|
12
|
+
* assembled over the CANDIDATE Layer pair with a scripted deterministic model; every
|
|
13
|
+
* `DurableRuntimeFailpointLocation` is armed one-shot across the six scenario shapes
|
|
14
|
+
* (plain / uncertain-tool / durable-steps / approval / join / delegation). After the injected
|
|
15
|
+
* fault the runner asserts the state stays CLASSIFIABLE (recovery + the public unblocking
|
|
16
|
+
* operations `resolveUnknown`/`resolveApproval` are the only levers used) and that the
|
|
17
|
+
* re-drive CONVERGES to `verifyThreadInvariants` with `requireAllSettled` — including a
|
|
18
|
+
* fully discharged digest-chain check, because the runner captures per-batch producer
|
|
19
|
+
* identity at append time.
|
|
20
|
+
* - **Tier 3 — real loss lever**: recorded honestly. A durable adapter either supplies a
|
|
21
|
+
* `CertificationCrashLever` executed in this run, cites its committed real-loss evidence
|
|
22
|
+
* (process-kill / eviction suites), or the certificate says `not-exercised`. A non-durable
|
|
23
|
+
* reference adapter records `not-applicable`.
|
|
24
|
+
*
|
|
25
|
+
* The runner is adapter-neutral and platform-neutral: it imports nothing Node-only, so the
|
|
26
|
+
* same entry point runs under `@effect/vitest` on Node and inside workerd (storage-cloudflare's
|
|
27
|
+
* in-workerd runner). It must run under a TestClock (Tier 1 drives lease expiry through
|
|
28
|
+
* virtual time), and requires only `Crypto.Crypto` from the environment.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* A real-loss lever supplied by an adapter that wants Tier 3 exercised IN this certification
|
|
32
|
+
* run (kill/evict/reopen around a designated row subset). Rows report with
|
|
33
|
+
* `suite: "real-loss"`. Failures must be captured per-row — the lever's error channel is
|
|
34
|
+
* `never` so a certificate is always produced.
|
|
35
|
+
*/
|
|
36
|
+
type CertificationCrashLever = Effect.Effect<ReadonlyArray<CertificationCaseResult>>;
|
|
37
|
+
interface CertifyDurableAdaptersOptions<LedgerE = never, StoreE = never> {
|
|
38
|
+
/** Adapter pair identity named by the certificate (durability is read from the ledger). */
|
|
39
|
+
readonly adapter: {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly version?: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The candidate Layer pair. When both ports must share one connection root (the ADR-0011
|
|
45
|
+
* "same file" rule), pass the SAME combined Layer instance for both fields — Layer
|
|
46
|
+
* memoization builds it once. A candidate may require `Crypto.Crypto` (the memory reference
|
|
47
|
+
* does); the certification's own environment supplies nothing else.
|
|
48
|
+
*/
|
|
49
|
+
readonly submissionLedger: Layer.Layer<SubmissionLedger, LedgerE, Crypto.Crypto>;
|
|
50
|
+
readonly threadStore: Layer.Layer<ThreadStore, StoreE, Crypto.Crypto>;
|
|
51
|
+
/** Defaults to `WakeScheduler.layerNoop`; the runner re-drives lanes explicitly. */
|
|
52
|
+
readonly wakeScheduler?: Layer.Layer<WakeScheduler> | undefined;
|
|
53
|
+
/** Executes Tier 3 in this run; takes precedence over `tierThreeEvidence`. */
|
|
54
|
+
readonly crashLever?: CertificationCrashLever | undefined;
|
|
55
|
+
/** Repository-relative citations of committed real-loss suites (Tier 3 `recorded-evidence`). */
|
|
56
|
+
readonly tierThreeEvidence?: ReadonlyArray<string> | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* The candidate ledger's configured ownership lease (defaults to the D5 default, 30s).
|
|
59
|
+
* Every Tier-2 re-drive round advances the TestClock past this lease before reclaiming:
|
|
60
|
+
* a live lease may block ALL new claims (the SQL adapters do; the memory reference also
|
|
61
|
+
* allows same-producer reclaim), so the adapter-NEUTRAL recovery lever after a mid-Attempt
|
|
62
|
+
* fault is lease expiry — exactly the documented D5 liveness mechanism, driven through
|
|
63
|
+
* virtual time.
|
|
64
|
+
*/
|
|
65
|
+
readonly ownershipLeaseDuration?: Duration.Duration | undefined;
|
|
66
|
+
}
|
|
67
|
+
/** The six Tier-2 scenario shapes in sweep order. */
|
|
68
|
+
declare const CERTIFICATION_SCENARIOS: ReadonlyArray<CertificationScenario>;
|
|
69
|
+
/**
|
|
70
|
+
* Coordinator failpoint locations that none of the six scenario shapes can reach, recorded
|
|
71
|
+
* honestly instead of silently claimed: all three sit on operator/abort paths the shapes do
|
|
72
|
+
* not take. They are pinned in-process by the P5/S2 suites
|
|
73
|
+
* (`packages/testing/test/durable-tools.test.ts` "resolveUnknown is idempotent across the
|
|
74
|
+
* intent failpoint", `durable-runtime.test.ts` abort rows,
|
|
75
|
+
* `durable-subagents.test.ts` abort propagation) and by the process-kill/eviction crash
|
|
76
|
+
* matrices. Runner tests assert the observed never-fired set equals EXACTLY this list, so a
|
|
77
|
+
* protocol change that silently stops exercising a location fails the certification.
|
|
78
|
+
*/
|
|
79
|
+
declare const TIER2_UNREACHED_LOCATIONS: ReadonlyArray<DurableRuntimeFailpointLocation>;
|
|
80
|
+
/** Locations of `tier2` rows whose armed fault never fired in ANY scenario, sorted. */
|
|
81
|
+
declare const tier2NeverFiredLocations: (tier2: ReadonlyArray<CertificationSweepResult>) => ReadonlyArray<DurableRuntimeFailpointLocation>;
|
|
82
|
+
/**
|
|
83
|
+
* Resolve the Tier-3 record honestly (plan §1): a non-durable reference adapter has no real
|
|
84
|
+
* loss to exercise (`not-applicable`); a supplied lever runs NOW (`exercised`); committed
|
|
85
|
+
* real-loss citations are recorded (`recorded-evidence`); otherwise the certificate says
|
|
86
|
+
* `not-exercised` — a scoped statement, never a silent claim.
|
|
87
|
+
*/
|
|
88
|
+
declare const resolveTierThree: (durability: "durable-cloudflare" | "durable-node" | "non-durable", options: {
|
|
89
|
+
readonly crashLever?: CertificationCrashLever | undefined;
|
|
90
|
+
readonly tierThreeEvidence?: ReadonlyArray<string> | undefined;
|
|
91
|
+
}) => Effect.Effect<CertificationTierThreeReport, never, never>;
|
|
92
|
+
/**
|
|
93
|
+
* Certify one durable adapter pair (plan §1, §8 WP2). Runs Tier 2 FIRST over pristine
|
|
94
|
+
* storage (each cell converges to all-settled before the next starts, so the recovery scan
|
|
95
|
+
* never sees foreign leftovers), then Tier 1's port contract cases (whose lanes deliberately
|
|
96
|
+
* end in every nonterminal shape), then records Tier 3. Requires `Crypto.Crypto` and a
|
|
97
|
+
* TestClock-backed environment; the candidate Layers are built exactly once.
|
|
98
|
+
*/
|
|
99
|
+
declare const certifyDurableAdapters: <LedgerE = never, StoreE = never>(options: CertifyDurableAdaptersOptions<LedgerE, StoreE>) => Effect.Effect<CertificationReport, LedgerE | StoreE, Crypto.Crypto>;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { CERTIFICATION_SCENARIOS, CertificationCrashLever, CertifyDurableAdaptersOptions, TIER2_UNREACHED_LOCATIONS, certifyDurableAdapters, resolveTierThree, tier2NeverFiredLocations };
|
|
102
|
+
//# sourceMappingURL=certification.d.mts.map
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import { Cause, Clock, DateTime, Duration, Effect, Exit, Layer, Option, Ref, Schema, Stream } from "effect";
|
|
2
|
+
import { LanguageModel, Model, Tool, Toolkit } from "effect/unstable/ai";
|
|
3
|
+
import { Subagent, SubagentPolicy, SubagentReservationsMemoryLive, SubagentRuntime } from "@effect-agent/capabilities";
|
|
4
|
+
import { Agent, AgentPolicy, IdGenerator, RunId, ThreadId, ToolCallId, TurnId } from "@effect-agent/core";
|
|
5
|
+
import { DurableStep, DurableStepError } from "@effect-agent/engine";
|
|
6
|
+
import { ApprovalDecisionCommand, DEFAULT_OWNERSHIP_LEASE_DURATION, DefinitionDigests, DeploymentId, Digest, DurableAgentRuntime, DurableRuntimeConfig, DurableRuntimeFailpointError, DurableRuntimeFailpointLocation, DurableWorkerBinding, IdempotencyKey, LoadCheckpointRequest, Principal, ProducerId, ResolutionSafeToRetry, SubmissionLedger, SubmissionLookupById, ThreadExportRequest, ThreadStore, ToolReconciler, UnknownResolutionCommand, WakeScheduler, childThreadIdFor, verifyThreadInvariants } from "@effect-agent/thread";
|
|
7
|
+
import { CertificationReport, CertificationSweepResult, CertificationTierThreeReport, CertifiedAdapterIdentity, DurableRuntimeFailpointTestControl, certifyPorts } from "@effect-agent/thread/testing";
|
|
8
|
+
import { TestClock } from "effect/testing";
|
|
9
|
+
//#region src/certification.ts
|
|
10
|
+
/** The six Tier-2 scenario shapes in sweep order. */
|
|
11
|
+
const CERTIFICATION_SCENARIOS = [
|
|
12
|
+
"plain",
|
|
13
|
+
"uncertain-tool",
|
|
14
|
+
"durable-steps",
|
|
15
|
+
"approval",
|
|
16
|
+
"join",
|
|
17
|
+
"delegation"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Coordinator failpoint locations that none of the six scenario shapes can reach, recorded
|
|
21
|
+
* honestly instead of silently claimed: all three sit on operator/abort paths the shapes do
|
|
22
|
+
* not take. They are pinned in-process by the P5/S2 suites
|
|
23
|
+
* (`packages/testing/test/durable-tools.test.ts` "resolveUnknown is idempotent across the
|
|
24
|
+
* intent failpoint", `durable-runtime.test.ts` abort rows,
|
|
25
|
+
* `durable-subagents.test.ts` abort propagation) and by the process-kill/eviction crash
|
|
26
|
+
* matrices. Runner tests assert the observed never-fired set equals EXACTLY this list, so a
|
|
27
|
+
* protocol change that silently stops exercising a location fails the certification.
|
|
28
|
+
*/
|
|
29
|
+
const TIER2_UNREACHED_LOCATIONS = [
|
|
30
|
+
"abort:after-intent",
|
|
31
|
+
"compaction:after-canonical-append",
|
|
32
|
+
"policy:before-reservation-append",
|
|
33
|
+
"policy:after-reservation-append",
|
|
34
|
+
"resolve:after-intent",
|
|
35
|
+
"subagent:after-child-abort-intent"
|
|
36
|
+
];
|
|
37
|
+
/** Locations of `tier2` rows whose armed fault never fired in ANY scenario, sorted. */
|
|
38
|
+
const tier2NeverFiredLocations = (tier2) => {
|
|
39
|
+
const fired = /* @__PURE__ */ new Set();
|
|
40
|
+
for (const row of tier2) if (row.failpointFired) fired.add(row.location);
|
|
41
|
+
return DurableRuntimeFailpointLocation.literals.filter((location) => !fired.has(location)).sort();
|
|
42
|
+
};
|
|
43
|
+
const SHA_A = Schema.decodeSync(Digest)("a".repeat(64));
|
|
44
|
+
const DIGESTS = DefinitionDigests.make({
|
|
45
|
+
agent: SHA_A,
|
|
46
|
+
model: SHA_A,
|
|
47
|
+
tools: SHA_A
|
|
48
|
+
});
|
|
49
|
+
const CHILD_DIGEST_STRINGS = {
|
|
50
|
+
agent: "b".repeat(64),
|
|
51
|
+
model: "c".repeat(64),
|
|
52
|
+
tools: "d".repeat(64)
|
|
53
|
+
};
|
|
54
|
+
const CHILD_DIGESTS = DefinitionDigests.make({
|
|
55
|
+
agent: Schema.decodeSync(Digest)(CHILD_DIGEST_STRINGS.agent),
|
|
56
|
+
model: Schema.decodeSync(Digest)(CHILD_DIGEST_STRINGS.model),
|
|
57
|
+
tools: Schema.decodeSync(Digest)(CHILD_DIGEST_STRINGS.tools)
|
|
58
|
+
});
|
|
59
|
+
const PRINCIPAL = Schema.decodeSync(Principal)("principal-certification");
|
|
60
|
+
const decodeThreadId = Schema.decodeSync(ThreadId);
|
|
61
|
+
const decodeIdempotencyKey = Schema.decodeSync(IdempotencyKey);
|
|
62
|
+
const decodeToolCallId = Schema.decodeSync(ToolCallId);
|
|
63
|
+
const usage = {
|
|
64
|
+
inputTokens: {},
|
|
65
|
+
outputTokens: {}
|
|
66
|
+
};
|
|
67
|
+
const finalParts = (text) => [
|
|
68
|
+
{
|
|
69
|
+
type: "text-start",
|
|
70
|
+
id: "answer"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "text-delta",
|
|
74
|
+
id: "answer",
|
|
75
|
+
delta: text
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: "text-end",
|
|
79
|
+
id: "answer"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: "finish",
|
|
83
|
+
reason: "stop",
|
|
84
|
+
usage
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const toolCallPart = (id, name, params) => ({
|
|
88
|
+
type: "tool-call",
|
|
89
|
+
id,
|
|
90
|
+
name,
|
|
91
|
+
params,
|
|
92
|
+
providerExecuted: false
|
|
93
|
+
});
|
|
94
|
+
const toolTurn = (...calls) => [...calls, {
|
|
95
|
+
type: "finish",
|
|
96
|
+
reason: "tool-calls",
|
|
97
|
+
usage
|
|
98
|
+
}];
|
|
99
|
+
/**
|
|
100
|
+
* Stateless scripted model that decides by PROMPT SHAPE instead of call count: while the
|
|
101
|
+
* prompt carries no committed tool result the model declares `toolParts` (when given),
|
|
102
|
+
* otherwise it answers with the final text. Deciding on the canonical prompt keeps every cell
|
|
103
|
+
* deterministic regardless of where the injected fault fell — a re-invoked Turn re-declares
|
|
104
|
+
* the same batch and a resumed batch flows into the final answer, so every scenario always
|
|
105
|
+
* exercises its tool path and always converges.
|
|
106
|
+
*/
|
|
107
|
+
const promptShapeModel = (name, finalText, toolParts) => Model.make("scripted", name, Layer.effect(LanguageModel.LanguageModel, LanguageModel.make({
|
|
108
|
+
generateText: () => Effect.succeed([]),
|
|
109
|
+
streamText: (request) => {
|
|
110
|
+
const hasToolResult = request.prompt.content.some((message) => message.role === "tool");
|
|
111
|
+
const parts = toolParts === void 0 || hasToolResult ? finalParts(finalText) : toolParts;
|
|
112
|
+
return Stream.fromIterable(parts);
|
|
113
|
+
}
|
|
114
|
+
})));
|
|
115
|
+
const CERTIFICATION_MAX_DURATION = "10 minutes";
|
|
116
|
+
const policy = AgentPolicy.make({
|
|
117
|
+
maxTurns: 4,
|
|
118
|
+
maxToolCalls: 4,
|
|
119
|
+
maxDuration: CERTIFICATION_MAX_DURATION,
|
|
120
|
+
toolConcurrency: 2
|
|
121
|
+
});
|
|
122
|
+
const QuestionInput = Schema.Struct({ question: Schema.String });
|
|
123
|
+
const AnswerOutput = Schema.Struct({ answer: Schema.String });
|
|
124
|
+
/** plain / join: no tools — the pure Turn/submission/join seams. */
|
|
125
|
+
const plainDefinition = Agent.make("certify-plain", {
|
|
126
|
+
input: QuestionInput,
|
|
127
|
+
output: AnswerOutput,
|
|
128
|
+
instructions: "Answer as JSON.",
|
|
129
|
+
toolkit: Toolkit.empty,
|
|
130
|
+
policy
|
|
131
|
+
});
|
|
132
|
+
/** uncertain-tool: unannotated → fail-closed `uncertain`, enters the prepared/settled protocol. */
|
|
133
|
+
const Book = Tool.make("book", {
|
|
134
|
+
parameters: Schema.Struct({ ref: Schema.String }),
|
|
135
|
+
success: Schema.Struct({ confirmation: Schema.String })
|
|
136
|
+
});
|
|
137
|
+
const bookToolkit = Toolkit.make(Book);
|
|
138
|
+
const uncertainDefinition = Agent.make("certify-uncertain", {
|
|
139
|
+
input: QuestionInput,
|
|
140
|
+
output: AnswerOutput,
|
|
141
|
+
instructions: "Book it.",
|
|
142
|
+
toolkit: bookToolkit,
|
|
143
|
+
policy
|
|
144
|
+
});
|
|
145
|
+
/** durable-steps: declaring `DurableStep` as a dependency is what makes the Tool durable. */
|
|
146
|
+
const Itinerary = Tool.make("itinerary", {
|
|
147
|
+
parameters: Schema.Struct({ ref: Schema.String }),
|
|
148
|
+
success: Schema.Struct({ state: Schema.String }),
|
|
149
|
+
failure: DurableStepError,
|
|
150
|
+
dependencies: [DurableStep]
|
|
151
|
+
});
|
|
152
|
+
const itineraryToolkit = Toolkit.make(Itinerary);
|
|
153
|
+
const stepsDefinition = Agent.make("certify-steps", {
|
|
154
|
+
input: QuestionInput,
|
|
155
|
+
output: AnswerOutput,
|
|
156
|
+
instructions: "Reserve the itinerary.",
|
|
157
|
+
toolkit: itineraryToolkit,
|
|
158
|
+
policy
|
|
159
|
+
});
|
|
160
|
+
/** approval: fail-closed — no `DurableApprovalResolver` Layer, so undecided approvals suspend. */
|
|
161
|
+
const BookApproval = Tool.make("book", {
|
|
162
|
+
parameters: Schema.Struct({ ref: Schema.String }),
|
|
163
|
+
success: Schema.Struct({ confirmation: Schema.String }),
|
|
164
|
+
needsApproval: true
|
|
165
|
+
});
|
|
166
|
+
const approvalToolkit = Toolkit.make(BookApproval);
|
|
167
|
+
const approvalDefinition = Agent.make("certify-approval", {
|
|
168
|
+
input: QuestionInput,
|
|
169
|
+
output: AnswerOutput,
|
|
170
|
+
instructions: "Book after approval.",
|
|
171
|
+
toolkit: approvalToolkit,
|
|
172
|
+
policy
|
|
173
|
+
});
|
|
174
|
+
/** delegation: durable attached child plus an ordinary uncertain sibling in ONE batch. */
|
|
175
|
+
const childDefinition = Agent.make("certify-child", {
|
|
176
|
+
input: QuestionInput,
|
|
177
|
+
output: AnswerOutput,
|
|
178
|
+
instructions: "Answer as JSON.",
|
|
179
|
+
toolkit: Toolkit.empty,
|
|
180
|
+
policy: AgentPolicy.make({
|
|
181
|
+
maxTurns: 2,
|
|
182
|
+
maxToolCalls: 1,
|
|
183
|
+
maxDuration: CERTIFICATION_MAX_DURATION,
|
|
184
|
+
toolConcurrency: 1
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
var CertifyDelegationFailed = class extends Schema.TaggedError()("CertifyDelegationFailed", { childErrorTag: Schema.String }) {};
|
|
188
|
+
const researchDelegation = Subagent.define("delegate_research", {
|
|
189
|
+
description: "Research one bounded question and return findings.",
|
|
190
|
+
target: childDefinition,
|
|
191
|
+
parameters: Schema.Struct({ topic: Schema.String }),
|
|
192
|
+
success: Schema.Struct({ summary: Schema.String }),
|
|
193
|
+
failure: CertifyDelegationFailed,
|
|
194
|
+
prepareInput: ({ topic }) => Effect.succeed({ question: `research:${topic}` }),
|
|
195
|
+
projectResult: (output) => Effect.succeed({ summary: `finding:${output.answer}` }),
|
|
196
|
+
policy: SubagentPolicy.make({
|
|
197
|
+
maxChildren: 2,
|
|
198
|
+
maxConcurrency: 2,
|
|
199
|
+
maxTurns: 4,
|
|
200
|
+
maxToolCalls: 4,
|
|
201
|
+
maxDuration: CERTIFICATION_MAX_DURATION
|
|
202
|
+
})
|
|
203
|
+
});
|
|
204
|
+
const Lookup = Tool.make("lookup", {
|
|
205
|
+
parameters: Schema.Struct({ key: Schema.String }),
|
|
206
|
+
success: Schema.Struct({ value: Schema.String })
|
|
207
|
+
});
|
|
208
|
+
const coordinatorDefinition = Agent.make("certify-coordinator", {
|
|
209
|
+
input: Schema.Struct({ mission: Schema.String }),
|
|
210
|
+
output: Schema.Struct({ report: Schema.String }),
|
|
211
|
+
instructions: "Delegate and look up, then answer as JSON.",
|
|
212
|
+
toolkit: Toolkit.make(researchDelegation.tool, Lookup),
|
|
213
|
+
policy: AgentPolicy.make({
|
|
214
|
+
maxTurns: 4,
|
|
215
|
+
maxToolCalls: 3,
|
|
216
|
+
maxDuration: CERTIFICATION_MAX_DURATION,
|
|
217
|
+
toolConcurrency: 2
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
const mapChildFailure = (failure) => CertifyDelegationFailed.make({ childErrorTag: failure._tag });
|
|
221
|
+
const DELEGATE_CALL = decodeToolCallId("delegate-1");
|
|
222
|
+
/** Fixture-only identity source consumed by the delegation Layer's ephemeral capture. */
|
|
223
|
+
const identifiers = Layer.effect(IdGenerator, Effect.gen(function* () {
|
|
224
|
+
const counter = yield* Ref.make(0);
|
|
225
|
+
const next = (decode, prefix) => Ref.getAndUpdate(counter, (value) => value + 1).pipe(Effect.map((value) => decode(`${prefix}-${value}`)));
|
|
226
|
+
return {
|
|
227
|
+
nextThreadId: next(decodeThreadId, "certify-fixture-thread"),
|
|
228
|
+
nextRunId: next(Schema.decodeSync(RunId), "certify-fixture-run"),
|
|
229
|
+
nextTurnId: next(Schema.decodeSync(TurnId), "certify-fixture-turn")
|
|
230
|
+
};
|
|
231
|
+
}));
|
|
232
|
+
const delegationSupport = Layer.mergeAll(SubagentReservationsMemoryLive, identifiers);
|
|
233
|
+
const submitOptionsFor = (slug, threadId) => ({
|
|
234
|
+
threadId,
|
|
235
|
+
principal: PRINCIPAL,
|
|
236
|
+
idempotencyKey: decodeIdempotencyKey(`certify-key-${slug}`),
|
|
237
|
+
definitions: DIGESTS
|
|
238
|
+
});
|
|
239
|
+
/** One single-agent cell: one lane, one Submission, one registered exact-digest binding. */
|
|
240
|
+
const makeSingleAgentCell = (definition, resolved, slug) => {
|
|
241
|
+
const threadId = decodeThreadId(`certify-${slug}`);
|
|
242
|
+
const submit = Effect.gen(function* () {
|
|
243
|
+
return [yield* (yield* DurableAgentRuntime).submit({ definition: {
|
|
244
|
+
id: definition.id,
|
|
245
|
+
input: definition.input
|
|
246
|
+
} }, { question: `certify ${slug}` }, submitOptionsFor(slug, threadId))];
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
bindings: [resolved],
|
|
250
|
+
submit,
|
|
251
|
+
lanes: () => [threadId]
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const makeCell = Effect.fn("Certification.makeCell")(function* (scenario, slug) {
|
|
255
|
+
switch (scenario) {
|
|
256
|
+
case "plain": {
|
|
257
|
+
const binding = Agent.withModel(plainDefinition, promptShapeModel("certify-plain", "{\"answer\":\"done\"}"));
|
|
258
|
+
const resolved = yield* DurableWorkerBinding.make(binding, DIGESTS);
|
|
259
|
+
return makeSingleAgentCell(plainDefinition, resolved, slug);
|
|
260
|
+
}
|
|
261
|
+
case "uncertain-tool": {
|
|
262
|
+
const binding = Agent.withModel(uncertainDefinition, promptShapeModel("certify-uncertain", "{\"answer\":\"booked\"}", toolTurn(toolCallPart("book-1", "book", { ref: `r-${slug}` }))));
|
|
263
|
+
const toolLayer = bookToolkit.toLayer({ book: ({ ref }) => Effect.succeed({ confirmation: `confirmed-${ref}` }) });
|
|
264
|
+
const resolved = yield* DurableWorkerBinding.make(binding, DIGESTS).pipe(Effect.provide(toolLayer));
|
|
265
|
+
return makeSingleAgentCell(uncertainDefinition, resolved, slug);
|
|
266
|
+
}
|
|
267
|
+
case "durable-steps": {
|
|
268
|
+
const binding = Agent.withModel(stepsDefinition, promptShapeModel("certify-steps", "{\"answer\":\"reserved\"}", toolTurn(toolCallPart("itinerary-1", "itinerary", { ref: `trip-${slug}` }))));
|
|
269
|
+
const toolLayer = itineraryToolkit.toLayer({ itinerary: ({ ref }) => Effect.gen(function* () {
|
|
270
|
+
const step = yield* DurableStep;
|
|
271
|
+
return { state: `${yield* step.do("reserve-flight", Schema.String, Effect.succeed(`flight-${ref}`))}+${yield* step.do("reserve-lodging", Schema.String, Effect.succeed(`lodging-${ref}`))}` };
|
|
272
|
+
}) });
|
|
273
|
+
const resolved = yield* DurableWorkerBinding.make(binding, DIGESTS).pipe(Effect.provide(toolLayer));
|
|
274
|
+
return makeSingleAgentCell(stepsDefinition, resolved, slug);
|
|
275
|
+
}
|
|
276
|
+
case "approval": {
|
|
277
|
+
const binding = Agent.withModel(approvalDefinition, promptShapeModel("certify-approval", "{\"answer\":\"approved\"}", toolTurn(toolCallPart("book-1", "book", { ref: `r-${slug}` }))));
|
|
278
|
+
const toolLayer = approvalToolkit.toLayer({ book: ({ ref }) => Effect.succeed({ confirmation: `confirmed-${ref}` }) });
|
|
279
|
+
const resolved = yield* DurableWorkerBinding.make(binding, DIGESTS).pipe(Effect.provide(toolLayer));
|
|
280
|
+
return makeSingleAgentCell(approvalDefinition, resolved, slug);
|
|
281
|
+
}
|
|
282
|
+
case "join": {
|
|
283
|
+
const binding = Agent.withModel(plainDefinition, promptShapeModel("certify-join", "{\"answer\":\"host answer\"}"));
|
|
284
|
+
const resolved = yield* DurableWorkerBinding.make(binding, DIGESTS);
|
|
285
|
+
const threadId = decodeThreadId(`certify-${slug}`);
|
|
286
|
+
const submitOne = (key, question) => Effect.gen(function* () {
|
|
287
|
+
return yield* (yield* DurableAgentRuntime).submit({ definition: {
|
|
288
|
+
id: plainDefinition.id,
|
|
289
|
+
input: plainDefinition.input
|
|
290
|
+
} }, { question }, {
|
|
291
|
+
threadId,
|
|
292
|
+
principal: PRINCIPAL,
|
|
293
|
+
idempotencyKey: decodeIdempotencyKey(key),
|
|
294
|
+
definitions: DIGESTS
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
return {
|
|
298
|
+
bindings: [resolved],
|
|
299
|
+
submit: Effect.gen(function* () {
|
|
300
|
+
return [yield* submitOne(`certify-key-${slug}-host`, "host question"), yield* submitOne(`certify-key-${slug}-queued`, "queued question")];
|
|
301
|
+
}),
|
|
302
|
+
lanes: () => [threadId]
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
case "delegation": {
|
|
306
|
+
const childBinding = Agent.withModel(childDefinition, promptShapeModel("certify-child", "{\"answer\":\"child-answer\"}"));
|
|
307
|
+
const parentBinding = Agent.withModel(coordinatorDefinition, promptShapeModel("certify-parent", "{\"report\":\"done\"}", toolTurn(toolCallPart("delegate-1", "delegate_research", { topic: "paris" }), toolCallPart("lookup-1", "lookup", { key: "hotels" }))));
|
|
308
|
+
const delegationLayer = SubagentRuntime.layer(researchDelegation, childBinding, {
|
|
309
|
+
mapChildFailure,
|
|
310
|
+
durable: { targetDigests: CHILD_DIGEST_STRINGS }
|
|
311
|
+
}).pipe(Layer.provide(delegationSupport));
|
|
312
|
+
const lookupLayer = Toolkit.make(Lookup).toLayer({ lookup: ({ key }) => Effect.succeed({ value: `found-${key}` }) });
|
|
313
|
+
const parentResolved = yield* DurableWorkerBinding.make(parentBinding, DIGESTS).pipe(Effect.provide(Layer.mergeAll(delegationLayer, lookupLayer)));
|
|
314
|
+
const childResolved = yield* DurableWorkerBinding.make(childBinding, CHILD_DIGESTS);
|
|
315
|
+
const threadId = decodeThreadId(`certify-${slug}`);
|
|
316
|
+
return {
|
|
317
|
+
bindings: [parentResolved, childResolved],
|
|
318
|
+
submit: Effect.gen(function* () {
|
|
319
|
+
return [yield* (yield* DurableAgentRuntime).submit({ definition: {
|
|
320
|
+
id: coordinatorDefinition.id,
|
|
321
|
+
input: coordinatorDefinition.input
|
|
322
|
+
} }, { mission: "plan" }, submitOptionsFor(slug, threadId))];
|
|
323
|
+
}),
|
|
324
|
+
lanes: (receipts) => {
|
|
325
|
+
const parent = receipts.at(0);
|
|
326
|
+
return parent === void 0 ? [threadId] : [threadId, childThreadIdFor(parent.submissionId, DELEGATE_CALL)];
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
/** Maximum recovery/drive/unblock rounds before a cell is reported non-convergent. */
|
|
333
|
+
const MAX_REDRIVE_ROUNDS = 8;
|
|
334
|
+
/**
|
|
335
|
+
* Verify one lane after convergence: canonical export + every lane Submission the ledger or
|
|
336
|
+
* the log names (the same collection rule as the admin `verify` member), fed to the shared
|
|
337
|
+
* invariant checker in convergence mode WITH the captured per-batch producer directory, so
|
|
338
|
+
* the digest chain is fully recomputed instead of skipped.
|
|
339
|
+
*/
|
|
340
|
+
const verifyLane = Effect.fn("Certification.verifyLane")(function* (lane, batchProducers) {
|
|
341
|
+
const store = yield* ThreadStore;
|
|
342
|
+
const ledger = yield* SubmissionLedger;
|
|
343
|
+
const exported = yield* store.export(ThreadExportRequest.make({ threadId: lane }));
|
|
344
|
+
const rows = /* @__PURE__ */ new Map();
|
|
345
|
+
const nonterminal = yield* Stream.runCollect(ledger.scanNonterminal);
|
|
346
|
+
for (const submission of nonterminal) if (submission.threadId === lane) rows.set(submission.submissionId, submission);
|
|
347
|
+
const named = /* @__PURE__ */ new Set();
|
|
348
|
+
for (const envelope of exported.records) {
|
|
349
|
+
const payload = envelope.record.payload;
|
|
350
|
+
if (payload._tag === "UserInputRecorded" || payload._tag === "SubmissionSettled" || payload._tag === "AbortRequested") {
|
|
351
|
+
if (payload.submissionId !== void 0) named.add(payload.submissionId);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
for (const submissionId of named) {
|
|
355
|
+
if (rows.has(submissionId)) continue;
|
|
356
|
+
const found = yield* ledger.lookup(SubmissionLookupById.make({ submissionId }));
|
|
357
|
+
if (Option.isSome(found) && found.value.threadId === lane) rows.set(submissionId, found.value);
|
|
358
|
+
}
|
|
359
|
+
const checkpoint = store.checkpoints === void 0 ? Option.none() : yield* store.checkpoints.load(LoadCheckpointRequest.make({ threadId: lane }));
|
|
360
|
+
return yield* verifyThreadInvariants({
|
|
361
|
+
export: exported,
|
|
362
|
+
submissions: [...rows.values()],
|
|
363
|
+
batchProducers,
|
|
364
|
+
checkpoint: Option.getOrUndefined(checkpoint),
|
|
365
|
+
checkpointsSupported: store.checkpoints !== void 0,
|
|
366
|
+
requireAllSettled: true
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
const failureTagOf = (cause) => {
|
|
370
|
+
const failure = Cause.findErrorOption(cause);
|
|
371
|
+
if (Option.isSome(failure)) {
|
|
372
|
+
const error = failure.value;
|
|
373
|
+
if (typeof error === "object" && error !== null && "_tag" in error) return String(error._tag);
|
|
374
|
+
return String(error).slice(0, 256);
|
|
375
|
+
}
|
|
376
|
+
return "defect";
|
|
377
|
+
};
|
|
378
|
+
/** One Tier-2 sweep cell: arm `location` one-shot, drive `scenario`, converge, verify. */
|
|
379
|
+
const runSweepCell = Effect.fn("Certification.runSweepCell")(function* (scenario, location, batchProducers, leaseAdvance) {
|
|
380
|
+
const runtime = yield* DurableAgentRuntime;
|
|
381
|
+
const ledger = yield* SubmissionLedger;
|
|
382
|
+
const control = yield* DurableRuntimeFailpointTestControl;
|
|
383
|
+
const slug = `${scenario}-${location.replaceAll(":", "-")}`;
|
|
384
|
+
const failed = (detail, fired) => CertificationSweepResult.make({
|
|
385
|
+
scenario,
|
|
386
|
+
location,
|
|
387
|
+
failpointFired: fired,
|
|
388
|
+
status: "failed",
|
|
389
|
+
digestChainVerified: false,
|
|
390
|
+
detail: detail.slice(0, 4096)
|
|
391
|
+
});
|
|
392
|
+
const cell = yield* makeCell(scenario, slug);
|
|
393
|
+
const fired = yield* Ref.make(false);
|
|
394
|
+
yield* control.setHandler((hit) => hit !== location ? Effect.void : Ref.getAndSet(fired, true).pipe(Effect.flatMap((already) => already ? Effect.void : Effect.fail(DurableRuntimeFailpointError.make({ location: hit })))));
|
|
395
|
+
let receipts;
|
|
396
|
+
const firstSubmit = yield* Effect.exit(cell.submit);
|
|
397
|
+
if (Exit.isSuccess(firstSubmit)) receipts = firstSubmit.value;
|
|
398
|
+
else {
|
|
399
|
+
const secondSubmit = yield* Effect.exit(cell.submit);
|
|
400
|
+
if (Exit.isFailure(secondSubmit)) {
|
|
401
|
+
yield* control.clear;
|
|
402
|
+
return failed(`submission replay did not recover: ${failureTagOf(secondSubmit.cause)}`, yield* Ref.get(fired));
|
|
403
|
+
}
|
|
404
|
+
receipts = secondSubmit.value;
|
|
405
|
+
}
|
|
406
|
+
const lanes = cell.lanes(receipts);
|
|
407
|
+
const driveLane = (lane) => runtime.processThreadResolved(lane, cell.bindings);
|
|
408
|
+
const allSettled = Effect.gen(function* () {
|
|
409
|
+
for (const receipt of receipts) {
|
|
410
|
+
const snapshot = yield* ledger.lookup(SubmissionLookupById.make({ submissionId: receipt.submissionId }));
|
|
411
|
+
if (Option.isNone(snapshot) || snapshot.value.state !== "settled") return false;
|
|
412
|
+
}
|
|
413
|
+
return true;
|
|
414
|
+
});
|
|
415
|
+
let converged = false;
|
|
416
|
+
for (let round = 0; round < MAX_REDRIVE_ROUNDS && !converged; round++) {
|
|
417
|
+
yield* TestClock.adjust(leaseAdvance);
|
|
418
|
+
yield* Effect.exit(runtime.runRecovery);
|
|
419
|
+
for (const lane of lanes) yield* Effect.exit(driveLane(lane));
|
|
420
|
+
for (const lane of lanes) {
|
|
421
|
+
const explains = yield* Effect.exit(runtime.explainThread(lane));
|
|
422
|
+
if (Exit.isFailure(explains)) continue;
|
|
423
|
+
for (const explanation of explains.value) {
|
|
424
|
+
for (const unknown of explanation.evidence.unknownCalls) {
|
|
425
|
+
if (unknown.resolved) continue;
|
|
426
|
+
yield* Effect.exit(runtime.resolveUnknown(UnknownResolutionCommand.make({
|
|
427
|
+
submissionId: explanation.submission.submissionId,
|
|
428
|
+
toolCallId: unknown.toolCallId,
|
|
429
|
+
author: "certification-runner",
|
|
430
|
+
reason: `re-drive after injected fault at ${location}`,
|
|
431
|
+
resolution: ResolutionSafeToRetry.make()
|
|
432
|
+
})));
|
|
433
|
+
}
|
|
434
|
+
for (const pending of explanation.evidence.approvalsPending) {
|
|
435
|
+
if (explanation.evidence.approvalDecisions.some((decision) => decision.toolCallId === pending.toolCallId)) continue;
|
|
436
|
+
yield* Effect.exit(runtime.resolveApproval(ApprovalDecisionCommand.make({
|
|
437
|
+
submissionId: explanation.submission.submissionId,
|
|
438
|
+
toolCallId: pending.toolCallId,
|
|
439
|
+
decision: "approved",
|
|
440
|
+
resolver: "certification-runner",
|
|
441
|
+
reason: `re-drive after injected fault at ${location}`
|
|
442
|
+
})));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const settled = yield* Effect.exit(allSettled);
|
|
447
|
+
converged = Exit.isSuccess(settled) && settled.value;
|
|
448
|
+
}
|
|
449
|
+
yield* control.clear;
|
|
450
|
+
const wasFired = yield* Ref.get(fired);
|
|
451
|
+
if (!converged) return failed(`did not converge within ${MAX_REDRIVE_ROUNDS} re-drive rounds`, wasFired);
|
|
452
|
+
let digestChainVerified = true;
|
|
453
|
+
const failedChecks = [];
|
|
454
|
+
for (const lane of lanes) {
|
|
455
|
+
const verdict = yield* Effect.exit(verifyLane(lane, batchProducers));
|
|
456
|
+
if (Exit.isFailure(verdict)) return failed(`lane ${lane} could not be verified: ${failureTagOf(verdict.cause)}`, wasFired);
|
|
457
|
+
for (const check of verdict.value.checks) {
|
|
458
|
+
if (check.status === "failed") failedChecks.push(`${lane}:${check.name}${check.detail === void 0 ? "" : ` (${check.detail})`}`);
|
|
459
|
+
if (check.name === "digest-chain" && check.status !== "passed") digestChainVerified = false;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (failedChecks.length > 0 || !digestChainVerified) return failed(failedChecks.length > 0 ? `invariant checks failed: ${failedChecks.join("; ")}` : "the digest chain was not fully recomputed", wasFired);
|
|
463
|
+
return CertificationSweepResult.make({
|
|
464
|
+
scenario,
|
|
465
|
+
location,
|
|
466
|
+
failpointFired: wasFired,
|
|
467
|
+
status: wasFired ? "converged" : "not-triggered",
|
|
468
|
+
digestChainVerified
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
/**
|
|
472
|
+
* Resolve the Tier-3 record honestly (plan §1): a non-durable reference adapter has no real
|
|
473
|
+
* loss to exercise (`not-applicable`); a supplied lever runs NOW (`exercised`); committed
|
|
474
|
+
* real-loss citations are recorded (`recorded-evidence`); otherwise the certificate says
|
|
475
|
+
* `not-exercised` — a scoped statement, never a silent claim.
|
|
476
|
+
*/
|
|
477
|
+
const resolveTierThree = Effect.fn("Certification.resolveTierThree")(function* (durability, options) {
|
|
478
|
+
if (durability === "non-durable") return CertificationTierThreeReport.make({
|
|
479
|
+
status: "not-applicable",
|
|
480
|
+
evidence: [],
|
|
481
|
+
cases: [],
|
|
482
|
+
detail: "the adapter declares non-durable state (reference/conformance adapter); there is no real loss to exercise"
|
|
483
|
+
});
|
|
484
|
+
if (options.crashLever !== void 0) {
|
|
485
|
+
const cases = yield* options.crashLever;
|
|
486
|
+
return CertificationTierThreeReport.make({
|
|
487
|
+
status: cases.length === 0 ? "not-exercised" : "exercised",
|
|
488
|
+
evidence: options.tierThreeEvidence ?? [],
|
|
489
|
+
cases,
|
|
490
|
+
...cases.length === 0 ? { detail: "the supplied crash lever executed no real-loss cases" } : {}
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
if (options.tierThreeEvidence !== void 0 && options.tierThreeEvidence.length > 0) return CertificationTierThreeReport.make({
|
|
494
|
+
status: "recorded-evidence",
|
|
495
|
+
evidence: options.tierThreeEvidence,
|
|
496
|
+
cases: []
|
|
497
|
+
});
|
|
498
|
+
return CertificationTierThreeReport.make({
|
|
499
|
+
status: "not-exercised",
|
|
500
|
+
evidence: [],
|
|
501
|
+
cases: [],
|
|
502
|
+
detail: "no crash lever was supplied and no committed real-loss evidence was cited; Tier 3 is NOT discharged for this adapter"
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
const nowUtc = Effect.map(Clock.currentTimeMillis, (millis) => DateTime.toUtc(DateTime.makeUnsafe(millis)));
|
|
506
|
+
/**
|
|
507
|
+
* Certify one durable adapter pair (plan §1, §8 WP2). Runs Tier 2 FIRST over pristine
|
|
508
|
+
* storage (each cell converges to all-settled before the next starts, so the recovery scan
|
|
509
|
+
* never sees foreign leftovers), then Tier 1's port contract cases (whose lanes deliberately
|
|
510
|
+
* end in every nonterminal shape), then records Tier 3. Requires `Crypto.Crypto` and a
|
|
511
|
+
* TestClock-backed environment; the candidate Layers are built exactly once.
|
|
512
|
+
*/
|
|
513
|
+
const certifyDurableAdapters = (options) => {
|
|
514
|
+
const batchProducers = /* @__PURE__ */ new Map();
|
|
515
|
+
const capturingStore = Layer.effect(ThreadStore)(Effect.gen(function* () {
|
|
516
|
+
const inner = yield* ThreadStore;
|
|
517
|
+
return ThreadStore.of({
|
|
518
|
+
...inner,
|
|
519
|
+
append: (request) => Effect.sync(() => {
|
|
520
|
+
batchProducers.set(request.batch.batchId, request.batch.producerId);
|
|
521
|
+
}).pipe(Effect.andThen(inner.append(request)))
|
|
522
|
+
});
|
|
523
|
+
})).pipe(Layer.provide(options.threadStore));
|
|
524
|
+
const support = Layer.mergeAll(options.submissionLedger, capturingStore, options.wakeScheduler ?? WakeScheduler.layerNoop, DurableRuntimeFailpointTestControl.layer, ToolReconciler.uncertain, DurableRuntimeConfig.layer({
|
|
525
|
+
deploymentId: Schema.decodeSync(DeploymentId)("deployment-certification"),
|
|
526
|
+
producerId: Schema.decodeSync(ProducerId)("producer-certification"),
|
|
527
|
+
settlementPollInterval: Duration.millis(50),
|
|
528
|
+
leaseRenewalInterval: Duration.seconds(5),
|
|
529
|
+
abortPollInterval: Duration.millis(50)
|
|
530
|
+
}));
|
|
531
|
+
const environment = DurableAgentRuntime.layer.pipe(Layer.provideMerge(support));
|
|
532
|
+
const leaseAdvance = Duration.millis(Duration.toMillis(options.ownershipLeaseDuration ?? DEFAULT_OWNERSHIP_LEASE_DURATION) + 1e3);
|
|
533
|
+
return Effect.gen(function* () {
|
|
534
|
+
const ledger = yield* SubmissionLedger;
|
|
535
|
+
const tier2 = [];
|
|
536
|
+
for (const scenario of CERTIFICATION_SCENARIOS) for (const location of DurableRuntimeFailpointLocation.literals) tier2.push(yield* runSweepCell(scenario, location, batchProducers, leaseAdvance));
|
|
537
|
+
const tier1 = yield* certifyPorts();
|
|
538
|
+
const capabilities = yield* ledger.capabilities;
|
|
539
|
+
const tier3 = yield* resolveTierThree(capabilities.durability, options);
|
|
540
|
+
const generatedAt = yield* nowUtc;
|
|
541
|
+
const ok = tier1.every((result) => result.status === "passed") && tier2.every((result) => result.status !== "failed") && tier3.cases.every((result) => result.status === "passed");
|
|
542
|
+
return CertificationReport.make({
|
|
543
|
+
format: "effect-agent/certification@2",
|
|
544
|
+
adapter: CertifiedAdapterIdentity.make({
|
|
545
|
+
name: options.adapter.name,
|
|
546
|
+
...options.adapter.version === void 0 ? {} : { version: options.adapter.version },
|
|
547
|
+
durability: capabilities.durability
|
|
548
|
+
}),
|
|
549
|
+
generatedAt,
|
|
550
|
+
tier1,
|
|
551
|
+
tier2,
|
|
552
|
+
tier3,
|
|
553
|
+
ok,
|
|
554
|
+
fullyCertified: ok && capabilities.durability !== "non-durable" && tier3.status === "exercised" && tier3.cases.length > 0 && tier3.cases.every((result) => result.suite === "real-loss")
|
|
555
|
+
});
|
|
556
|
+
}).pipe(Effect.provide(environment));
|
|
557
|
+
};
|
|
558
|
+
//#endregion
|
|
559
|
+
export { CERTIFICATION_SCENARIOS, TIER2_UNREACHED_LOCATIONS, certifyDurableAdapters, resolveTierThree, tier2NeverFiredLocations };
|
|
560
|
+
|
|
561
|
+
//# sourceMappingURL=certification.mjs.map
|