Skip to content

refactor: migrate workflow run repository tests from mocks to …#33837

Merged
asukaminato0721 merged 4 commits intolanggenius:mainfrom
YB0y:refactor/migrate-workflow-run-repo-tests-to-testcontainers
Mar 21, 2026
Merged

refactor: migrate workflow run repository tests from mocks to …#33837
asukaminato0721 merged 4 commits intolanggenius:mainfrom
YB0y:refactor/migrate-workflow-run-repo-tests-to-testcontainers

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Mar 20, 2026

Part of #32454

Changes

  • Added api/tests/test_containers_integration_tests/repositories/test_workflow_run_repository.py — 11 integration tests covering pagination (no-filter, status filter, has_more, cursor-based, invalid cursor, tenant isolation) and count queries (grouped counts, status filter, invalid status, time range, combined filters)
  • Removed api/tests/unit_tests/repositories/test_workflow_run_repository.py — replaced by the integration tests above

Screenshots

Before After
N/A N/A

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 make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. refactor labels Mar 20, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the testing approach for the WorkflowRun repository. It transitions from using isolated, mock-dependent unit tests to comprehensive integration tests that leverage testcontainers. This change ensures that the repository's data access and filtering logic, including complex pagination and counting functionalities, are thoroughly validated against a real database environment, thereby enhancing the reliability and accuracy of the tests.

Highlights

  • Test Refactoring: Migrated WorkflowRun repository tests from mock-based unit tests to testcontainers-based integration tests for more robust validation.
  • New Integration Tests: Added 11 new integration tests covering get_paginated_workflow_runs (pagination, status filtering, cursor-based, tenant isolation) and get_workflow_runs_count (grouped counts, status filtering, time range, combined filters).
  • Test Removal: Removed the old mock-based unit tests for the WorkflowRun repository, as they have been superseded by the new integration tests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great improvement, migrating the workflow run repository tests from mocks to integration tests using testcontainers. This provides much higher confidence by testing against a real database instance. The new tests are well-structured and cover a good range of scenarios for pagination and counting. I have a couple of minor suggestions to improve code clarity and test precision.

@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Mar 20, 2026

@asukaminato0721 Could you please review my PR and share any feedback?

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-21 02:26:55.723376227 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-21 02:26:46.307374742 +0000
@@ -913,6 +913,8 @@
    --> tests/test_containers_integration_tests/repositories/test_sqlalchemy_api_workflow_node_execution_repository.py:122:70
 ERROR Generator function should return `Generator` [bad-return]
    --> tests/test_containers_integration_tests/repositories/test_sqlalchemy_api_workflow_run_repository.py:112:56
+ERROR Generator function should return `Generator` [bad-return]
+  --> tests/test_containers_integration_tests/repositories/test_workflow_run_repository.py:88:56
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/dataset_service_update_delete.py:40:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -5535,8 +5537,6 @@
   --> tests/unit_tests/repositories/test_sqlalchemy_execution_extra_content_repository.py:97:23
 ERROR Argument `_FakeSessionMaker` is not assignable to parameter `session_maker` with type `sessionmaker[Session]` in function `repositories.sqlalchemy_execution_extra_content_repository.SQLAlchemyExecutionExtraContentRepository.__init__` [bad-argument-type]
    --> tests/unit_tests/repositories/test_sqlalchemy_execution_extra_content_repository.py:159:23
-ERROR Cannot instantiate `DifyAPISQLAlchemyWorkflowRunRepository` because the following members are abstract: `save` [bad-instantiation]
-  --> tests/unit_tests/repositories/test_workflow_run_repository.py:24:54
 ERROR Argument `Literal['workflow-run']` is not assignable to parameter `value` with type `SQLCoreOperations[WorkflowNodeExecutionTriggeredFrom] | WorkflowNodeExecutionTriggeredFrom` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> tests/unit_tests/repositories/workflow_node_execution/test_sqlalchemy_repository.py:295:31
 ERROR Argument `Literal['account']` is not assignable to parameter `value` with type `CreatorUserRole | SQLCoreOperations[CreatorUserRole]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-21 02:39:45.772627325 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-21 02:39:36.794655587 +0000
@@ -27,9 +27,9 @@
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/ping.py:10:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
-  --> controllers/console/setup.py:40:2
+  --> controllers/console/setup.py:39:2
 ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
-  --> controllers/console/setup.py:65:2
+  --> controllers/console/setup.py:64:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/version.py:30:2
 ERROR `result` may be uninitialized [unbound-name]
@@ -913,6 +913,8 @@
    --> tests/test_containers_integration_tests/repositories/test_sqlalchemy_api_workflow_node_execution_repository.py:122:70
 ERROR Generator function should return `Generator` [bad-return]
    --> tests/test_containers_integration_tests/repositories/test_sqlalchemy_api_workflow_run_repository.py:112:56
+ERROR Generator function should return `Generator` [bad-return]
+  --> tests/test_containers_integration_tests/repositories/test_workflow_run_repository.py:89:56
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/dataset_service_update_delete.py:40:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -5535,8 +5537,6 @@
   --> tests/unit_tests/repositories/test_sqlalchemy_execution_extra_content_repository.py:97:23
 ERROR Argument `_FakeSessionMaker` is not assignable to parameter `session_maker` with type `sessionmaker[Session]` in function `repositories.sqlalchemy_execution_extra_content_repository.SQLAlchemyExecutionExtraContentRepository.__init__` [bad-argument-type]
    --> tests/unit_tests/repositories/test_sqlalchemy_execution_extra_content_repository.py:159:23
-ERROR Cannot instantiate `DifyAPISQLAlchemyWorkflowRunRepository` because the following members are abstract: `save` [bad-instantiation]
-  --> tests/unit_tests/repositories/test_workflow_run_repository.py:24:54
 ERROR Argument `Literal['workflow-run']` is not assignable to parameter `value` with type `SQLCoreOperations[WorkflowNodeExecutionTriggeredFrom] | WorkflowNodeExecutionTriggeredFrom` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> tests/unit_tests/repositories/workflow_node_execution/test_sqlalchemy_repository.py:295:31
 ERROR Argument `Literal['account']` is not assignable to parameter `value` with type `CreatorUserRole | SQLCoreOperations[CreatorUserRole]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

@asukaminato0721
Copy link
Copy Markdown
Contributor

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great improvement, replacing mocked unit tests for the workflow run repository with comprehensive integration tests using testcontainers. The new tests cover various scenarios including pagination, filtering, error handling, and tenant isolation, which increases confidence in the repository's implementation. I've found a couple of areas for minor improvements to enhance test robustness and code clarity.

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 migrates workflow run repository tests from mock-based unit tests to real database integration tests backed by Testcontainers, aligning coverage with actual SQLAlchemy/DB behavior for pagination and count queries.

Changes:

  • Added a new Testcontainers integration test suite for get_paginated_workflow_runs and get_workflow_runs_count (pagination, cursor behavior, tenant isolation, status/time_range filters).
  • Removed the prior mock-based unit test module for the same repository behaviors.

Reviewed changes

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

File Description
api/tests/unit_tests/repositories/test_workflow_run_repository.py Removes mock-based unit tests that asserted query behavior via patched sessions.
api/tests/test_containers_integration_tests/repositories/test_workflow_run_repository.py Adds DB-backed integration tests covering pagination and count queries with real enum binding/validation behavior.

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

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-21 04:32:15.486916081 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-21 04:32:06.415885219 +0000
@@ -913,6 +913,8 @@
    --> tests/test_containers_integration_tests/repositories/test_sqlalchemy_api_workflow_node_execution_repository.py:122:70
 ERROR Generator function should return `Generator` [bad-return]
    --> tests/test_containers_integration_tests/repositories/test_sqlalchemy_api_workflow_run_repository.py:112:56
+ERROR Generator function should return `Generator` [bad-return]
+  --> tests/test_containers_integration_tests/repositories/test_workflow_run_repository.py:89:56
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/dataset_service_update_delete.py:40:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -5535,8 +5537,6 @@
   --> tests/unit_tests/repositories/test_sqlalchemy_execution_extra_content_repository.py:97:23
 ERROR Argument `_FakeSessionMaker` is not assignable to parameter `session_maker` with type `sessionmaker[Session]` in function `repositories.sqlalchemy_execution_extra_content_repository.SQLAlchemyExecutionExtraContentRepository.__init__` [bad-argument-type]
    --> tests/unit_tests/repositories/test_sqlalchemy_execution_extra_content_repository.py:159:23
-ERROR Cannot instantiate `DifyAPISQLAlchemyWorkflowRunRepository` because the following members are abstract: `save` [bad-instantiation]
-  --> tests/unit_tests/repositories/test_workflow_run_repository.py:24:54
 ERROR Argument `Literal['workflow-run']` is not assignable to parameter `value` with type `SQLCoreOperations[WorkflowNodeExecutionTriggeredFrom] | WorkflowNodeExecutionTriggeredFrom` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> tests/unit_tests/repositories/workflow_node_execution/test_sqlalchemy_repository.py:295:31
 ERROR Argument `Literal['account']` is not assignable to parameter `value` with type `CreatorUserRole | SQLCoreOperations[CreatorUserRole]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

@asukaminato0721 asukaminato0721 changed the title Refactor(tests): migrate workflow run repository tests from mocks to … refactor: migrate workflow run repository tests from mocks to … Mar 21, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 21, 2026
@asukaminato0721 asukaminato0721 merged commit 097773c into langgenius:main Mar 21, 2026
13 of 16 checks passed
@YB0y YB0y deleted the refactor/migrate-workflow-run-repo-tests-to-testcontainers branch March 21, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants