Skip to content

test(desktop): pin profile-owned remote WebSocket target - #1

Merged
Tigrannnnnnn merged 2 commits into
Tigrannnnnnn:fix/per-profile-remote-ws-routingfrom
cmoiccool:pr-85750-remote-ws-target
Aug 14, 2026
Merged

Tigrannnnnnn merged 2 commits into
Tigrannnnnnn:fix/per-profile-remote-ws-routingfrom
cmoiccool:pr-85750-remote-ws-target

Conversation

@cmoiccool

@cmoiccool cmoiccool commented Aug 14, 2026 •

Copy link
Copy Markdown

What does this PR do?

Strengthens the regression coverage in NousResearch#85750 for profile-owned remote backends.

The existing test proves that a profile-owned descriptor does not reuse the primary gateway. This follow-up additionally verifies that the profile's exact remote wsUrl is passed to HermesGateway.connect().

This is a test-only change. It does not modify the production fix.

Related work

Changes made

  • Capture calls to the mocked HermesGateway.connect().
  • Model a profile-owned remote connection carrying profile but not sharedPrimary.
  • Assert that its exact dedicated remote wsUrl is dialed.
  • Assert that the primary gateway is not selected.

The fixture uses the reserved .invalid domain and synthetic credentials; the gateway client is mocked and no network request is made.

How to test

RED on affected main at c896c09c42:

Test Files  1 failed
Tests       1 failed | 1 passed
Expected connect() once; received 0 calls

GREEN on the NousResearch#85750 head at e74ea76700:

cd apps/desktop
npm test -- --run \
  src/store/gateway-shared-remote.test.ts \
  src/store/profile.test.ts
Test Files  2 passed
Tests       13 passed

Additional verification:

Full Desktop Vitest suite: 511 files passed, 1 skipped; 4,880 tests passed, 2 skipped
TypeScript typecheck: passed
ESLint: 0 errors (88 existing warnings)
git diff --check: passed

Type of change

  • Tests (strengthening regression coverage)
  • Production behavior change

Checklist

  • Read the contributing guide
  • Searched existing issues and PRs
  • Contains only the test strengthening requested on Fix/per profile remote ws routing NousResearch/hermes-agent#85750
  • Demonstrated RED on the affected implementation and GREEN on the proposed fix
  • Ran focused and complete Desktop test suites
  • Ran typecheck, lint, and diff validation

Summary by Sourcery

Strengthen desktop gateway regression coverage for profile-owned remote WebSocket connections.

Tests:

  • Add a hoisted HermesGateway connect mock to capture WebSocket dial attempts.
  • Update the shared-remote profile test to model a fully specified remote descriptor and assert that HermesGateway.connect is called with the profile’s exact wsUrl and does not reuse the primary gateway.

Copilot AI lite review requested due to automatic review settings August 14, 2026 14:41
@sourcery-ai

sourcery-ai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR strengthens regression coverage for profile-owned remote backends by mocking HermesGateway.connect in a shared place and asserting that ensureGatewayForProfile passes the exact profile-owned remote WebSocket URL to the gateway while not reusing the primary gateway.

Sequence diagram for profile-owned remote WebSocket connection in tests

sequenceDiagram
  actor Tester
  participant setPrimaryGateway
  participant installDesktop
  participant ensureGatewayForProfile
  participant getConnection
  participant HermesGateway
  participant $gateway

  Tester->>setPrimaryGateway: setPrimaryGateway(primary, default)
  Tester->>installDesktop: installDesktop({ getConnection })

  Tester->>ensureGatewayForProfile: ensureGatewayForProfile(worker)
  ensureGatewayForProfile->>getConnection: getConnection()
  getConnection-->>ensureGatewayForProfile: descriptor(wsUrl)

  ensureGatewayForProfile->>HermesGateway: connect(wsUrl)

  ensureGatewayForProfile->>$gateway: $gateway.get()
  $gateway-->>Tester: gatewayInstance
  alt [primary not reused]
    Tester->>Tester: expect(gatewayInstance).not.toBe(primary)
    Tester->>Tester: expect(gatewayMocks.connect).toHaveBeenCalledWith(wsUrl)
  end
Loading

File-Level Changes

Change Details Files
Strengthen the gateway-shared-remote regression test to assert that a profile-owned remote backend dials its exact WebSocket URL via HermesGateway.connect and does not reuse the primary gateway.
  • Introduce a hoisted gatewayMocks object to capture calls to HermesGateway.connect across the test file.
  • Refactor the HermesGateway mock to delegate its connect method to gatewayMocks.connect instead of throwing.
  • Model a realistic profile-owned remote connection in installDesktop.getConnection, including authMode, baseUrl, mode, profile, token, and wsUrl fields.
  • Rename and rewrite the profile-owned descriptor test to assert HermesGateway.connect is called once with the exact wsUrl and that the resulting gateway instance differs from the primary.
apps/desktop/src/store/gateway-shared-remote.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Because gatewayMocks.connect is hoisted and shared across tests, consider explicitly resetting its call history in beforeEach/afterEach in this file to avoid cross-test coupling and make the expectations more robust.
  • The test hardcodes a specific wsUrl string; consider constructing the expected URL from the descriptor fields within the test so that the assertion remains stable if the URL-building logic changes (e.g., query params or path).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Because `gatewayMocks.connect` is hoisted and shared across tests, consider explicitly resetting its call history in `beforeEach`/`afterEach` in this file to avoid cross-test coupling and make the expectations more robust.
- The test hardcodes a specific `wsUrl` string; consider constructing the expected URL from the descriptor fields within the test so that the assertion remains stable if the URL-building logic changes (e.g., query params or path).

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown

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 strengthens Desktop regression coverage around ensureGatewayForProfile when profiles use profile-owned remote backends, verifying that the exact dedicated wsUrl is passed through to HermesGateway.connect() rather than reusing the primary gateway connection.

Changes:

  • Hoists and captures the HermesGateway.connect() mock so tests can assert dial attempts and arguments.
  • Updates the “profile-owned remote” test case to provide a fully-specified remote descriptor (including wsUrl) and asserts the exact URL is used.
  • Keeps the existing assertion that the primary gateway is not selected for profile-owned remote connections.
Suppressed comments (1)

apps/desktop/src/store/gateway-shared-remote.test.ts:72

  • If connect is restored to “throw by default” for stronger shared-primary coverage, this test needs to explicitly allow the expected dial so it doesn’t fail for the intended path.
    setPrimaryGateway(primary as never, 'default')
    installDesktop({
      getConnection: vi.fn(async () => ({
        authMode: 'token',

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/desktop/src/store/gateway-shared-remote.test.ts
@Tigrannnnnnn
Tigrannnnnnn merged commit 71bff94 into Tigrannnnnnn:fix/per-profile-remote-ws-routing Aug 14, 2026
1 check 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.

3 participants