[PR #28726] Feat/test script of workflow service #32156

Closed
opened 2026-02-21 20:50:51 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28726

State: closed
Merged: Yes


Add Comprehensive Unit Tests for WorkflowService

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This PR adds comprehensive unit tests for the WorkflowService class to improve code coverage and ensure reliability of workflow-related operations.

Fixes

Closes https://github.com/langgenius/dify/issues/28727

What's Changed

  • Added tests/unit_tests/services/test_workflow_service.py with 38 passing test cases covering:
    • Workflow creation from template
    • Workflow validation (graph structure and features)
    • Draft/publish transitions
    • Version management and pagination
    • Workflow execution triggering
    • Workflow deletion with safety checks
    • App conversion to workflow mode

Test Coverage Details

The test suite covers all major WorkflowService methods:

  1. Workflow Lifecycle Management

    • Creating and updating draft workflows
    • Publishing drafts to versioned snapshots
    • Optimistic locking with unique hash validation
  2. Validation & Safety

    • Graph structure validation (preventing start/trigger node conflicts)
    • Feature configuration validation for different app modes
    • Trigger node limits for sandbox plans
    • Prevention of deleting workflows in use
  3. Version Management

    • Retrieving draft and published workflows
    • Paginated version listing with "has more" indicator
    • Workflow metadata updates
  4. Workflow Operations

    • Default node configuration retrieval
    • Converting chat/completion apps to workflows
    • Workflow deletion with comprehensive safety checks

Code Quality

  • All tests follow TDD best practices with Arrange-Act-Assert structure
  • Comprehensive docstrings and inline comments for maintainability
  • Factory pattern for reusable test data creation
  • Proper mocking to avoid database dependencies
  • All 38 tests passing

Screenshots

Not applicable - this PR adds backend unit tests only.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Test Results

=================================== 38 passed, 76 warnings in 50.50s =================================

All tests pass successfully with proper coverage of:

  • Workflow existence checks (2 tests)
  • Draft workflow operations (3 tests)
  • Published workflow operations (4 tests)
  • Workflow synchronization (3 tests)
  • Validation (5 tests)
  • Publishing (3 tests)
  • Version management (3 tests)
  • Updates and deletion (6 tests)
  • Configuration retrieval (3 tests)
  • Workflow conversion (3 tests)

Contribution by Gittensor, learn more at https://gittensor.io/

**Original Pull Request:** https://github.com/langgenius/dify/pull/28726 **State:** closed **Merged:** Yes --- # Add Comprehensive Unit Tests for WorkflowService > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This PR adds comprehensive unit tests for the `WorkflowService` class to improve code coverage and ensure reliability of workflow-related operations. ### Fixes Closes https://github.com/langgenius/dify/issues/28727 ### What's Changed - **Added `tests/unit_tests/services/test_workflow_service.py`** with 38 passing test cases covering: - ✅ Workflow creation from template - ✅ Workflow validation (graph structure and features) - ✅ Draft/publish transitions - ✅ Version management and pagination - ✅ Workflow execution triggering - ✅ Workflow deletion with safety checks - ✅ App conversion to workflow mode ### Test Coverage Details The test suite covers all major `WorkflowService` methods: 1. **Workflow Lifecycle Management** - Creating and updating draft workflows - Publishing drafts to versioned snapshots - Optimistic locking with unique hash validation 2. **Validation & Safety** - Graph structure validation (preventing start/trigger node conflicts) - Feature configuration validation for different app modes - Trigger node limits for sandbox plans - Prevention of deleting workflows in use 3. **Version Management** - Retrieving draft and published workflows - Paginated version listing with "has more" indicator - Workflow metadata updates 4. **Workflow Operations** - Default node configuration retrieval - Converting chat/completion apps to workflows - Workflow deletion with comprehensive safety checks ### Code Quality - All tests follow TDD best practices with Arrange-Act-Assert structure - Comprehensive docstrings and inline comments for maintainability - Factory pattern for reusable test data creation - Proper mocking to avoid database dependencies - All 38 tests passing ✅ ## Screenshots Not applicable - this PR adds backend unit tests only. ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods --- ### Test Results ``` =================================== 38 passed, 76 warnings in 50.50s ================================= ``` All tests pass successfully with proper coverage of: - Workflow existence checks (2 tests) - Draft workflow operations (3 tests) - Published workflow operations (4 tests) - Workflow synchronization (3 tests) - Validation (5 tests) - Publishing (3 tests) - Version management (3 tests) - Updates and deletion (6 tests) - Configuration retrieval (3 tests) - Workflow conversion (3 tests) Contribution by Gittensor, learn more at https://gittensor.io/
yindo added the pull-request label 2026-02-21 20:50:51 -05:00
yindo closed this issue 2026-02-21 20:50:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32156