Skip to content

Conversation

@mtmk
Copy link
Member

@mtmk mtmk commented Nov 4, 2025

This PR is a fix for the KV Mirror related features implemented in PR Added Domain support for stream mirroring and sourcing and KV full support for the same. #631

This pull request refactors how domain-to-external API conversion is handled for JetStream stream configurations and adds comprehensive tests to ensure correct behavior. The main change is the introduction of a shared method to adjust stream configurations for domain settings, ensuring consistent and correct conversion of Domain fields to the External.Api property for both mirrors and sources across all stream-related operations. Additionally, new tests verify that this conversion is performed as expected.

Core refactoring and consistency improvements:

  • Introduced a new private static method AdjustStreamConfigForDomain in NatsJSContext.Streams.cs to handle conversion of Domain fields to External.Api for both mirrors and sources, replacing duplicated logic in CreateStreamAsync, UpdateStreamAsync, and CreateOrUpdateStreamAsync. All three methods now call this helper for consistent behavior. [1] [2] [3] [4]
  • Updated the ConvertDomain method to throw an exception if both Domain and an existing External.Deliver are set, ensuring correct configuration and preventing invalid states.

Testing improvements:

  • Added a new test class StreamDomainAdjustmentTest that verifies domain-to-external API conversion for stream creation, update, and create-or-update operations, both with and without domains set on sources. These tests check both the outgoing payload and the returned configuration, ensuring the conversion is performed and that the Domain property is not serialized in the payload.

  • fixes Updating a stream with external sources doesn't set the external JS API string as expected #994

mtmk added 3 commits November 4, 2025 12:30
Includes tests to verify domain is properly converted to `external.api` in stream configurations during create, update, and createOrUpdate operations. Adjusted validation in `NatsJSContext` to handle domain and external conflicts.
Copy link
Contributor

Copilot AI left a comment

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 refactors domain-to-external-API conversion logic for JetStream stream operations and adjusts validation to allow Domain and External.Api to coexist.

  • Extracted duplicate domain conversion logic into a shared AdjustStreamConfigForDomain method
  • Modified validation to only throw when both Domain and External.Deliver are set (not just External)
  • Added comprehensive tests verifying domain conversion for all stream operation methods

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/NATS.Client.JetStream/NatsJSContext.Streams.cs Refactored domain conversion logic from three methods into a single shared method
src/NATS.Client.JetStream/NatsJSContext.cs Updated validation logic to allow Domain with External.Api (only blocks External.Deliver)
tests/NATS.Client.JetStream.Tests/StreamDomainAdjustmentTest.cs Added test coverage for domain-to-external-API conversion in all stream operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mtmk mtmk self-assigned this Nov 5, 2025
@mtmk mtmk added the bug fix label Nov 5, 2025
Copy link
Contributor

@scottf scottf left a comment

Choose a reason for hiding this comment

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

LGTM

@mtmk mtmk merged commit 62abb69 into main Nov 26, 2025
24 of 25 checks passed
@mtmk mtmk deleted the fix-js-src-domain-adjustment-on-update branch November 26, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Updating a stream with external sources doesn't set the external JS API string as expected

3 participants