Skip to content

Add workflow export functionality and update changelog#7357

Merged
sfmskywalker merged 11 commits intorelease/3.6.1from
bug/export-zip
Mar 11, 2026
Merged

Add workflow export functionality and update changelog#7357
sfmskywalker merged 11 commits intorelease/3.6.1from
bug/export-zip

Conversation

@sfmskywalker
Copy link
Copy Markdown
Member

@sfmskywalker sfmskywalker commented Mar 10, 2026

Purpose

Introduce a new workflow export interface and update the changelog.


Scope

Select one primary concern:

  • Bug fix (behavior change)
  • Refactor (no behavior change)
  • Documentation update
  • Formatting / code cleanup
  • Dependency / build update
  • New feature

Description

Problem

The existing workflow export function did not take into account invalid path characters.
Secondary problem: the Export endppoint was too big.

Solution

Implemented IWorkflowDefinitionExporter interface for exporting workflow definitions as JSON or ZIP archives while handling invalid filename characters.

Extracted export code to a separate service.


Verification

Steps:

  1. Use the export functionality in the application to generate JSON/ZIP archives.

Expected outcome: Exported files are correct.


Screenshots / Recordings (if applicable)


Commit Convention

We recommend using conventional commit prefixes:

  • fix: – Bug fixes (behavior change)
  • feat: – New features
  • refactor: – Code changes without behavior change
  • docs: – Documentation updates
  • chore: – Maintenance, tooling, or dependency updates
  • test: – Test additions or modifications

Clear commit messages make reviews easier and history more meaningful.


Checklist

  • The PR is focused on a single concern
  • Commit messages follow the recommended convention
  • Tests added or updated (if applicable)
  • Documentation updated (if applicable)
  • No unrelated cleanup included
  • All tests pass

Introduced `IWorkflowDefinitionExporter` interface and its implementation to export workflow definitions as JSON or ZIP archives. Simplified `Export` endpoint logic by utilizing the new exporter service. Updated package version to 3.6.1.
@sfmskywalker sfmskywalker changed the base branch from main to release/3.6.1 March 10, 2026 20:23
@sfmskywalker sfmskywalker requested a review from Copilot March 10, 2026 20:24
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 10, 2026

Greptile Summary

This PR extracts the workflow export logic from the API endpoint into a dedicated WorkflowDefinitionExporter service behind the new IWorkflowDefinitionExporter interface, fixing a bug where invalid path characters in workflow names could corrupt exported filenames (e.g. a workflow named folder/child would produce a ZIP entry with a / in its name, creating a nested path inside the archive instead of a flat file).

Key changes:

  • New IWorkflowDefinitionExporter interface with methods for exporting single (ExportAsync) and multiple (ExportManyAsync) workflow definitions, plus lower-level ExportDefinitionAsync/ExportDefinitionsAsync methods that accept already-loaded entities.
  • New WorkflowDefinitionExporter service implementing the above interface, including a SanitizeFileName helper that replaces invalid filename characters with -, with an explicit backslash check for cross-platform correctness (Linux does not include \ in Path.GetInvalidFileNameChars()).
  • WorkflowManagementFeature registers the new service alongside the existing WorkflowDefinitionImporter.
  • The export API endpoint is significantly simplified — all business logic now delegates to IWorkflowDefinitionExporter.
  • A regression test (WorkflowDefinitionExporterRegressionTests) verifies the slash-in-name fix, though it is placed in WorkflowReferenceGraphBuilderTests.cs rather than the dedicated (empty) WorkflowDefinitionExporterTests.cs file.
  • Version bump to 3.6.1 and changelog updates for the EF Core package rename breaking change.

Confidence Score: 4/5

  • This PR is safe to merge — it is a clean refactor with a targeted bug fix, backed by a regression test, and introduces no breaking API changes.
  • The core bug fix (invalid filename characters) is correct and well-tested. The refactoring faithfully preserves all previous export behavior (JSON for single, ZIP for multiple, consumer inclusion logic, deterministic timestamps). Minor style issues exist: a redundant interface overload and a misplaced/empty test file, but neither affects correctness or runtime behavior.
  • No files require special attention for correctness. WorkflowDefinitionExporterTests.cs and IWorkflowDefinitionExporter.cs have minor organization/design issues worth a follow-up.

Important Files Changed

Filename Overview
src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionExporter.cs New service implementing IWorkflowDefinitionExporter; extraction of all export logic from the API endpoint. Filename sanitization correctly handles cross-platform invalid characters (including explicit backslash check for Linux). ZIP creation preserves deterministic timestamps. No functional issues found.
src/modules/Elsa.Workflows.Management/Contracts/IWorkflowDefinitionExporter.cs New interface for exporting workflow definitions. Contains a redundant 3-parameter ExportAsync overload that is a pure delegation wrapper for the 4-parameter overload, unnecessarily increasing interface surface area for implementors and mocks.
src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Export/Endpoint.cs Endpoint significantly simplified by delegating all export logic to IWorkflowDefinitionExporter. Clean refactor with correct handling of not-found (404) and no-content (204) cases.
src/modules/Elsa.Workflows.Management/Models/WorkflowDefinitionExportResult.cs Simple record type holding binary export data and a suggested filename. Clean, minimal, no issues.
src/modules/Elsa.Workflows.Management/Features/WorkflowManagementFeature.cs One-line addition registering WorkflowDefinitionExporter as a scoped service for IWorkflowDefinitionExporter. Correct placement alongside the analogous WorkflowDefinitionImporter registration.
test/unit/Elsa.Workflows.Management.UnitTests/Services/WorkflowDefinitionExporterTests.cs File is essentially empty — contains only a comment redirecting to WorkflowReferenceGraphBuilderTests.cs, where the actual WorkflowDefinitionExporterRegressionTests class lives. This breaks the naming convention and will mislead developers looking for exporter tests.
test/unit/Elsa.Workflows.Management.UnitTests/Services/WorkflowReferenceGraphBuilderTests.cs Existing graph builder tests unchanged. A new WorkflowDefinitionExporterRegressionTests class was appended, covering the slash-in-name regression. The test is well-constructed and correctly verifies that ZIP entries are flat (no path separators in entry names).

Sequence Diagram

sequenceDiagram
    participant Client
    participant ExportEndpoint as Export Endpoint
    participant Exporter as WorkflowDefinitionExporter
    participant Store as IWorkflowDefinitionStore
    participant GraphBuilder as IWorkflowReferenceGraphBuilder
    participant Mapper as WorkflowDefinitionMapper

    alt Single definition export (DefinitionId provided)
        Client->>ExportEndpoint: GET /export?definitionId=X&includeConsumingWorkflows=false
        ExportEndpoint->>Exporter: ExportAsync(definitionId, versionOptions, includeConsumingWorkflows)
        Exporter->>Store: FindManyAsync({DefinitionId, VersionOptions})
        Store-->>Exporter: WorkflowDefinition or null
        alt Definition not found
            Exporter-->>ExportEndpoint: null
            ExportEndpoint-->>Client: 404 Not Found
        else Found, no consumers
            Exporter->>Mapper: MapAsync(definition)
            Mapper-->>Exporter: WorkflowDefinitionModel
            Exporter->>Exporter: SerializeWorkflowDefinitionAsync (adds $schema header)
            Exporter->>Exporter: GetFileName → SanitizeFileName
            Exporter-->>ExportEndpoint: WorkflowDefinitionExportResult(json, filename.json)
            ExportEndpoint-->>Client: 200 application/octet-stream (JSON file)
        else Found, include consumers
            Exporter->>GraphBuilder: BuildGraphAsync([definitionId])
            GraphBuilder-->>Exporter: WorkflowReferenceGraph
            Exporter->>Store: FindManyAsync({DefinitionIds, Latest})
            Store-->>Exporter: Consumer definitions
            Exporter->>Exporter: CreateZipArchiveAsync (deterministic ZIP epoch)
            Exporter-->>ExportEndpoint: WorkflowDefinitionExportResult(zip, workflow-definitions.zip)
            ExportEndpoint-->>Client: 200 application/octet-stream (ZIP file)
        end
    else Multiple definitions export (Ids provided)
        Client->>ExportEndpoint: GET /export?ids=A,B,C
        ExportEndpoint->>Exporter: ExportManyAsync(ids, includeConsumingWorkflows)
        Exporter->>Store: FindManyAsync({Ids})
        Store-->>Exporter: List of WorkflowDefinitions
        alt No definitions found
            Exporter-->>ExportEndpoint: null
            ExportEndpoint-->>Client: 204 No Content
        else Definitions found
            opt includeConsumingWorkflows
                Exporter->>GraphBuilder: BuildGraphAsync(definitionIds)
                GraphBuilder-->>Exporter: WorkflowReferenceGraph
                Exporter->>Store: FindManyAsync consumer definitions
            end
            Exporter->>Exporter: CreateZipArchiveAsync
            Exporter-->>ExportEndpoint: WorkflowDefinitionExportResult(zip, workflow-definitions.zip)
            ExportEndpoint-->>Client: 200 application/octet-stream (ZIP file)
        end
    end
Loading

Last reviewed commit: 542daf2

Comment thread src/modules/Elsa.Workflows.Management/Contracts/IWorkflowDefinitionExporter.cs Outdated
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

Introduces a dedicated workflow definition export service in Elsa.Workflows.Management, used by the workflow export API endpoint, to support exporting JSON/ZIP while sanitizing invalid filename characters. Also adds a regression test for ZIP entry naming and bumps the package workflow base version.

Changes:

  • Added IWorkflowDefinitionExporter + WorkflowDefinitionExporter to export workflow definitions as JSON or ZIP with filename sanitization.
  • Refactored the WorkflowDefinitions Export endpoint to delegate export logic to the new exporter service.
  • Added a regression test for ZIP exports with workflow names containing path separators; bumped GitHub Actions base_version to 3.6.1.

Reviewed changes

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

Show a summary per file
File Description
src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionExporter.cs New exporter implementation (JSON + deterministic ZIP generation + filename sanitization).
src/modules/Elsa.Workflows.Management/Contracts/IWorkflowDefinitionExporter.cs New public export contract for single/multi export.
src/modules/Elsa.Workflows.Management/Models/WorkflowDefinitionExportResult.cs New result model for binary export payload + suggested filename.
src/modules/Elsa.Workflows.Management/Features/WorkflowManagementFeature.cs Registers the exporter in DI.
src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Export/Endpoint.cs Simplifies endpoint by delegating export work to the exporter service.
test/unit/Elsa.Workflows.Management.UnitTests/Services/WorkflowReferenceGraphBuilderTests.cs Adds regression test validating sanitized ZIP entry names.
test/unit/Elsa.Workflows.Management.UnitTests/Services/WorkflowDefinitionExporterTests.cs Adds a placeholder comment file referencing where tests live.
.github/workflows/packages.yml Bumps base_version from 3.6.0 to 3.6.1.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread .github/workflows/packages.yml
Comment thread src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionExporter.cs Outdated
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 10 out of 11 changed files in this pull request and generated 4 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionExporter.cs Outdated
Comment thread .github/workflows/packages.yml
Comment thread src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionExporter.cs Outdated
sfmskywalker and others added 2 commits March 11, 2026 10:21
…FileNameSanitizerTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sfmskywalker sfmskywalker requested a review from FransVanEk March 11, 2026 10:15
@sfmskywalker sfmskywalker merged commit a0f0a3c into release/3.6.1 Mar 11, 2026
6 of 7 checks passed
@sfmskywalker sfmskywalker deleted the bug/export-zip branch March 11, 2026 16:20
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.

3 participants