Skip to content

Conversation

@mickelr
Copy link
Contributor

@mickelr mickelr commented Mar 14, 2025

COMPLETES #< INSERT LINK TO ISSUE >

https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-585446

This pull request addresses

Force close socket connection of previous LLM data channel, before register and connect a new data channel.

by making the following changes

Pass code 3050 and reson "done (permanent)" to socket when disconnect LLM

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

@mickelr mickelr requested review from a team as code owners March 14, 2025 07:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

📝 Walkthrough

Walkthrough

This pull request modifies the disconnection flow for the LLM functionality. The disconnectLLM method in the LLMChannel class now accepts an options parameter, which is forwarded to the internal disconnect call. The corresponding interface, ILLMChannel, is updated to require an object with code and reason when disconnecting. The meeting module is adjusted so that when a meeting is joined, the updated disconnectLLM is called with an options object (using code 3050 and a descriptive reason); otherwise, it is invoked without parameters. Additionally, a new test suite is introduced to verify that successful and failing disconnections are properly handled under the new implementation.

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
warning [email protected]: Glob versions prior to v9 are no longer supported
warning intern > [email protected]: Glob versions prior to v9 are no longer supported
warning intern > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jasmine > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning [email protected]: 16.1.1
warning sinon > @sinonjs/samsam > [email protected]: This package is deprecated. Use the optional chaining (?.) operator instead.
warning wd > [email protected]: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning wd > archiver > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > [email protected]: request has been deprecated, see request/request#3142
warning wd > archiver > archiver-utils > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > request > [email protected]: this library is no longer supported
warning wd > request > [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning @babel/cli > [email protected]: Glob versions prior to v9 are no longer supported
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning @babel/runtime-corejs2 > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning babel-plugin-lodash > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > [email protected]: 16.1.1
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning workspace-aggregator-caa6024d-3a9f-4706-9ff5-954d091d3055 > @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3facc and 3475650.

📒 Files selected for processing (2)
  • packages/@webex/internal-plugin-llm/src/llm.ts (1 hunks)
  • packages/@webex/plugin-meetings/src/meeting/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/@webex/internal-plugin-llm/src/llm.ts
  • packages/@webex/plugin-meetings/src/meeting/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Packages
  • GitHub Check: AWS Amplify Console Web Preview

🪧 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.
  • @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.

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.

@mickelr mickelr added the validated If the pull request is validated for automation. label Mar 14, 2025
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: 2

🧹 Nitpick comments (3)
packages/@webex/plugin-meetings/src/controls-options-manager/util.ts (1)

304-306: Consider adding validation logic for the new control.

The implementation for viewTheParticipantListForWebinar always returns true, unlike other controls that have specific validation logic. If there are conditions under which this control should not be updated, consider implementing a validation method similar to canUpdateViewTheParticipantsList.

If no specific validation is needed, please add a comment explaining why this control is always allowed to be updated to improve code maintainability.

      case Control.viewTheParticipantListForWebinar:
+       // No specific validation needed for webinar participant list control
        determinant = true;
        break;
packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (2)

115-151: Inconsistent testing frameworks between new and existing tests.

The new test suite for disconnectLLM uses Jest testing methods (jest.fn(), expect().toHaveBeenCalledWith(), etc.) while the rest of the file uses Sinon and Chai (sinon.stub(), assert.equal(), etc.). This inconsistency can make the codebase harder to maintain.

Consider updating the new tests to use Sinon and Chai for consistency:

- disconnect: jest.fn(() => Promise.resolve()),
+ disconnect: sinon.stub().resolves(),

- expect(instance.disconnect).toHaveBeenCalledWith({});
- expect(instance.locusUrl).toBeUndefined();
+ sinon.assert.calledOnceWithExactly(instance.disconnect, {});
+ assert.equal(instance.locusUrl, undefined);

- instance.disconnect.mockRejectedValue(new Error('Disconnect failed'));
+ instance.disconnect.rejects(new Error('Disconnect failed'));

- await expect(instance.disconnectLLM({})).rejects.toThrow('Disconnect failed');
+ await assert.isRejected(instance.disconnectLLM({}), Error, 'Disconnect failed');

137-138: Add test case for the specific disconnect options mentioned in PR objectives.

The current test only verifies that options are passed through, but doesn't test the specific options mentioned in the PR objectives ({ code: 3050, reason: 'done (permanent)' }).

Consider adding an additional test case with the specific options:

it('should pass specific disconnect options', async () => {
  const options = { code: 3050, reason: 'done (permanent)' };
  await instance.disconnectLLM(options);
  
  expect(instance.disconnect).toHaveBeenCalledWith(options);
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c70bf9 and 0b29ac1.

📒 Files selected for processing (7)
  • packages/@webex/internal-plugin-llm/src/llm.ts (1 hunks)
  • packages/@webex/internal-plugin-llm/src/llm.types.ts (1 hunks)
  • packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (1 hunks)
  • packages/@webex/plugin-meetings/src/controls-options-manager/enums.ts (1 hunks)
  • packages/@webex/plugin-meetings/src/controls-options-manager/util.ts (1 hunks)
  • packages/@webex/plugin-meetings/src/meeting/index.ts (1 hunks)
  • packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js (3 hunks)
🔇 Additional comments (7)
packages/@webex/plugin-meetings/src/controls-options-manager/enums.ts (1)

15-15: Addition of new enum member looks good.

The new viewTheParticipantListForWebinar enum member extends the Control enum to support webinar-specific participant list viewing functionality, which aligns with the existing naming convention.

packages/@webex/internal-plugin-llm/src/llm.types.ts (1)

6-6: Interface update looks good.

The disconnectLLM method signature now accepts an options object with code and reason properties, which aligns with the PR objective to provide better context when disconnecting LLM channels.

packages/@webex/internal-plugin-llm/src/llm.ts (1)

119-125:

❓ Verification inconclusive

Implementation aligns with interface update.

The updated method signature and implementation correctly pass the options object to the underlying disconnect method, supporting the PR objective of forcibly closing previous connections with specific codes.

However, verify backward compatibility for any existing calls to disconnectLLM() without options.


🏁 Script executed:

#!/bin/bash
# Search for any calls to disconnectLLM without parameters
rg "disconnectLLM\(\s*\)" --type ts

Length of output: 37


Action Required: Verify Backward Compatibility for disconnectLLM Calls
The current update aligns with the interface by forwarding the options object to disconnect. However, our automated search for calls to disconnectLLM() without arguments provided inconclusive results. Please manually verify that no parts of the codebase invoke disconnectLLM() without the required options parameter. Ensure all usage of disconnectLLM is reviewed to maintain backward compatibility.

packages/@webex/plugin-meetings/src/meeting/index.ts (1)

7789-7796: Positive change to enforce proper LLM disconnection.

The modification to pass a disconnect code and reason when disconnecting from the LLM data channel is a good improvement. This ensures a clean closure of the previous connection before establishing a new one, preventing potential issues with lingering connections.

The code 3050 with reason 'done (permanent)' signals to the socket that this is an intentional, permanent disconnection rather than a temporary one that might automatically reconnect.

packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js (3)

11254-11257: Good test coverage for the new disconnect parameters.

Verifying that disconnectLLM is called with code: 3050 and reason: 'done (permanent)' confirms the intended “permanent” disconnection scenario. The test logic is consistent with the stated PR objective to force close the existing channel before reconnecting.


11287-11290: Validate code consistency across all test cases.

This assertion again checks for code: 3050 and reason: 'done (permanent)', ensuring standard behavior in multiple scenarios. Consistency across tests helps avoid regressions and keeps expectations unified.


11319-11319:

✅ Verification successful

Confirm that passing undefined to disconnectLLM is intended.

This test verifies a case where no disconnection parameters are specified. Confirm that this scenario is strategically valid and does not conflict with the permanent disconnection approach in other tests.

Run the following script to search for all test references to disconnectLLM to ensure consistent usage patterns:


🏁 Script executed:

#!/bin/bash
# Description: Locate all test references to `disconnectLLM` and compare arguments.

rg -A 4 "disconnectLLM"

Length of output: 73274


Confirmation of Undefined Disconnection Behavior
I verified that the test case passing undefined to disconnectLLM intentionally simulates the scenario where no disconnection parameters are provided. In the test file, other cases explicitly pass an object (e.g., with { code: 3050, reason: 'done (permanent)' }), while this case ensures that the absence of disconnection parameters is handled appropriately without interfering with the permanent disconnection behavior in different scenarios. This usage aligns with the overall test patterns.

@aws-amplify-us-east-2
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4150.d3m3l2kee0btzx.amplifyapp.com

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

🧹 Nitpick comments (1)
packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (1)

138-142: Add test for disconnectLLM without options parameter.

The PR adds support for an options parameter to disconnectLLM, but it's important to test that the method still works correctly when called without parameters to maintain backward compatibility.

Consider adding a test case:

it('should handle disconnect call without options parameter', async () => {
  // Set the properties to test clearing
  llmService.locusUrl = 'someUrl';
  llmService.datachannelUrl = 'someUrl';
  llmService.binding = {};
  llmService.webSocketUrl = 'someUrl';

  await llmService.disconnectLLM();

  sinon.assert.calledOnce(llmService.disconnect);
  assert.equal(llmService.locusUrl, undefined);
  assert.equal(llmService.datachannelUrl, undefined);
  assert.equal(llmService.binding, undefined);
  assert.equal(llmService.webSocketUrl, undefined);
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b29ac1 and 0107c10.

📒 Files selected for processing (2)
  • packages/@webex/internal-plugin-llm/src/llm.ts (1 hunks)
  • packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@webex/internal-plugin-llm/src/llm.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Packages
  • GitHub Check: AWS Amplify Console Web Preview
🔇 Additional comments (1)
packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (1)

115-143: Improved test coverage for disconnectLLM method.

The new test suite effectively covers both the success path and error handling for the disconnectLLM method. This aligns with the PR objective of ensuring proper disconnection of the LLM data channel before establishing a new connection.

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

♻️ Duplicate comments (3)
packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (3)

136-144: 🛠️ Refactor suggestion

Missing specific parameter testing per PR objective

According to the PR objective, a specific disconnect code of 3050 and reason "done (permanent)" should be used. The test should verify these specific parameters.

Update the test to verify the specific parameters:

   it('should call disconnect and clear relevant properties', async () => {
-    await instance.disconnectLLM({});
+    const disconnectOptions = { code: 3050, reason: 'done (permanent)' };
+    await instance.disconnectLLM(disconnectOptions);
 
-    expect(instance.disconnect).toHaveBeenCalledWith({});
+    expect(instance.disconnect).toHaveBeenCalledWith(disconnectOptions);
     expect(instance.locusUrl).toBeUndefined();
     expect(instance.datachannelUrl).toBeUndefined();
     expect(instance.binding).toBeUndefined();
     expect(instance.webSocketUrl).toBeUndefined();
   });

115-151: 🛠️ Refactor suggestion

Test suite uses inconsistent testing frameworks

This test suite uses Jest testing methods (jest.fn(), mockRejectedValue, expect()) while the rest of the file uses Sinon for stubbing and Chai for assertions.

Update the test to use a consistent testing approach with the rest of the file:

 describe('disconnectLLM', () => {
   let instance;

   beforeEach(() => {
     instance = {
-      disconnect: jest.fn(() => Promise.resolve()),
+      disconnect: sinon.stub().resolves(),
       locusUrl: 'someUrl',
       datachannelUrl: 'someUrl',
       binding: {},
       webSocketUrl: 'someUrl',
       disconnectLLM: function (options) {
         return this.disconnect(options).then(() => {
           this.locusUrl = undefined;
           this.datachannelUrl = undefined;
           this.binding = undefined;
           this.webSocketUrl = undefined;
         });
       }
     };
   });

   it('should call disconnect and clear relevant properties', async () => {
     await instance.disconnectLLM({});

-    expect(instance.disconnect).toHaveBeenCalledWith({});
-    expect(instance.locusUrl).toBeUndefined();
-    expect(instance.datachannelUrl).toBeUndefined();
-    expect(instance.binding).toBeUndefined();
-    expect(instance.webSocketUrl).toBeUndefined();
+    sinon.assert.calledOnceWithExactly(instance.disconnect, {});
+    assert.equal(instance.locusUrl, undefined);
+    assert.equal(instance.datachannelUrl, undefined);
+    assert.equal(instance.binding, undefined);
+    assert.equal(instance.webSocketUrl, undefined);
   });

   it('should handle errors from disconnect gracefully', async () => {
-    instance.disconnect.mockRejectedValue(new Error('Disconnect failed'));
-
-    await expect(instance.disconnectLLM({})).rejects.toThrow('Disconnect failed');
+    instance.disconnect.rejects(new Error('Disconnect failed'));
+
+    try {
+      await instance.disconnectLLM({});
+      assert.fail('Should have thrown an error');
+    } catch (error) {
+      assert.equal(error.message, 'Disconnect failed');
+    }
   });
 });

119-133: 🛠️ Refactor suggestion

Test uses a mock implementation instead of the actual LLMService

This test creates a separate mock implementation of disconnectLLM instead of testing the actual implementation in llmService. This approach tests the mock rather than the real implementation.

Update the test to use the actual llmService instance that's already created in the outer beforeEach block:

 describe('disconnectLLM', () => {
-  let instance;
-
   beforeEach(() => {
-    instance = {
-      disconnect: jest.fn(() => Promise.resolve()),
-      locusUrl: 'someUrl',
-      datachannelUrl: 'someUrl',
-      binding: {},
-      webSocketUrl: 'someUrl',
-      disconnectLLM: function (options) {
-        return this.disconnect(options).then(() => {
-          this.locusUrl = undefined;
-          this.datachannelUrl = undefined;
-          this.binding = undefined;
-          this.webSocketUrl = undefined;
-        });
-      }
-    };
+    // The disconnect method is already stubbed in the outer beforeEach
   });

   it('should call disconnect and clear relevant properties', async () => {
-    await instance.disconnectLLM({});
+    // Set properties to test clearing
+    llmService.locusUrl = 'someUrl';
+    llmService.datachannelUrl = 'someUrl';
+    llmService.binding = {};
+    llmService.webSocketUrl = 'someUrl';
+    
+    await llmService.disconnectLLM({});
🧹 Nitpick comments (1)
packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (1)

125-132: Implement explicit error handling in disconnectLLM

The current implementation of disconnectLLM doesn't explicitly handle errors from the disconnect call. While errors will still propagate, it would be better to have explicit error handling.

Add explicit error handling to the disconnectLLM implementation:

   disconnectLLM: function (options) {
-    return this.disconnect(options).then(() => {
-      this.locusUrl = undefined;
-      this.datachannelUrl = undefined;
-      this.binding = undefined;
-      this.webSocketUrl = undefined;
-    });
+    return this.disconnect(options)
+      .then(() => {
+        this.locusUrl = undefined;
+        this.datachannelUrl = undefined;
+        this.binding = undefined;
+        this.webSocketUrl = undefined;
+      })
+      .catch((error) => {
+        // Log error or perform additional error handling if needed
+        throw error;
+      });
   }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed832a and 9a3facc.

📒 Files selected for processing (2)
  • packages/@webex/internal-plugin-llm/src/llm.ts (1 hunks)
  • packages/@webex/internal-plugin-llm/test/unit/spec/llm.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@webex/internal-plugin-llm/src/llm.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Determine Changed Packages
  • GitHub Check: AWS Amplify Console Web Preview


/**
* Disconnects websocket connection
* @param {object} options
Copy link
Collaborator

Choose a reason for hiding this comment

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

update the param with individual sub objects

Copy link
Collaborator

Choose a reason for hiding this comment

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

i also dont see isJoined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update the param with individual sub objects

updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i also dont see isJoined

isJoined is not a part of the options object

@arun3528 arun3528 changed the title Feat/Practice Session - force close mercury before reconnect a new data channel feat(llm): force close mercury before reconnect a new data channel Mar 17, 2025
@JudyZhuHz JudyZhuHz merged commit 511eda1 into webex:next Mar 18, 2025
13 checks passed
@mickelr mickelr deleted the feat/forceCloseMercury branch March 18, 2025 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

validated If the pull request is validated for automation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants