Skip to content

feat(vitest): route workflow trigger through globalThis mock#1188

Draft
toiroakr wants to merge 2 commits into
mainfrom
fix/workflow-boarder
Draft

feat(vitest): route workflow trigger through globalThis mock#1188
toiroakr wants to merge 2 commits into
mainfrom
fix/workflow-boarder

Conversation

@toiroakr
Copy link
Copy Markdown
Contributor

@toiroakr toiroakr commented May 18, 2026

Summary

  • Mirror the Platform JSON serialization boundary in wjob.trigger() / wf.trigger() so vitest catches NaN/Infinity/BigInt/class-instance payloads the same way the real Platform does.
  • Route both wjob.trigger() and wf.trigger() through globalThis.tailor.workflow.triggerJobFunction / triggerWorkflow, matching the existing wait/resolve mock pattern.
  • Add a globalThis-keyed registry (registerJob / registerWorkflow) so the mock can look up bodies by name across module instances; bodies are registered as a side effect of createWorkflowJob / createWorkflow. The registry module also exports a shared getPlatformWorkflow() shim used by both job.ts and workflow.ts.
  • Add platformSerialize utility (with tests) used at the mock boundary to validate payloads and strip top-level undefined; root-level function / symbol values throw a specific TypeError instead of a generic message.
  • Unify mockTriggerWorkflow: the main job is now invoked via mockTriggerJobFunction, so it appears in triggeredJobs and honors setJobHandler / enqueueResult uniformly with other jobs.
  • Update docs/testing.md to describe the new uniform behavior, the body-fallback for the Workflow Mock when no handler/result is configured, and the tailor-runtime environment requirement.

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
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 18, 2026

⚠️ No Changeset found

Latest commit: e6a77c8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

⚡ pkg.pr.new

@tailor-platform/sdk

pnpm add https://pkg.pr.new/@tailor-platform/sdk@e6a77c8
pnpm dlx https://pkg.pr.new/@tailor-platform/sdk@e6a77c8 --help

@tailor-platform/create-sdk

pnpm add https://pkg.pr.new/@tailor-platform/create-sdk@e6a77c8
pnpm dlx https://pkg.pr.new/@tailor-platform/create-sdk@e6a77c8 my-app

commit: e6a77c8

@github-actions

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
@github-actions
Copy link
Copy Markdown

Code Metrics Report (packages/sdk)

main (5d0f1b5) #1188 (3235f71) +/-
Coverage 61.8% 62.0% +0.2%
Code to Test Ratio 1:0.4 1:0.4 +0.0
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%)

Files Coverage +/- Status
packages/sdk/src/configure/services/workflow/job.ts 100.0% +16.6% modified
packages/sdk/src/configure/services/workflow/registry.ts 95.4% +95.4% added
packages/sdk/src/configure/services/workflow/workflow.ts 100.0% +66.6% modified
packages/sdk/src/utils/platform-serialize.ts 100.0% +100.0% added
packages/sdk/src/vitest/mock.ts 89.1% +1.2% modified

SDK Configure Bundle Size

main (5d0f1b5) #1188 (3235f71) +/-
configure-index-size 17KB 17.1KB 0.1KB
dependency-chunks-size 34.43KB 36.7KB 2.27KB
total-bundle-size 51.43KB 53.8KB 2.37KB

Runtime Performance

main (5d0f1b5) #1188 (3235f71) +/-
Generate Median 3,058ms 3,042ms -16ms
Generate Max 3,132ms 3,079ms -53ms
Apply Build Median 3,092ms 3,056ms -36ms
Apply Build Max 3,185ms 3,216ms 31ms

Type Performance (instantiations)

main (5d0f1b5) #1188 (3235f71) +/-
tailordb-basic 35,130 36,972 1,842
tailordb-optional 3,841 3,841 0
tailordb-relation 7,428 7,428 0
tailordb-validate 2,566 2,566 0
tailordb-hooks 5,767 5,767 0
tailordb-object 12,136 12,136 0
tailordb-enum 2,462 2,462 0
resolver-basic 9,424 9,424 0
resolver-nested 26,111 26,111 0
resolver-array 18,187 18,187 0
executor-schedule 4,234 4,234 0
executor-webhook 873 873 0
executor-record 8,166 8,166 0
executor-resolver 4,369 4,369 0
executor-operation-function 869 869 0
executor-operation-gql 869 869 0
executor-operation-webhook 888 888 0
executor-operation-workflow 1,714 1,714 0

Reported by octocov

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 workflowMock trigger/wait/resolve behavior to serialize payloads and optionally execute registered bodies.
  • Adds platformSerialize with 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.

Comment on lines +665 to +671
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 };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants