feat(vitest): run a full workflow locally through .trigger()#1308
feat(vitest): run a full workflow locally through .trigger()#1308toiroakr wants to merge 5 commits into
Conversation
…ialize boundary .trigger() now routes through the installed tailor.workflow shim with a global job registry that runs real bodies by default, so a full workflow can run locally via mockWorkflow(). Trigger args and results cross a JSON-serialize boundary, surfacing non-serializable payloads as test failures the same way the platform would. A build-time TAILOR_PLATFORM_BUNDLE gate, applied across every function bundler, folds the test-only registry shim out of production bundles.
🦋 Changeset detectedLatest commit: 5c5c268 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
⚡ pkg.pr.new@tailor-platform/sdk@tailor-platform/create-sdk
|
…ds no mockWorkflow The tailor-runtime environment now installs a default tailor.workflow runner (registry execution + the JSON serialize boundary), so workflow.mainJob.trigger() runs the full chain locally without acquiring mockWorkflow(). mockWorkflow() now only overlays that default to override responses, set the env, assert on triggeredJobs, or drive wait/resolve. buildJobContext and WORKFLOW_TEST_ENV_KEY move to the vi-free test-env-key module so both the environment realm and the mock share them.
…n the JSON boundary .trigger() falls back to running the registered job/workflow body locally across the same JSON serialize boundary when no tailor.workflow shim is installed, so it works without the tailor-runtime environment and without mockWorkflow() while keeping the serialize boundary. The tailor-runtime default runner and this fallback share one runner core in registry.ts. Also hardens the boundary: align RegisteredJobBody context.invoker to optional (matching the public WorkflowJobContext), validate the deprecated env-var is a JSON object, throw a clear error when platformSerialize's root collapses to undefined, preserve triggerWorkflow call arity so a forwarded undefined options is recorded, and clarify the wait/resolve not-available message.
… a raw substring The TAILOR_PLATFORM_BUNDLE fold now uses an anchored regex (leading lookbehind rejecting a longer owner/identifier, trailing word boundary rejecting a longer key like _BUNDLE_MODE) instead of a raw replaceAll. rolldown exposes no `define` option, so a transform-level replace remains the mechanism; a unit test pins the precise-match behavior. The exact token appearing inside a string literal is accepted: it is an internal flag that never appears as a string in bundled function code, and substituting `true` there would be harmless anyway.
📖 Docs Consistency Check✅ No inconsistencies found between documentation and implementation. Checked AreasDocumentation Files:
Code Examples:
Implementation:
What Changed in This PRThe PR introduces the ability to run workflow jobs locally without
The documentation in
Minor Enhancement Opportunity (Optional)While not an inconsistency,
|
Summary
feat/using-mock(feat(vitest): expose mock controllers as using-friendly factories #1282).workflow.mainJob.trigger()runs thereal registered job bodies of a full workflow chain in a unit test with no
mockWorkflow()needed and no deployment. In thetailor-runtimeenvironmenta default
tailor.workflowrunner provides this; outside it,.trigger()fallsback to the same local runner — so it works with no env and no mock too.
non-serializable payload fails the test exactly as it would in production.
mockWorkflow()overlays the default runner only when you need to override jobswith
wf.setJobHandler(...)/wf.enqueueResult(...)(the rest still run theirreal bodies), set the env via
wf.setEnv(...), assert onwf.triggeredJobs, ordrive
wait/resolve.TAILOR_PLATFORM_BUNDLEgate, applied across every functionbundler (workflow, resolver, executor, auth, seed, migrate, query, tailordb
hooks, function), tree-shakes the test-only registry/serialize runner out of
production bundles so no unsubstituted
process.envreaches the Platform Webruntime. A bundler test asserts the gate folds it away.
testing.md"Running a full workflow locally" shows the no-mock flow.Notes
using mockWorkflow()factory API instead of the previous singleton mocks.