Skip to content

Typescript SDK Integration#55

Open
lornakelly wants to merge 5 commits intoserverlessworkflow:mainfrom
lornakelly:43/sdk-integration
Open

Typescript SDK Integration#55
lornakelly wants to merge 5 commits intoserverlessworkflow:mainfrom
lornakelly:43/sdk-integration

Conversation

@lornakelly
Copy link
Copy Markdown
Contributor

@lornakelly lornakelly commented Apr 1, 2026

Closes: #43

Summary

This PR integrates the @serverlessworkflow/sdk package into the diagram editor and creates an abstraction layer that isolates SDK dependencies and provides type-safe workflow parsing and validation.

Changes

  • Added @serverlessworkflow/sdk and js-yaml dependencies to the project
  • Created workflowSdk.ts abstraction layer with validateWorkflow() and parseWorkflow() functions
  • Implemented type-safe error handling using WorkflowParseResult
  • Added integration tests to cover valid, invalid, and edge-case inputs in both YAML and JSON formats
  • Created test fixtures with valid/invalid workflows in YAML and JSON formats
  • Updated core module documentation explaining the abstraction layer's purpose
  • Added __snapshots__ to .rat-excludes to exclude generated snapshot files from license header checks

Signed-off-by: Lorna-Kelly <lornakelly88@gmail.com>
Signed-off-by: Lorna-Kelly <lornakelly88@gmail.com>
Copilot AI review requested due to automatic review settings April 1, 2026 08:09
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 integrates the @serverlessworkflow/sdk package into the diagram editor as specified in issue #43. The integration creates a lightweight abstraction layer that isolates SDK dependencies and provides type-safe workflow parsing and validation capabilities. This decouples the diagram editor from SDK-specific implementation details, making it easier to adapt as the specification evolves.

Changes:

  • Added @serverlessworkflow/sdk (v1.0.1) as a production dependency with a thin abstraction layer
  • Implemented three core functions: deserializeWorkflow(), validateWorkflow(), and parseWorkflow() for workflow processing
  • Introduced WorkflowParseResult discriminated union type for type-safe error handling
  • Added comprehensive unit tests covering success and error scenarios for all functions
  • Created test fixtures with valid and invalid workflow examples in both YAML and JSON formats
  • Updated core module documentation to explain the abstraction layer's purpose

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pnpm-workspace.yaml Added @serverlessworkflow/sdk v1.0.1 to the shared catalog
pnpm-lock.yaml Updated lock file with SDK and its dependencies (ajv, js-yaml, etc.)
src/core/workflowSdk.ts New abstraction layer providing SDK-independent workflow operations
src/core/index.ts Updated to export the new SDK abstraction functions
src/core/README.md Added documentation for the workflowSdk module
tests/core/workflowSdk.test.ts Comprehensive unit tests for all three functions with mocked SDK
tests/fixtures/workflows.ts Test fixtures containing valid and invalid workflow definitions
package.json Added @serverlessworkflow/sdk as a production dependency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Lorna-Kelly <lornakelly88@gmail.com>
@lornakelly lornakelly force-pushed the 43/sdk-integration branch from b65b667 to 8255eb2 Compare April 1, 2026 09:29
Copilot AI review requested due to automatic review settings April 1, 2026 09:29
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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

pnpm-workspace.yaml:10

  • The PR description states "Added lint config to ignore lock yaml file as oxlint doesnt support it", but no changes to lint configuration files are visible in the provided diffs. Verify whether this change was intended or if the description is inaccurate.
packages:
  - packages/*
catalog:
  "@chromatic-com/storybook": ^5.0.1
  "@serverlessworkflow/sdk": ^1.0.1
  "@storybook/addon-a11y": ^10.2.19
  "@storybook/addon-docs": ^10.2.19
  "@storybook/addon-vitest": ^10.2.19
  "@storybook/react-vite": ^10.2.19
  "@testing-library/dom": ^10.4.1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@fantonangeli fantonangeli left a comment

Choose a reason for hiding this comment

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

Thanks a lot @lornakelly , I wrote a few comments regarding the tests

} from "../fixtures/workflows";
import { Classes, validate } from "@serverlessworkflow/sdk";

vi.mock("@serverlessworkflow/sdk", () => ({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are unit tests, and the mocks are useful to verify that we call the SDK correctly
However there is the mock and, if the SDK introduces a bug, we don't have a failing test.
Do you agree to also add a couple of tests, using the real SDK without the mock, but also keeping the mocked tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was thinking of this but ultimately decided that calling the sdk directly is more of an integration test than unit so stuck with simple unit tests for a start. I agree though, ill add a few tests that call the sdk directly as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As part of refactor, replaced unit tests with integration tests

mockValidate.mockReturnValue(undefined);
const result = parseWorkflow(BASIC_VALID_WORKFLOW_JSON);
expect(result.success).toBe(true);
if (result.success) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

result.success is already checked by the expect.
The same for the tests below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The if block is for typescript, not the test itself, i cant access result.workflow without it. Is there a better way you know of? Otherwise, I can add a comment to make it clearer though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Totally true, I was trying locally.
But I'm worried that if someone accidentally remove:

expect(result.success).toBe(true);

There is a possibility that the test doesn't enter the if.
As a solution, I just tried:

    expect(result).toMatchObject({
      success: true,
      workflow: JSON.parse(BASIC_VALID_WORKFLOW_JSON)
    });

Also using snapshots, which helps with big objects for other tests, and vitest will automatically maintain them:

    expect(result).toMatchSnapshot();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used snapshots in integration tests, thanks for the suggestion!

@lornakelly lornakelly removed the request for review from handreyrc April 2, 2026 14:10
Signed-off-by: Lorna-Kelly <lornakelly88@gmail.com>
Copilot AI review requested due to automatic review settings April 3, 2026 09:58
@lornakelly lornakelly force-pushed the 43/sdk-integration branch from 547bf9a to af67060 Compare April 3, 2026 09:58
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

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…rialize

Signed-off-by: Lorna-Kelly <lornakelly88@gmail.com>
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

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

feat: Integrate TypeScript SDK (spec 1.0) into diagram editor

4 participants