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

Support websocket workspace #1376

Merged
merged 6 commits into from
Jan 9, 2025
Merged

Support websocket workspace #1376

merged 6 commits into from
Jan 9, 2025

Conversation

paulfalgout
Copy link
Member

@paulfalgout paulfalgout commented Jan 8, 2025

Shortcut Story ID: [sc-58278]

For the moment at least all websocket subscriptions.. similar to api requests can by default pass the current workspace.

We might run into issue in the future where we want to monitor across workspace, but we'll tackle that when we get there as it will likely coincide with changes to how we interact with the API as well. (ie: get a notification from a different workspace.. make a request on that different workspace)

In addition to this is a bit of cleanup of unused features or flake-related issues

  • I had added getResource to model in order to make it easier to feed the subscription service { id: type } but later we just made the subscription service support an array of models so it's no longer needed.
  • I removed the connectionResponseMessage from the mock websocket server as it was never used and likely never will be
  • I removed wsIntercept for a stub for any handler. wsIntercept was difficullt to manage timing wise. Removing it uncovered issues for more consistent tests.
  • websockets were closing at the end of the tests causing the app to resubscribe which that message did overlap tests causing some bleed into the new stub
  • similarly we were sending an empty subscribe in the tests because onOpen sometimes passed data and sometimes didn't depending on timing.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved WebSocket service handling and connection management
    • Enhanced resource subscription logic
  • Refactor

    • Simplified WebSocket message processing in testing environment
    • Streamlined WebSocket notification handling
    • Removed deprecated resource retrieval method
  • Tests

    • Updated WebSocket testing support
    • Improved test assertions for WebSocket interactions

ws service supports models now.
Part of the filters work, this can currently always be added
We didn’t ever use this.  Likely never will
if a socket just opens by default it’s not an issue.
It reopens during changing tests
@paulfalgout paulfalgout requested a review from nmajor25 January 8, 2025 17:58
Copy link

coderabbitai bot commented Jan 8, 2025

Walkthrough

This pull request introduces modifications to the WebSocket service and related components across multiple files. The changes focus on enhancing WebSocket subscription handling, simplifying resource request mechanisms, and improving test infrastructure. Key modifications include adding workspace context to subscriptions, refactoring message handling in test support utilities, and streamlining the way resources are requested and processed during WebSocket interactions.

Changes

File Change Summary
src/js/apps/patients/patient/flow/flow_app.js Removed invoke from import and simplified subscribe method resource request
src/js/base/model.js Removed getResource() method from Backbone model
src/js/services/ws.cy.js Added workspace constant, updated WebSocket service test cases with structured data handling
src/js/services/ws.js Added currentWorkspace in _subscribe, modified onOpen and onClose methods
test/integration/patients/patient/patient-flow.js Updated WebSocket notification handling and assertions
test/support/websockets.js Simplified WebSocket message handling, removed sendMessage and related functions

Sequence Diagram

sequenceDiagram
    participant Client
    participant WebSocketService
    participant Server
    
    Client->>WebSocketService: Initialize Connection
    WebSocketService->>Server: Open Connection
    WebSocketService->>Server: Subscribe with Workspace Context
    Server-->>WebSocketService: Acknowledge Subscription
    WebSocketService-->>Client: Ready for Notifications
Loading

Possibly related PRs

Suggested reviewers

  • nmajor25

Poem

🐰 Websockets dance, a rabbit's delight,
Workspace context now shining bright
Resources flow with elegant ease
No more invoke, just pure release
Code hops forward, clean and light! 🌟


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>, please review it.
    • 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 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 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 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. (Beta)
  • @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: 0

🧹 Nitpick comments (3)
src/js/services/ws.js (1)

98-98: Consider adding a constant for the test environment flag.

The _TEST_ variable should be defined as a constant at the module level for better maintainability.

+const IS_TEST_ENV = typeof _TEST_ !== 'undefined';
+
 onClose() {
   this.stopHeartbeat();
-  if (!_TEST_ && this.resources.length) this._subscribe();
+  if (!IS_TEST_ENV && this.resources.length) this._subscribe();
 }
test/integration/patients/patient/patient-flow.js (2)

2681-2681: Fix indentation.

The line is not properly indented compared to the surrounding code.

-      .wait('@routeFlowActions');
+      .wait('@routeFlowActions');

2688-2696: Verify WebSocket subscription resources.

The test verifies that the WebSocket subscription includes both the flow and action resources. However, the test could be more robust:

  1. The assertion uses a deep equality check which might be too strict
  2. The order of resources in the array might not matter

Consider making the test more resilient:

-      .then(stub => {
-        expect(stub.getCall(0).args[0].data.resources).to.deep.equal([
-          getRelationship(testSocketFlow).data,
-          getRelationship(testSocketAction).data,
-        ]);
+      .then(stub => {
+        const resources = stub.getCall(0).args[0].data.resources;
+        const expectedResources = [
+          getRelationship(testSocketFlow).data,
+          getRelationship(testSocketAction).data,
+        ];
+        
+        expect(resources).to.have.length(2);
+        expect(resources).to.deep.include.members(expectedResources);
       });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d864a9 and 9727555.

📒 Files selected for processing (6)
  • src/js/apps/patients/patient/flow/flow_app.js (2 hunks)
  • src/js/base/model.js (0 hunks)
  • src/js/services/ws.cy.js (6 hunks)
  • src/js/services/ws.js (3 hunks)
  • test/integration/patients/patient/patient-flow.js (1 hunks)
  • test/support/websockets.js (2 hunks)
💤 Files with no reviewable changes (1)
  • src/js/base/model.js
🔇 Additional comments (7)
test/support/websockets.js (2)

Line range hint 7-19: LGTM! Simplified message handling improves test maintainability.

The refactoring from complex message routing to direct message handling reduces test complexity and potential timing issues.


Line range hint 25-39: LGTM! Streamlined mock WebSocket setup.

The removal of connectionResponseMessage and simplified command structure makes the test setup more straightforward and reduces potential points of failure.

src/js/services/ws.js (2)

39-48: LGTM! Enhanced subscription context with workspace ID.

The addition of workspace context to subscriptions aligns with the PR objectives and improves the subscription payload structure.


77-78: LGTM! Improved data handling robustness.

The conditional check for data existence prevents potential issues with undefined data during connection open.

src/js/services/ws.cy.js (2)

8-8: LGTM! Consistent workspace handling in tests.

The addition of the workspace constant and its integration with Radio replies maintains consistency across tests.

Also applies to: 25-25, 36-36


170-179: LGTM! Well-structured test data helper.

The testData helper function improves code reusability and maintains consistent test data structure.

src/js/apps/patients/patient/flow/flow_app.js (1)

101-101: LGTM! Simplified subscription logic.

The direct array spread approach is cleaner and more maintainable than the previous invoke method.

Copy link
Contributor

@nmajor25 nmajor25 left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@paulfalgout paulfalgout merged commit 0f2ed7c into develop Jan 9, 2025
6 checks passed
@paulfalgout paulfalgout deleted the socket-filters branch January 9, 2025 07: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