@powerhousedao/switchboard 6.2.3-dev.83 → 6.2.3-dev.85
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/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +24 -0
- package/dist/index.mjs +11 -8
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/workflows.mjs +3 -3
- package/dist/{server-ChIFIbah.mjs → server-YNY3Qw9a.mjs} +39 -22
- package/dist/server-YNY3Qw9a.mjs.map +1 -0
- package/dist/server.d.mts +9 -1
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -1
- package/dist/{workflows-COM3MKfD.mjs → workflows-DkIrfmdn.mjs} +475 -9
- package/dist/workflows-DkIrfmdn.mjs.map +1 -0
- package/package.json +16 -16
- package/test/goldens/packages.graphql +1 -1
- package/test/goldens/privacy.graphql +1 -1
- package/test/goldens/reactor-drive-nodes.graphql +1 -1
- package/test/goldens/resolvers.json +5 -0
- package/test/goldens/supergraph.graphql +116 -1
- package/test/goldens/workflow-runtime.graphql +116 -1
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +81 -0
- package/test/workflow/resolvers.test.ts +106 -0
- package/test/workflow/waitpoint-routes.test.ts +284 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/dist/server-ChIFIbah.mjs.map +0 -1
- package/dist/workflows-COM3MKfD.mjs.map +0 -1
|
@@ -28,6 +28,27 @@ scalar Amount_Percentage
|
|
|
28
28
|
|
|
29
29
|
scalar Amount_Tokens
|
|
30
30
|
|
|
31
|
+
"""
|
|
32
|
+
Who may decide an approval, and how the editor renders it.
|
|
33
|
+
"""
|
|
34
|
+
type ApprovalRequest {
|
|
35
|
+
title: String!
|
|
36
|
+
"""
|
|
37
|
+
Markdown.
|
|
38
|
+
"""
|
|
39
|
+
body: String
|
|
40
|
+
approveLabel: String!
|
|
41
|
+
rejectLabel: String!
|
|
42
|
+
"""
|
|
43
|
+
none | reject | both
|
|
44
|
+
"""
|
|
45
|
+
reasonRequiredOn: String!
|
|
46
|
+
"""
|
|
47
|
+
DIDs allowed to decide; empty means anyone with write access.
|
|
48
|
+
"""
|
|
49
|
+
approvers: [String!]!
|
|
50
|
+
}
|
|
51
|
+
|
|
31
52
|
scalar AttachmentRef
|
|
32
53
|
|
|
33
54
|
"""
|
|
@@ -451,6 +472,20 @@ type OAuthAttempt {
|
|
|
451
472
|
error: String
|
|
452
473
|
}
|
|
453
474
|
|
|
475
|
+
"""
|
|
476
|
+
How a host signs in with a publisher's OAuth2 app: DESKTOP, the app's
|
|
477
|
+
desktop client for a callback to this machine; WEB, its web client, whose
|
|
478
|
+
file this host has; RELAY, through the app's relay, which forwards the
|
|
479
|
+
provider's answer here and exchanges codes without this host holding the
|
|
480
|
+
secret; NONE, not at all.
|
|
481
|
+
"""
|
|
482
|
+
enum OAuthSignInMode {
|
|
483
|
+
DESKTOP
|
|
484
|
+
WEB
|
|
485
|
+
RELAY
|
|
486
|
+
NONE
|
|
487
|
+
}
|
|
488
|
+
|
|
454
489
|
type OAuthStart {
|
|
455
490
|
state: String!
|
|
456
491
|
"""
|
|
@@ -673,6 +708,47 @@ scalar Unknown
|
|
|
673
708
|
|
|
674
709
|
scalar Upload
|
|
675
710
|
|
|
711
|
+
"""
|
|
712
|
+
A point where a run paused, and how it resumes.
|
|
713
|
+
"""
|
|
714
|
+
type WaitpointRecord {
|
|
715
|
+
id: String!
|
|
716
|
+
runId: String!
|
|
717
|
+
workflowId: String!
|
|
718
|
+
stepId: String!
|
|
719
|
+
stepKey: String!
|
|
720
|
+
stepPath: String!
|
|
721
|
+
pieceName: String!
|
|
722
|
+
blockName: String!
|
|
723
|
+
"""
|
|
724
|
+
DELAY | WEBHOOK
|
|
725
|
+
"""
|
|
726
|
+
type: String!
|
|
727
|
+
"""
|
|
728
|
+
approval | webhook | delay
|
|
729
|
+
"""
|
|
730
|
+
kind: String!
|
|
731
|
+
"""
|
|
732
|
+
PENDING | COMPLETED | CONSUMED | EXPIRED | CANCELLED
|
|
733
|
+
"""
|
|
734
|
+
status: String!
|
|
735
|
+
createdAt: String!
|
|
736
|
+
"""
|
|
737
|
+
DELAY only: when the run resumes.
|
|
738
|
+
"""
|
|
739
|
+
resumeAt: String
|
|
740
|
+
expiresAt: String
|
|
741
|
+
resolvedAt: String
|
|
742
|
+
"""
|
|
743
|
+
The DID that resolved it from the editor.
|
|
744
|
+
"""
|
|
745
|
+
decidedBy: String
|
|
746
|
+
"""
|
|
747
|
+
Set by the Request approval block; null otherwise.
|
|
748
|
+
"""
|
|
749
|
+
approval: ApprovalRequest
|
|
750
|
+
}
|
|
751
|
+
|
|
676
752
|
type WebhookEndpointRecord {
|
|
677
753
|
workflowId: String!
|
|
678
754
|
url: String!
|
|
@@ -717,6 +793,10 @@ type WorkflowRunRecord {
|
|
|
717
793
|
workflowVersion: Int!
|
|
718
794
|
triggerKind: String!
|
|
719
795
|
triggerPayload: Unknown
|
|
796
|
+
"""
|
|
797
|
+
PENDING | RUNNING | WAITING | SUCCEEDED | FAILED | CANCELLED. WAITING: paused
|
|
798
|
+
at a waitpoint (approval, webhook or delay); the run holds no worker.
|
|
799
|
+
"""
|
|
720
800
|
status: String!
|
|
721
801
|
error: String
|
|
722
802
|
errorName: String
|
|
@@ -735,6 +815,10 @@ type WorkflowRunRecord {
|
|
|
735
815
|
"""
|
|
736
816
|
warningNotes: [String!]!
|
|
737
817
|
steps: [WorkflowStepRunRecord!]!
|
|
818
|
+
"""
|
|
819
|
+
Where the run paused, resolved ones included.
|
|
820
|
+
"""
|
|
821
|
+
waitpoints: [WaitpointRecord!]!
|
|
738
822
|
}
|
|
739
823
|
|
|
740
824
|
type WorkflowRunResultPage {
|
|
@@ -808,6 +892,21 @@ type WorkflowRuntimeMutations {
|
|
|
808
892
|
"""
|
|
809
893
|
rerun(runId: String!): WorkflowRunPayload!
|
|
810
894
|
"""
|
|
895
|
+
Approves or rejects a PENDING WEBHOOK waitpoint, resuming its run. Needs
|
|
896
|
+
write access to the workflow; with approvers listed, the caller's DID must
|
|
897
|
+
be one. reason may be required, per approval.reasonRequiredOn.
|
|
898
|
+
"""
|
|
899
|
+
resolveWaitpoint(
|
|
900
|
+
waitpointId: String!
|
|
901
|
+
approved: Boolean!
|
|
902
|
+
reason: String
|
|
903
|
+
): WaitpointRecord!
|
|
904
|
+
"""
|
|
905
|
+
Cancels a WAITING or PENDING run and its open waitpoints. A RUNNING run
|
|
906
|
+
cannot be cancelled yet.
|
|
907
|
+
"""
|
|
908
|
+
cancelRun(runId: String!): WorkflowRunPayload
|
|
909
|
+
"""
|
|
811
910
|
Mints a managed secret for a connection or workflow document and returns
|
|
812
911
|
its ref; only that document resolves it. The value is stored encrypted
|
|
813
912
|
and is never readable back over any API.
|
|
@@ -901,6 +1000,15 @@ type WorkflowRuntimeQueries {
|
|
|
901
1000
|
): WorkflowRunResultPage!
|
|
902
1001
|
run(id: String!): WorkflowRunRecord
|
|
903
1002
|
"""
|
|
1003
|
+
WAITING runs, each with its waitpoints. Scope them to one
|
|
1004
|
+
workflow, or to every workflow a drive holds; workflowId wins.
|
|
1005
|
+
"""
|
|
1006
|
+
waitingRuns(
|
|
1007
|
+
driveId: String
|
|
1008
|
+
workflowId: String
|
|
1009
|
+
first: Int
|
|
1010
|
+
): [WorkflowRunRecord!]!
|
|
1011
|
+
"""
|
|
904
1012
|
The descriptor (props, auth, ports) of one action or trigger, as the
|
|
905
1013
|
version that runs it describes it; triggers come back under "trigger".
|
|
906
1014
|
"""
|
|
@@ -1025,6 +1133,13 @@ type WorkflowRuntimeQueries {
|
|
|
1025
1133
|
"""
|
|
1026
1134
|
oauthRedirectUri: String
|
|
1027
1135
|
"""
|
|
1136
|
+
How startOAuth would sign in with the publisher's OAuth2 app appId (a
|
|
1137
|
+
connection's oauth_app) on this host, so an editor can tell before it
|
|
1138
|
+
opens one. redirectUri as for startOAuth. NONE for an app this host does
|
|
1139
|
+
not know, or when it cannot name its callback.
|
|
1140
|
+
"""
|
|
1141
|
+
oauthSignIn(appId: String!, redirectUri: String): OAuthSignInMode!
|
|
1142
|
+
"""
|
|
1028
1143
|
The switchboard this runtime lives in: what an app records as the runner
|
|
1029
1144
|
of the workflows and connections it sets up here.
|
|
1030
1145
|
"""
|
|
@@ -1286,7 +1401,7 @@ type Workflow_WorkflowPolicy {
|
|
|
1286
1401
|
"""
|
|
1287
1402
|
runTimeoutSeconds: Int!
|
|
1288
1403
|
"""
|
|
1289
|
-
|
|
1404
|
+
Bounds how long a run may stay suspended on a waitpoint: a waitpoint expires this long after it is created, ending the run CANCELLED with WaitpointExpired. A Delay longer than this is refused.
|
|
1290
1405
|
"""
|
|
1291
1406
|
maxSuspensionDays: Int!
|
|
1292
1407
|
"""
|
|
@@ -24,11 +24,20 @@ describe("redactWebhookPath", () => {
|
|
|
24
24
|
);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
it("redacts a waitpoint's resume token and its sub-path", () => {
|
|
28
|
+
expect(
|
|
29
|
+
redactWebhookPath(
|
|
30
|
+
`/api/@powerhousedao/workflow/waitpoints/${TOKEN}/confirm?action=approve`,
|
|
31
|
+
),
|
|
32
|
+
).toBe("/api/@powerhousedao/workflow/waitpoints/[redacted]");
|
|
33
|
+
});
|
|
34
|
+
|
|
27
35
|
it("never returns anything containing the token", () => {
|
|
28
36
|
for (const url of [
|
|
29
37
|
`/webhooks/${TOKEN}`,
|
|
30
38
|
`/reactor/webhooks/${TOKEN}`,
|
|
31
39
|
`/a/b/c/webhooks/${TOKEN}?x=1`,
|
|
40
|
+
`/a/waitpoints/${TOKEN}/sync`,
|
|
32
41
|
]) {
|
|
33
42
|
expect(redactWebhookPath(url)).not.toContain(TOKEN);
|
|
34
43
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { parseOAuthApps } from "../../src/workflow/oauth-apps-config.js";
|
|
4
|
+
|
|
5
|
+
const DIR = path.resolve("/project");
|
|
6
|
+
const RELAY = {
|
|
7
|
+
clientId: "relay-cid",
|
|
8
|
+
redirectUri: "https://sektar.io/api/oauth/callback",
|
|
9
|
+
tokenUrl: "https://sektar.io/api/oauth/token",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe("workflows.oauthApps", () => {
|
|
13
|
+
it("resolves client files from the config file's folder and keeps a relay", () => {
|
|
14
|
+
expect(
|
|
15
|
+
parseOAuthApps(
|
|
16
|
+
[
|
|
17
|
+
{
|
|
18
|
+
id: "sektar-google",
|
|
19
|
+
clients: { desktop: "secrets/desktop.json" },
|
|
20
|
+
relay: RELAY,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
DIR,
|
|
24
|
+
),
|
|
25
|
+
).toEqual([
|
|
26
|
+
{
|
|
27
|
+
id: "sektar-google",
|
|
28
|
+
clients: { desktop: path.join(DIR, "secrets/desktop.json") },
|
|
29
|
+
relay: RELAY,
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("drops a relay that is not an object, keeping the app", () => {
|
|
35
|
+
const dropped: [string, unknown][] = [];
|
|
36
|
+
const apps = parseOAuthApps(
|
|
37
|
+
[
|
|
38
|
+
{ id: "string", clients: { web: "w.json" }, relay: RELAY.redirectUri },
|
|
39
|
+
{ id: "list", clients: { web: "w.json" }, relay: [RELAY] },
|
|
40
|
+
{ id: "null", clients: { web: "w.json" }, relay: null },
|
|
41
|
+
{ id: "none", clients: { web: "w.json" } },
|
|
42
|
+
],
|
|
43
|
+
DIR,
|
|
44
|
+
(id, relay) => dropped.push([id, relay]),
|
|
45
|
+
);
|
|
46
|
+
expect(apps.map((app) => app.id)).toEqual([
|
|
47
|
+
"string",
|
|
48
|
+
"list",
|
|
49
|
+
"null",
|
|
50
|
+
"none",
|
|
51
|
+
]);
|
|
52
|
+
for (const app of apps) expect(app).not.toHaveProperty("relay");
|
|
53
|
+
expect(dropped).toEqual([
|
|
54
|
+
["string", RELAY.redirectUri],
|
|
55
|
+
["list", [RELAY]],
|
|
56
|
+
["null", null],
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("leaves out entries without an id and reads a non-list as none", () => {
|
|
61
|
+
expect(parseOAuthApps([{ clients: {} }, null, { id: "" }], DIR)).toEqual(
|
|
62
|
+
[],
|
|
63
|
+
);
|
|
64
|
+
expect(parseOAuthApps({ id: "x" }, DIR)).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -203,3 +203,84 @@ describe("startOAuth", () => {
|
|
|
203
203
|
);
|
|
204
204
|
});
|
|
205
205
|
});
|
|
206
|
+
|
|
207
|
+
describe("oauthSignIn", () => {
|
|
208
|
+
const PATH = "/api/@powerhousedao/workflow/oauth/callback";
|
|
209
|
+
const CTX = { headers: {}, db: {}, user: { address: "0xabc" } } as never;
|
|
210
|
+
|
|
211
|
+
function build(
|
|
212
|
+
callbackUrl: string | undefined,
|
|
213
|
+
mode: "desktop" | "web" | "relay" | "none",
|
|
214
|
+
) {
|
|
215
|
+
const runtime = {
|
|
216
|
+
oauthSignInMode: vi.fn(() => Promise.resolve(mode)),
|
|
217
|
+
};
|
|
218
|
+
const resolvers = getResolvers(
|
|
219
|
+
runtime as unknown as WorkflowRuntimeService,
|
|
220
|
+
callbackUrl ? { callbackUrl } : undefined,
|
|
221
|
+
) as Record<string, Record<string, Resolver>>;
|
|
222
|
+
return { runtime, signIn: resolvers.WorkflowRuntimeQueries.oauthSignIn };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
it.each([
|
|
226
|
+
["desktop", "DESKTOP"],
|
|
227
|
+
["web", "WEB"],
|
|
228
|
+
["relay", "RELAY"],
|
|
229
|
+
["none", "NONE"],
|
|
230
|
+
] as const)(
|
|
231
|
+
"answers the runtime's %s decision for the host's own callback as %s",
|
|
232
|
+
async (mode, answer) => {
|
|
233
|
+
const own = `https://env.vetra.io${PATH}`;
|
|
234
|
+
const { runtime, signIn } = build(own, mode);
|
|
235
|
+
await expect(
|
|
236
|
+
signIn(
|
|
237
|
+
{},
|
|
238
|
+
{
|
|
239
|
+
appId: "sektar-google",
|
|
240
|
+
redirectUri: `https://evil.example${PATH}`,
|
|
241
|
+
},
|
|
242
|
+
CTX,
|
|
243
|
+
),
|
|
244
|
+
).resolves.toBe(answer);
|
|
245
|
+
expect(runtime.oauthSignInMode).toHaveBeenCalledWith(
|
|
246
|
+
"sektar-google",
|
|
247
|
+
own,
|
|
248
|
+
);
|
|
249
|
+
},
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
it("takes the caller's redirect when the host knows only its path", async () => {
|
|
253
|
+
const { runtime, signIn } = build(PATH, "desktop");
|
|
254
|
+
await expect(
|
|
255
|
+
signIn(
|
|
256
|
+
{},
|
|
257
|
+
{ appId: "sektar-google", redirectUri: `http://localhost:4001${PATH}` },
|
|
258
|
+
CTX,
|
|
259
|
+
),
|
|
260
|
+
).resolves.toBe("DESKTOP");
|
|
261
|
+
expect(runtime.oauthSignInMode).toHaveBeenCalledWith(
|
|
262
|
+
"sektar-google",
|
|
263
|
+
`http://localhost:4001${PATH}`,
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("answers NONE when the host cannot name the callback a sign-in would use", async () => {
|
|
268
|
+
const noRoutes = build(undefined, "web");
|
|
269
|
+
await expect(
|
|
270
|
+
noRoutes.signIn({}, { appId: "sektar-google" }, CTX),
|
|
271
|
+
).resolves.toBe("NONE");
|
|
272
|
+
const pathOnly = build(PATH, "web");
|
|
273
|
+
await expect(
|
|
274
|
+
pathOnly.signIn({}, { appId: "sektar-google" }, CTX),
|
|
275
|
+
).resolves.toBe("NONE");
|
|
276
|
+
await expect(
|
|
277
|
+
pathOnly.signIn(
|
|
278
|
+
{},
|
|
279
|
+
{ appId: "sektar-google", redirectUri: "https://x.example/elsewhere" },
|
|
280
|
+
CTX,
|
|
281
|
+
),
|
|
282
|
+
).resolves.toBe("NONE");
|
|
283
|
+
expect(noRoutes.runtime.oauthSignInMode).not.toHaveBeenCalled();
|
|
284
|
+
expect(pathOnly.runtime.oauthSignInMode).not.toHaveBeenCalled();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -34,6 +34,41 @@ function runsInfo(query: string) {
|
|
|
34
34
|
const emptyPage = (): Promise<unknown> =>
|
|
35
35
|
Promise.resolve({ records: [], hasNextPage: false, cursor: null });
|
|
36
36
|
|
|
37
|
+
function waitpointRow(id: string, runId: string) {
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
run_id: runId,
|
|
41
|
+
workflow_id: "wf-1",
|
|
42
|
+
step_id: "step-1",
|
|
43
|
+
step_key: "step_1",
|
|
44
|
+
step_path: "step-1",
|
|
45
|
+
piece_name: "@powerhousedao/piece-approval",
|
|
46
|
+
block_name: "approval",
|
|
47
|
+
type: "WEBHOOK",
|
|
48
|
+
kind: "approval",
|
|
49
|
+
status: "PENDING",
|
|
50
|
+
created_at: "2026-10-28T00:00:00.000Z",
|
|
51
|
+
resume_at: null,
|
|
52
|
+
expires_at: null,
|
|
53
|
+
resolved_at: null,
|
|
54
|
+
decided_by: null,
|
|
55
|
+
approval: '{"title":"Pay?"}',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The run journal's waitpoint read: one pending approval per run.
|
|
60
|
+
function waitpointStore() {
|
|
61
|
+
return {
|
|
62
|
+
listWaitpointsForRuns: vi.fn((runIds: string[]) =>
|
|
63
|
+
Promise.resolve(
|
|
64
|
+
new Map(
|
|
65
|
+
runIds.map((runId) => [runId, [waitpointRow(`wp-${runId}`, runId)]]),
|
|
66
|
+
),
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
37
72
|
function fakeRuntime() {
|
|
38
73
|
return {
|
|
39
74
|
webhookEndpoint: vi.fn(() => Promise.resolve(null)),
|
|
@@ -43,6 +78,9 @@ function fakeRuntime() {
|
|
|
43
78
|
run: vi.fn(() => Promise.resolve(null)),
|
|
44
79
|
fire: vi.fn(() => Promise.resolve({})),
|
|
45
80
|
rerun: vi.fn(() => Promise.resolve({})),
|
|
81
|
+
waitingRuns: vi.fn((): Promise<unknown[]> => Promise.resolve([])),
|
|
82
|
+
waitpointsForRun: vi.fn(() => Promise.resolve([{ id: "wp-2" }])),
|
|
83
|
+
store: vi.fn(() => Promise.resolve(waitpointStore())),
|
|
46
84
|
testStep: vi.fn(() => Promise.resolve({})),
|
|
47
85
|
stepOutputTree: vi.fn(() => Promise.resolve({})),
|
|
48
86
|
blockResolutions: vi.fn(() => Promise.resolve([])),
|
|
@@ -78,6 +116,7 @@ function build() {
|
|
|
78
116
|
queries: resolvers.WorkflowRuntimeQueries,
|
|
79
117
|
mutations: resolvers.WorkflowRuntimeMutations,
|
|
80
118
|
secretRecord: resolvers.SecretRecord,
|
|
119
|
+
runRecord: resolvers.WorkflowRunRecord,
|
|
81
120
|
};
|
|
82
121
|
}
|
|
83
122
|
|
|
@@ -367,3 +406,70 @@ describe("piece search", () => {
|
|
|
367
406
|
expect(runtime.searchPieces).not.toHaveBeenCalled();
|
|
368
407
|
});
|
|
369
408
|
});
|
|
409
|
+
|
|
410
|
+
describe("waitpoints", () => {
|
|
411
|
+
it("serves waiting runs with the waitpoints the runtime listed", async () => {
|
|
412
|
+
const { runtime, queries, runRecord } = build();
|
|
413
|
+
runtime.waitingRuns.mockResolvedValueOnce([
|
|
414
|
+
{
|
|
415
|
+
run: {
|
|
416
|
+
row: { id: "run-1", status: "WAITING", trigger_payload: null },
|
|
417
|
+
steps: [],
|
|
418
|
+
},
|
|
419
|
+
waitpoints: [{ id: "wp-1" }],
|
|
420
|
+
},
|
|
421
|
+
]);
|
|
422
|
+
|
|
423
|
+
const runs = (await queries.waitingRuns(
|
|
424
|
+
{},
|
|
425
|
+
{ driveId: "drive-1", first: 10 },
|
|
426
|
+
CTX,
|
|
427
|
+
)) as { id: string }[];
|
|
428
|
+
|
|
429
|
+
expect(runtime.waitingRuns).toHaveBeenCalledWith(
|
|
430
|
+
{ driveId: "drive-1", workflowId: undefined, first: 10 },
|
|
431
|
+
CTX,
|
|
432
|
+
);
|
|
433
|
+
expect(await runRecord.waitpoints(runs[0], {}, CTX)).toEqual([
|
|
434
|
+
{ id: "wp-1" },
|
|
435
|
+
]);
|
|
436
|
+
expect(runtime.waitpointsForRun).not.toHaveBeenCalled();
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("reads the waitpoints of every run in a request with one store call", async () => {
|
|
440
|
+
const { runtime, runRecord } = build();
|
|
441
|
+
const store = waitpointStore();
|
|
442
|
+
runtime.store.mockResolvedValueOnce(store);
|
|
443
|
+
const ctx = { ...CTX } as Context;
|
|
444
|
+
const [first, second, again] = (await Promise.all([
|
|
445
|
+
runRecord.waitpoints({ id: "run-1" }, {}, ctx),
|
|
446
|
+
runRecord.waitpoints({ id: "run-2" }, {}, ctx),
|
|
447
|
+
runRecord.waitpoints({ id: "run-1" }, {}, ctx),
|
|
448
|
+
])) as Array<Array<{ id: string }>>;
|
|
449
|
+
|
|
450
|
+
expect(first).toEqual([
|
|
451
|
+
expect.objectContaining({
|
|
452
|
+
id: "wp-run-1",
|
|
453
|
+
runId: "run-1",
|
|
454
|
+
kind: "approval",
|
|
455
|
+
approval: { title: "Pay?" },
|
|
456
|
+
}),
|
|
457
|
+
]);
|
|
458
|
+
expect(second!.map((waitpoint) => waitpoint.id)).toEqual(["wp-run-2"]);
|
|
459
|
+
expect(again).toBe(first);
|
|
460
|
+
expect(runtime.store).toHaveBeenCalledTimes(1);
|
|
461
|
+
expect(store.listWaitpointsForRuns).toHaveBeenCalledWith([
|
|
462
|
+
"run-1",
|
|
463
|
+
"run-2",
|
|
464
|
+
]);
|
|
465
|
+
// The parent resolver served the run; no second run read.
|
|
466
|
+
expect(runtime.waitpointsForRun).not.toHaveBeenCalled();
|
|
467
|
+
expect(runtime.run).not.toHaveBeenCalled();
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it("serves no waitpoints when the run journal is unavailable", async () => {
|
|
471
|
+
const { runtime, runRecord } = build();
|
|
472
|
+
runtime.store.mockResolvedValueOnce(undefined as never);
|
|
473
|
+
expect(await runRecord.waitpoints({ id: "run-9" }, {}, CTX)).toEqual([]);
|
|
474
|
+
});
|
|
475
|
+
});
|