feat(vitest): route workflow trigger through globalThis mock#1188
feat(vitest): route workflow trigger through globalThis mock#1188toiroakr wants to merge 2 commits into
Conversation
Mirror the Platform JSON serialization boundary in workflow mocks so tests catch invalid payloads (NaN/Infinity/BigInt/class instances) the same way the real Platform does. Both wjob.trigger() and wf.trigger() now delegate to globalThis.tailor.workflow.triggerJobFunction / triggerWorkflow, matching the wait/resolve pattern. - Add platformSerialize utility validating JSON-boundary safety - Introduce a globalThis-keyed registry so the mock can look up job and workflow bodies by name across module instances - Route wf.trigger() through mockTriggerJobFunction so main-job invocations are recorded in triggeredJobs and honor setJobHandler / enqueueResult uniformly
|
⚡ pkg.pr.new@tailor-platform/sdk@tailor-platform/create-sdk
|
This comment has been minimized.
This comment has been minimized.
…ialize errors - Move getPlatformWorkflow() into registry.ts so job.ts / workflow.ts share one shim - Note body fallback behaviour in the Workflow Mock docs section - Throw specific TypeError messages for root-level function / symbol in platformSerialize
Code Metrics Report (packages/sdk)
Details | | main (5d0f1b5) | #1188 (3235f71) | +/- |
|--------------------|----------------|-----------------|-------|
+ | Coverage | 61.8% | 62.0% | +0.2% |
| Files | 362 | 364 | +2 |
| Lines | 12638 | 12698 | +60 |
+ | Covered | 7818 | 7881 | +63 |
+ | Code to Test Ratio | 1:0.4 | 1:0.4 | +0.0 |
| Code | 82717 | 83111 | +394 |
+ | Test | 34475 | 34729 | +254 |Code coverage of files in pull request scope (87.0% → 90.5%)
SDK Configure Bundle Size
Runtime Performance
Type Performance (instantiations)
Reported by octocov |
There was a problem hiding this comment.
Pull request overview
This PR updates Vitest workflow mocking to route workflow/job triggers through the injected globalThis.tailor.workflow mock and better emulate Platform JSON serialization boundaries.
Changes:
- Adds a shared workflow/job registry and
getPlatformWorkflow()shim for local mock delegation. - Updates
workflowMocktrigger/wait/resolve behavior to serialize payloads and optionally execute registered bodies. - Adds
platformSerializewith tests and updates workflow testing documentation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/sdk/src/vitest/mock.ts |
Routes trigger calls through registered workflow/job bodies and serializes workflow mock payloads. |
packages/sdk/src/vitest/__tests__/mock.test.ts |
Adds async workflow delegation and serialization boundary tests. |
packages/sdk/src/vitest/__tests__/integration/vitest.config.ts |
Adds @/ alias for integration test resolution. |
packages/sdk/src/utils/platform-serialize.ts |
Adds JSON-boundary validation/round-trip helper. |
packages/sdk/src/utils/platform-serialize.test.ts |
Covers serialization success and rejection cases. |
packages/sdk/src/configure/services/workflow/workflow.ts |
Registers workflows and routes .trigger() to platform workflow shim. |
packages/sdk/src/configure/services/workflow/registry.ts |
Adds global registry and workflow shim lookup. |
packages/sdk/src/configure/services/workflow/job.ts |
Registers job bodies and routes .trigger() to platform workflow shim. |
packages/sdk/docs/testing.md |
Documents the new mock fallback and runtime environment requirement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let env: TailorEnv = {} as TailorEnv; | ||
| try { | ||
| env = JSON.parse(process.env[WORKFLOW_TEST_ENV_KEY] || "{}"); | ||
| } catch { | ||
| // Malformed env JSON: leave env as the empty object so the test can still run. | ||
| } | ||
| return { env, invoker: null }; |
Summary
wjob.trigger()/wf.trigger()so vitest catches NaN/Infinity/BigInt/class-instance payloads the same way the real Platform does.wjob.trigger()andwf.trigger()throughglobalThis.tailor.workflow.triggerJobFunction/triggerWorkflow, matching the existing wait/resolve mock pattern.registerJob/registerWorkflow) so the mock can look up bodies by name across module instances; bodies are registered as a side effect ofcreateWorkflowJob/createWorkflow. The registry module also exports a sharedgetPlatformWorkflow()shim used by bothjob.tsandworkflow.ts.platformSerializeutility (with tests) used at the mock boundary to validate payloads and strip top-levelundefined; root-levelfunction/symbolvalues throw a specific TypeError instead of a generic message.mockTriggerWorkflow: the main job is now invoked viamockTriggerJobFunction, so it appears intriggeredJobsand honorssetJobHandler/enqueueResultuniformly with other jobs.docs/testing.mdto describe the new uniform behavior, the body-fallback for the Workflow Mock when no handler/result is configured, and thetailor-runtimeenvironment requirement.