Skip to content

refactor(workflow, request, tus): streamline request handling and workflow testing #897

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

Merged
merged 1 commit into from
Jul 9, 2025

Conversation

pcfreak30
Copy link
Member

@pcfreak30 pcfreak30 commented Jul 9, 2025

  • Remove ErrDuplicateRequest and update QueryRequest signature in core/request.go
  • Add QueryRequestData method to request service with struct-to-map conversion
  • Enhance workflow testing with direct request service access
  • Improve TUSRequest model field definitions
  • Fix workflow conversion metadata handling

Summary by CodeRabbit

  • New Features

    • Added new methods for converting requests to workflows and retrieving requests in testing utilities.
    • Introduced a method for querying request data with additional filtering options.
  • Refactor

    • Centralized and streamlined request service usage in workflow testing utilities.
    • Updated workflow metadata handling for improved structure and consistency.
  • Style

    • Updated database field tags for improved clarity and alignment with column names.
  • Chores

    • Removed unused error variables and package imports.

Copy link

changeset-bot bot commented Jul 9, 2025

⚠️ No Changeset found

Latest commit: a1409d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Jul 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new QueryRequestData method to the RequestService interface and its default implementation, enabling advanced querying of requests based on dynamic data models and filters. The WorkflowTest struct is extended to store a RequestService instance and provide new helper methods. Struct tags in TUSRequest are updated for explicit column mapping.

Changes

File(s) Change Summary
core/request.go Removed ErrDuplicateRequest, switched interface{} to any in QueryRequest, added QueryRequestData to interface.
service/request.go Added QueryRequestData method and requestModelToMap helper for dynamic query construction.
core/testing/workflow.go Added requestSvc field to WorkflowTest, updated constructor, and added helper methods for request/workflow handling.
db/models/tus_request.go Updated struct tags for TUSRequest fields for explicit column names.
service/tus.go Switched from QueryRequest to QueryRequestData in UploadExists.
service/workflow.go Refactored metadata handling in ConvertRequestToWorkflow to ensure correct JSON structure.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RequestService
    participant DB

    Client->>RequestService: QueryRequestData(ctx, query, filter)
    RequestService->>DB: Build query from struct fields and filter
    DB-->>RequestService: Return matching *models.Request or error
    RequestService-->>Client: Return result
Loading
sequenceDiagram
    participant Test
    participant WorkflowTest
    participant RequestService

    Test->>WorkflowTest: GetRequest(requestID)
    WorkflowTest->>RequestService: QueryRequest(ctx, ...)
    RequestService-->>WorkflowTest: *models.Request or error
    WorkflowTest-->>Test: *models.Request (fail test on error)
Loading

Possibly related PRs

Poem

In the warren of code, new queries hop,
With any and filters, requests never stop.
WorkflowTest grows, with helpers anew,
TUS tags now clearer, as columns shine through.
🐇 The rabbit approves, with a joyful leap,
For code that is tidy, robust, and deep!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74ad84f and a1409d0.

📒 Files selected for processing (6)
  • core/request.go (1 hunks)
  • core/testing/workflow.go (4 hunks)
  • db/models/tus_request.go (1 hunks)
  • service/request.go (3 hunks)
  • service/tus.go (1 hunks)
  • service/workflow.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9735f2 and 74ad84f.

📒 Files selected for processing (6)
  • core/request.go (1 hunks)
  • core/testing/workflow.go (4 hunks)
  • db/models/tus_request.go (1 hunks)
  • service/request.go (3 hunks)
  • service/tus.go (1 hunks)
  • service/workflow.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
db/models/tus_request.go (1)
db/models/request.go (1)
  • Request (21-33)
service/tus.go (2)
db/models/tus_request.go (1)
  • TUSRequest (17-24)
core/request.go (1)
  • RequestFilter (53-59)
core/testing/workflow.go (5)
core/request.go (2)
  • RequestService (12-51)
  • REQUEST_SERVICE (10-10)
core/testing/testing.go (2)
  • TestContext (218-230)
  • TB (215-215)
core/context.go (1)
  • GetService (299-312)
core/workflow.go (2)
  • WorkflowService (49-71)
  • WORKFLOW_SERVICE (14-14)
db/models/request.go (1)
  • Request (21-33)
core/request.go (2)
core/context.go (1)
  • Context (18-46)
db/models/request.go (1)
  • Request (21-33)
service/request.go (4)
core/request.go (1)
  • RequestFilter (53-59)
db/models/request.go (1)
  • Request (21-33)
db/models/data_models/data_models.go (1)
  • RequestDataModel (3-10)
db/db.go (1)
  • RetryOnLock (119-154)
🔇 Additional comments (12)
service/tus.go (1)

75-77: LGTM!

The migration to QueryRequestData is appropriate and aligns with the enhanced querying capabilities introduced in the request service.

db/models/tus_request.go (1)

19-23: Database indexes are maintained via migrations, no changes required

The SQLite migration db/migrations/sqlite/20250308183521_init.sql already defines the unique indexes you removed from the GORM tags:

  • CREATE UNIQUE INDEX idx_tus_requests_tus_upload_id ON tus_requests (tus_upload_id);
  • CREATE UNIQUE INDEX idx_tus_requests_request_id ON tus_requests (request_id);

Since the database constraints remain in your migrations, removing the uniqueIndex struct tags does not affect data integrity or query performance. You can safely proceed without adding additional indexes in code.

service/workflow.go (1)

802-822: Good refactoring of metadata handling.

The separation of workflow options processing and metadata marshaling improves code clarity and ensures proper data nesting. The workflow options are now correctly embedded in the Data field before the complete metadata is marshaled.

core/request.go (1)

33-34: Clean interface extension with modern Go syntax.

The addition of QueryRequestData method and the update to use any instead of interface{} improve the API. The new method provides enhanced querying capabilities while maintaining backward compatibility.

core/testing/workflow.go (8)

18-18: Good addition of the request service field.

Adding the requestSvc field to the struct is a solid improvement that will eliminate repeated service retrieval calls throughout the test methods.


24-24: Proper initialization of the request service.

The initialization follows the established pattern and correctly uses the generic GetService function with the appropriate service constant.

Also applies to: 29-29


48-48: Improved efficiency by using stored service.

Good refactoring - using the stored requestSvc field instead of retrieving the service locally improves performance and consistency.


89-89: Consistent use of stored service.

The refactoring maintains consistency with the pattern established in other methods.


96-96: Appropriate use of stored service for status retrieval.

The change correctly uses the stored service instance for retrieving request status information.


119-122: Well-designed wrapper method.

The ConvertRequestToWorkflow method provides a clean interface for workflow conversion operations and properly delegates to the underlying workflow service.


124-128: Appropriate test helper method.

The MustConvertRequestToWorkflow method follows the established pattern of "Must" methods that fail the test on error, providing a convenient way to handle operations that should always succeed in test scenarios.


130-135: Useful request retrieval helper.

The GetRequest method provides a convenient way to retrieve requests in tests with proper error handling. This complements the existing test infrastructure well.

…kflow testing

- Remove ErrDuplicateRequest and update QueryRequest signature in core/request.go
- Add QueryRequestData method to request service with struct-to-map conversion
- Enhance workflow testing with direct request service access
- Improve TUSRequest model field definitions
- Fix workflow conversion metadata handling
@pcfreak30 pcfreak30 merged commit 28dd875 into develop Jul 9, 2025
0 of 2 checks passed
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.

1 participant