@tailor-platform/sdk 1.82.0 → 1.83.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.
- package/CHANGELOG.md +8 -0
- package/dist/application-CP7JKG9R.mjs +3 -0
- package/dist/{application-CVeA53ok.mjs → application-Cp0FxIm2.mjs} +3 -3
- package/dist/application-Cp0FxIm2.mjs.map +1 -0
- package/dist/cli/index.mjs +3 -3
- package/dist/cli/lib.mjs +2 -2
- package/dist/completion/zsh-worker.zsh +1 -1
- package/dist/configure/index.mjs +3 -3
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/workflow/execution-policy.d.mts +2 -2
- package/dist/{globals-DUqEetIh.mjs → globals-DraXTdqg.mjs} +6 -5
- package/dist/globals-DraXTdqg.mjs.map +1 -0
- package/dist/{register-typescript-runtime-O7zQNif0.mjs → register-typescript-runtime-CCHyKeXO.mjs} +125 -11
- package/dist/register-typescript-runtime-CCHyKeXO.mjs.map +1 -0
- package/dist/{registry-CXi7rJq7.mjs → registry-Ct0Wgxp1.mjs} +3 -3
- package/dist/registry-Ct0Wgxp1.mjs.map +1 -0
- package/dist/runtime/index.mjs +1 -1
- package/dist/runtime/workflow.d.mts +39 -21
- package/dist/runtime/workflow.mjs +2 -2
- package/dist/utils/test/index.mjs +18 -12
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/utils/test/mock.d.mts +2 -2
- package/dist/vitest/environment.mjs +1 -1
- package/dist/vitest/index.mjs +30 -24
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mocks/file.d.mts +1 -1
- package/dist/vitest/mocks/workflow.d.mts +20 -15
- package/dist/vitest/setup.mjs +1 -1
- package/dist/{workflow-CkIDJpdg.mjs → workflow-B2mwc7aT.mjs} +17 -9
- package/dist/workflow-B2mwc7aT.mjs.map +1 -0
- package/docs/runtime.md +1 -1
- package/docs/services/tailordb-migration.md +5 -3
- package/docs/services/workflow.md +2 -2
- package/docs/testing.md +1 -1
- package/package.json +2 -2
- package/dist/application-CP0W2sQo.mjs +0 -3
- package/dist/application-CVeA53ok.mjs.map +0 -1
- package/dist/globals-DUqEetIh.mjs.map +0 -1
- package/dist/register-typescript-runtime-O7zQNif0.mjs.map +0 -1
- package/dist/registry-CXi7rJq7.mjs.map +0 -1
- package/dist/workflow-CkIDJpdg.mjs.map +0 -1
|
@@ -68,7 +68,7 @@ function workflows() {
|
|
|
68
68
|
/**
|
|
69
69
|
* Register a job body keyed by job name. Called as a side effect by
|
|
70
70
|
* `createWorkflowJob` so the vitest mock can execute the body when
|
|
71
|
-
* `globalThis.tailor.workflow.
|
|
71
|
+
* `globalThis.tailor.workflow.execJobFunction(name, args)` is invoked.
|
|
72
72
|
*
|
|
73
73
|
* In production builds the bundler rewrites `.trigger()` calls so this registry
|
|
74
74
|
* is never read; the gated write is dropped as dead code.
|
|
@@ -121,7 +121,7 @@ async function runRegisteredWorkflow(name, args) {
|
|
|
121
121
|
function dispatchTriggerJob(name, args, options) {
|
|
122
122
|
const workflow = currentPlatformWorkflow();
|
|
123
123
|
if (!workflow) return runRegisteredJob(name, args);
|
|
124
|
-
return arguments.length >= 3 ? workflow.
|
|
124
|
+
return arguments.length >= 3 ? workflow.execJobFunction(name, args, options) : workflow.execJobFunction(name, args);
|
|
125
125
|
}
|
|
126
126
|
function dispatchTriggerWorkflow(name, args, options) {
|
|
127
127
|
const workflow = currentPlatformWorkflow();
|
|
@@ -131,4 +131,4 @@ function dispatchTriggerWorkflow(name, args, options) {
|
|
|
131
131
|
|
|
132
132
|
//#endregion
|
|
133
133
|
export { getRegisteredWorkflow as a, runRegisteredJob as c, getRegisteredJob as i, runRegisteredWorkflow as l, dispatchTriggerJob as n, registerJob as o, dispatchTriggerWorkflow as r, registerWorkflow as s, TRIGGER_DEFAULT as t, platformSerialize as u };
|
|
134
|
-
//# sourceMappingURL=registry-
|
|
134
|
+
//# sourceMappingURL=registry-Ct0Wgxp1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-Ct0Wgxp1.mjs","names":[],"sources":["../src/utils/test/platform-serialize.ts","../src/configure/services/workflow/registry.ts"],"sourcesContent":["/**\n * Validate and serialize a value as it would cross the Platform JSON boundary.\n *\n * Mirrors the runtime checks the platform performs on workflow arguments,\n * wait payloads, and trigger inputs so that local tests fail in the same\n * places production fails.\n *\n * Throws on:\n * - `NaN` / `Infinity` / `-Infinity` (`JSON.stringify` would silently emit `null`)\n * - `BigInt` (TypeError is thrown by `JSON.stringify`; we emit a clearer message)\n * - Non-plain objects (class instances, including `Date`, `Map`, `Set`, `Error`,\n * and user-defined DTOs whose prototype is not `Object.prototype`)\n *\n * The replacer reads `this[key]` so the check sees the original value before\n * any `toJSON` conversion (e.g. `Date.prototype.toJSON`).\n * @param value - Value to validate and round-trip\n * @returns The JSON-normalized value (undefined/function properties stripped, etc.)\n */\nexport function platformSerialize<T>(value: T): T {\n // Top-level undefined is allowed (jobs may take no input).\n if (value === undefined) return undefined as T;\n\n // Root function/symbol stringify to `undefined`; throw a specific message here.\n if (typeof value === \"function\") {\n throw new TypeError(\"platformSerialize: function is not JSON-serializable at <root>\");\n }\n if (typeof value === \"symbol\") {\n throw new TypeError(\"platformSerialize: Symbol is not JSON-serializable at <root>\");\n }\n\n const serialized = JSON.stringify(value, function (key, val) {\n if (typeof val === \"number\" && !Number.isFinite(val)) {\n throw new TypeError(\n `platformSerialize: non-finite number at ${formatPath(key)}: ${String(val)}`,\n );\n }\n if (typeof val === \"bigint\") {\n throw new TypeError(\n `platformSerialize: BigInt is not JSON-serializable at ${formatPath(key)}`,\n );\n }\n // Look at the pre-toJSON value so Date/Map/Set/etc. can be detected.\n const raw = (this as Record<string, unknown>)[key];\n if (raw !== null && typeof raw === \"object\" && !Array.isArray(raw)) {\n const proto = Object.getPrototypeOf(raw);\n if (proto !== Object.prototype && proto !== null) {\n const ctor = (raw as { constructor?: { name?: string } }).constructor?.name ?? \"anonymous\";\n throw new TypeError(\n `platformSerialize: non-plain object at ${formatPath(key)} (${ctor} instance)`,\n );\n }\n }\n return val;\n });\n\n // `JSON.stringify` returns `undefined` when the root collapses (e.g. a `toJSON`\n // returning `undefined`); parsing that would throw opaquely.\n // JSON.stringify returns undefined for non-serializable values\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (serialized === undefined) {\n throw new TypeError(\"platformSerialize: value is not JSON-serializable at <root>\");\n }\n\n return JSON.parse(serialized) as T;\n}\n\nfunction formatPath(key: string): string {\n return key === \"\" ? \"<root>\" : `\"${key}\"`;\n}\n","import { platformSerialize } from \"#/utils/test/platform-serialize\";\nimport { buildJobContext } from \"./test-env-key\";\nimport type { TailorEnv, TailorInvoker } from \"#/runtime/types\";\nimport type { ExecJobFunctionOptions, StartWorkflowOptions } from \"#/runtime/workflow\";\n\n/**\n * Body signature shared by workflow jobs at registry-write time.\n * The user's `createWorkflowJob`/`createWorkflow` body uses concrete types,\n * but the registry erases them for storage.\n */\nexport type RegisteredJobBody = (\n args: unknown,\n context: { env: TailorEnv; invoker?: TailorInvoker },\n) => unknown | Promise<unknown>;\n\nexport interface RegisteredWorkflow {\n mainJobName: string;\n}\n\nconst JOB_REGISTRY_KEY: unique symbol = Symbol.for(\"tailor-platform/sdk:job-registry\");\nconst WORKFLOW_REGISTRY_KEY: unique symbol = Symbol.for(\"tailor-platform/sdk:workflow-registry\");\n\ntype PlatformWorkflow = {\n startWorkflow: (name: string, args?: unknown, options?: StartWorkflowOptions) => Promise<string>;\n triggerWorkflow: (\n name: string,\n args?: unknown,\n options?: StartWorkflowOptions,\n ) => Promise<string>;\n execJobFunction: (name: string, args?: unknown, options?: ExecJobFunctionOptions) => unknown;\n startJobFunction: (name: string, args?: unknown, options?: ExecJobFunctionOptions) => unknown;\n triggerJobFunction: (name: string, args?: unknown, options?: ExecJobFunctionOptions) => unknown;\n};\n\ntype GlobalWithRegistry = typeof globalThis & {\n [JOB_REGISTRY_KEY]?: Map<string, RegisteredJobBody>;\n [WORKFLOW_REGISTRY_KEY]?: Map<string, RegisteredWorkflow>;\n tailor?: { workflow?: PlatformWorkflow };\n};\n\nfunction jobs(): Map<string, RegisteredJobBody> {\n const g = globalThis as GlobalWithRegistry;\n let map = g[JOB_REGISTRY_KEY];\n if (!map) {\n map = new Map();\n g[JOB_REGISTRY_KEY] = map;\n }\n return map;\n}\n\nfunction workflows(): Map<string, RegisteredWorkflow> {\n const g = globalThis as GlobalWithRegistry;\n let map = g[WORKFLOW_REGISTRY_KEY];\n if (!map) {\n map = new Map();\n g[WORKFLOW_REGISTRY_KEY] = map;\n }\n return map;\n}\n\n/**\n * Register a job body keyed by job name. Called as a side effect by\n * `createWorkflowJob` so the vitest mock can execute the body when\n * `globalThis.tailor.workflow.execJobFunction(name, args)` is invoked.\n *\n * In production builds the bundler rewrites `.trigger()` calls so this registry\n * is never read; the gated write is dropped as dead code.\n * @param name - Job name\n * @param body - Job body function\n */\nexport function registerJob(name: string, body: RegisteredJobBody): void {\n jobs().set(name, body);\n}\n\n/**\n * Look up a registered job body by name.\n * @param name - Job name\n * @returns The registered body, or undefined when no job is registered\n */\nexport function getRegisteredJob(name: string): RegisteredJobBody | undefined {\n return jobs().get(name);\n}\n\n/**\n * Register a workflow's main job name so the mock can run the workflow locally.\n * @param name - Workflow name\n * @param mainJobName - Name of the workflow's main job\n */\nexport function registerWorkflow(name: string, mainJobName: string): void {\n workflows().set(name, { mainJobName });\n}\n\n/**\n * Look up a registered workflow by name.\n * @param name - Workflow name\n * @returns The registered workflow, or undefined\n */\nexport function getRegisteredWorkflow(name: string): RegisteredWorkflow | undefined {\n return workflows().get(name);\n}\n\nfunction currentPlatformWorkflow(): PlatformWorkflow | undefined {\n // globalThis may not have the tailor property at runtime\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n return (globalThis as GlobalWithRegistry).tailor?.workflow;\n}\n\n// A valid placeholder UUID, so callers that validate the execution id behave the\n// same locally as against the platform.\nexport const TRIGGER_DEFAULT = \"00000000-0000-4000-8000-000000000000\";\n\nfunction serializeReturn(out: unknown): unknown {\n return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);\n}\n\n// Runs the registered body across the platform JSON boundary. Shared by the\n// `tailor-runtime` default runner and the no-shim `.trigger()` fallback below.\nexport function runRegisteredJob(name: string, args?: unknown): unknown {\n const body = getRegisteredJob(name);\n const out = body ? body(platformSerialize(args), buildJobContext()) : null;\n return serializeReturn(out);\n}\n\nexport async function runRegisteredWorkflow(name: string, args?: unknown): Promise<string> {\n const workflow = getRegisteredWorkflow(name);\n if (workflow) await runRegisteredJob(workflow.mainJobName, args);\n return TRIGGER_DEFAULT;\n}\n\n// `.trigger()` routes through the installed `tailor.workflow` shim, falling back\n// to running the registered body/workflow locally when none is installed.\n// Preserve arity: the shim sees a 2-argument call when the caller supplied no\n// options, and a 3-argument call otherwise, mirroring the bundler rewrite so\n// mocks observe the same shape in local execution and in bundled workflows.\nexport function dispatchTriggerJob(\n name: string,\n args?: unknown,\n options?: ExecJobFunctionOptions,\n): unknown {\n const workflow = currentPlatformWorkflow();\n if (!workflow) return runRegisteredJob(name, args);\n // oxlint-disable-next-line prefer-rest-params\n return arguments.length >= 3\n ? workflow.execJobFunction(name, args, options)\n : workflow.execJobFunction(name, args);\n}\n\n// Accepts `unknown` because the SDK-side `.trigger()` accepts a wider options\n// shape than the platform surface (e.g. `authInvoker` may be a machine-user\n// name string that the bundler normalizes at build time). Local execution\n// forwards the value verbatim; only the bundled path enforces the platform\n// contract.\nexport function dispatchTriggerWorkflow(\n name: string,\n args?: unknown,\n options?: unknown,\n): Promise<string> {\n const workflow = currentPlatformWorkflow();\n if (!workflow) return runRegisteredWorkflow(name, args);\n // oxlint-disable-next-line prefer-rest-params\n return arguments.length >= 3\n ? workflow.triggerWorkflow(name, args, options as StartWorkflowOptions | undefined)\n : workflow.triggerWorkflow(name, args);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBAAqB,OAAa;CAEhD,IAAI,UAAU,QAAW,OA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S,gBAAgB,MAAM,MAAM,OAA2C,IAChF,SAAS,gBAAgB,MAAM,IAAI;AACzC"}
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { s as iconv_exports } from "../iconv-D2vi8G36.mjs";
|
|
|
2
2
|
import { r as secretmanager_exports } from "../secretmanager-BVxw3ih_.mjs";
|
|
3
3
|
import { t as authconnection_exports } from "../authconnection-BGQM8FZI.mjs";
|
|
4
4
|
import { n as idp_exports } from "../idp-Bx25ZBdN.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { u as workflow_exports } from "../workflow-B2mwc7aT.mjs";
|
|
6
6
|
import { t as context_exports } from "../context-Bd266-ru.mjs";
|
|
7
7
|
import { a as file_exports } from "../file-_oUZo76X.mjs";
|
|
8
8
|
import { t as aigateway_exports } from "../aigateway-B3oZZE6v.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare namespace workflow_d_exports {
|
|
2
|
-
export { AuthInvoker, ExecutionPolicyKey, StartJobFunctionOptions, StartWorkflowOptions, TailorWorkflowAPI, TriggerJobFunctionOptions, TriggerWorkflowOptions, resolve, resumeWorkflow, resumeWorkflowExecution, startJobFunction, startWorkflow, triggerJobFunction, triggerWorkflow, wait };
|
|
2
|
+
export { AuthInvoker, ExecJobFunctionOptions, ExecutionPolicyKey, StartJobFunctionOptions, StartWorkflowOptions, TailorWorkflowAPI, TriggerJobFunctionOptions, TriggerWorkflowOptions, execJobFunction, resolve, resumeWorkflow, resumeWorkflowExecution, startJobFunction, startWorkflow, triggerJobFunction, triggerWorkflow, wait };
|
|
3
3
|
}
|
|
4
4
|
/**
|
|
5
5
|
* Workflow utilities.
|
|
@@ -8,11 +8,12 @@ declare namespace workflow_d_exports {
|
|
|
8
8
|
* At runtime this delegates to `globalThis.tailor.workflow`. Use `mockWorkflow`
|
|
9
9
|
* from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.
|
|
10
10
|
*
|
|
11
|
-
* The canonical names (`startWorkflow`, `
|
|
11
|
+
* The canonical names (`startWorkflow`, `execJobFunction`,
|
|
12
12
|
* `resumeWorkflowExecution`) mirror the public `tailor.v1` RPC vocabulary.
|
|
13
13
|
* The pre-alignment names (`triggerWorkflow`, `triggerJobFunction`,
|
|
14
|
-
* `resumeWorkflow`) are kept as
|
|
15
|
-
* implementations, so existing code continues to work
|
|
14
|
+
* `startJobFunction`, `resumeWorkflow`) are kept as aliases that reference
|
|
15
|
+
* the same platform implementations, so existing code continues to work
|
|
16
|
+
* unchanged.
|
|
16
17
|
* @example
|
|
17
18
|
* import { workflow } from "@tailor-platform/sdk/runtime";
|
|
18
19
|
*
|
|
@@ -48,8 +49,8 @@ declare const executionPolicyKeyBrand: unique symbol;
|
|
|
48
49
|
type ExecutionPolicyKey = string & {
|
|
49
50
|
readonly [executionPolicyKeyBrand]: never;
|
|
50
51
|
};
|
|
51
|
-
/** Options for {@link
|
|
52
|
-
interface
|
|
52
|
+
/** Options for {@link execJobFunction}. */
|
|
53
|
+
interface ExecJobFunctionOptions {
|
|
53
54
|
/**
|
|
54
55
|
* Execution policy key matched by the platform against the policies
|
|
55
56
|
* declared with `defineWorkflowExecutionPolicies` in `tailor.config.ts`.
|
|
@@ -57,10 +58,15 @@ interface StartJobFunctionOptions {
|
|
|
57
58
|
executionPolicyKey?: ExecutionPolicyKey;
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @deprecated Use {@link
|
|
61
|
+
* Alias for {@link ExecJobFunctionOptions}. Kept for backward compatibility.
|
|
62
|
+
* @deprecated Use {@link ExecJobFunctionOptions} instead.
|
|
62
63
|
*/
|
|
63
|
-
type
|
|
64
|
+
type StartJobFunctionOptions = ExecJobFunctionOptions;
|
|
65
|
+
/**
|
|
66
|
+
* Frozen alias for {@link ExecJobFunctionOptions}. Kept for backward compatibility.
|
|
67
|
+
* @deprecated Use {@link ExecJobFunctionOptions} instead.
|
|
68
|
+
*/
|
|
69
|
+
type TriggerJobFunctionOptions = ExecJobFunctionOptions;
|
|
64
70
|
/**
|
|
65
71
|
* Platform API surface for `tailor.workflow`. Describes the shape the platform
|
|
66
72
|
* runtime injects on `globalThis.tailor.workflow`.
|
|
@@ -103,20 +109,25 @@ interface TailorWorkflowAPI {
|
|
|
103
109
|
*/
|
|
104
110
|
resumeWorkflow(executionId: string): Promise<string>;
|
|
105
111
|
/**
|
|
106
|
-
*
|
|
112
|
+
* Executes a job function and returns its result.
|
|
107
113
|
*
|
|
108
114
|
* Canonical name that mirrors the `tailor.v1` RPC vocabulary.
|
|
109
|
-
* {@link
|
|
110
|
-
* platform implementation.
|
|
115
|
+
* {@link startJobFunction} and {@link triggerJobFunction} are aliases that
|
|
116
|
+
* resolve to the same platform implementation.
|
|
111
117
|
* @param jobName - Job name as defined in the workflow
|
|
112
118
|
* @param args - Arguments forwarded to the job
|
|
113
|
-
* @param options - Optional
|
|
119
|
+
* @param options - Optional exec options (e.g. `executionPolicyKey`)
|
|
114
120
|
* @returns The job's return value
|
|
115
121
|
*/
|
|
122
|
+
execJobFunction(jobName: string, args?: any, options?: ExecJobFunctionOptions): any;
|
|
123
|
+
/**
|
|
124
|
+
* Alias for {@link execJobFunction}. Kept for backward compatibility.
|
|
125
|
+
* @deprecated Use {@link execJobFunction} instead.
|
|
126
|
+
*/
|
|
116
127
|
startJobFunction(jobName: string, args?: any, options?: StartJobFunctionOptions): any;
|
|
117
128
|
/**
|
|
118
|
-
* Frozen alias for {@link
|
|
119
|
-
* @deprecated Use {@link
|
|
129
|
+
* Frozen alias for {@link execJobFunction}. Kept for backward compatibility.
|
|
130
|
+
* @deprecated Use {@link execJobFunction} instead.
|
|
120
131
|
*/
|
|
121
132
|
triggerJobFunction(jobName: string, args?: any, options?: TriggerJobFunctionOptions): any;
|
|
122
133
|
/**
|
|
@@ -162,15 +173,22 @@ declare const resumeWorkflowExecution: TailorWorkflowAPI["resumeWorkflowExecutio
|
|
|
162
173
|
*/
|
|
163
174
|
declare const resumeWorkflow: TailorWorkflowAPI["resumeWorkflow"];
|
|
164
175
|
/**
|
|
165
|
-
* See {@link TailorWorkflowAPI.
|
|
166
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.
|
|
176
|
+
* See {@link TailorWorkflowAPI.execJobFunction}.
|
|
177
|
+
* @param args - Forwarded to {@link TailorWorkflowAPI.execJobFunction}
|
|
178
|
+
* @returns The job's return value
|
|
179
|
+
*/
|
|
180
|
+
declare const execJobFunction: TailorWorkflowAPI["execJobFunction"];
|
|
181
|
+
/**
|
|
182
|
+
* Alias for {@link execJobFunction}. Kept for backward compatibility.
|
|
183
|
+
* @deprecated Use {@link execJobFunction} instead.
|
|
184
|
+
* @param args - Forwarded to {@link TailorWorkflowAPI.execJobFunction}
|
|
167
185
|
* @returns The job's return value
|
|
168
186
|
*/
|
|
169
187
|
declare const startJobFunction: TailorWorkflowAPI["startJobFunction"];
|
|
170
188
|
/**
|
|
171
|
-
* Frozen alias for {@link
|
|
172
|
-
* @deprecated Use {@link
|
|
173
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.
|
|
189
|
+
* Frozen alias for {@link execJobFunction}. Kept for backward compatibility.
|
|
190
|
+
* @deprecated Use {@link execJobFunction} instead.
|
|
191
|
+
* @param args - Forwarded to {@link TailorWorkflowAPI.execJobFunction}
|
|
174
192
|
* @returns The job's return value
|
|
175
193
|
*/
|
|
176
194
|
declare const triggerJobFunction: TailorWorkflowAPI["triggerJobFunction"];
|
|
@@ -187,4 +205,4 @@ declare const wait: TailorWorkflowAPI["wait"];
|
|
|
187
205
|
*/
|
|
188
206
|
declare const resolve: TailorWorkflowAPI["resolve"];
|
|
189
207
|
//#endregion
|
|
190
|
-
export { AuthInvoker, ExecutionPolicyKey, StartJobFunctionOptions, StartWorkflowOptions, TailorWorkflowAPI, TriggerJobFunctionOptions, TriggerWorkflowOptions, resolve, resumeWorkflow, resumeWorkflowExecution, startJobFunction, startWorkflow, triggerJobFunction, triggerWorkflow, wait, workflow_d_exports };
|
|
208
|
+
export { AuthInvoker, ExecJobFunctionOptions, ExecutionPolicyKey, StartJobFunctionOptions, StartWorkflowOptions, TailorWorkflowAPI, TriggerJobFunctionOptions, TriggerWorkflowOptions, execJobFunction, resolve, resumeWorkflow, resumeWorkflowExecution, startJobFunction, startWorkflow, triggerJobFunction, triggerWorkflow, wait, workflow_d_exports };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as startJobFunction, c as triggerWorkflow, i as resumeWorkflowExecution, l as wait, n as resolve, o as startWorkflow, r as resumeWorkflow, s as triggerJobFunction, t as execJobFunction } from "../workflow-B2mwc7aT.mjs";
|
|
2
2
|
|
|
3
|
-
export { resolve, resumeWorkflow, resumeWorkflowExecution, startJobFunction, startWorkflow, triggerJobFunction, triggerWorkflow, wait };
|
|
3
|
+
export { execJobFunction, resolve, resumeWorkflow, resumeWorkflowExecution, startJobFunction, startWorkflow, triggerJobFunction, triggerWorkflow, wait };
|
|
@@ -41,7 +41,7 @@ function setupTailordbMock(resolver = () => []) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Sets up a mock for `globalThis.tailor.workflow.
|
|
44
|
+
* Sets up a mock for `globalThis.tailor.workflow.execJobFunction` used in bundled workflow tests.
|
|
45
45
|
* `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,
|
|
46
46
|
* so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
|
|
47
47
|
* @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
@@ -50,6 +50,13 @@ function setupTailordbMock(resolver = () => []) {
|
|
|
50
50
|
*/
|
|
51
51
|
function setupWorkflowMock(handler) {
|
|
52
52
|
const triggeredJobs = [];
|
|
53
|
+
const execJobFunction = (jobName, args) => {
|
|
54
|
+
triggeredJobs.push({
|
|
55
|
+
jobName,
|
|
56
|
+
args
|
|
57
|
+
});
|
|
58
|
+
return handler(jobName, args);
|
|
59
|
+
};
|
|
53
60
|
GlobalThis.tailor = {
|
|
54
61
|
...GlobalThis.tailor,
|
|
55
62
|
workflow: {
|
|
@@ -60,13 +67,9 @@ function setupWorkflowMock(handler) {
|
|
|
60
67
|
throw new Error("tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.");
|
|
61
68
|
},
|
|
62
69
|
...GlobalThis.tailor?.workflow,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
args
|
|
67
|
-
});
|
|
68
|
-
return handler(jobName, args);
|
|
69
|
-
}
|
|
70
|
+
execJobFunction,
|
|
71
|
+
startJobFunction: execJobFunction,
|
|
72
|
+
triggerJobFunction: execJobFunction
|
|
70
73
|
}
|
|
71
74
|
};
|
|
72
75
|
return { triggeredJobs };
|
|
@@ -107,7 +110,7 @@ function setupTailorErrorsMock() {
|
|
|
107
110
|
}
|
|
108
111
|
/**
|
|
109
112
|
* Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
|
|
110
|
-
* `
|
|
113
|
+
* `execJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
|
|
111
114
|
* so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.
|
|
112
115
|
* @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
113
116
|
* `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.
|
|
@@ -119,12 +122,15 @@ function setupTailorErrorsMock() {
|
|
|
119
122
|
function setupWaitPointMock(config) {
|
|
120
123
|
const waitCalls = [];
|
|
121
124
|
const resolveCalls = [];
|
|
125
|
+
const throwUnmocked = () => {
|
|
126
|
+
throw new Error("tailor.workflow.execJobFunction is not mocked. Use setupWorkflowMock() in tests.");
|
|
127
|
+
};
|
|
122
128
|
GlobalThis.tailor = {
|
|
123
129
|
...GlobalThis.tailor,
|
|
124
130
|
workflow: {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
execJobFunction: throwUnmocked,
|
|
132
|
+
startJobFunction: throwUnmocked,
|
|
133
|
+
triggerJobFunction: throwUnmocked,
|
|
128
134
|
...GlobalThis.tailor?.workflow,
|
|
129
135
|
wait: (key, payload) => {
|
|
130
136
|
waitCalls.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ContextInvoker } from \"#/runtime/context\";\nimport type { TailorInvoker } from \"#/runtime/types\";\nimport type { TriggerJobFunctionOptions } from \"#/runtime/workflow\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype WaitHandler = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => Promise<void> | void;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n triggerJobFunction: (\n jobName: string,\n args: unknown,\n options?: TriggerJobFunctionOptions,\n ) => unknown;\n wait?: (key: string, payload?: unknown) => unknown;\n resolve?: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n };\n context: {\n getInvoker: () => ContextInvoker | null;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.\n * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,\n * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param handler - Function that handles triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n wait: () => {\n throw new Error(\n \"tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n resolve: async () => {\n throw new Error(\n \"tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled\n * resolver/executor/workflow tests.\n * @deprecated With the `tailor-runtime` environment from `@tailor-platform/sdk/vitest`, drive the invoker via `vi.spyOn(globalThis.tailor.context, \"getInvoker\").mockReturnValue(...)` for bundled tests, or pass `invoker` directly to `.body()` when unit-testing resolvers/executors/workflow jobs against the TypeScript source.\n * @param invoker - The `TailorInvoker` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorInvoker): void {\n const raw: ContextInvoker | null = invoker\n ? {\n id: invoker.id,\n type: invoker.type,\n workspaceId: invoker.workspaceId,\n attributes: invoker.attributeList as string[],\n attributeMap: invoker.attributes as Record<string, unknown>,\n }\n : null;\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n context: {\n getInvoker: () => raw,\n },\n } as typeof GlobalThis.tailor;\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n * @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.\n * `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.\n * @param config - Optional handlers for wait and resolve calls.\n * @param config.onWait - Handler called when wait is invoked.\n * @param config.onResolve - Handler called when resolve is invoked.\n * @returns Object containing arrays of wait and resolve calls for assertions.\n */\nexport function setupWaitPointMock(config?: { onWait?: WaitHandler; onResolve?: ResolveHandler }): {\n waitCalls: { key: string; payload: unknown }[];\n resolveCalls: { executionId: string; key: string }[];\n} {\n const waitCalls: { key: string; payload: unknown }[] = [];\n const resolveCalls: { executionId: string; key: string }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: () => {\n throw new Error(\n \"tailor.workflow.triggerJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n wait: (key: string, payload?: unknown) => {\n waitCalls.push({ key, payload });\n return config?.onWait?.(key, payload);\n },\n resolve: async (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => {\n resolveCalls.push({ executionId, key });\n await config?.onResolve?.(executionId, key, callback);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { waitCalls, resolveCalls };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n * @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,\n * not the application's — verify your code through unit tests against the TypeScript source and\n * E2E tests against a deployed application instead. This export will be removed in a future release.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output, TailorUser } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport { WORKFLOW_TEST_ENV_KEY } from \"#/configure/services/workflow/job\";\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown) => {\n return Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n const nestedValue =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n // For nested array fields, recurse per element and pass through non-array values\n // (e.g. null/undefined for optional fields) so validation sees the original value.\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(nestedValue);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n user: unauthenticatedTailorUser,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;;AAwDA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,iBAAgC,CAAC,GAGjE;CACA,MAAM,kBAA0D,CAAC;CACjE,MAAM,iBAA2D,CAAC;CAElE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;GACjD,KAAK,SAAS;IAAE;IAAW,OAAO;GAAM;GACxC,eAAe,KAAK,KAAK,MAAM;EACjC;EAEA,MAAM,UAAyB,CAE/B;EAEA,MAAM,MAAqB;GACzB,KAAK,OAAO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AAW,IACnC,YAAY,KAAK,SAAS,WAAW,IAAI,CAAC,IAC1C;SAEJ,OAAO,OAAO,WAAW,WAAW;GAExC,OAAO,IAAI,MAAM,SAAS,OAAO,QAAQ;IACvC,OAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAQ,KAAiC;KACnC;KACN,MAAM;IACR,CAAC;IACD,IAAI,OAAO,gBAAgB,MACzB,OAAO,OAAO,OAAO,IAAI,CAAC,YAAY;GAE1C,OAAO,IAAI,QAAQ,OAAO,SAAS,UACjC,OAAO,OAAQ,KAAiC;GAElD,OAAO;EACT,GACA,CAAC,CACH;CACF;AACF;;;;;;;;;AAUA,SAAgB,qBAEd,YACA,MACA;CACA,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,KAAK;GACzB,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,MAAM;GACR,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ContextInvoker } from \"#/runtime/context\";\nimport type { TailorInvoker } from \"#/runtime/types\";\nimport type { ExecJobFunctionOptions } from \"#/runtime/workflow\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype WaitHandler = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => Promise<void> | void;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n execJobFunction: (\n jobName: string,\n args: unknown,\n options?: ExecJobFunctionOptions,\n ) => unknown;\n startJobFunction: (\n jobName: string,\n args: unknown,\n options?: ExecJobFunctionOptions,\n ) => unknown;\n triggerJobFunction: (\n jobName: string,\n args: unknown,\n options?: ExecJobFunctionOptions,\n ) => unknown;\n wait?: (key: string, payload?: unknown) => unknown;\n resolve?: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n };\n context: {\n getInvoker: () => ContextInvoker | null;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.execJobFunction` used in bundled workflow tests.\n * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,\n * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param handler - Function that handles triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\n\n const execJobFunction = (jobName: string, args: unknown): unknown => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n };\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n wait: () => {\n throw new Error(\n \"tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n resolve: async () => {\n throw new Error(\n \"tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n execJobFunction,\n startJobFunction: execJobFunction,\n triggerJobFunction: execJobFunction,\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled\n * resolver/executor/workflow tests.\n * @deprecated With the `tailor-runtime` environment from `@tailor-platform/sdk/vitest`, drive the invoker via `vi.spyOn(globalThis.tailor.context, \"getInvoker\").mockReturnValue(...)` for bundled tests, or pass `invoker` directly to `.body()` when unit-testing resolvers/executors/workflow jobs against the TypeScript source.\n * @param invoker - The `TailorInvoker` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorInvoker): void {\n const raw: ContextInvoker | null = invoker\n ? {\n id: invoker.id,\n type: invoker.type,\n workspaceId: invoker.workspaceId,\n attributes: invoker.attributeList as string[],\n attributeMap: invoker.attributes as Record<string, unknown>,\n }\n : null;\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n context: {\n getInvoker: () => raw,\n },\n } as typeof GlobalThis.tailor;\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n * @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.\n * `execJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.\n * @param config - Optional handlers for wait and resolve calls.\n * @param config.onWait - Handler called when wait is invoked.\n * @param config.onResolve - Handler called when resolve is invoked.\n * @returns Object containing arrays of wait and resolve calls for assertions.\n */\nexport function setupWaitPointMock(config?: { onWait?: WaitHandler; onResolve?: ResolveHandler }): {\n waitCalls: { key: string; payload: unknown }[];\n resolveCalls: { executionId: string; key: string }[];\n} {\n const waitCalls: { key: string; payload: unknown }[] = [];\n const resolveCalls: { executionId: string; key: string }[] = [];\n\n const throwUnmocked = (): never => {\n throw new Error(\n \"tailor.workflow.execJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n };\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n execJobFunction: throwUnmocked,\n startJobFunction: throwUnmocked,\n triggerJobFunction: throwUnmocked,\n ...GlobalThis.tailor?.workflow,\n wait: (key: string, payload?: unknown) => {\n waitCalls.push({ key, payload });\n return config?.onWait?.(key, payload);\n },\n resolve: async (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => {\n resolveCalls.push({ executionId, key });\n await config?.onResolve?.(executionId, key, callback);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { waitCalls, resolveCalls };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n * @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,\n * not the application's — verify your code through unit tests against the TypeScript source and\n * E2E tests against a deployed application instead. This export will be removed in a future release.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output, TailorUser } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport { WORKFLOW_TEST_ENV_KEY } from \"#/configure/services/workflow/job\";\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown) => {\n return Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n const nestedValue =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n // For nested array fields, recurse per element and pass through non-array values\n // (e.g. null/undefined for optional fields) so validation sees the original value.\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(nestedValue);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n user: unauthenticatedTailorUser,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;;AAkEA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,iBAAgC,CAAC,GAGjE;CACA,MAAM,kBAA0D,CAAC;CACjE,MAAM,iBAA2D,CAAC;CAElE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;GACjD,KAAK,SAAS;IAAE;IAAW,OAAO;GAAM;GACxC,eAAe,KAAK,KAAK,MAAM;EACjC;EAEA,MAAM,UAAyB,CAE/B;EAEA,MAAM,MAAqB;GACzB,KAAK,OAAO,QAAQ;EACtB;EAEA,MAAM,YAAY,OAAe,SAAoB,CAAC,GAAiC;GACrF,gBAAgB,KAAK;IAAE;IAAO;GAAO,CAAC;GACtC,OAAO,EAAE,MAAM,SAAS,OAAO,MAAM,EAAE;EACzC;CACF;CAEA,WAAW,WAAW,EACpB,QAAQ,mBACV;CAEA,OAAO;EAAE;EAAiB;CAAe;AAC3C;;;;;;;;;AAUA,SAAgB,kBAAkB,SAEhC;CACA,MAAM,gBAAsD,CAAC;CAE7D,MAAM,mBAAmB,SAAiB,SAA2B;EACnE,cAAc,KAAK;GAAE;GAAS;EAAK,CAAC;EACpC,OAAO,QAAQ,SAAS,IAAI;CAC9B;CAEA,WAAW,SAAS;EAClB,GAAG,WAAW;EACd,UAAU;GACR,YAAY;IACV,MAAM,IAAI,MACR,iGACF;GACF;GACA,SAAS,YAAY;IACnB,MAAM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ACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,KAAK;GACzB,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,MAAM;GACR,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
|
|
@@ -22,7 +22,7 @@ declare function setupTailordbMock(resolver?: QueryResolver): {
|
|
|
22
22
|
}[];
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
|
-
* Sets up a mock for `globalThis.tailor.workflow.
|
|
25
|
+
* Sets up a mock for `globalThis.tailor.workflow.execJobFunction` used in bundled workflow tests.
|
|
26
26
|
* `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,
|
|
27
27
|
* so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
|
|
28
28
|
* @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
@@ -50,7 +50,7 @@ declare function setupInvokerMock(invoker: TailorInvoker): void;
|
|
|
50
50
|
declare function setupTailorErrorsMock(): void;
|
|
51
51
|
/**
|
|
52
52
|
* Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
|
|
53
|
-
* `
|
|
53
|
+
* `execJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
|
|
54
54
|
* so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.
|
|
55
55
|
* @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
56
56
|
* `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-
|
|
1
|
+
import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-DraXTdqg.mjs";
|
|
2
2
|
import * as globals from "globals";
|
|
3
3
|
|
|
4
4
|
//#region src/vitest/environment.ts
|
package/dist/vitest/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getRegisteredWorkflow, i as getRegisteredJob, t as TRIGGER_DEFAULT, u as platformSerialize } from "../registry-
|
|
1
|
+
import { a as getRegisteredWorkflow, i as getRegisteredJob, t as TRIGGER_DEFAULT, u as platformSerialize } from "../registry-Ct0Wgxp1.mjs";
|
|
2
2
|
import { a as writeWorkflowTestEnv, i as readWorkflowTestEnv, n as buildJobContext, r as clearWorkflowTestEnv } from "../test-env-key-DuZycyWM.mjs";
|
|
3
3
|
import { t as assertDefined } from "../assert-DBxo8jPo.mjs";
|
|
4
4
|
import { i as withDispose, n as tailorRoot, r as tailordbRoot, t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
|
|
@@ -1314,10 +1314,10 @@ function replaceTrigger(definition) {
|
|
|
1314
1314
|
* Acquire a disposable mock for workflow operations (`tailor.workflow`).
|
|
1315
1315
|
* Restored on dispose.
|
|
1316
1316
|
*
|
|
1317
|
-
* Canonical names (`startWorkflow`, `
|
|
1318
|
-
* and their
|
|
1319
|
-
* share the same underlying `vi.fn`, so calls through
|
|
1320
|
-
* once and handlers configured on
|
|
1317
|
+
* Canonical names (`startWorkflow`, `execJobFunction`, `resumeWorkflowExecution`)
|
|
1318
|
+
* and their aliases (`triggerWorkflow`, `startJobFunction`, `triggerJobFunction`,
|
|
1319
|
+
* `resumeWorkflow`) share the same underlying `vi.fn`, so calls through any
|
|
1320
|
+
* name are recorded once and handlers configured on any name apply to all.
|
|
1321
1321
|
* @returns Disposable workflow mock control object
|
|
1322
1322
|
* @example
|
|
1323
1323
|
* ```typescript
|
|
@@ -1340,31 +1340,32 @@ function mockWorkflow() {
|
|
|
1340
1340
|
const workflowSpies = /* @__PURE__ */ new Map();
|
|
1341
1341
|
const waitPointMocks = /* @__PURE__ */ new Map();
|
|
1342
1342
|
const scopedMocks = /* @__PURE__ */ new Set();
|
|
1343
|
-
const
|
|
1343
|
+
const defaultExecJob = (jobName, args, _options) => {
|
|
1344
1344
|
const body = getRegisteredJob(jobName);
|
|
1345
1345
|
return body ? body(args, buildJobContext()) : null;
|
|
1346
1346
|
};
|
|
1347
1347
|
const defaultTriggerWorkflow = async (workflowName, args, _options) => {
|
|
1348
1348
|
const wf = getRegisteredWorkflow(workflowName);
|
|
1349
1349
|
if (wf) {
|
|
1350
|
-
const out =
|
|
1350
|
+
const out = execJobFunction(wf.mainJobName, platformSerialize(args));
|
|
1351
1351
|
if (out instanceof Promise) await out;
|
|
1352
1352
|
}
|
|
1353
1353
|
return TRIGGER_DEFAULT;
|
|
1354
1354
|
};
|
|
1355
1355
|
const defaultResumeWorkflow = async (executionId) => executionId;
|
|
1356
|
-
const
|
|
1356
|
+
const execJobFunction = vi.fn(defaultExecJob);
|
|
1357
1357
|
const triggerWorkflow = vi.fn(defaultTriggerWorkflow);
|
|
1358
1358
|
const resumeWorkflow = vi.fn(defaultResumeWorkflow);
|
|
1359
1359
|
const wait = vi.fn((_key, _payload) => null);
|
|
1360
1360
|
const resolve = vi.fn(async (_executionId, _key, _callback) => {});
|
|
1361
1361
|
const jobFunctionShim = (...call) => {
|
|
1362
|
-
const out = call.length >= 3 ?
|
|
1362
|
+
const out = call.length >= 3 ? execJobFunction(call[0], platformSerialize(call[1]), call[2]) : execJobFunction(call[0], platformSerialize(call[1]));
|
|
1363
1363
|
return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
|
|
1364
1364
|
};
|
|
1365
1365
|
const workflowShim = (...call) => call.length >= 3 ? triggerWorkflow(call[0], platformSerialize(call[1]), call[2]) : triggerWorkflow(call[0], platformSerialize(call[1]));
|
|
1366
1366
|
const resumeShim = (executionId) => resumeWorkflow(executionId);
|
|
1367
1367
|
root.workflow = {
|
|
1368
|
+
execJobFunction: jobFunctionShim,
|
|
1368
1369
|
startJobFunction: jobFunctionShim,
|
|
1369
1370
|
triggerJobFunction: jobFunctionShim,
|
|
1370
1371
|
startWorkflow: workflowShim,
|
|
@@ -1378,13 +1379,18 @@ function mockWorkflow() {
|
|
|
1378
1379
|
})
|
|
1379
1380
|
};
|
|
1380
1381
|
return withDispose({
|
|
1381
|
-
/** The `
|
|
1382
|
-
|
|
1382
|
+
/** The `execJobFunction` `vi.fn`. */
|
|
1383
|
+
execJobFunction,
|
|
1383
1384
|
/**
|
|
1384
|
-
*
|
|
1385
|
-
* @deprecated Use `
|
|
1385
|
+
* Alias of `execJobFunction` (same `vi.fn` reference).
|
|
1386
|
+
* @deprecated Use `execJobFunction` instead.
|
|
1386
1387
|
*/
|
|
1387
|
-
|
|
1388
|
+
startJobFunction: execJobFunction,
|
|
1389
|
+
/**
|
|
1390
|
+
* Frozen alias of `execJobFunction` (same `vi.fn` reference).
|
|
1391
|
+
* @deprecated Use `execJobFunction` instead.
|
|
1392
|
+
*/
|
|
1393
|
+
triggerJobFunction: execJobFunction,
|
|
1388
1394
|
/** The `startWorkflow` `vi.fn`. */
|
|
1389
1395
|
startWorkflow: triggerWorkflow,
|
|
1390
1396
|
/**
|
|
@@ -1466,29 +1472,29 @@ function mockWorkflow() {
|
|
|
1466
1472
|
* @param handler - Function returning a result for a job name, args, and options
|
|
1467
1473
|
*/
|
|
1468
1474
|
setJobHandler(handler) {
|
|
1469
|
-
|
|
1475
|
+
execJobFunction.mockImplementation((name, args, options) => handler(name, args, options));
|
|
1470
1476
|
},
|
|
1471
1477
|
/**
|
|
1472
|
-
* Enqueue a single result for the next `
|
|
1478
|
+
* Enqueue a single result for the next `execJobFunction` call (FIFO;
|
|
1473
1479
|
* takes priority over `setJobHandler`).
|
|
1474
1480
|
* @param result - Result to return from the next call
|
|
1475
1481
|
*/
|
|
1476
1482
|
enqueueResult(result) {
|
|
1477
|
-
|
|
1483
|
+
execJobFunction.mockImplementationOnce(() => result);
|
|
1478
1484
|
},
|
|
1479
1485
|
/**
|
|
1480
|
-
* Enqueue results for multiple subsequent `
|
|
1486
|
+
* Enqueue results for multiple subsequent `execJobFunction` calls (FIFO).
|
|
1481
1487
|
* @param results - Results to enqueue, one per upcoming call
|
|
1482
1488
|
*/
|
|
1483
1489
|
enqueueResults(...results) {
|
|
1484
|
-
for (const result of results)
|
|
1490
|
+
for (const result of results) execJobFunction.mockImplementationOnce(() => result);
|
|
1485
1491
|
},
|
|
1486
1492
|
/**
|
|
1487
|
-
* All jobs
|
|
1493
|
+
* All jobs executed via `execJobFunction`, in order.
|
|
1488
1494
|
* @returns Triggered jobs array
|
|
1489
1495
|
*/
|
|
1490
1496
|
get triggeredJobs() {
|
|
1491
|
-
return
|
|
1497
|
+
return execJobFunction.mock.calls.map(([jobName, args, options]) => ({
|
|
1492
1498
|
jobName,
|
|
1493
1499
|
args,
|
|
1494
1500
|
...options !== void 0 && { options }
|
|
@@ -1558,7 +1564,7 @@ function mockWorkflow() {
|
|
|
1558
1564
|
},
|
|
1559
1565
|
/** Clear recorded calls while preserving configured responses. */
|
|
1560
1566
|
clear() {
|
|
1561
|
-
|
|
1567
|
+
execJobFunction.mockClear();
|
|
1562
1568
|
triggerWorkflow.mockClear();
|
|
1563
1569
|
resumeWorkflow.mockClear();
|
|
1564
1570
|
wait.mockClear();
|
|
@@ -1567,8 +1573,8 @@ function mockWorkflow() {
|
|
|
1567
1573
|
},
|
|
1568
1574
|
/** Reset all workflow responses and recorded calls (keeps the mock installed). */
|
|
1569
1575
|
reset() {
|
|
1570
|
-
|
|
1571
|
-
|
|
1576
|
+
execJobFunction.mockReset();
|
|
1577
|
+
execJobFunction.mockImplementation(defaultExecJob);
|
|
1572
1578
|
triggerWorkflow.mockReset();
|
|
1573
1579
|
triggerWorkflow.mockImplementation(defaultTriggerWorkflow);
|
|
1574
1580
|
resumeWorkflow.mockReset();
|