Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pi migration #1892

Merged
merged 10 commits into from
Jul 9, 2024
Merged

Pi migration #1892

merged 10 commits into from
Jul 9, 2024

Conversation

jasquat
Copy link
Contributor

@jasquat jasquat commented Jul 8, 2024

Supports #1671

Adds an api to migrate a process instance to the new version of the api.

New APIs:

  • GET: /process-instances/{modified_process_model_identifier}/{process_instance_id}/check-can-migrate
  • POST: /process-instance-migrate/{modified_process_model_identifier}/{process_instance_id}

Summary by CodeRabbit

  • New Features

    • Introduced API endpoints for checking migration eligibility and migrating process instances.
    • Added new event type process_instance_migrated.
    • Added new exception ProcessInstanceMigrationNotSafeError.
    • Introduced permissions for process instance migration.
  • Bug Fixes

    • Included new test cases to ensure the functionality of process instance migration and permission settings.
  • Tests

    • Added comprehensive tests for migration functionalities, including updating GUIDs and permission checks.

Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

Walkthrough

These changes introduce functionalities for checking migration eligibility and migrating process instances to a new version of their process model. New API endpoints, error handling, and event types are added to support these operations. Modifications also include new methods in the ProcessInstanceProcessor and ProcessInstanceService classes to check migration safety and perform migrations. Tests have been added and updated to verify these new capabilities.

Changes

Files Change Summary
.../api.yml Added endpoints for checking migration eligibility and migrating process instances
.../exceptions/error.py Introduced ProcessInstanceMigrationNotSafeError exception class
.../models/process_instance_event.py Added process_instance_migrated event type to the ProcessInstanceEventType enum
.../routes/process_instances_controller.py Introduced methods process_instance_check_can_migrate and process_instance_migrate for handling migration checks and migrations
.../services/authorization_service.py Added new permission for the path /process-instance-migrate
.../services/process_instance_processor.py Added new method update_guids_on_tasks and related imports
.../services/process_instance_service.py Added methods for checking migration feasibility and migrating process instances
.../helpers/base_test.py Added method create_and_run_process_instance to facilitate testing
.../integration/test_process_instances_controller.py Added tests for process instance migration and migration eligibility checks
.../unit/test_authorization_service.py Added tests for authorization related to process instance migration
.../unit/test_process_instance_processor.py Added tests for updating GUIDs within BPMN process instances
.../unit/test_process_instance_service.py Added tests for migrating process instances and ensuring migration safety
.../data/migration-test-with-subprocess/... Added BPMN files representing initial and new stages of the model for migration tests

Sequence Diagram(s)

sequenceDiagram
    participant Client as API Client
    participant Server as Server
    participant Processor as ProcessInstanceProcessor
    participant Service as ProcessInstanceService

    Client->>Server: GET /process-instances/{model_id}/{instance_id}/check-can-migrate
    Server->>Service: Check process instance can migrate
    Service->>Processor: Validate migration
    Processor-->>Service: Migration valid/invalid
    Service-->>Server: Migration valid/invalid
    Server-->>Client: Migration valid/invalid response
    Note over Client,Server: Client checks if migration is possible

    Client->>Server: POST /process-instance-migrate/{model_id}/{instance_id}
    Server->>Service: Migrate process instance
    Service->>Processor: Perform migration
    Processor-->>Service: Migration result
    Service-->>Server: Migration successful/failed
    Server-->>Client: Migration result response
    Note over Client,Server: Client initiates the migration process
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5f8f42c and 22a4227.

Files ignored due to path filters (1)
  • spiffworkflow-backend/poetry.lock is excluded by !**/*.lock
Files selected for processing (14)
  • spiffworkflow-backend/src/spiffworkflow_backend/api.yml (2 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/exceptions/error.py (1 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_event.py (1 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py (2 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py (2 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py (6 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py (5 hunks)
  • spiffworkflow-backend/tests/data/migration-test-with-subprocess/migration-initial.bpmn (1 hunks)
  • spiffworkflow-backend/tests/data/migration-test-with-subprocess/migration-new.bpmn (1 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/helpers/base_test.py (1 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py (2 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.py (3 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py (1 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_service.py (2 hunks)
Files skipped from review due to trivial changes (2)
  • spiffworkflow-backend/src/spiffworkflow_backend/exceptions/error.py
  • spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_event.py
Additional comments not posted (35)
spiffworkflow-backend/tests/data/migration-test-with-subprocess/migration-initial.bpmn (5)

1-2: Metadata and namespaces look good.

The definitions element correctly includes necessary namespaces and metadata.


3-3: Process definition looks good.

The process element is correctly defined with a valid ID and is marked as executable.


4-11: Start and end events look good.

The startEvent and endEvent elements are correctly defined and connected via sequence flows.


12-27: Subprocess looks good.

The subProcess element is correctly defined and contains valid BPMN elements such as startEvent, manualTask, and endEvent.


28-71: BPMN diagram elements look good.

The BPMN diagram elements correctly represent the process and subprocess, including shapes and edges.

spiffworkflow-backend/tests/data/migration-test-with-subprocess/migration-new.bpmn (5)

1-2: Metadata and namespaces look good.

The definitions element correctly includes necessary namespaces and metadata.


3-3: Process definition looks good.

The process element is correctly defined with a valid ID and is marked as executable.


4-11: Start and end events look good.

The startEvent and endEvent elements are correctly defined and connected via sequence flows.


12-32: Subprocess looks good.

The subProcess element is correctly defined and contains valid BPMN elements such as startEvent, manualTask, and endEvent.


33-83: BPMN diagram elements look good.

The BPMN diagram elements correctly represent the process and subprocess, including shapes and edges.

spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py (3)

59-116: Test method for process instance migration looks good.

The test_process_instance_migrate method correctly covers the migration process and verifies the correctness of the migration.


117-163: Test method for checking process instance migration eligibility looks good.

The test_process_instance_check_can_migrate method correctly covers the check for migration eligibility and verifies the correctness of the check.


Line range hint 10-58: Test method for finding process instance by ID looks good.

The test_find_by_id method correctly covers the retrieval process and verifies the correctness of the retrieval.

spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_service.py (4)

157-214: Test method for process instance migration looks good.

The test_it_can_migrate_a_process_instance method correctly covers the migration process and verifies the correctness of the migration.


215-251: Test method for checking process instance migration eligibility looks good.

The test_it_can_check_if_a_process_instance_can_be_migrated method correctly covers the check for migration eligibility and verifies the correctness of the check.


252-293: Test method for handling unsafe migrations looks good.

The test_it_raises_if_a_process_instance_cannot_be_migrated_to_new_process_model_version method correctly covers the scenario where a process instance cannot be migrated and verifies the handling of unsafe migrations.


Line range hint 21-56: Test method for saving file data looks good.

The test_save_file_data_v0 method correctly covers the saving of file data with digest references and verifies the correctness of the process.

spiffworkflow-backend/tests/spiffworkflow_backend/helpers/base_test.py (1)

103-134: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to create_and_run_process_instance are correctly implemented.

Verification successful

Function usage verified.

The function create_and_run_process_instance is correctly implemented in the codebase.

  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_message_service.py
  • spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py
  • spiffworkflow-backend/src/spiffworkflow_backend/routes/webhooks_controller.py
  • spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py
  • spiffworkflow-backend/src/spiffworkflow_backend/routes/extensions_controller.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `create_and_run_process_instance` are correctly implemented.

# Test: Search for the function usage. Expect: Only occurances of the correct usage.
rg --type python $'create_and_run_process_instance'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify all function calls to `create_and_run_process_instance` are correctly implemented.

# Test: Search for the function usage. Expect: Only occurrences of the correct usage.
rg 'create_and_run_process_instance'

Length of output: 1083


Script:

#!/bin/bash
# Description: Extract lines around each occurrence of `create_and_run_process_instance` to review the context.

# Extract lines around the occurrences in the test_message_service.py
rg 'create_and_run_process_instance' -A 5 -B 5 spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_message_service.py

# Extract lines around the occurrences in the test_process_instances_controller.py
rg 'create_and_run_process_instance' -A 5 -B 5 spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py

# Extract lines around the occurrences in the base_test.py
rg 'create_and_run_process_instance' -A 5 -B 5 spiffworkflow-backend/tests/spiffworkflow_backend/helpers/base_test.py

# Extract lines around the occurrences in the webhooks_controller.py
rg 'create_and_run_process_instance' -A 5 -B 5 spiffworkflow-backend/src/spiffworkflow_backend/routes/webhooks_controller.py

# Extract lines around the occurrences in the process_instance_service.py
rg 'create_and_run_process_instance' -A 5 -B 5 spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py

# Extract lines around the occurrences in the extensions_controller.py
rg 'create_and_run_process_instance' -A 5 -B 5 spiffworkflow-backend/src/spiffworkflow_backend/routes/extensions_controller.py

Length of output: 3550

spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py (2)

567-574: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to process_instance_migrate are correctly implemented.


550-565: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to process_instance_check_can_migrate are correctly implemented.

Verification successful

Function process_instance_check_can_migrate is correctly implemented and tested.

  • The function is correctly referenced in the api.yml file as part of the API specification.
  • There is a corresponding test function test_process_instance_check_can_migrate in the test_process_instances_controller.py file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `process_instance_check_can_migrate` are correctly implemented.

# Test: Search for the function usage. Expect: Only occurances of the correct usage.
rg --type python $'process_instance_check_can_migrate'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify all function calls to `process_instance_check_can_migrate` are correctly implemented.

# Test: Search for the function usage. Expect: Only occurrences of the correct usage.
rg 'process_instance_check_can_migrate'

Length of output: 482


Script:

#!/bin/bash
# Description: Verify the function usage in the api.yml file and the test file.

# Check the relevant section in the api.yml file.
echo "Checking api.yml for function usage..."
rg -A 5 'operationId: spiffworkflow_backend.routes.process_instances_controller.process_instance_check_can_migrate' spiffworkflow-backend/src/spiffworkflow_backend/api.yml

# Check the relevant section in the test file.
echo "Checking test_process_instances_controller.py for function usage..."
rg -A 10 'def test_process_instance_check_can_migrate' spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py

Length of output: 1295

spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.py (2)

111-114: LGTM! But verify the test case implementation in the codebase.

The code changes are approved.

However, ensure that the test case for process-instance-migrate permission creation is correctly implemented.

Verification successful

LGTM! But verify the test case implementation in the codebase.

The code changes are approved.

The test case for process-instance-migrate permission creation is correctly implemented in spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.py.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test case implementation for `process-instance-migrate` permission creation.

# Test: Search for the test case usage. Expect: Only occurances of the correct usage.
rg --type python $'process-instance-migrate'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the test case implementation for `process-instance-migrate` permission creation.

# Test: Search for the test case usage. Expect: Only occurrences of the correct usage.
rg 'process-instance-migrate'

Length of output: 1084


199-202: LGTM! But verify the test case implementation in the codebase.

The code changes are approved.

However, ensure that the test case for process-instance-migrate permission creation is correctly implemented.

Verification successful

The test case for process-instance-migrate permission creation is correctly implemented.

The search results indicate that process-instance-migrate is being tested in the relevant files, including test_authorization_service.py.

  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.py
  • spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py
  • spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test case implementation for `process-instance-migrate` permission creation.

# Test: Search for the test case usage. Expect: Only occurances of the correct usage.
rg --type python $'process-instance-migrate'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the test case implementation for `process-instance-migrate` permission creation.

# Test: Search for the test case usage. Expect: Only occurrences of the correct usage.
rg --type py 'process-instance-migrate'

Length of output: 951

spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py (4)

20-23: LGTM! Imports are necessary and correctly used.

The imports from SpiffWorkflow.bpmn.util.diff are required for the migration functionalities, and the import from spiffworkflow_backend.exceptions.error is necessary for handling migration-related errors.


148-175: LGTM! The method correctly checks migration safety.

The check_process_instance_can_be_migrated method correctly uses diff_workflow to get the differences and checks if the migration is safe. It raises an appropriate exception if the migration is not safe.


178-221: LGTM! The method correctly performs the migration.

The migrate_process_instance_to_newest_model_version method correctly performs the migration by calling check_process_instance_can_be_migrated and using migrate_workflow. It handles errors appropriately and has a TODO comment for missing tests.


733-742: LGTM! The method correctly checks migration safety.

The can_migrate method correctly checks if the migration is safe by ensuring that no tasks in the workflow differences are in completed or started states.

spiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.py (2)

73-73: Addition of Migration Path Segment Approved

The new path segment /process-instance-migrate with the relevant permission create has been correctly added.


641-643: Addition of Migration Action Approved

The new process instance action migrate has been correctly added to the permission loop in set_support_permissions.

spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py (5)

1080-1085: Good test setup and teardown.

The test setup and teardown are well-structured, ensuring a clean environment for each test run.


1086-1093: Comprehensive test coverage.

The test covers the initialization and execution of process instances, ensuring the GUIDs are updated correctly.


1099-1100: Good use of ProcessInstanceService for task completion.

The test correctly uses ProcessInstanceService.complete_form_task for task completion.


1112-1117: Correctly verifies GUID updates.

The test correctly verifies that the GUIDs for tasks and subprocesses are updated.


1122-1125: Ensures consistency after GUID updates.

The test ensures that the task names remain consistent after GUID updates, which is crucial for process integrity.

spiffworkflow-backend/src/spiffworkflow_backend/api.yml (2)

1333-1365: Endpoint for checking process instance migration eligibility looks good.

The GET method and required path parameters are well-defined. The response schema is clear and consistent with other endpoints.


1498-1524: Endpoint for migrating process instances looks good.

The POST method and required path parameters are well-defined. The response schema is clear and consistent with other endpoints.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 22a4227 and cb772c2.

Files ignored due to path filters (1)
  • spiffworkflow-backend/poetry.lock is excluded by !**/*.lock
Files selected for processing (3)
  • spiffworkflow-backend/src/spiffworkflow_backend/exceptions/error.py (1 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py (2 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • spiffworkflow-backend/src/spiffworkflow_backend/exceptions/error.py
  • spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py
  • spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.py

@jasquat jasquat merged commit ec21ffb into main Jul 9, 2024
23 checks passed
@jasquat jasquat deleted the pi-migration branch July 9, 2024 18:35
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.

2 participants