@open-conduit/sdk 0.0.0-stage → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/actions.d.ts +145 -0
  4. package/dist/actions.js +281 -0
  5. package/dist/actiontest.d.ts +80 -0
  6. package/dist/actiontest.js +190 -0
  7. package/dist/artifactstore.d.ts +133 -0
  8. package/dist/artifactstore.js +364 -0
  9. package/dist/backup.d.ts +99 -0
  10. package/dist/backup.js +178 -0
  11. package/dist/containertest.d.ts +71 -0
  12. package/dist/containertest.js +294 -0
  13. package/dist/errors.d.ts +127 -0
  14. package/dist/errors.js +180 -0
  15. package/dist/executor.d.ts +374 -0
  16. package/dist/executor.js +556 -0
  17. package/dist/executortest.d.ts +183 -0
  18. package/dist/executortest.js +534 -0
  19. package/dist/extension.d.ts +855 -0
  20. package/dist/extension.js +1822 -0
  21. package/dist/feed.d.ts +20 -0
  22. package/dist/feed.js +88 -0
  23. package/dist/forward.d.ts +38 -0
  24. package/dist/forward.js +163 -0
  25. package/dist/forwardca.d.ts +21 -0
  26. package/dist/forwardca.js +144 -0
  27. package/dist/hooks.d.ts +108 -0
  28. package/dist/hooks.js +13 -0
  29. package/dist/host.d.ts +295 -0
  30. package/dist/host.js +486 -0
  31. package/dist/index.d.ts +34 -0
  32. package/dist/index.js +31 -0
  33. package/dist/jsonrpc.d.ts +39 -0
  34. package/dist/jsonrpc.js +350 -0
  35. package/dist/probe.d.ts +61 -0
  36. package/dist/probe.js +92 -0
  37. package/dist/providertest.d.ts +59 -0
  38. package/dist/providertest.js +168 -0
  39. package/dist/resources.d.ts +208 -0
  40. package/dist/resources.js +303 -0
  41. package/dist/sandbox.d.ts +84 -0
  42. package/dist/sandbox.js +85 -0
  43. package/dist/schema.d.ts +71 -0
  44. package/dist/schema.js +252 -0
  45. package/dist/setup.d.ts +145 -0
  46. package/dist/setup.js +179 -0
  47. package/dist/setuptest.d.ts +90 -0
  48. package/dist/setuptest.js +319 -0
  49. package/dist/storetest.d.ts +64 -0
  50. package/dist/storetest.js +740 -0
  51. package/dist/telemetry.d.ts +86 -0
  52. package/dist/telemetry.js +46 -0
  53. package/dist/testing.d.ts +756 -0
  54. package/dist/testing.js +2165 -0
  55. package/dist/toolbelt.d.ts +91 -0
  56. package/dist/toolbelt.js +216 -0
  57. package/dist/tunnel.d.ts +62 -0
  58. package/dist/tunnel.js +93 -0
  59. package/dist/wire.d.ts +5359 -0
  60. package/dist/wire.js +2211 -0
  61. package/package.json +29 -4
@@ -0,0 +1,534 @@
1
+ // An executor as the host reaches it over the wire (extproc's
2
+ // remoteExecutor), and the conformance checks the Go suite holds an
3
+ // executor to: conformance.CheckExecutor, CheckInjectExecutor and
4
+ // CheckStateSweeper, for a TypeScript executor reached through the test
5
+ // host (TestHost.executor). Each check resolves when the executor keeps the
6
+ // contract and rejects with what it broke. checkTurnEnds holds an
7
+ // executor that calls the toolbelt to the rule the chat-completions
8
+ // executor keeps: a call whose result parks the run ends the turn. The Go
9
+ // suites, run against the packaged executor under a real host, are the
10
+ // contract; these let a package's own tests hold it there first.
11
+ import { mkdtemp, rm } from "node:fs/promises";
12
+ import { createServer } from "node:http";
13
+ import { tmpdir } from "node:os";
14
+ import { join } from "node:path";
15
+ import { Code, ProtocolError } from "./errors.js";
16
+ import { fromWireResult, invalidResult, } from "./executor.js";
17
+ import { matches } from "./schema.js";
18
+ import { ExecutorRunResult, Result, LiveResult, AttachSpec, ContainerAttachSpec, InteractiveLaunchSpec, StateSweepReport, ValidateResult, } from "./wire.js";
19
+ /** A RunRequest as the host sends it, with every required field filled in. */
20
+ export function testRunRequest(o = {}) {
21
+ const at = "2026-10-24T12:00:00.000Z";
22
+ const work = o.workId ?? "work";
23
+ const execution = o.executionId ?? "execution";
24
+ return {
25
+ work: {
26
+ id: work,
27
+ kind: "task",
28
+ scope_id: o.scopeId ?? "scope",
29
+ state: "running",
30
+ correlation_keys: null,
31
+ context: {},
32
+ revision: 1,
33
+ created_at: at,
34
+ updated_at: at,
35
+ },
36
+ execution: {
37
+ id: execution,
38
+ work_id: work,
39
+ executor_binding: "binding",
40
+ attempt: 1,
41
+ state: "running",
42
+ trigger_id: o.trigger?.id ?? "trigger",
43
+ lease: { owner: "sdktest", epoch: o.epoch ?? 1, expires_at: at },
44
+ revision: 1,
45
+ created_at: at,
46
+ updated_at: at,
47
+ },
48
+ trigger: o.trigger ?? { id: "trigger", type: "fixture.trigger" },
49
+ ...(o.inputs?.length ? { inputs: o.inputs } : {}),
50
+ context: {
51
+ config: {
52
+ ...(o.configSchema ? { schema: o.configSchema } : {}),
53
+ data: o.config ?? {},
54
+ },
55
+ ...(o.context ?? {}),
56
+ },
57
+ };
58
+ }
59
+ function decoded(schema, method, raw) {
60
+ if (!matches(schema, raw))
61
+ throw new ProtocolError(Code.Invalid, `malformed ${method} result: ${JSON.stringify(raw)}`);
62
+ return raw;
63
+ }
64
+ let runs = 0;
65
+ /** @internal */
66
+ export function testExecutor(name, w) {
67
+ if (w.decl === undefined)
68
+ throw new Error(`sdktest: the extension declares no executor ${name}`);
69
+ const decl = w.decl;
70
+ const start = async (method, r, state, persist) => {
71
+ const run = `sdktest-run-${++runs}`;
72
+ const tracked = w.open(run, persist, {
73
+ sandbox: r.context.sandbox === true,
74
+ container: r.context.container === true,
75
+ });
76
+ let handle;
77
+ try {
78
+ const out = decoded(ExecutorRunResult, method, await w.call(method, {
79
+ executor: name,
80
+ run_id: run,
81
+ request: r,
82
+ ...(state === undefined ? {} : { state }),
83
+ }));
84
+ handle = out.handle;
85
+ }
86
+ catch (err) {
87
+ w.close(run);
88
+ // The extension failed because the host refused persistence: the
89
+ // host's own error, not its echo (as extproc reports it).
90
+ const perr = tracked.persistErr();
91
+ if (perr !== undefined)
92
+ throw perr;
93
+ throw err;
94
+ }
95
+ return {
96
+ wait: async (signal) => {
97
+ const out = decoded(Result, "executor.wait", await w.call("executor.wait", { executor: name, handle }, signal));
98
+ w.close(run);
99
+ const res = fromWireResult(out);
100
+ const invalid = invalidResult(res);
101
+ if (invalid !== "")
102
+ throw new ProtocolError(Code.Invalid, `result: ${invalid}`);
103
+ return res;
104
+ },
105
+ };
106
+ };
107
+ const target = async (method, declared, p) => {
108
+ // Undeclared, it is refused without a call, as extproc refuses it.
109
+ if (!declared)
110
+ throw new ProtocolError(Code.Unsupported, method);
111
+ return w.call(method, { executor: name, ...p });
112
+ };
113
+ const c = decl.capabilities;
114
+ const x = decl.controls ?? {};
115
+ const validate = async (kind, p) => decoded(ValidateResult, "validate", await w.call("validate", { kind, type: name, ...p }));
116
+ // As the host reads an answer: a failed call is the default.
117
+ const quietly = async (fn, otherwise) => {
118
+ try {
119
+ return await fn();
120
+ }
121
+ catch {
122
+ return otherwise;
123
+ }
124
+ };
125
+ return {
126
+ name,
127
+ capabilities: c,
128
+ controls: x,
129
+ run: (r, persist) => start("executor.run", r, undefined, persist),
130
+ recover: (r, state, persist) => start("executor.recover", r, state, persist),
131
+ resume: async (r, state, persist) => {
132
+ if (!c.resume)
133
+ throw new ProtocolError(Code.Unsupported, "resume");
134
+ return start("executor.resume", r, state, persist);
135
+ },
136
+ interrupt: async (execution) => {
137
+ await target("executor.interrupt", c.interrupt, {
138
+ execution_id: execution,
139
+ });
140
+ },
141
+ inject: async (execution, event) => {
142
+ await target("executor.inject", c.inject, {
143
+ execution_id: execution,
144
+ event,
145
+ });
146
+ },
147
+ stop: async (execution, epoch) => {
148
+ await target("executor.stop", x.stop, { execution_id: execution, epoch });
149
+ },
150
+ forget: async (execution) => {
151
+ await target("executor.forget", x.forget, { execution_id: execution });
152
+ },
153
+ sweep: async (known) => {
154
+ if (!x.sweep)
155
+ throw new ProtocolError(Code.Unsupported, "executor.sweep");
156
+ const sweep = `sdktest-sweep-${++runs}`;
157
+ w.sweeps.set(sweep, known);
158
+ try {
159
+ return decoded(StateSweepReport, "executor.sweep", await w.call("executor.sweep", { executor: name, sweep }));
160
+ }
161
+ finally {
162
+ w.sweeps.delete(sweep);
163
+ }
164
+ },
165
+ live: async (execution, tail = 0) => decoded(LiveResult, "executor.live", await target("executor.live", x.live, {
166
+ execution_id: execution,
167
+ ...(tail > 0 ? { tail } : {}),
168
+ })),
169
+ attach: async (work) => decoded(AttachSpec, "executor.attach", await target("executor.attach", x.attach, { work_id: work })),
170
+ containerAttach: async (work, config, o = {}) => decoded(ContainerAttachSpec, "executor.container_attach", await target("executor.container_attach", x.container_attach, {
171
+ work,
172
+ config: { data: config ?? {} },
173
+ ...(o.secrets ? { secrets: o.secrets } : {}),
174
+ home: o.home ?? "/sdktest/home",
175
+ })),
176
+ interactiveLaunch: async (r) => decoded(InteractiveLaunchSpec, "executor.interactive_launch", await target("executor.interactive_launch", x.interactive_launch, {
177
+ playbook: r.playbook,
178
+ name: r.name,
179
+ ...(r.summary ? { summary: r.summary } : {}),
180
+ ...(r.allow?.length ? { allow: r.allow } : {}),
181
+ ...(r.dir ? { dir: r.dir } : {}),
182
+ files_dir: r.filesDir ?? "/sdktest/files",
183
+ ...(r.program ? { program: r.program } : {}),
184
+ })),
185
+ resourceMode: async (config) => !decl.resource_mode
186
+ ? ""
187
+ : quietly(async () => (await validate("executor_mode", { config: config ?? {} }))
188
+ .mode ?? "", ""),
189
+ playbook: async (config) => !decl.playbook
190
+ ? ""
191
+ : quietly(async () => ((await validate("executor_playbook", { config: config ?? {} }))
192
+ .playbook ?? "")
193
+ .split(/\s+/)
194
+ .filter(Boolean)
195
+ .join(" "), ""),
196
+ versionProbe: async (config) => {
197
+ if (!decl.version_probe)
198
+ return undefined;
199
+ const probe = await quietly(async () => (await validate("executor_probe", { config: config ?? {} })).probe, undefined);
200
+ if (!probe?.argv?.length)
201
+ return undefined;
202
+ return { argv: probe.argv, env: probe.env ?? [] };
203
+ },
204
+ folderConfig: async (config, folder, resource) => {
205
+ if (!decl.folder_config)
206
+ return config;
207
+ const out = await validate("executor_folder", {
208
+ config: config ?? {},
209
+ folder,
210
+ ...(resource ? { resource } : {}),
211
+ });
212
+ if (out.config === undefined)
213
+ throw new Error("the extension answered no adapted binding config for its folder");
214
+ return out.config;
215
+ },
216
+ };
217
+ }
218
+ const fail = (message) => {
219
+ throw new Error(message);
220
+ };
221
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
222
+ const toolbelts = new Set(["none", "cli", "mcp", "sdk"]);
223
+ function code(err) {
224
+ return err instanceof ProtocolError ? err.code : "";
225
+ }
226
+ /**
227
+ * Checks the attempt lifecycle (conformance.CheckExecutor): run saves its
228
+ * continuity state before it is acknowledged, and its result is valid;
229
+ * recover adopts the attempt from that state without launching a
230
+ * replacement, saving the identical state again under its lease, and
231
+ * keeps the result; recover refuses state it doesn't hold as not
232
+ * adoptable; and a run whose state the host refuses to save fails with
233
+ * that refusal. r must finish on its own.
234
+ */
235
+ export async function checkExecutor(x, r) {
236
+ if (!toolbelts.has(x.capabilities.toolbelt))
237
+ fail(`toolbelt ${x.capabilities.toolbelt} must be none, cli, mcp or sdk`);
238
+ let persisted = false;
239
+ let state = {};
240
+ const h = await x.run(r, (s) => {
241
+ persisted = true;
242
+ state = s;
243
+ });
244
+ if (!persisted)
245
+ fail("run acknowledged before recovery metadata");
246
+ const result = await h.wait();
247
+ let reacknowledged = false;
248
+ const adopted = await x.recover(r, state, (p) => {
249
+ if (!same(p, state))
250
+ throw new Error("recovery launched replacement");
251
+ reacknowledged = true;
252
+ });
253
+ if (!reacknowledged)
254
+ fail("recovery adopted without re-acknowledging its metadata under the new lease");
255
+ const recovered = await adopted.wait();
256
+ if (!same(result, recovered))
257
+ fail(`recovery changed result: ${JSON.stringify(result)} vs ${JSON.stringify(recovered)}`);
258
+ try {
259
+ await x.recover(r, {}, () => { });
260
+ fail("unknown recovery state accepted");
261
+ }
262
+ catch (err) {
263
+ if (code(err) !== Code.NotAdoptable)
264
+ fail(`unknown recovery state accepted: ${String(err)}`);
265
+ }
266
+ const refused = new Error("persistence failed");
267
+ try {
268
+ const h = await x.run(r, () => {
269
+ throw refused;
270
+ });
271
+ await h.wait();
272
+ fail("recovery persistence failure ignored");
273
+ }
274
+ catch (err) {
275
+ if (err !== refused)
276
+ fail(`recovery persistence failure ignored: ${String(err)}`);
277
+ }
278
+ }
279
+ /**
280
+ * Checks the inject acknowledgement (conformance.CheckInjectExecutor):
281
+ * inject to an execution the executor doesn't hold is not accepting; to
282
+ * the running attempt, and again with the same Event, it is accepted; the
283
+ * result proves the attempt took the Event in, exactly once; after the
284
+ * result inject is not accepting; and recover gives the same proof.
285
+ */
286
+ export async function checkInjectExecutor(f) {
287
+ const x = f.executor;
288
+ if (!x.capabilities.inject)
289
+ fail("executor does not advertise inject");
290
+ const r = f.request;
291
+ let state = {};
292
+ const h = await x.run(r, (s) => {
293
+ state = s;
294
+ });
295
+ await f.ready?.();
296
+ const first = {
297
+ id: "inject-conformance-first",
298
+ type: "fixture.message",
299
+ source: "fixture",
300
+ delivery_id: "first",
301
+ data: { schema: "fixture.message.v1", data: { text: "also this" } },
302
+ };
303
+ const notAccepting = async (what, execution, e) => {
304
+ try {
305
+ await x.inject(execution, e);
306
+ }
307
+ catch (err) {
308
+ if (code(err) === Code.NotAccepting)
309
+ return;
310
+ fail(`inject ${what}: ${String(err)}, want not_accepting`);
311
+ }
312
+ fail(`inject ${what}: accepted, want not_accepting`);
313
+ };
314
+ await notAccepting("to an unknown execution", "inject-conformance-unknown", first);
315
+ const id = r.execution.id;
316
+ await x
317
+ .inject(id, first)
318
+ .catch((err) => fail(`inject to the running attempt: ${String(err)}`));
319
+ await x
320
+ .inject(id, first)
321
+ .catch((err) => fail(`retried inject of the same event: ${String(err)}`));
322
+ await f.finish?.();
323
+ const result = await h.wait();
324
+ const consumed = result.consumedInputs ?? [];
325
+ if (consumed.length !== 1 || consumed[0] !== first.id)
326
+ fail(`consumption proof ${JSON.stringify(consumed)}, want exactly [${first.id}]`);
327
+ await notAccepting("after the result", id, {
328
+ id: "inject-conformance-late",
329
+ type: "fixture.message",
330
+ source: "fixture",
331
+ delivery_id: "late",
332
+ });
333
+ const adopted = await x.recover(r, state, (p) => {
334
+ if (!same(p, state))
335
+ throw new Error("recovery launched replacement");
336
+ });
337
+ const recovered = await adopted.wait();
338
+ if (!same(recovered.consumedInputs ?? [], consumed))
339
+ fail(`recovery changed the consumption proof: ${JSON.stringify(recovered.consumedInputs)} vs ${JSON.stringify(consumed)}`);
340
+ }
341
+ /**
342
+ * Checks a state sweep (conformance.CheckStateSweeper): a sweep whose
343
+ * known call fails fails, releasing nothing; a sweep asks about the
344
+ * unknown execution, at most MaxKnownBatch at a time, and reports it
345
+ * removed, never the known one; after it the known attempt still recovers
346
+ * with its result and the unknown one is not adoptable; a second sweep
347
+ * removes nothing more.
348
+ */
349
+ export async function checkStateSweeper(f) {
350
+ const x = f.executor;
351
+ if (!x.controls.sweep)
352
+ fail("executor does not sweep its state");
353
+ const known = f.known.execution.id;
354
+ const unknown = f.unknown.execution.id;
355
+ if (known === "" || unknown === "" || known === unknown)
356
+ fail("fixture needs two different executions");
357
+ const finish = async (r) => {
358
+ let state = {};
359
+ const h = await x.run(r, (s) => {
360
+ state = s;
361
+ });
362
+ return { r, state, result: await h.wait() };
363
+ };
364
+ const k = await finish(f.known);
365
+ const u = await finish(f.unknown);
366
+ const adopt = async (a) => {
367
+ const h = await x.recover(a.r, a.state, () => { });
368
+ if (!same(await h.wait(), a.result))
369
+ fail("recovery changed the result");
370
+ };
371
+ try {
372
+ await x.sweep(() => {
373
+ throw new Error("known failed");
374
+ });
375
+ fail("a sweep whose known call failed did not fail");
376
+ }
377
+ catch (err) {
378
+ if (err instanceof Error && err.message.startsWith("a sweep whose"))
379
+ throw err;
380
+ }
381
+ for (const a of [k, u])
382
+ await adopt(a).catch((err) => fail(`a sweep whose known call failed released ${a.r.execution.id}: ${String(err)}`));
383
+ const asked = [];
384
+ const oracle = (ids) => {
385
+ if (ids.length > 256)
386
+ throw new Error(`asked about ${ids.length} executions at once`);
387
+ asked.push(...ids);
388
+ return ids.filter((id) => id === known);
389
+ };
390
+ const report = await x.sweep(oracle);
391
+ if (!asked.includes(unknown))
392
+ fail(`the sweep never asked about ${unknown}`);
393
+ if (!(report.removed ?? []).includes(unknown))
394
+ fail(`the sweep did not report ${unknown} removed: ${JSON.stringify(report)}`);
395
+ if ((report.removed ?? []).includes(known))
396
+ fail(`the sweep removed ${known}, which the host holds`);
397
+ await adopt(k).catch((err) => fail(`the known attempt no longer recovers after a sweep: ${String(err)}`));
398
+ try {
399
+ await adopt(u);
400
+ fail(`the unknown attempt's state outlived the sweep`);
401
+ }
402
+ catch (err) {
403
+ if (code(err) !== Code.NotAdoptable)
404
+ fail(`the unknown attempt's state outlived the sweep: recover returned ${String(err)}`);
405
+ }
406
+ const again = await x.sweep(oracle);
407
+ if ((again.removed ?? []).length > 0)
408
+ fail(`a second sweep removed ${JSON.stringify(again.removed)}`);
409
+ }
410
+ /**
411
+ * A toolbelt for executor tests, served on a Unix socket in a directory
412
+ * of its own as the host serves an execution's: POST /v1/toolbelt/call
413
+ * and GET /v1/toolbelt/guidance under its one token. A call to an
414
+ * operation in parks (and the builtin wait) answers with a Wait, as the
415
+ * host answers a call that parks the run; answer overrides any call's
416
+ * result. It records every call it takes.
417
+ */
418
+ export class TestToolbelt {
419
+ token = "sdktest-toolbelt-token";
420
+ calls = [];
421
+ parks;
422
+ answer;
423
+ #server;
424
+ #dir;
425
+ #socket;
426
+ constructor(server, dir, parks) {
427
+ this.#server = server;
428
+ this.#dir = dir;
429
+ this.#socket = join(dir, "toolbelt.sock");
430
+ this.parks = new Set(parks);
431
+ }
432
+ /** Starts one, parking the run on calls to parks. Close it when the test ends. */
433
+ static async start(parks = []) {
434
+ const dir = await mkdtemp(join(tmpdir(), "sdktest-toolbelt-"));
435
+ let belt;
436
+ const server = createServer((req, res) => {
437
+ void belt.#serve(req).then(([status, body]) => {
438
+ res.writeHead(status, { "Content-Type": "application/json" });
439
+ res.end(JSON.stringify(body));
440
+ }, () => {
441
+ res.writeHead(500);
442
+ res.end();
443
+ });
444
+ });
445
+ belt = new TestToolbelt(server, dir, parks);
446
+ await new Promise((resolve, reject) => {
447
+ server.once("error", reject);
448
+ server.listen(join(dir, "toolbelt.sock"), resolve);
449
+ });
450
+ return belt;
451
+ }
452
+ /** The endpoint an execution context names it by. */
453
+ get endpoint() {
454
+ return `unix://${this.#socket}`;
455
+ }
456
+ /** The execution context's toolbelt fields. */
457
+ get context() {
458
+ return { toolbelt_endpoint: this.endpoint, toolbelt_token: this.token };
459
+ }
460
+ async close() {
461
+ await new Promise((resolve) => this.#server.close(() => resolve()));
462
+ await rm(this.#dir, { recursive: true, force: true });
463
+ }
464
+ async #serve(req) {
465
+ const chunks = [];
466
+ for await (const c of req)
467
+ chunks.push(c);
468
+ const auth = req.headers.authorization ?? "";
469
+ const token = auth.startsWith("Bearer ") ? auth.slice(7) : "";
470
+ if (token !== this.token)
471
+ return [401, { error: { code: "unauthorized", message: "bad token" } }];
472
+ if (req.method === "GET" && req.url === "/v1/toolbelt/guidance")
473
+ return [200, { data: { guidance: [], operations: [], granted: [] } }];
474
+ if (req.method !== "POST" || req.url !== "/v1/toolbelt/call")
475
+ return [404, { error: { code: "not_found", message: "no such path" } }];
476
+ let body;
477
+ try {
478
+ body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
479
+ }
480
+ catch {
481
+ return [400, { error: { code: "bad_request", message: "not JSON" } }];
482
+ }
483
+ if (typeof body.operation !== "string" || body.operation === "")
484
+ return [400, { error: { code: "bad_request", message: "no operation" } }];
485
+ const c = {
486
+ operation: body.operation,
487
+ input: body.input,
488
+ requestId: typeof body.request_id === "string" ? body.request_id : "",
489
+ token,
490
+ };
491
+ this.calls.push(c);
492
+ const given = this.answer?.(c);
493
+ if (given !== undefined)
494
+ return [200, { data: given }];
495
+ const n = this.calls.length;
496
+ const wait = {
497
+ id: `wait/${n}`,
498
+ work_id: "work",
499
+ state: "active",
500
+ description: `parked by ${c.operation}`,
501
+ };
502
+ if (c.operation === "wait")
503
+ return [200, { data: { wait } }];
504
+ if (c.operation === "declare_outcome")
505
+ return [200, { data: {} }];
506
+ if (c.operation === "read_context")
507
+ return [200, { data: { context: { schema: "", data: {} } } }];
508
+ const output = { schema: `${c.operation}.v1`, data: {} };
509
+ if (this.parks.has(c.operation))
510
+ return [200, { data: { output, wait } }];
511
+ return [200, { data: { output } }];
512
+ }
513
+ }
514
+ /**
515
+ * Checks that a call whose result parks the run ends the turn, whichever
516
+ * operation made it: the attempt makes no toolbelt call after it, and
517
+ * ends with a waiting or handoff outcome rather than going on to complete
518
+ * or fail.
519
+ */
520
+ export async function checkTurnEnds(f) {
521
+ if (!f.belt.parks.has(f.park))
522
+ fail(`the toolbelt doesn't park on ${f.park}`);
523
+ const before = f.belt.calls.length;
524
+ const h = await f.executor.run(f.request, () => { });
525
+ const result = await h.wait();
526
+ const calls = f.belt.calls.slice(before).map((c) => c.operation);
527
+ const at = calls.indexOf(f.park);
528
+ if (at < 0)
529
+ fail(`the attempt never called ${f.park}: ${JSON.stringify(calls)}`);
530
+ if (at !== calls.length - 1)
531
+ fail(`the attempt went on calling after ${f.park} parked the run: ${JSON.stringify(calls.slice(at + 1))}`);
532
+ if (result.outcome.kind !== "waiting" && result.outcome.kind !== "handoff")
533
+ fail(`the parked attempt ended ${result.outcome.kind}, want waiting or handoff`);
534
+ }