Add workflow export functionality and update changelog#7357
Add workflow export functionality and update changelog#7357sfmskywalker merged 11 commits intorelease/3.6.1from
Conversation
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.
Greptile SummaryThis PR extracts the workflow export logic from the API endpoint into a dedicated Key changes:
Confidence Score: 4/5
|
| 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
Last reviewed commit: 542daf2
There was a problem hiding this comment.
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+WorkflowDefinitionExporterto 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_versionto 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.
…er` and its implementation in `WorkflowDefinitionExporter`.
…sion tests are covered in `WorkflowReferenceGraphBuilderTests`.
…ionExporter.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…WorkflowDefinitionExporter` to use it. Implement unit tests for the sanitizer.
…initionExporterRegressionTests`.
There was a problem hiding this comment.
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.
…icate ID from JSON file names.
…FileNameSanitizerTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Purpose
Introduce a new workflow export interface and update the changelog.
Scope
Select one primary concern:
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
IWorkflowDefinitionExporterinterface for exporting workflow definitions as JSON or ZIP archives while handling invalid filename characters.Extracted export code to a separate service.
Verification
Steps:
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 featuresrefactor:– Code changes without behavior changedocs:– Documentation updateschore:– Maintenance, tooling, or dependency updatestest:– Test additions or modificationsClear commit messages make reviews easier and history more meaningful.
Checklist