[PR #28604] Feat/test workflow models #32103

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

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

State: closed
Merged: Yes


Add Comprehensive Unit Tests for Workflow Models

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 implements comprehensive unit tests for workflow models in api/tests/unit_tests/models/test_workflow_models.py.

Fixes

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

Test Coverage (38 tests total)

1. Workflow Model Validation (8 tests)

  • Workflow creation with required fields
  • WorkflowType enum validation and value_of method
  • Graph and features JSON parsing
  • Marked name and comment handling
  • VERSION_DRAFT constant validation

2. WorkflowRun State Transitions (13 tests)

  • Creation with required fields
  • State transitions: running → succeeded/failed/stopped/paused
  • Paused state resumption (paused → running)
  • Partial-succeeded status with exceptions count
  • Inputs/outputs JSON handling
  • Graph preservation across workflow runs
  • Serialization (to_dict) and deserialization (from_dict)

3. NodeExecution Relationships (10 tests)

  • Node execution creation with workflow_run_id
  • Predecessor node relationships
  • Single-step debugging (no workflow_run_id)
  • Inputs, outputs, and process_data handling
  • Status transitions with elapsed time tracking
  • Error handling and metadata
  • Different node types (START, LLM, CODE, TOOL, IF_ELSE, END)

4. Graph Configuration Validation (7 tests)

  • Complex graph structures with nodes and edges
  • Empty graph configuration
  • Complex nested node data structures
  • Conditional branching (if-else with sourceHandle)
  • Loop/iteration structures
  • Null value handling for graph/inputs/outputs
  • Graph preservation across WorkflowRun instances

Key Features

  • All tests follow Arrange-Act-Assert pattern
  • Comprehensive coverage of workflow lifecycle and state transitions
  • Edge cases handled (null values, empty collections)
  • Type-safe with proper enum usage
  • Concise docstrings and inline comments
  • All 38 tests passing

Screenshots

Not applicable - 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

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

**Original Pull Request:** https://github.com/langgenius/dify/pull/28604 **State:** closed **Merged:** Yes --- # Add Comprehensive Unit Tests for Workflow Models > [!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 implements comprehensive unit tests for workflow models in `api/tests/unit_tests/models/test_workflow_models.py`. ### Fixes Closes https://github.com/langgenius/dify/issues/28603 ### Test Coverage (38 tests total) **1. Workflow Model Validation (8 tests)** - Workflow creation with required fields - WorkflowType enum validation and value_of method - Graph and features JSON parsing - Marked name and comment handling - VERSION_DRAFT constant validation **2. WorkflowRun State Transitions (13 tests)** - Creation with required fields - State transitions: running → succeeded/failed/stopped/paused - Paused state resumption (paused → running) - Partial-succeeded status with exceptions count - Inputs/outputs JSON handling - Graph preservation across workflow runs - Serialization (to_dict) and deserialization (from_dict) **3. NodeExecution Relationships (10 tests)** - Node execution creation with workflow_run_id - Predecessor node relationships - Single-step debugging (no workflow_run_id) - Inputs, outputs, and process_data handling - Status transitions with elapsed time tracking - Error handling and metadata - Different node types (START, LLM, CODE, TOOL, IF_ELSE, END) **4. Graph Configuration Validation (7 tests)** - Complex graph structures with nodes and edges - Empty graph configuration - Complex nested node data structures - Conditional branching (if-else with sourceHandle) - Loop/iteration structures - Null value handling for graph/inputs/outputs - Graph preservation across WorkflowRun instances ### Key Features - ✅ All tests follow **Arrange-Act-Assert** pattern - ✅ Comprehensive coverage of workflow lifecycle and state transitions - ✅ Edge cases handled (null values, empty collections) - ✅ Type-safe with proper enum usage - ✅ Concise docstrings and inline comments - ✅ **All 38 tests passing** ## Screenshots Not applicable - 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 Contribution by Gittensor, learn more at https://gittensor.io/
yindo added the pull-request label 2026-02-21 20:50:45 -05:00
yindo closed this issue 2026-02-21 20:50:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32103