@powerhousedao/switchboard 6.2.3-staging.0 → 6.3.0-dev.1
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/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/default-composition.test.d.ts +2 -0
- package/.tsbuild/test/default-composition.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts +13 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts +3 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts +7 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas-mixed-package.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas-mixed-package.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- 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/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.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/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/Auth.md +108 -2
- package/CHANGELOG.md +1065 -1
- package/README.md +69 -24
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-DKK_wPrO.mjs +497 -0
- package/dist/from-env-DKK_wPrO.mjs.map +1 -0
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +40 -219
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-VW52B8KD.mjs +32 -0
- package/dist/mcp-VW52B8KD.mjs.map +1 -0
- package/dist/migrate.mjs +5 -4
- package/dist/migrate.mjs.map +1 -1
- package/dist/observability-CldagyT_.mjs +224 -0
- package/dist/observability-CldagyT_.mjs.map +1 -0
- package/dist/observability.d.mts +30 -0
- package/dist/observability.d.mts.map +1 -0
- package/dist/observability.mjs +4 -0
- package/dist/plugin-host-tTjDTNz0.d.mts +46 -0
- package/dist/plugin-host-tTjDTNz0.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +80 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-HQnhqf2H.mjs +91 -0
- package/dist/privacy-HQnhqf2H.mjs.map +1 -0
- package/dist/privacy-UodgY0i_.mjs +44 -0
- package/dist/privacy-UodgY0i_.mjs.map +1 -0
- package/dist/renown-layers-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-BJ-OFAox.mjs +359 -0
- package/dist/schema-BJ-OFAox.mjs.map +1 -0
- package/dist/schema-w1lShimw.d.mts +258 -0
- package/dist/schema-w1lShimw.d.mts.map +1 -0
- package/dist/server-BS-PFzoK.mjs +2752 -0
- package/dist/server-BS-PFzoK.mjs.map +1 -0
- package/dist/server.d.mts +94 -228
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -4
- package/dist/types-Bk4T4D9F.d.mts +318 -0
- package/dist/types-Bk4T4D9F.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +29 -3
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-mdYUh3Us.mjs +1947 -0
- package/dist/workflows-mdYUh3Us.mjs.map +1 -0
- package/package.json +86 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/byte-grants.test.ts +4 -1
- package/test/attachments/download-target.test.ts +36 -20
- package/test/attachments/index.test.ts +13 -1
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +1 -0
- package/test/attachments/routes.test.ts +132 -12
- package/test/attachments/service-config.test.ts +28 -16
- package/test/boot-auth-config.test.ts +146 -0
- package/test/boot-create-signature-policy.test.ts +15 -13
- package/test/boot-desktop-auth.test.ts +278 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +27 -27
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -0
- package/test/boot-unsupported-stored-documents.test.ts +23 -19
- package/test/boot-without-renown.test.ts +11 -9
- package/test/boot-without-require-signatures.test.ts +12 -10
- package/test/boot-worker-trust-policy.test.ts +11 -10
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/config-from-env.test.ts +968 -0
- package/test/config-merge.test.ts +351 -0
- package/test/config-schema.test.ts +183 -0
- package/test/default-composition.test.ts +290 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +104 -1
- package/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.ts +16 -0
- package/test/fixtures/mixed-subgraphs/subgraphs/index.ts +3 -0
- package/test/fixtures/mixed-subgraphs/subgraphs/tally/index.ts +73 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +441 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +7 -9
- package/test/served-schemas-mixed-package.test.ts +251 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +82 -10
- package/test/workflow/resolvers.test.ts +230 -38
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/test/workflow/webhook-trigger-test.test.ts +8 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +128 -60
- package/test/workflow-runtime.test.ts +1005 -237
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +5 -2
- package/tsdown.config.ts +12 -0
- package/vitest.config.ts +66 -1
- package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
- package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
- package/dist/server-sQoWp21G.mjs +0 -2939
- package/dist/server-sQoWp21G.mjs.map +0 -1
- package/dist/utils-uaBlzyjS.mjs +0 -86
- package/dist/utils-uaBlzyjS.mjs.map +0 -1
- package/test/mcp-flag.test.ts +0 -56
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// What the workflow subgraph does with the caller behind a request: every
|
|
2
|
-
// workflow-scoped field hands it to the runtime,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
IAuthorizationService,
|
|
6
|
-
} from "@powerhousedao/reactor-api";
|
|
2
|
+
// workflow-scoped field, secrets included, hands it to the runtime, which
|
|
3
|
+
// gates secrets on their owner document and creator rather than on admin.
|
|
4
|
+
import type { Context } from "@powerhousedao/reactor-api";
|
|
7
5
|
import {
|
|
8
6
|
WORKFLOW_SYNCING_MESSAGE,
|
|
9
7
|
WorkflowSyncingError,
|
|
@@ -36,6 +34,41 @@ function runsInfo(query: string) {
|
|
|
36
34
|
const emptyPage = (): Promise<unknown> =>
|
|
37
35
|
Promise.resolve({ records: [], hasNextPage: false, cursor: null });
|
|
38
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
|
+
|
|
39
72
|
function fakeRuntime() {
|
|
40
73
|
return {
|
|
41
74
|
webhookEndpoint: vi.fn(() => Promise.resolve(null)),
|
|
@@ -45,40 +78,51 @@ function fakeRuntime() {
|
|
|
45
78
|
run: vi.fn(() => Promise.resolve(null)),
|
|
46
79
|
fire: vi.fn(() => Promise.resolve({})),
|
|
47
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())),
|
|
48
84
|
testStep: vi.fn(() => Promise.resolve({})),
|
|
49
85
|
stepOutputTree: vi.fn(() => Promise.resolve({})),
|
|
50
86
|
blockResolutions: vi.fn(() => Promise.resolve([])),
|
|
87
|
+
searchPieces: vi.fn(() =>
|
|
88
|
+
Promise.resolve({ status: "ready", pieces: [], indexedPieces: 0 }),
|
|
89
|
+
),
|
|
90
|
+
reactorAccessDenial: vi.fn((): string | undefined => undefined),
|
|
51
91
|
testTrigger: vi.fn(() => Promise.resolve(null)),
|
|
52
92
|
cancelTriggerTestFor: vi.fn(() => Promise.resolve(true)),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
),
|
|
93
|
+
createSecret: vi.fn(() => Promise.resolve({ ref: "secret://v1:00" })),
|
|
94
|
+
rotateSecret: vi.fn(() => Promise.resolve({ ref: "secret://v1:00" })),
|
|
95
|
+
deleteSecret: vi.fn(() => Promise.resolve()),
|
|
96
|
+
secretStat: vi.fn(() => Promise.resolve(null)),
|
|
97
|
+
listSecrets: vi.fn(() => Promise.resolve([])),
|
|
98
|
+
canManageSecret: vi.fn(() => Promise.resolve(false)),
|
|
99
|
+
secrets: vi.fn(),
|
|
60
100
|
};
|
|
61
101
|
}
|
|
62
102
|
|
|
63
|
-
function build(
|
|
103
|
+
function build() {
|
|
64
104
|
const runtime = fakeRuntime();
|
|
65
|
-
const authorizationService = {
|
|
66
|
-
isSupremeAdmin: vi.fn(() => isAdmin),
|
|
67
|
-
} as unknown as IAuthorizationService;
|
|
68
105
|
const resolvers = getResolvers(
|
|
69
106
|
runtime as unknown as WorkflowRuntimeService,
|
|
70
|
-
|
|
107
|
+
undefined,
|
|
108
|
+
undefined,
|
|
109
|
+
(documentId) =>
|
|
110
|
+
documentId === "wf-hidden"
|
|
111
|
+
? Promise.reject(new Error("You may not read this workflow"))
|
|
112
|
+
: Promise.resolve(),
|
|
71
113
|
) as Record<string, Record<string, Resolver>>;
|
|
72
114
|
return {
|
|
73
115
|
runtime,
|
|
74
116
|
queries: resolvers.WorkflowRuntimeQueries,
|
|
75
117
|
mutations: resolvers.WorkflowRuntimeMutations,
|
|
118
|
+
secretRecord: resolvers.SecretRecord,
|
|
119
|
+
runRecord: resolvers.WorkflowRunRecord,
|
|
76
120
|
};
|
|
77
121
|
}
|
|
78
122
|
|
|
79
123
|
describe("the workflow resolvers and the caller", () => {
|
|
80
124
|
it("hands the caller to every workflow-scoped field", async () => {
|
|
81
|
-
const { runtime, queries, mutations } = build(
|
|
125
|
+
const { runtime, queries, mutations } = build();
|
|
82
126
|
|
|
83
127
|
await queries.webhookEndpoint({}, { workflowId: "wf-1" }, CTX);
|
|
84
128
|
await queries.triggerStates({}, {}, CTX);
|
|
@@ -122,7 +166,7 @@ describe("the workflow resolvers and the caller", () => {
|
|
|
122
166
|
});
|
|
123
167
|
|
|
124
168
|
it("passes the caller's drive, and tags a still-syncing workflow", async () => {
|
|
125
|
-
const { runtime, queries, mutations } = build(
|
|
169
|
+
const { runtime, queries, mutations } = build();
|
|
126
170
|
const drive = { driveId: "drive-1" };
|
|
127
171
|
|
|
128
172
|
await queries.webhookEndpoint({}, { workflowId: "wf-1", ...drive }, CTX);
|
|
@@ -143,32 +187,68 @@ describe("the workflow resolvers and the caller", () => {
|
|
|
143
187
|
expect(runtime.testStep).toHaveBeenCalledWith("wf-1", "s1", CTX, drive);
|
|
144
188
|
});
|
|
145
189
|
|
|
146
|
-
it("
|
|
147
|
-
const { runtime, mutations } = build(
|
|
190
|
+
it("hands every secret field to the runtime with the caller, never the store", async () => {
|
|
191
|
+
const { runtime, queries, mutations, secretRecord } = build();
|
|
192
|
+
const stat = { ref: "secret://v1:00", ownerId: "conn-1" };
|
|
148
193
|
|
|
194
|
+
await mutations.createSecret(
|
|
195
|
+
{},
|
|
196
|
+
{ value: "s3cret", documentId: "conn-1" },
|
|
197
|
+
CTX,
|
|
198
|
+
);
|
|
199
|
+
await mutations.rotateSecret({}, { ref: stat.ref, value: "s" }, CTX);
|
|
149
200
|
await expect(
|
|
150
|
-
mutations.
|
|
151
|
-
).
|
|
152
|
-
await
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
201
|
+
mutations.deleteSecret({}, { ref: stat.ref }, CTX),
|
|
202
|
+
).resolves.toBe(true);
|
|
203
|
+
await queries.secret({}, { ref: stat.ref }, CTX);
|
|
204
|
+
await queries.secrets({}, {}, CTX);
|
|
205
|
+
await secretRecord.manageable(stat, {}, CTX);
|
|
206
|
+
|
|
207
|
+
expect(runtime.createSecret).toHaveBeenCalledWith(
|
|
208
|
+
{ value: "s3cret", label: undefined, ownerId: "conn-1" },
|
|
209
|
+
CTX,
|
|
210
|
+
);
|
|
211
|
+
expect(runtime.rotateSecret).toHaveBeenCalledWith(stat.ref, "s", CTX);
|
|
212
|
+
expect(runtime.deleteSecret).toHaveBeenCalledWith(stat.ref, CTX);
|
|
213
|
+
expect(runtime.secretStat).toHaveBeenCalledWith(stat.ref, CTX);
|
|
214
|
+
expect(runtime.listSecrets).toHaveBeenCalledWith(CTX);
|
|
215
|
+
expect(runtime.canManageSecret).toHaveBeenCalledWith(stat, CTX);
|
|
216
|
+
// Nothing reaches the raw store, whose get returns values.
|
|
159
217
|
expect(runtime.secrets).not.toHaveBeenCalled();
|
|
160
218
|
});
|
|
161
219
|
|
|
162
|
-
it("
|
|
163
|
-
const { runtime, mutations } = build(
|
|
220
|
+
it("tags a secret minted for a document still syncing", async () => {
|
|
221
|
+
const { runtime, mutations } = build();
|
|
222
|
+
runtime.createSecret.mockRejectedValueOnce(new WorkflowSyncingError());
|
|
223
|
+
|
|
224
|
+
await expect(
|
|
225
|
+
mutations.createSecret({}, { value: "s", documentId: "c1" }, CTX),
|
|
226
|
+
).rejects.toMatchObject({
|
|
227
|
+
extensions: { code: "WORKFLOW_SYNCING", retryable: true },
|
|
228
|
+
});
|
|
229
|
+
});
|
|
164
230
|
|
|
165
|
-
|
|
231
|
+
it("serves why a workflow got no reactor access, naming the publisher", async () => {
|
|
232
|
+
const { runtime, queries } = build();
|
|
233
|
+
runtime.reactorAccessDenial.mockReturnValueOnce(
|
|
234
|
+
'The publisher 0xabc cannot read reactor connection "conn-1"',
|
|
235
|
+
);
|
|
166
236
|
|
|
167
|
-
expect(
|
|
237
|
+
await expect(
|
|
238
|
+
queries.reactorAccessDenial({}, { workflowId: "wf-1" }, CTX),
|
|
239
|
+
).resolves.toBe(
|
|
240
|
+
'The publisher 0xabc cannot read reactor connection "conn-1"',
|
|
241
|
+
);
|
|
242
|
+
await expect(
|
|
243
|
+
queries.reactorAccessDenial({}, { workflowId: "wf-1" }, CTX),
|
|
244
|
+
).resolves.toBeNull();
|
|
245
|
+
await expect(
|
|
246
|
+
queries.reactorAccessDenial({}, { workflowId: "wf-hidden" }, CTX),
|
|
247
|
+
).rejects.toThrow("You may not read this workflow");
|
|
168
248
|
});
|
|
169
249
|
|
|
170
250
|
it("serves the piece version a run's steps ran", async () => {
|
|
171
|
-
const { runtime, queries } = build(
|
|
251
|
+
const { runtime, queries } = build();
|
|
172
252
|
runtime.run.mockResolvedValueOnce({
|
|
173
253
|
row: { id: "run-1", warnings: 1, trigger_payload: null },
|
|
174
254
|
steps: [
|
|
@@ -198,11 +278,24 @@ describe("the workflow resolvers and the caller", () => {
|
|
|
198
278
|
versionNote: "Pinned 3.0.0 is not available; runs 2.1.0 from registry",
|
|
199
279
|
});
|
|
200
280
|
});
|
|
281
|
+
|
|
282
|
+
it("serves how many iterations a capped run detail holds back", async () => {
|
|
283
|
+
const { runtime, queries } = build();
|
|
284
|
+
runtime.run.mockResolvedValueOnce({
|
|
285
|
+
row: { id: "run-1", warnings: 0, trigger_payload: null },
|
|
286
|
+
steps: [],
|
|
287
|
+
iterationsTotal: 1200,
|
|
288
|
+
} as never);
|
|
289
|
+
const run = (await queries.run({}, { id: "run-1" }, CTX)) as {
|
|
290
|
+
iterationsTotal: number | null;
|
|
291
|
+
};
|
|
292
|
+
expect(run.iterationsTotal).toBe(1200);
|
|
293
|
+
});
|
|
201
294
|
});
|
|
202
295
|
|
|
203
296
|
describe("the runs listing and step data", () => {
|
|
204
297
|
it("reads step blobs only when the query selects them", async () => {
|
|
205
|
-
const { runtime, queries } = build(
|
|
298
|
+
const { runtime, queries } = build();
|
|
206
299
|
const withData = (query: string) =>
|
|
207
300
|
queries.runs({}, {}, CTX, runsInfo(query)).then(
|
|
208
301
|
() =>
|
|
@@ -242,7 +335,7 @@ describe("the runs listing and step data", () => {
|
|
|
242
335
|
|
|
243
336
|
describe("the runs page", () => {
|
|
244
337
|
it("passes paging through and serves the page", async () => {
|
|
245
|
-
const { runtime, queries } = build(
|
|
338
|
+
const { runtime, queries } = build();
|
|
246
339
|
runtime.runsPage.mockResolvedValueOnce({
|
|
247
340
|
records: [],
|
|
248
341
|
hasNextPage: true,
|
|
@@ -281,7 +374,7 @@ describe("the runs page", () => {
|
|
|
281
374
|
});
|
|
282
375
|
|
|
283
376
|
it("reports a cursor it did not issue as bad input", async () => {
|
|
284
|
-
const { runtime, queries } = build(
|
|
377
|
+
const { runtime, queries } = build();
|
|
285
378
|
const invalid = new Error("Invalid runs cursor");
|
|
286
379
|
invalid.name = "InvalidRunCursorError";
|
|
287
380
|
runtime.runsPage.mockRejectedValueOnce(invalid);
|
|
@@ -294,3 +387,102 @@ describe("the runs page", () => {
|
|
|
294
387
|
expect(error.extensions?.code).toBe("BAD_USER_INPUT");
|
|
295
388
|
});
|
|
296
389
|
});
|
|
390
|
+
|
|
391
|
+
describe("piece search", () => {
|
|
392
|
+
it("passes a valid filter through", async () => {
|
|
393
|
+
const { runtime, queries } = build();
|
|
394
|
+
await queries.searchPieces(
|
|
395
|
+
{},
|
|
396
|
+
{ query: "send", kind: "trigger", sources: ["registry", "local"] },
|
|
397
|
+
CTX,
|
|
398
|
+
);
|
|
399
|
+
expect(runtime.searchPieces).toHaveBeenCalledWith("send", {
|
|
400
|
+
kind: "trigger",
|
|
401
|
+
sources: ["registry", "local"],
|
|
402
|
+
categories: undefined,
|
|
403
|
+
limit: undefined,
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("refuses a kind or source it does not know, rather than widen", () => {
|
|
408
|
+
const { runtime, queries } = build();
|
|
409
|
+
expect(() =>
|
|
410
|
+
queries.searchPieces({}, { query: "send", kind: "triggers" }, CTX),
|
|
411
|
+
).toThrow(/kind is "action" or "trigger"/);
|
|
412
|
+
expect(() =>
|
|
413
|
+
queries.searchPieces(
|
|
414
|
+
{},
|
|
415
|
+
{ query: "send", kind: "action", sources: ["Registry"] },
|
|
416
|
+
CTX,
|
|
417
|
+
),
|
|
418
|
+
).toThrow(/got Registry/);
|
|
419
|
+
expect(runtime.searchPieces).not.toHaveBeenCalled();
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
describe("waitpoints", () => {
|
|
424
|
+
it("serves waiting runs with the waitpoints the runtime listed", async () => {
|
|
425
|
+
const { runtime, queries, runRecord } = build();
|
|
426
|
+
runtime.waitingRuns.mockResolvedValueOnce([
|
|
427
|
+
{
|
|
428
|
+
run: {
|
|
429
|
+
row: { id: "run-1", status: "WAITING", trigger_payload: null },
|
|
430
|
+
steps: [],
|
|
431
|
+
},
|
|
432
|
+
waitpoints: [{ id: "wp-1" }],
|
|
433
|
+
},
|
|
434
|
+
]);
|
|
435
|
+
|
|
436
|
+
const runs = (await queries.waitingRuns(
|
|
437
|
+
{},
|
|
438
|
+
{ driveId: "drive-1", first: 10 },
|
|
439
|
+
CTX,
|
|
440
|
+
)) as { id: string }[];
|
|
441
|
+
|
|
442
|
+
expect(runtime.waitingRuns).toHaveBeenCalledWith(
|
|
443
|
+
{ driveId: "drive-1", workflowId: undefined, first: 10 },
|
|
444
|
+
CTX,
|
|
445
|
+
);
|
|
446
|
+
expect(await runRecord.waitpoints(runs[0], {}, CTX)).toEqual([
|
|
447
|
+
{ id: "wp-1" },
|
|
448
|
+
]);
|
|
449
|
+
expect(runtime.waitpointsForRun).not.toHaveBeenCalled();
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("reads the waitpoints of every run in a request with one store call", async () => {
|
|
453
|
+
const { runtime, runRecord } = build();
|
|
454
|
+
const store = waitpointStore();
|
|
455
|
+
runtime.store.mockResolvedValueOnce(store);
|
|
456
|
+
const ctx = { ...CTX } as Context;
|
|
457
|
+
const [first, second, again] = (await Promise.all([
|
|
458
|
+
runRecord.waitpoints({ id: "run-1" }, {}, ctx),
|
|
459
|
+
runRecord.waitpoints({ id: "run-2" }, {}, ctx),
|
|
460
|
+
runRecord.waitpoints({ id: "run-1" }, {}, ctx),
|
|
461
|
+
])) as Array<Array<{ id: string }>>;
|
|
462
|
+
|
|
463
|
+
expect(first).toEqual([
|
|
464
|
+
expect.objectContaining({
|
|
465
|
+
id: "wp-run-1",
|
|
466
|
+
runId: "run-1",
|
|
467
|
+
kind: "approval",
|
|
468
|
+
approval: { title: "Pay?" },
|
|
469
|
+
}),
|
|
470
|
+
]);
|
|
471
|
+
expect(second!.map((waitpoint) => waitpoint.id)).toEqual(["wp-run-2"]);
|
|
472
|
+
expect(again).toBe(first);
|
|
473
|
+
expect(runtime.store).toHaveBeenCalledTimes(1);
|
|
474
|
+
expect(store.listWaitpointsForRuns).toHaveBeenCalledWith([
|
|
475
|
+
"run-1",
|
|
476
|
+
"run-2",
|
|
477
|
+
]);
|
|
478
|
+
// The parent resolver served the run; no second run read.
|
|
479
|
+
expect(runtime.waitpointsForRun).not.toHaveBeenCalled();
|
|
480
|
+
expect(runtime.run).not.toHaveBeenCalled();
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it("serves no waitpoints when the run journal is unavailable", async () => {
|
|
484
|
+
const { runtime, runRecord } = build();
|
|
485
|
+
runtime.store.mockResolvedValueOnce(undefined as never);
|
|
486
|
+
expect(await runRecord.waitpoints({ id: "run-9" }, {}, CTX)).toEqual([]);
|
|
487
|
+
});
|
|
488
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WorkflowRuntimeService } from "@powerhousedao/reactor-workflow";
|
|
2
|
+
import { hostname } from "node:os";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { getResolvers } from "../../src/workflow/resolvers.js";
|
|
5
|
+
|
|
6
|
+
type Resolver = (...args: unknown[]) => unknown;
|
|
7
|
+
|
|
8
|
+
describe("the runtime's host", () => {
|
|
9
|
+
it("is the switchboard on this machine, the id apps record as runner", () => {
|
|
10
|
+
const resolvers = getResolvers({} as WorkflowRuntimeService) as Record<
|
|
11
|
+
string,
|
|
12
|
+
Record<string, Resolver>
|
|
13
|
+
>;
|
|
14
|
+
expect(resolvers.WorkflowRuntimeQueries.host()).toEqual({
|
|
15
|
+
id: `switchboard@${hostname()}`,
|
|
16
|
+
label: hostname(),
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// The resume URL over a real socket: GET never resumes, the confirm page
|
|
2
|
+
// escapes what it shows, and POST hands the request to the runtime.
|
|
3
|
+
import {
|
|
4
|
+
createHttpAdapter,
|
|
5
|
+
HttpRouteService,
|
|
6
|
+
} from "@powerhousedao/reactor-api";
|
|
7
|
+
import {
|
|
8
|
+
afterAll,
|
|
9
|
+
beforeAll,
|
|
10
|
+
beforeEach,
|
|
11
|
+
describe,
|
|
12
|
+
expect,
|
|
13
|
+
it,
|
|
14
|
+
vi,
|
|
15
|
+
} from "vitest";
|
|
16
|
+
import {
|
|
17
|
+
MAX_REASON_LENGTH,
|
|
18
|
+
registerWaitpointRoutes,
|
|
19
|
+
waitpointBaseUrlOf,
|
|
20
|
+
type WaitpointRouteRuntime,
|
|
21
|
+
} from "../../src/workflow/waitpoint-routes.js";
|
|
22
|
+
|
|
23
|
+
const TOKEN = "tok_abc";
|
|
24
|
+
|
|
25
|
+
describe("the waitpoint resume routes", () => {
|
|
26
|
+
let base: string;
|
|
27
|
+
let close: () => Promise<void>;
|
|
28
|
+
const runtime = {
|
|
29
|
+
describeWaitpointByToken:
|
|
30
|
+
vi.fn<WaitpointRouteRuntime["describeWaitpointByToken"]>(),
|
|
31
|
+
resumeWaitpointByToken:
|
|
32
|
+
vi.fn<WaitpointRouteRuntime["resumeWaitpointByToken"]>(),
|
|
33
|
+
resumeWaitpointByTokenSync:
|
|
34
|
+
vi.fn<WaitpointRouteRuntime["resumeWaitpointByTokenSync"]>(),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
const { adapter } = await createHttpAdapter("express");
|
|
39
|
+
adapter.setupMiddleware({});
|
|
40
|
+
const server = await adapter.listen(0, undefined, "127.0.0.1");
|
|
41
|
+
const { port } = server.address() as { port: number };
|
|
42
|
+
const url = `http://127.0.0.1:${port}`;
|
|
43
|
+
const routes = new HttpRouteService({
|
|
44
|
+
httpAdapter: adapter,
|
|
45
|
+
publicUrl: url,
|
|
46
|
+
});
|
|
47
|
+
const scope = routes.scopeFor("@powerhousedao/workflow");
|
|
48
|
+
registerWaitpointRoutes(scope, runtime);
|
|
49
|
+
base = `${waitpointBaseUrlOf(scope)!}/${TOKEN}`;
|
|
50
|
+
close = () => new Promise((done) => server.close(() => done()));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterAll(() => close());
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
runtime.describeWaitpointByToken.mockReset().mockResolvedValue({
|
|
57
|
+
workflowName: "Invoice <b>approval</b>",
|
|
58
|
+
stepName: `Ask "finance"`,
|
|
59
|
+
status: "PENDING",
|
|
60
|
+
waitingSince: "2026-10-28T09:30:00.000Z",
|
|
61
|
+
});
|
|
62
|
+
runtime.resumeWaitpointByToken
|
|
63
|
+
.mockReset()
|
|
64
|
+
.mockResolvedValue({ status: "resumed" });
|
|
65
|
+
runtime.resumeWaitpointByTokenSync.mockReset().mockResolvedValue({
|
|
66
|
+
status: "resumed",
|
|
67
|
+
reply: {
|
|
68
|
+
status: 201,
|
|
69
|
+
contentType: "application/json",
|
|
70
|
+
body: '{"ok":true}',
|
|
71
|
+
headers: { "x-next": "later" },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const form = (action: string, reason = "", accept = "text/html") =>
|
|
77
|
+
fetch(`${base}/confirm?action=${action}`, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers: {
|
|
80
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
81
|
+
accept,
|
|
82
|
+
},
|
|
83
|
+
body: new URLSearchParams({ reason }).toString(),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("lives under the workflow package's namespace", () => {
|
|
87
|
+
expect(base).toMatch(
|
|
88
|
+
/\/api\/@powerhousedao\/workflow\/waitpoints\/tok_abc$/,
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("serves no resume URL from a host with no public origin", async () => {
|
|
93
|
+
const { adapter } = await createHttpAdapter("express");
|
|
94
|
+
const routes = new HttpRouteService({ httpAdapter: adapter });
|
|
95
|
+
const scope = routes.scopeFor("@powerhousedao/workflow");
|
|
96
|
+
expect(scope.baseUrl).toMatch(/^\/api\//);
|
|
97
|
+
expect(waitpointBaseUrlOf(scope)).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// The bare URL's page posts to /confirm, relative to the token.
|
|
101
|
+
it.each([
|
|
102
|
+
[
|
|
103
|
+
"GET",
|
|
104
|
+
"?action=approve",
|
|
105
|
+
200,
|
|
106
|
+
'formaction="tok_abc/confirm?action=approve"',
|
|
107
|
+
],
|
|
108
|
+
["GET", "/sync", 405, undefined],
|
|
109
|
+
["GET", "/confirm", 200, "<form"],
|
|
110
|
+
["HEAD", "", 200, ""],
|
|
111
|
+
["HEAD", "/sync", 405, ""],
|
|
112
|
+
["HEAD", "/confirm", 200, ""],
|
|
113
|
+
] as const)(
|
|
114
|
+
"never resumes on %s %s, answering %i",
|
|
115
|
+
async (method, path, status, body) => {
|
|
116
|
+
const response = await fetch(`${base}${path}`, { method });
|
|
117
|
+
expect(response.status).toBe(status);
|
|
118
|
+
if (status === 405) expect(response.headers.get("allow")).toBe("POST");
|
|
119
|
+
const text = await response.text();
|
|
120
|
+
if (body === "") expect(text).toBe("");
|
|
121
|
+
else if (body) expect(text).toContain(body);
|
|
122
|
+
expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
|
|
123
|
+
expect(runtime.resumeWaitpointByTokenSync).not.toHaveBeenCalled();
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
it("serves an escaped confirm page under a strict CSP", async () => {
|
|
128
|
+
const response = await fetch(`${base}/confirm?x=1`);
|
|
129
|
+
expect(response.status).toBe(200);
|
|
130
|
+
expect(response.headers.get("content-type")).toContain("text/html");
|
|
131
|
+
const csp = response.headers.get("content-security-policy") ?? "";
|
|
132
|
+
expect(csp).toContain("default-src 'none'");
|
|
133
|
+
expect(csp).toContain("form-action 'self'");
|
|
134
|
+
expect(response.headers.get("referrer-policy")).toBe("no-referrer");
|
|
135
|
+
const body = await response.text();
|
|
136
|
+
expect(runtime.describeWaitpointByToken).toHaveBeenCalledWith(TOKEN);
|
|
137
|
+
expect(body).toContain("Invoice <b>approval</b>");
|
|
138
|
+
expect(body).toContain("Ask "finance"");
|
|
139
|
+
expect(body).not.toContain("<b>");
|
|
140
|
+
expect(body).not.toContain("<script");
|
|
141
|
+
expect(body).toContain('formaction="?x=1&action=approve"');
|
|
142
|
+
expect(body).toContain('formaction="?x=1&action=disapprove"');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("describes the workflow and the wait, times in UTC", async () => {
|
|
146
|
+
runtime.describeWaitpointByToken.mockResolvedValueOnce({
|
|
147
|
+
workflowName: "Vendor sign-off",
|
|
148
|
+
workflowDescription: "Ask <the vendor> to sign off\non the new terms.",
|
|
149
|
+
stepName: "Ask vendor",
|
|
150
|
+
actionName: "Create Approval Links",
|
|
151
|
+
status: "PENDING",
|
|
152
|
+
startedAt: "2026-10-28T09:29:00.000Z",
|
|
153
|
+
triggerName: "Manual Trigger",
|
|
154
|
+
waitingSince: "2026-10-28T09:30:00.000Z",
|
|
155
|
+
expiresAt: "2026-11-04T09:30:00.000Z",
|
|
156
|
+
});
|
|
157
|
+
const body = await (await fetch(`${base}/confirm`)).text();
|
|
158
|
+
expect(body).toContain(
|
|
159
|
+
"Ask <the vendor> to sign off\non the new terms.",
|
|
160
|
+
);
|
|
161
|
+
expect(body).toContain("<dd>Ask vendor · Create Approval Links</dd>");
|
|
162
|
+
expect(body).toContain(
|
|
163
|
+
"<dd>28 Oct 2026, 09:29 UTC, by Manual Trigger</dd>",
|
|
164
|
+
);
|
|
165
|
+
expect(body).toContain(
|
|
166
|
+
"<dt>Waiting since</dt><dd>28 Oct 2026, 09:30 UTC</dd>",
|
|
167
|
+
);
|
|
168
|
+
expect(body).toContain("<dt>Expires</dt><dd>4 Nov 2026, 09:30 UTC</dd>");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("names the action only when the step's own name differs", async () => {
|
|
172
|
+
runtime.describeWaitpointByToken.mockResolvedValueOnce({
|
|
173
|
+
workflowName: "wf",
|
|
174
|
+
stepName: "Create approval links",
|
|
175
|
+
actionName: "Create Approval Links",
|
|
176
|
+
status: "PENDING",
|
|
177
|
+
waitingSince: "2026-10-28T09:30:00.000Z",
|
|
178
|
+
});
|
|
179
|
+
const body = await (await fetch(`${base}/confirm`)).text();
|
|
180
|
+
expect(body).toContain("<dd>Create approval links</dd>");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it.each([
|
|
184
|
+
["COMPLETED", "Already responded"],
|
|
185
|
+
["CONSUMED", "Already responded"],
|
|
186
|
+
["EXPIRED", "Request expired"],
|
|
187
|
+
["CANCELLED", "Run cancelled"],
|
|
188
|
+
] as const)("shows a %s waitpoint without a form", async (status, title) => {
|
|
189
|
+
runtime.describeWaitpointByToken.mockResolvedValueOnce({
|
|
190
|
+
workflowName: "wf",
|
|
191
|
+
stepName: "step",
|
|
192
|
+
status,
|
|
193
|
+
waitingSince: "2026-10-28T09:30:00.000Z",
|
|
194
|
+
});
|
|
195
|
+
const body = await (await fetch(`${base}/confirm`)).text();
|
|
196
|
+
expect(body).toContain(title);
|
|
197
|
+
expect(body).not.toContain("<form");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("answers 404 for a token the runtime does not know", async () => {
|
|
201
|
+
runtime.describeWaitpointByToken.mockResolvedValueOnce(undefined);
|
|
202
|
+
expect((await fetch(`${base}/confirm`)).status).toBe(404);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("resumes on POST with body, headers and query, answering JSON", async () => {
|
|
206
|
+
const response = await fetch(`${base}?a=1`, {
|
|
207
|
+
method: "POST",
|
|
208
|
+
headers: {
|
|
209
|
+
"content-type": "application/json",
|
|
210
|
+
authorization: "Bearer secret",
|
|
211
|
+
},
|
|
212
|
+
body: JSON.stringify({ ok: true }),
|
|
213
|
+
});
|
|
214
|
+
expect(response.status).toBe(200);
|
|
215
|
+
expect(await response.json()).toMatchObject({ status: "resumed" });
|
|
216
|
+
const [token, payload] = runtime.resumeWaitpointByToken.mock.calls[0]!;
|
|
217
|
+
expect(token).toBe(TOKEN);
|
|
218
|
+
expect(payload.body).toEqual({ ok: true });
|
|
219
|
+
expect(payload.queryParams).toEqual({ a: "1" });
|
|
220
|
+
expect(payload.headers?.["content-type"]).toBe("application/json");
|
|
221
|
+
// Credentials are not journaled with the payload.
|
|
222
|
+
expect(payload.headers?.authorization).toBeUndefined();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("answers the sync sub-path with the resumed run's reply", async () => {
|
|
226
|
+
const response = await fetch(`${base}/sync`, { method: "POST" });
|
|
227
|
+
expect(runtime.resumeWaitpointByTokenSync).toHaveBeenCalledOnce();
|
|
228
|
+
expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
|
|
229
|
+
expect(response.status).toBe(201);
|
|
230
|
+
expect(response.headers.get("x-next")).toBe("later");
|
|
231
|
+
expect(await response.json()).toEqual({ ok: true });
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("answers a gone waitpoint on the sync sub-path with 410", async () => {
|
|
235
|
+
runtime.resumeWaitpointByTokenSync.mockResolvedValue({ status: "gone" });
|
|
236
|
+
const response = await fetch(`${base}/sync`, { method: "POST" });
|
|
237
|
+
expect(response.status).toBe(410);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("answers the confirm form with an HTML page", async () => {
|
|
241
|
+
const response = await form("disapprove", "too expensive");
|
|
242
|
+
expect(response.headers.get("content-type")).toContain("text/html");
|
|
243
|
+
expect(await response.text()).toContain("You disapproved this request.");
|
|
244
|
+
const [, payload] = runtime.resumeWaitpointByToken.mock.calls[0]!;
|
|
245
|
+
expect(payload.body).toEqual({ reason: "too expensive" });
|
|
246
|
+
expect(payload.queryParams).toEqual({
|
|
247
|
+
action: "disapprove",
|
|
248
|
+
reason: "too expensive",
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("refuses a confirm POST without an action, recording nothing", async () => {
|
|
253
|
+
expect((await form("maybe")).status).toBe(400);
|
|
254
|
+
expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("refuses an over-long reason, recording nothing", async () => {
|
|
258
|
+
const response = await form("approve", "x".repeat(MAX_REASON_LENGTH + 1));
|
|
259
|
+
expect(response.status).toBe(400);
|
|
260
|
+
expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("refuses a body past 1 MiB", async () => {
|
|
264
|
+
const response = await fetch(base, {
|
|
265
|
+
method: "POST",
|
|
266
|
+
headers: { "content-type": "text/plain" },
|
|
267
|
+
body: "x".repeat(1_048_577),
|
|
268
|
+
});
|
|
269
|
+
expect(response.status).toBe(413);
|
|
270
|
+
expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("answers a repeat as already responded and a gone waitpoint as 410", async () => {
|
|
274
|
+
runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "already" });
|
|
275
|
+
const already = await form("approve");
|
|
276
|
+
expect(already.status).toBe(200);
|
|
277
|
+
expect(await already.text()).toContain("Already responded");
|
|
278
|
+
|
|
279
|
+
runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "gone" });
|
|
280
|
+
const gone = await fetch(base, { method: "POST" });
|
|
281
|
+
expect(gone.status).toBe(410);
|
|
282
|
+
expect(await gone.json()).toMatchObject({
|
|
283
|
+
status: "gone",
|
|
284
|
+
discarded: true,
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("tells a sub-flow's response whether it was discarded", async () => {
|
|
289
|
+
const respond = () =>
|
|
290
|
+
fetch(base, {
|
|
291
|
+
method: "POST",
|
|
292
|
+
headers: { "content-type": "application/json" },
|
|
293
|
+
body: JSON.stringify({ status: "success", data: { ok: true } }),
|
|
294
|
+
});
|
|
295
|
+
runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "resumed" });
|
|
296
|
+
expect(await (await respond()).json()).toMatchObject({
|
|
297
|
+
status: "resumed",
|
|
298
|
+
discarded: false,
|
|
299
|
+
});
|
|
300
|
+
runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "already" });
|
|
301
|
+
expect(await (await respond()).json()).toMatchObject({
|
|
302
|
+
status: "already",
|
|
303
|
+
discarded: false,
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|