Skip to content

feat: add local testing support for workflows#478

Merged
toiroakr merged 4 commits intomainfrom
feat/workflow-local-test
Jan 26, 2026
Merged

feat: add local testing support for workflows#478
toiroakr merged 4 commits intomainfrom
feat/workflow-local-test

Conversation

@toiroakr
Copy link
Copy Markdown
Contributor

@toiroakr toiroakr commented Jan 25, 2026

Summary

  • createWorkflowJob: .trigger() now executes body directly for local testing
  • createWorkflow: .trigger() now calls mainJob.trigger() for local testing
  • Export WORKFLOW_TEST_ENV_KEY from @tailor-platform/sdk/test for env configuration
  • Add workflow trigger test examples to testing template

Usage

import { WORKFLOW_TEST_ENV_KEY } from "@tailor-platform/sdk/test";
import { vi, test, afterEach } from "vitest";

afterEach(() => {
  vi.unstubAllEnvs();
});

// Unit test with mocked dependent jobs
test("workflow with mocks", async () => {
  vi.spyOn(addNumbers, "trigger").mockResolvedValue(7);
  const result = await workflow.mainJob.body({ a: 3, b: 4 }, { env: {} });
  expect(result).toBe(21);
});

// Integration test (all jobs execute)
test("workflow integration", async () => {
  vi.stubEnv(WORKFLOW_TEST_ENV_KEY, JSON.stringify({ NODE_ENV: "test" }));
  const result = await workflow.trigger({ a: 3, b: 4 });
  expect(result).toBe(21);
});

Test plan

  • Unit tests pass for individual jobs using .body()
  • Integration tests pass for workflow using .trigger()
  • Existing tests continue to pass

🤖 Generated with Claude Code


Open with Devin

- createWorkflowJob: .trigger() executes body directly for local testing
- createWorkflow: .trigger() calls mainJob.trigger() for local testing
- Export WORKFLOW_TEST_ENV_KEY from @tailor-platform/sdk/test
- Add workflow trigger test examples to testing template

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@toiroakr toiroakr requested a review from remiposo as a code owner January 25, 2026 04:20
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 25, 2026

🦋 Changeset detected

Latest commit: 1e38927

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@tailor-platform/sdk Minor
@tailor-platform/create-sdk Minor

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
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/tailor-platform/sdk/@tailor-platform/create-sdk@478

commit: 1e38927

@github-actions

This comment has been minimized.

Add documentation for testing workflows locally:
- Job unit tests with .body()
- Mocking dependent jobs with vi.spyOn()
- Integration tests with .trigger() and WORKFLOW_TEST_ENV_KEY

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

View issues and 4 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/sdk/src/configure/services/workflow/workflow.ts Outdated
Comment on lines +40 to +41
trigger: async (args) => {
return await config.mainJob.trigger(...([args] as unknown as []));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 options parameter with authInvoker is silently ignored in local testing

The new trigger implementation ignores the options parameter, which contains authInvoker for authentication context.

Click to expand

Interface declares options parameter

At workflow.ts:15-18:

trigger: (
  args: Parameters<Job["trigger"]>[0],
  options?: { authInvoker: AuthInvoker<string> },
) => Promise<string>;

Implementation ignores it

At workflow.ts:40:

trigger: async (args) => {  // 'options' not captured

Impact

If a user writes code like:

await workflow.trigger({ id: 1 }, { authInvoker: auth.invoker("admin") });

In local testing, the authInvoker is silently ignored. In production (after bundler transformation), it's used by tailor.workflow.triggerWorkflow(). This behavioral difference could mask authentication-related bugs during local testing.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 8 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/create-sdk/templates/testing/src/workflow/trigger.test.ts
Update integration test example to use workflow.mainJob.trigger()
instead of workflow.trigger() to get the actual result.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Code Metrics Report (packages/sdk)

main (e2c5e83) #478 (55173b4) +/-
Coverage 47.5% 47.5% -0.1%
Code to Test Ratio 1:0.3 1:0.3 0.0
Details
  |                    | main (e2c5e83) | #478 (55173b4) |  +/-  |
  |--------------------|----------------|----------------|-------|
- | Coverage           |          47.5% |          47.5% | -0.1% |
  |   Files            |            182 |            182 |     0 |
  |   Lines            |           5199 |           5202 |    +3 |
+ |   Covered          |           2473 |           2474 |    +1 |
  | Code to Test Ratio |          1:0.3 |          1:0.3 |   0.0 |
  |   Code             |          28822 |          28822 |     0 |
  |   Test             |           9735 |           9735 |     0 |

Code coverage of files in pull request scope (57.1% → 50.0%)

Files Coverage +/- Status
packages/sdk/src/configure/services/workflow/job.ts 57.1% -2.9% modified
packages/sdk/src/configure/services/workflow/workflow.ts 33.3% -16.7% modified

SDK Configure Bundle Size

main (e2c5e83) #478 (55173b4) +/-
configure-index-size 4.86KB 5KB 0.14KB
dependency-chunks-size 24.33KB 24.62KB 0.29KB
total-bundle-size 29.19KB 29.62KB 0.43KB

Runtime Performance

main (e2c5e83) #478 (55173b4) +/-
Generate Median 2,423ms 2,254ms -169ms
Generate Max 2,613ms 2,285ms -328ms
Apply Build Median 2,641ms 2,463ms -178ms
Apply Build Max 2,693ms 2,495ms -198ms

Type Performance (instantiations)

main (e2c5e83) #478 (55173b4) +/-
tailordb-basic 133,470 133,486 16
tailordb-optional 5,249 5,249 0
tailordb-relation 5,122 5,122 0
tailordb-validate 4,013 4,013 0
tailordb-hooks 7,166 7,166 0
tailordb-object 12,953 12,953 0
tailordb-enum 3,881 3,881 0
resolver-basic 13,789 13,789 0
resolver-nested 30,536 30,536 0
resolver-array 22,580 22,580 0
executor-schedule 11,233 11,233 0
executor-webhook 7,791 7,791 0
executor-record 12,436 12,436 0
executor-resolver 14,959 14,959 0
executor-operation-function 7,769 7,769 0
executor-operation-gql 7,772 7,772 0
executor-operation-webhook 7,785 7,785 0
executor-operation-workflow 9,058 9,058 0

Reported by octocov

Copy link
Copy Markdown
Contributor

@remiposo remiposo left a comment

Choose a reason for hiding this comment

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

LGTM

@toiroakr toiroakr merged commit dce0040 into main Jan 26, 2026
19 checks passed
@toiroakr toiroakr deleted the feat/workflow-local-test branch January 26, 2026 04:30
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